/** * Factory method to create a LoadContext instance. * * @param entityClass class of the loaded entities */ public static <E extends Entity> LoadContext<E> create(Class<E> entityClass) { return new LoadContext<>(entityClass); }
protected FileDescriptor getFileDescriptor(HttpServletRequest request, HttpServletResponse response) throws IOException { UUID fileId; try { fileId = UUID.fromString(request.getParameter("f")); } catch (Exception e) { log.error("Error parsing fileId from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } FileDescriptor fileDescriptor = dataService.load(new LoadContext<>(FileDescriptor.class).setId(fileId)); if (fileDescriptor == null) response.sendError(HttpServletResponse.SC_NOT_FOUND); return fileDescriptor; }
@Nullable protected AbstractSearchFolder loadFolder(UUID folderId) { return dataService.load(new LoadContext<>(AppFolder.class).setId(folderId)); }
@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 User loadUser(UUID userId) { LoadContext<User> loadContext = new LoadContext<>(User.class); LoadContext.Query query = new LoadContext.Query("select u from sec$User u where u.id = :userId"); query.setParameter("userId", userId); loadContext.setQuery(query); List<User> users = dataService.loadList(loadContext); return users.isEmpty() ? null : users.get(0); }
/** * 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<ProcDefinition> getProcDefinitionsByName(String name) { LoadContext ctx = new LoadContext(ProcDefinition.class); ctx.setQuery(new LoadContext.Query("select pd from bpm$ProcDefinition pd where pd.name = :name") .setParameter("name", name)); return dataManager.loadList(ctx); }
/** * 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); } }
@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 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); }
@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); } }
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 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 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<>()); } } } }
public void deleteEntity(String entityName, String entityId, String modelVersion) { entityName = restControllerUtils.transformEntityNameIfRequired(entityName, modelVersion, JsonTransformationDirection.FROM_VERSION); MetaClass metaClass = restControllerUtils.getMetaClass(entityName); checkCanDeleteEntity(metaClass); Object id = getIdFromString(entityId, metaClass); Entity entity = dataManager.load(new LoadContext<>(metaClass).setId(id)); checkEntityIsNotNull(entityName, entityId, entity); dataManager.remove(entity); }
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; }