@Override public MetaClass resolveCategorizedEntityClass() { if (categorizedEntityClass == null) { return mainDs.getMetaClass(); } else { return categorizedEntityClass; } }
@Override public MetaClass getEntityMetaClass() { return datasource.getMetaClass(); }
protected MetaClass resolveMetaClass(Datasource datasource) { return datasource instanceof RuntimePropsDatasource ? ((RuntimePropsDatasource) datasource).resolveCategorizedEntityClass() : datasource.getMetaClass(); } }
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; }
@Override public void setup(String id, Datasource masterDs, String property) { this.id = id; this.masterDs = masterDs; metaProperty = masterDs.getMetaClass().getProperty(property); initParentDsListeners(); }
@Override public void setup(String id, Datasource masterDs, String property) { this.id = id; this.masterDs = masterDs; metaProperty = masterDs.getMetaClass().getProperty(property); initParentDsListeners(); }
@Override protected void loadEditable(Component component, Element element) { FieldGroup fieldGroup = (FieldGroup) component; if (fieldGroup.getDatasource() != null) { MetaClass metaClass = fieldGroup.getDatasource().getMetaClass(); boolean editableByPermission = (getSecurity().isEntityOpPermitted(metaClass, EntityOp.CREATE) || getSecurity().isEntityOpPermitted(metaClass, EntityOp.UPDATE)); if (!editableByPermission) { fieldGroup.setEditable(false); return; } } String editable = element.attributeValue("editable"); if (StringUtils.isNotEmpty(editable)) { fieldGroup.setEditable(Boolean.parseBoolean(editable)); } }
protected MetaProperty getInverseProperty() { MetaPropertyPath mpp = getMaster().getMetaClass().getPropertyPath(metaPropertyPath.toPathString()); if (mpp == null) { return null; } return mpp.getMetaProperty().getInverse(); }
protected void checkPermission() { Security security = AppBeans.get(Security.NAME); MetaClass parentMetaClass = masterDs.getMetaClass(); if (!security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY)) { throw new AccessDeniedException(PermissionType.ENTITY_ATTR, parentMetaClass + "." + metaProperty.getName()); } }
@Override protected boolean checkRemovePermission() { CollectionDatasource ds = target.getDatasource(); if (ds instanceof PropertyDatasource) { PropertyDatasource propertyDatasource = (PropertyDatasource) ds; MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass(); MetaProperty metaProperty = propertyDatasource.getProperty(); boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY); if (!attrPermitted) { return false; } } return true; }
protected MetaClass getMetaClass(FieldGroup resultComponent, FieldGroup.FieldConfig field) { if (field.isCustom()) { return null; } Datasource datasource; if (field.getDatasource() != null) { datasource = field.getDatasource(); } else if (resultComponent.getDatasource() != null) { datasource = resultComponent.getDatasource(); } else { throw new GuiDevelopmentException(String.format("Unable to get datasource for field '%s'", field.getId()), context.getFullFrameId()); } return datasource.getMetaClass(); }
protected Collection<T> getCollection() { Security security = AppBeans.get(Security.NAME); MetaClass parentMetaClass = masterDs.getMetaClass(); MetaClass propertyMetaClass = metaProperty.getRange().asClass(); if (!security.isEntityOpPermitted(propertyMetaClass, EntityOp.READ) || !security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.VIEW)) { return new ArrayList<>(); // Don't use Collections.emptyList() to avoid confusing UnsupportedOperationExceptions } else { final Instance master = masterDs.getItem(); //noinspection unchecked return master == null ? null : (Collection<T>) master.getValue(metaProperty.getName()); } }
@Override public void setItem(Entity item) { Entity newItem = valuesFormatsDs.getDataSupplier().newInstance(valuesFormatsDs.getMetaClass()); metadata.getTools().copy(item, newItem); ((ReportValueFormat) newItem).setId((UUID) item.getId()); super.setItem(newItem); } }
public RuntimePropsDatasourceImpl(DsContext dsContext, DataSupplier dataSupplier, String id, String mainDsId, @Nullable MetaClass categorizedEntityClass) { this.categorizedEntityClass = categorizedEntityClass; this.id = id; this.dsContext = dsContext; this.dataSupplier = dataSupplier; this.dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.NAME); this.metaClass = new DynamicAttributesMetaClass(); this.setMainDs(mainDsId); this.setCommitMode(CommitMode.DATASTORE); this.attributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributesForMetaClass(resolveCategorizedEntityClass()); for (CategoryAttribute attribute : attributes) { MetaProperty metaProperty = DynamicAttributesUtils.getMetaPropertyPath(mainDs.getMetaClass(), attribute).getMetaProperty(); this.metaClass.addProperty(metaProperty, attribute); } }
@Override protected boolean isPermitted() { if (target == null || target.getDatasource() == null) { return false; } CollectionDatasource ownerDs = target.getDatasource(); if (ownerDs instanceof PropertyDatasource) { PropertyDatasource datasource = (PropertyDatasource) ownerDs; MetaClass parentMetaClass = datasource.getMaster().getMetaClass(); MetaProperty metaProperty = datasource.getProperty(); boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY); if (!attrPermitted) { return false; } } return super.isPermitted(); }
@Override public void setBeanLocator(BeanLocator beanLocator) { MetaClass metaClass = datasource.getMetaClass(); MetadataTools metadataTools = beanLocator.get(MetadataTools.NAME); MetaPropertyPath metaPropertyPath = metadataTools.resolveMetaPropertyPath(metaClass, property); checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", property, metaClass); this.metaPropertyPath = metaPropertyPath; this.datasource.addStateChangeListener(this::datasourceStateChanged); this.datasource.addItemChangeListener(this::datasourceItemChanged); this.datasource.addItemPropertyChangeListener(this::datasourceItemPropertyChanged); if (datasource.getState() == Datasource.State.VALID) { setState(BindingState.ACTIVE); } }
private void initPropertyDatasourceAttributes(Element element, Datasource ds, String property) { String id = getDatasourceId(element); MetaClass metaClass = ds.getMetaClass(); metaClass.getPropertyNN(property); // check property existence builder.reset() .setMetaClass(metaClass) .setId(id) .setMaster(ds) .setProperty(property) .setAllowCommit(getAllowCommit(element)); }
protected String getDefaultCaption(FieldGroup.FieldConfig fieldConfig, Datasource fieldDatasource) { String caption = fieldConfig.getCaption(); if (caption == null) { String propertyId = fieldConfig.getProperty(); MetaPropertyPath propertyPath = fieldDatasource != null ? fieldDatasource.getMetaClass().getPropertyPath(propertyId) : null; if (propertyPath != null) { MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(propertyPath); String propertyName = propertyPath.getMetaProperty().getName(); caption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName); } } return caption; }
protected void applyPermissions(Component fieldComponent) { if (fieldComponent instanceof DatasourceComponent) { DatasourceComponent dsComponent = (DatasourceComponent) fieldComponent; MetaPropertyPath propertyPath = dsComponent.getMetaPropertyPath(); Datasource datasource = dsComponent.getDatasource(); if (datasource != null && propertyPath != null) { MetaClass metaClass = datasource.getMetaClass(); Security security = getSecurity(); if (!security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString()) && dsComponent instanceof Component.Editable) { ((Component.Editable) dsComponent).setEditable(false); } if (!security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) { dsComponent.setVisible(false); } } } }
@Override public void setItem(Entity item) { ReportInputParameter newParameter = (ReportInputParameter) metadata.create(parameterDs.getMetaClass()); metadata.getTools().copy(item, newParameter); newParameter.setId((UUID) item.getId()); if (newParameter.getParameterClass() == null) { newParameter.setParameterClass(parameterClassResolver.resolveClass(newParameter)); } super.setItem(newParameter); enableControlsByParamType(newParameter.getType()); initScreensLookup(); initTransformations(); }