@Override protected void prepareLoadContext(LoadContext context) { context.setLoadDynamicAttributes(loadDynamicAttributes); context.setQueryKey(queryKey == null ? 0 : queryKey); context.getPrevQueries().addAll(prevQueries); }
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); }
/** * 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; }
throw new RestAPIException("Error on executing the query", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e); ctx.setLoadDynamicAttributes(BooleanUtils.isTrue(dynamicAttributes));
ctx.setLoadDynamicAttributes(BooleanUtils.isTrue(dynamicAttributes));
@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; }
public String loadEntity(String entityName, String entityId, @Nullable String viewName, @Nullable Boolean returnNulls, @Nullable Boolean dynamicAttributes, @Nullable String modelVersion) { entityName = restControllerUtils.transformEntityNameIfRequired(entityName, modelVersion, JsonTransformationDirection.FROM_VERSION); MetaClass metaClass = restControllerUtils.getMetaClass(entityName); checkCanReadEntity(metaClass); LoadContext<Entity> ctx = new LoadContext<>(metaClass); Object id = getIdFromString(entityId, metaClass); ctx.setId(id); if (!Strings.isNullOrEmpty(viewName)) { View view = restControllerUtils.getView(metaClass, viewName); ctx.setView(view); } ctx.setLoadDynamicAttributes(BooleanUtils.isTrue(dynamicAttributes)); Entity entity = dataManager.load(ctx); checkEntityIsNotNull(entityName, entityId, entity); List<EntitySerializationOption> serializationOptions = new ArrayList<>(); serializationOptions.add(EntitySerializationOption.SERIALIZE_INSTANCE_NAME); if (BooleanUtils.isTrue(returnNulls)) serializationOptions.add(EntitySerializationOption.SERIALIZE_NULLS); restControllerUtils.applyAttributesSecurity(entity); String json = entitySerializationAPI.toJson(entity, ctx.getView(), serializationOptions.toArray(new EntitySerializationOption[0])); json = restControllerUtils.transformJsonIfRequired(entityName, modelVersion, JsonTransformationDirection.TO_VERSION, json); return json; }
protected List<Entity> loadItemsWithDirectKey(LoadDescriptor ld) { LoadContext.Query query = new LoadContext.Query( String.format("select e from %s e where e.%s in :ids", ld.getMetaClass(), metadataTools.getPrimaryKeyName(ld.getMetaClass()))); List<Object> ids = ld.getSelectedItems().stream() .map(Entity::getId) .collect(Collectors.toList()); query.setParameter("ids", ids); LoadContext<Entity> lc = new LoadContext<>(ld.getMetaClass()); lc.setSoftDeletion(false); lc.setQuery(query); lc.setView(ld.getView()); lc.setLoadDynamicAttributes(ld.isLoadDynamicAttributes()); return dataManager.secure().loadList(lc); } }
/** * Loads single item by id. * * @param meta item's meta class * @param id item's id * @param view view * @return loaded item if found, null otherwise */ protected Entity loadSingleItem(MetaClass meta, Object id, View view) { String primaryKeyName = metadata.getTools().getPrimaryKeyName(meta); if (primaryKeyName == null) { throw new IllegalStateException(String.format("Entity %s has no primary key", meta.getName())); } LoadContext ctx = new LoadContext(meta); ctx.setLoadDynamicAttributes(true); ctx.setSoftDeletion(false); ctx.setView(view); String query = String.format("select e from %s e where e.%s = :id", meta.getName(), primaryKeyName); LoadContext.Query q = ctx.setQueryString(query); q.setParameter("id", id); return dataSupplier.load(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"; } }
public static void fetchDynamicAttributes(Entity entity){ if (entity instanceof BaseGenericIdEntity) { LoadContext<BaseGenericIdEntity> loadContext = new LoadContext<>(entity.getMetaClass()); loadContext.setId(entity.getId()).setLoadDynamicAttributes(true); DataService dataService = AppBeans.get(DataService.NAME, DataService.class); BaseGenericIdEntity reloaded = dataService.load(loadContext); if (reloaded != null) { ((BaseGenericIdEntity) entity).setDynamicAttributes(reloaded.getDynamicAttributes()); } else { ((BaseGenericIdEntity) entity).setDynamicAttributes(new HashMap<>()); } } } }
protected void fetchDynamicAttributes(Entity entity) { if (entity instanceof BaseGenericIdEntity) { LoadContext<BaseGenericIdEntity> loadContext = new LoadContext<>(entity.getMetaClass()); loadContext.setId(entity.getId()).setLoadDynamicAttributes(true); DataService dataService = AppBeans.get(DataService.NAME, DataService.class); BaseGenericIdEntity reloaded = dataService.load(loadContext); if (reloaded != null) { ((BaseGenericIdEntity) entity).setDynamicAttributes(reloaded.getDynamicAttributes()); } else { ((BaseGenericIdEntity) entity).setDynamicAttributes(new HashMap<>()); } } } }
loadCtx.setLoadDynamicAttributes(Boolean.TRUE.equals(dynamicAttributes)); loadCtx.setId(objectId); if (loadInfo.getViewName() != null) {
/** * 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); }
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; }
loadCtx.setLoadDynamicAttributes(Boolean.TRUE.equals(queryRequest.loadDynamicAttributes())); LoadContext.Query query = new LoadContext.Query(queryRequest.getQuery());
.setSoftDeletion(false) .setView(regularView) .setLoadDynamicAttributes(true) .setId(srcEntity.getId()) .setAuthorizationRequired(true);
@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; }
/** * Reload dynamic attributes on the entity */ @SuppressWarnings("unchecked") public void reloadDynamicAttributes(BaseGenericIdEntity entity) { MetaClass metaClass = entity.getMetaClass(); View view = new View(metaClass.getJavaClass(), false) .addProperty(metadata.getTools().getPrimaryKeyName(metaClass)); LoadContext loadContext = new LoadContext(metaClass) .setView(view) .setLoadDynamicAttributes(true) .setId(entity.getId()); BaseGenericIdEntity reloadedEntity = (BaseGenericIdEntity) dataManager.load(loadContext); if (reloadedEntity != null) { entity.setDynamicAttributes(reloadedEntity.getDynamicAttributes()); } } }