LoadContext<E> createLoadContext() { LoadContext<E> loadContext = LoadContext.create(loader.entityClass).setId(id); loader.initCommonLoadContextParameters(loadContext); return loadContext; }
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)); }
protected LoadContext getLoadContextForForEntityLoadInfo(MetaClass metaClass, Object entityId) { LoadContext loadContext = LoadContext.create(metaClass.getJavaClass()); loadContext .setId(entityId); return loadContext; }
protected LoadContext getLoadContextForForEntityLoadInfo(MetaClass metaClass, Object entityId) { LoadContext loadContext = LoadContext.create(metaClass.getJavaClass()); loadContext .setId(entityId); return loadContext; }
@Override protected byte[] getContent(Object paramValue) { try { DataManager dataManager = AppBeans.get(DataManager.class); FileStorageAPI fileStorageAPI = AppBeans.get(FileStorageAPI.class); FileDescriptor file; if (paramValue instanceof FileDescriptor) { file = dataManager.load(new LoadContext<>(FileDescriptor.class).setId(((FileDescriptor) paramValue).getId())); } else { file = dataManager.load(new LoadContext<>(FileDescriptor.class).setId(UuidProvider.fromString(paramValue.toString()))); } byte[] bytes = fileStorageAPI.loadFile(file); return bytes; } catch (FileStorageException e) { throw new ReportFormattingException(String.format("Unable to get image from file storage. File id [%s]", paramValue), e); } } }
@Override public Object build(String string) { if (StringUtils.isBlank(string)) return null; EntityLoadInfo info = EntityLoadInfo.parse(string); if (info == null) throw new IllegalArgumentException("Invalid entity info: " + string); LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) ctx.setView(info.getViewName()); return ds.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 void changeGroupParent(UUID groupId, UUID newParentId) { checkUpdatePermission(Group.class); DataManager dataManager = this.dataManager.secure(); Group group = dataManager.load(LoadContext.create(Group.class) .setId(groupId) .setView(GROUP_COPY_VIEW)); LoadContext<Group> context = LoadContext.create(Group.class) .setId(newParentId) .setView(GROUP_COPY_VIEW); Group newParent = newParentId != null ? dataManager.load(context) : null; if (group != null) { group.setParent(newParent); } dataManager.commit(group); }
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 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<>()); } } } }
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 Object loadEntity(String id) { Metadata metadata = AppBeans.get(Metadata.class); MetaProperty pkProp = metadata.getTools().getPrimaryKeyProperty(metadata.getClassNN(javaClass)); Object objectId = null; if (pkProp != null) { Datatype<Object> datatype = pkProp.getRange().asDatatype(); try { objectId = datatype.parse(id); } catch (ParseException e) { throw new RuntimeException("Error parsing entity ID", e); } } LoadContext ctx = new LoadContext(javaClass).setId(objectId); DataService dataService = AppBeans.get(DataService.NAME); return dataService.load(ctx); }
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); }
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; }
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 Entity loadEntityInstance(EntityLoadInfo info) { Metadata metadata = AppBeans.get(Metadata.class); if (info.isNewEntity()) { return metadata.create(info.getMetaClass()); } LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId()); if (info.getViewName() != null) ctx.setView(info.getViewName()); Entity entity; try { DataManager dataManager = AppBeans.get(DataManager.class); entity = dataManager.load(ctx); } catch (Exception e) { throw new BpmException("Unable to load item: " + info, e); } return entity; } }