private void initCommonLoadContextParameters(LoadContext<E> loadContext) { loadContext.setJoinTransaction(transactional); if (view != null) loadContext.setView(view); else if (!Strings.isNullOrEmpty(viewName)) loadContext.setView(viewName); loadContext.setSoftDeletion(softDeletion); loadContext.setLoadDynamicAttributes(dynamicAttributes); }
@SuppressWarnings("unchecked") @Override public List<JmxInstance> getInstances() { LoadContext loadContext = new LoadContext(JmxInstance.class); loadContext.setView(View.LOCAL); loadContext.setQueryString("select jmx from sys$JmxInstance jmx"); List<JmxInstance> clusterInstances = dataService.loadList(loadContext); List<JmxInstance> jmxInstances = new ArrayList<>(clusterInstances.size() + 1); jmxInstances.add(getLocalInstance()); jmxInstances.addAll(clusterInstances); return jmxInstances; }
protected void initUserGroup(User user) { LoadContext<Group> ctx = new LoadContext<>(Group.class); ctx.setQueryString("select g from sec$Group g"); ctx.setView(View.MINIMAL); List<Group> groups = dataSupplier.loadList(ctx); if (groups.size() == 1) { user.setGroup(groups.get(0)); } }
protected Collection<? extends Entity> reloadEntities(Collection<? extends Entity> entities, View view) { List<Object> ids = entities.stream() .map(Entity::getId) .collect(Collectors.toList()); MetaClass metaClass = metadata.getClassNN(view.getEntityClass()); LoadContext.Query query = LoadContext.createQuery("select e from " + metaClass.getName() + " e where e.id in :ids") .setParameter("ids", ids); LoadContext<? extends Entity> ctx = LoadContext.create(view.getEntityClass()) .setQuery(query) .setView(view); return dataManager.loadList(ctx); }
/** * Return list of reports, available for user * * @param user - caller user */ public List<BIReport> getAvailableReports(@Nullable User user) { LoadContext<BIReport> ctx = new LoadContext<>(BIReport.class); ctx.setLoadDynamicAttributes(false); ctx.setView("biReport-edit-view"); ctx.setQueryString("select r from cubabi$BIReport r"); List<BIReport> reports = dataManager.loadList(ctx); reports = applySecurityPolicies(user, reports); return reports; }
protected List<com.haulmont.cuba.core.entity.Config> loadDbContent() { LoadContext<com.haulmont.cuba.core.entity.Config> loadContext = LoadContext.create(com.haulmont.cuba.core.entity.Config.class).setQuery( LoadContext.createQuery("select c from sys$Config c") ).setView("appProperties"); return dataManager.loadList(loadContext); }
private List<Tenant> createOptionList() { return dataManager.loadList(LoadContext.create(Tenant.class) .setQuery(LoadContext.createQuery("select e from cubasdbmt$Tenant e")) .setView("tenant-with-group")); }
/** * For entities with composite keys there will be a value of the 'uuid' property in the {@code entityId} parameter. */ protected Entity reloadEntity(MetaClass metaClass, Object entityId) { String ftsPrimaryKeyName = ftsService.getPrimaryKeyPropertyForFts(metaClass).getName(); String queryStr = String.format("select e from %s e where e.%s = :id", metaClass.getName(), ftsPrimaryKeyName); LoadContext lc = new LoadContext(metaClass) .setView(View.MINIMAL) .setQuery(LoadContext.createQuery(queryStr).setParameter("id", entityId)); List list = getDsContext().getDataSupplier().loadList(lc); return list.isEmpty() ? null : (Entity) list.get(0); } }
@Nullable protected ProcModel findModelByName(String modelName) { View view = new View(ProcModel.class) .addProperty("name") .addProperty("actModelId"); LoadContext<ProcModel> ctx = LoadContext.create(ProcModel.class).setView(view); ctx.setQueryString("select m from bpm$ProcModel m where m.name = :name") .setParameter("name", modelName); return dataManager.load(ctx); }
@Override public <E extends Entity> E reload(E entity, View view, @Nullable MetaClass metaClass, boolean loadDynamicAttributes) { if (metaClass == null) { metaClass = metadata.getSession().getClass(entity.getClass()); } LoadContext<E> context = new LoadContext<>(metaClass); context.setId(entity.getId()); context.setView(view); context.setLoadDynamicAttributes(loadDynamicAttributes); E reloaded = load(context); if (reloaded == null) throw new EntityAccessException(metaClass, entity.getId()); return reloaded; }
@Override public <E extends Entity> E reload(E entity, View view, @Nullable MetaClass metaClass, boolean loadDynamicAttributes) { if (metaClass == null) { metaClass = metadata.getSession().getClass(entity.getClass()); } LoadContext<E> context = new LoadContext<>(metaClass); context.setId(entity.getId()); context.setView(view); context.setLoadDynamicAttributes(loadDynamicAttributes); E reloaded = load(context); if (reloaded == null) throw new EntityAccessException(metaClass, entity.getId()); return reloaded; }
protected Entity loadEntity(EntityParameterValue parameter) { Class entityClass = metadata.getClass(parameter.getMetaClassName()).getJavaClass(); LoadContext loadContext = LoadContext.create(entityClass) .setId(java.util.UUID.fromString(parameter.getEntityId())) .setView(parameter.getViewName()); return dataManager.load(loadContext); }
@Override public List<UserSubstitution> getSubstitutedUsers(UUID userId) { LoadContext<UserSubstitution> ctx = new LoadContext<>(UserSubstitution.class); LoadContext.Query query = ctx.setQueryString("select us from sec$UserSubstitution us " + "where us.user.id = :userId and (us.endDate is null or us.endDate >= :currentDate) " + "and (us.startDate is null or us.startDate <= :currentDate) " + "and (us.substitutedUser.active = true or us.substitutedUser.active is null) order by us.substitutedUser.name"); query.setParameter("userId", userId); query.setParameter("currentDate", timeSource.currentTimestamp()); ctx.setView("app"); return dataManager.loadList(ctx); } }
@Override public List<SessionLogEntry> getAllSessionLogRecords(UUID userSessionId) { return authentication.withSystemUser(() -> { LoadContext<SessionLogEntry> loadContext = LoadContext.create(SessionLogEntry.class) .setView(SessionLogEntry.DEFAULT_VIEW) .setQuery( createQuery("select e from sec$SessionLogEntry e where e.sessionId = :sid order by e.startedTs asc") .setParameter("sid", userSessionId) ); return dataManager.loadList(loadContext); }); }
/** * Load filter entities from database and saves them in {@code filterEntities} collection. */ protected void loadFilterEntities() { LoadContext<FilterEntity> ctx = LoadContext.create(FilterEntity.class); ctx.setView("app"); ctx.setQueryString("select f from sec$Filter f left join f.user u " + "where f.componentId = :component and (u.id = :userId or u is null) order by f.name") .setParameter("component", ComponentsHelper.getFilterComponentPath(filter)) .setParameter("userId", userSessionSource.getUserSession().getCurrentOrSubstitutedUser().getId()); filterEntities = new ArrayList<>(dataService.loadList(ctx)); }
protected Entity loadEntityInstance(EntityLoadInfo info) { LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) { ctx.setView(info.getViewName()); } //noinspection unchecked return dataService.load(ctx); }
protected Dashboard loadDashboardByCode(String code) { LoadContext<PersistentDashboard> loadContext = LoadContext.create(PersistentDashboard.class) .setQuery(LoadContext.createQuery("select d from dashboard$PersistentDashboard d where d.code = :code") .setParameter("code", code)) .setView("_local"); PersistentDashboard entity = dataManager.load(loadContext); if (entity == null || entity.getDashboardModel() == null) { return null; } return jsonConverter.dashboardFromJson(entity.getDashboardModel()); }
protected Entity reloadInstance(Entity instance) { View reloadView = new View(instance.getMetaClass().getJavaClass(), true); LoadContext loadContext = new LoadContext(instance.getMetaClass()); loadContext.setSoftDeletion(false); loadContext.setId(instance.getId()); loadContext.setView(reloadView); DataSupplier supplier = getDataSupplier(); return supplier.load(loadContext); }
private void loadOne(EntityCrossDataStoreProperty entityCrossDataStoreProperty) { Entity entity = entityCrossDataStoreProperty.entity; CrossDataStoreProperty aProp = entityCrossDataStoreProperty.crossProp; Object id = entity.getValue(aProp.relatedPropertyName); LoadContext<Entity> loadContext = new LoadContext<>(aProp.property.getRange().asClass()); loadContext.setId(id); if (aProp.viewProperty.getView() != null) loadContext.setView(aProp.viewProperty.getView()); loadContext.setJoinTransaction(joinTransaction); Entity relatedEntity = dataManager.load(loadContext); entity.setValue(aProp.property.getName(), relatedEntity); }
protected Report loadReportInternal(String entityId) { checkCanReadEntity(metadata.getClassNN(Report.class)); LoadContext<Report> loadContext = new LoadContext<>(Report.class); loadContext.setView(ReportService.MAIN_VIEW_NAME) .setQueryString("select r from report$Report r where r.id = :id and r.restAccess = true") .setParameter("id", getReportIdFromString(entityId)); reportSecurityManager.applySecurityPolicies(loadContext, null, userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); Report report = dataManager.load(loadContext); checkEntityIsNotNull(metadata.getClassNN(Report.class).getName(), entityId, report); return report; }