protected void repairReferences(CommitContext context) { for (Entity entity : context.getCommitInstances()) { for (Entity otherEntity : context.getCommitInstances()) { if (!entity.equals(otherEntity)) { repairReferences(otherEntity, entity); } } } }
@Override public Set<Entity> commit(CommitContext context) { Set<Entity> set = new HashSet<>(); set.addAll(context.getCommitInstances()); set.addAll(context.getRemoveInstances()); return set; }
protected void initParentDsContextCommitListener() { getDsContext().addBeforeCommitListener(context -> { List<FileDescriptor> fileDescriptorsToCommit = new ArrayList<>(); Collection<Entity> commitInstances = context.getCommitInstances(); for (Entity commitInstance : commitInstances) { if (commitInstance instanceof ProcAttachment && PersistenceHelper.isNew(commitInstance)) { ProcAttachment procAttachment = (ProcAttachment) commitInstance; fileDescriptorsToCommit.add(procAttachment.getFile()); } } if (!fileDescriptorsToCommit.isEmpty()) { commitInstances.addAll(fileDescriptorsToCommit); context.setCommitInstances(commitInstances); } }); }
@Override public EntitySet commit(CommitContext context) { Set<Entity> result = new HashSet<>(); ReportService reportService = AppBeans.get(ReportService.NAME, ReportService.class); Report reportToStore = null; for (Entity entity : context.getCommitInstances()) { if (entity instanceof Report) { reportToStore = (Report) entity; } else if (entity instanceof ReportTemplate) { reportToStore = ((ReportTemplate) entity).getReport(); } } if (reportToStore != null) { result.add(reportService.storeReportEntity(reportToStore)); } return EntitySet.of(result); } }
protected Entity findReferenceEntity(Entity entity, EntityImportViewProperty viewProperty, CommitContext commitContext, Set<Entity> loadedEntities) { Entity result = Stream.concat(loadedEntities.stream(), commitContext.getCommitInstances().stream()) .filter(item -> item.equals(entity)) .findFirst().orElse(null); if (result == null) { LoadContext<? extends Entity> ctx = LoadContext.create(entity.getClass()) .setSoftDeletion(false) .setView(View.MINIMAL) .setId(entity.getId()); result = dataManager.load(ctx); if (result == null) { if (viewProperty.getReferenceImportBehaviour() == ReferenceImportBehaviour.ERROR_ON_MISSING) { throw new EntityImportException(String.format("Referenced entity for property '%s' with id = %s is missing", viewProperty.getName(), entity.getId())); } } else { loadedEntities.add(result); } } return result; }
protected void addCommitListeners() { String xml = reportService.convertToString(getItem()); getItem().setXml(xml); reportDs.getDsContext().addBeforeCommitListener(context -> { context.getCommitInstances() .removeIf(entity -> !(entity instanceof Report || entity instanceof ReportTemplate) ); }); }
Map<String, CommitContext> storeToContextMap = new TreeMap<>(); Set<Entity> toRepeat = new HashSet<>(); for (Entity entity : context.getCommitInstances()) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); String storeName = getStoreName(metaClass); boolean repeatRequired = writeCrossDataStoreReferences(entity, context.getCommitInstances()); if (repeatRequired) { toRepeat.add(entity); storeToContextMap.put(storeName, cc); cc.getCommitInstances().add(entity); View view = context.getViews().get(entity); if (view != null)
protected void checkPermissions(CommitContext context) { if (!isAuthorizationRequired(context)) return; Set<MetaClass> checkedCreateRights = new HashSet<>(); Set<MetaClass> checkedUpdateRights = new HashSet<>(); Set<MetaClass> checkedDeleteRights = new HashSet<>(); for (Entity entity : context.getCommitInstances()) { if (entity == null) continue; if (entityStates.isNew(entity)) { checkPermission(checkedCreateRights, entity.getMetaClass(), EntityOp.CREATE); } else { checkPermission(checkedUpdateRights, entity.getMetaClass(), EntityOp.UPDATE); } } for (Entity entity : context.getRemoveInstances()) { if (entity == null) continue; checkPermission(checkedDeleteRights, entity.getMetaClass(), EntityOp.DELETE); } }
protected CommitContext createCommitContext(DataSupplier dataservice, Map<DataSupplier, Collection<Datasource<Entity>>> commitData) { CommitContext context = new CommitContext(); context.setDiscardCommitted(discardCommitted); for (Datasource<Entity> datasource : commitData.get(dataservice)) { if (datasource instanceof DatasourceImplementation) { DatasourceImplementation<Entity> implementation = (DatasourceImplementation) datasource; boolean listenersEnabled = implementation.enableListeners(false); try { for (Entity entity : implementation.getItemsToCreate()) { addToContext(entity, datasource, context.getCommitInstances(), context.getViews()); } for (Entity entity : implementation.getItemsToUpdate()) { addToContext(entity, datasource, context.getCommitInstances(), context.getViews()); } for (Entity entity : implementation.getItemsToDelete()) { addToContext(entity, datasource, context.getRemoveInstances(), context.getViews()); } } finally { implementation.enableListeners(listenersEnabled); } } } repairReferences(context); return context; }
for (Entity commitInstance : commitContext.getCommitInstances()) { if (!PersistenceHelper.isNew(commitInstance)) { if (commitInstance instanceof SoftDelete && ((SoftDelete) commitInstance).isDeleted()) { for (Entity entity : commitContext.getCommitInstances()) { Set<ConstraintViolation<Entity>> violations = validator.validate(entity, Default.class, RestApiChecks.class); if (!violations.isEmpty()) {
public Set<Entity> commit(CommitContext context) { if (log.isDebugEnabled()) log.debug("commit: commitInstances=" + context.getCommitInstances() + ", removeInstances=" + context.getRemoveInstances()); for (Entity entity : context.getCommitInstances()) { if (entityStates.isNew(entity)) { if (isAuthorizationRequired(context)) { for (Entity entity : context.getCommitInstances()) { if (!entityStates.isNew(entity)) { if (isAuthorizationRequired(context)) {
for (Entity entity : commitContext.getCommitInstances()) { MetaClass metaClass = metadata.getSession().getClassNN(entity.getClass()); for (MetaProperty property : metaClass.getProperties()) { Entity e = getEntityById(commitContext.getCommitInstances(), refEntity.getId()); ((AbstractInstance) entity).setValue(property.getName(), e, false); } else if (BaseGenericIdEntity.class.isAssignableFrom(refEntity.getMetaClass().getJavaClass())) {