public void validateAdditionalRules(ValidationErrors errors) { // all previous validations return no errors if (crossFieldValidate && errors.isEmpty()) { BeanValidation beanValidation = getBeanLocator().get(BeanValidation.NAME); Validator validator = beanValidation.getValidator(); Set<ConstraintViolation<Entity>> violations = validator.validate(getItem(), UiCrossFieldChecks.class); violations.stream() .filter(violation -> { Path propertyPath = violation.getPropertyPath(); Path.Node lastNode = Iterables.getLast(propertyPath); return lastNode.getKind() == ElementKind.BEAN; }) .forEach(violation -> errors.add(violation.getMessage())); } }
protected MetaClass getMetaClassForLocking(Datasource ds) { Metadata metadata = getBeanLocator().get(Metadata.NAME); // lock original metaClass, if any, because by convention all the configuration is based on original entities MetaClass metaClass = metadata.getExtendedEntities().getOriginalMetaClass(ds.getMetaClass()); if (metaClass == null) { metaClass = ds.getMetaClass(); } return metaClass; }
public void releaseLock() { if (justLocked) { Datasource ds = getDatasourceInternal(); Entity entity = ds.getItem(); if (entity != null) { getBeanLocator().get(LockService.class).unlock(getMetaClassForLocking(ds).getName(), entity.getId().toString()); } } }
/** * This method is required for multi-level composition, when a user deletes records from nested editors, saves them * and then reopens. When an editor is opened, we reload the item from the database, hence we need to remove * nested items previously deleted by the user. */ protected void handlePreviouslyDeletedCompositionItems(Entity entity, DatasourceImplementation parentDs) { Metadata metadata = getBeanLocator().get(Metadata.NAME); for (MetaProperty property : metadata.getClassNN(entity.getClass()).getProperties()) { if (!PersistenceHelper.isLoaded(entity, property.getName())) return; if (property.getType() == MetaProperty.Type.COMPOSITION) { for (Datasource datasource : parentDs.getDsContext().getAll()) { if (datasource instanceof NestedDatasource && ((NestedDatasource) datasource).getMaster().equals(parentDs)) { Object value = entity.getValue(property.getName()); if (value instanceof Collection) { Collection collection = (Collection) value; //noinspection unchecked collection.removeAll(((DatasourceImplementation) datasource).getItemsToDelete()); } } } } } }
/** * Hook to be implemented in subclasses. Called by the framework after committing datasources. * The default implementation notifies about commit and calls {@link #postInit()} if the window is not closing. * * @param committed whether any data were actually changed and committed * @param close whether the window is going to be closed * @return true to continue, false to abort */ protected boolean postCommit(boolean committed, boolean close) { if (committed && !close) { if (showSaveNotification) { Entity entity = getItem(); MetadataTools metadataTools = getBeanLocator().get(MetadataTools.class); showNotification( messages.formatMainMessage("info.EntitySave", messages.getTools().getEntityCaption(entity.getMetaClass()), metadataTools.getInstanceName(entity)), NotificationType.TRAY); } postInit(); afterWindowApplyPostInit(); } return true; }
DynamicAttributesGuiTools dynamicAttributesGuiTools = getBeanLocator().get(DynamicAttributesGuiTools.NAME); if (dynamicAttributesGuiTools.screenContainsDynamicAttributes(ds.getView(), getFrame().getId())) { ds.setLoadDynamicAttributes(true); Object entityId = item.getId(); EntityStates entityStates = getBeanLocator().get(EntityStates.class); && !ds.getMetaClass().equals(item.getMetaClass())) { Entity newItem = ds.getDataSupplier().newInstance(ds.getMetaClass()); MetadataTools metadataTools = getBeanLocator().get(MetadataTools.NAME); metadataTools.copy(item, newItem); item = newItem; Security security = getBeanLocator().get(Security.NAME); if (!PersistenceHelper.isNew(item) && security.isEntityOpPermitted(ds.getMetaClass(), EntityOp.UPDATE)) { readOnly = false; LockService lockService = getBeanLocator().get(LockService.NAME); }); } else if (!(lockInfo instanceof LockNotSupported)) { UserSessionSource userSessionSource = getBeanLocator().get(UserSessionSource.NAME);
ComponentsHelper.findComponent(getFrame(), WINDOW_COMMIT_AND_CLOSE); Configuration configuration = getBeanLocator().get(Configuration.NAME);