@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)); } }
@Nullable @Override public LocalizedConstraintMessage findLocalizedConstraintMessage(String entityName, ConstraintOperationType operationType) { Preconditions.checkNotNullArgument(entityName); Preconditions.checkNotNullArgument(operationType); LoadContext<LocalizedConstraintMessage> loadContext = new LoadContext<>(LocalizedConstraintMessage.class); loadContext.setQueryString("select e from sec$LocalizedConstraintMessage e " + "where e.entityName = :name and e.operationType = :type") .setParameter("name", entityName) .setParameter("type", operationType); List<LocalizedConstraintMessage> localizations = dataManager.loadList(loadContext); if (CollectionUtils.isEmpty(localizations)) { return null; } else if (localizations.size() == 1) { return localizations.get(0); } else { throw new IllegalStateException("Several entities with the same 'entity name/operation type' combination"); } } }
protected List<ProcDefinition> findProcDefinitionsByModel(ProcModel model) { LoadContext<ProcDefinition> ctx = LoadContext.create(ProcDefinition.class); ctx.setQueryString( "select pd from bpm$ProcDefinition pd " + "where pd.model.id = :modelId order by pd.name, pd.deploymentDate desc") .setParameter("modelId", model.getId()); return dataManager.loadList(ctx); }
protected List<Entity> getQueryResult(String query) { MetaClass metaClass = entitiesMetaClasses.getValue(); if (metaClass == null) { return null; } String view = entityViews.getValue(); LoadContext<Entity> loadContext = new LoadContext<>(metaClass); loadContext.setView(view); Integer limit = entityLimitField.getValue(); if (limit == null) { loadContext.setQueryString(query); } else { loadContext.setQueryString(query).setMaxResults(limit); } return dataManager.loadList(loadContext); }
/** * 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; }
@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); }
public String loadReportsList() { checkCanReadEntity(metadata.getClassNN(Report.class)); LoadContext<Report> loadContext = new LoadContext<>(Report.class); loadContext.setView( new View(Report.class) .addProperty("id") .addProperty("name") .addProperty("code")) .setQueryString("select r from report$Report r where r.restAccess = true"); reportSecurityManager.applySecurityPolicies(loadContext, null, userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); List<Report> reports = dataManager.loadList(loadContext); List<ReportInfo> objects = reports.stream() .map(this::mapToReportInfo) .collect(Collectors.toList()); return createGson().toJson(objects); }
protected void addDefaultRoles(User user) { LoadContext<Role> ctx = new LoadContext<>(Role.class); ctx.setQueryString("select r from sec$Role r where r.defaultRole = true"); List<Role> defaultRoles = dataSupplier.loadList(ctx); List<UserRole> newRoles = new ArrayList<>(); if (user.getUserRoles() != null) { newRoles.addAll(user.getUserRoles()); } MetaClass metaClass = rolesDs.getMetaClass(); for (Role role : defaultRoles) { UserRole userRole = dataSupplier.newInstance(metaClass); userRole.setRole(role); userRole.setUser(user); newRoles.add(userRole); } user.setUserRoles(newRoles); }
protected List<Entity> loadEntityList(String[] ids) { Metadata metadata = AppBeans.get(Metadata.class); MetaClass metaClass = metadata.getSession().getClassNN(javaClass); LoadContext ctx = new LoadContext(javaClass); LoadContext.Query query = ctx.setQueryString("select e from " + metaClass.getName() + " e where e.id in :ids"); query.setParameter("ids", Arrays.asList(ids)); DataManager dataManager = AppBeans.get(DataManager.class); return dataManager.loadList(ctx); }
private void checkLoad() { if (presentations == null) { DataService ds = AppBeans.get(DataService.NAME); LoadContext ctx = new LoadContext(Presentation.class); ctx.setView("app"); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); UserSession session = sessionSource.getUserSession(); User user = session.getCurrentOrSubstitutedUser(); ctx.setQueryString("select p from sec$Presentation p " + "where p.componentId = :component and (p.user is null or p.user.id = :userId)") .setParameter("component", name) .setParameter("userId", user.getId()); final List<Presentation> list = ds.loadList(ctx); presentations = new LinkedHashMap<>(list.size()); for (final Presentation p : list) { presentations.put(p.getId(), p); } } }
/** * 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)); }
@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); } }
@Authenticated public String updateSecurityIndex() { LoadContext<Report> ctx = new LoadContext<>(Report.class); ctx.setLoadDynamicAttributes(true); ctx.setView("report.edit"); ctx.setQueryString("select r from report$Report r"); List<Report> resultList = dataManager.loadList(ctx); for (Report report : resultList) { reportingApi.storeReportEntity(report); } return "Index migrated successfully"; } }
/** * Return list of reports, available for certain screen, user and input parameter * * @param screenId - id of the screen * @param user - caller user * @param inputValueMetaClass - meta class of report input parameter */ public List<Report> getAvailableReports(@Nullable String screenId, @Nullable User user, @Nullable MetaClass inputValueMetaClass) { LoadContext<Report> lc = new LoadContext<>(Report.class); lc.setLoadDynamicAttributes(true); lc.setView(new View(Report.class) .addProperty("name") .addProperty("localeNames") .addProperty("description") .addProperty("code") .addProperty("group", metadata.getViewRepository().getView(ReportGroup.class, View.LOCAL))); lc.setQueryString("select r from report$Report r where r.system <> true"); reportSecurityManager.applySecurityPolicies(lc, screenId, user); reportSecurityManager.applyPoliciesByEntityParameters(lc, inputValueMetaClass); return dataService.loadList(lc); }
@SuppressWarnings("unchecked") protected void fillDefaultEntities(Class entityClass) { MetaClass metaClass = metadata.getClassNN(entityClass); if (attribute.getObjectDefaultEntityId() != null) { LoadContext<Entity> lc = new LoadContext<>(entityClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", metaClass.getName(), pkName)) .setParameter("entityId", attribute.getObjectDefaultEntityId()); Entity entity = dataManager.load(lc); if (entity != null) { defaultEntityField.setValue(entity); } else { defaultEntityField.setValue(null); } } }
public LoadContext<E> createLoadContext() { LoadContext<E> loadContext = LoadContext.create(container.getEntityMetaClass().getJavaClass()); if (entityId != null) { loadContext.setId(entityId); } else { LoadContext.Query query = loadContext.setQueryString(this.query); query.setCondition(condition); query.setParameters(parameters); } loadContext.setView(resolveView()); loadContext.setSoftDeletion(softDeletion); loadContext.setLoadDynamicAttributes(loadDynamicAttributes); return loadContext; }
protected void initIsDefaultCheckbox() { isDefault.setValue(BooleanUtils.isTrue(category.getIsDefault())); isDefault.addValueChangeListener(e -> { if (Boolean.TRUE.equals(e.getValue())) { LoadContext<Category> lc = new LoadContext<>(Category.class) .setView("category.defaultEdit"); lc.setQueryString("select c from sys$Category c where c.entityType = :entityType and not c.id = :id") .setParameter("entityType", category.getEntityType()) .setParameter("id", category.getId()); List<Category> result = dataManager.loadList(lc); for (Category cat : result) { cat.setIsDefault(false); } CommitContext commitCtx = new CommitContext(result); dataManager.commit(commitCtx); category.setIsDefault(true); } else if (Boolean.FALSE.equals(e.getValue())) { category.setIsDefault(false); } }); }
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; }
@Override public LoadContext<E> createLoadContext() { LoadContext<E> loadContext = LoadContext.create(container.getEntityMetaClass().getJavaClass()); LoadContext.Query query = loadContext.setQueryString(this.query); query.setCondition(condition); query.setSort(sort); query.setParameters(parameters); query.setCacheable(cacheable); if (firstResult > 0) query.setFirstResult(firstResult); if (maxResults < Integer.MAX_VALUE) query.setMaxResults(maxResults); loadContext.setView(resolveView()); loadContext.setSoftDeletion(softDeletion); loadContext.setLoadDynamicAttributes(loadDynamicAttributes); return loadContext; }