Search in sources :

Example 1 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class DynAttrManagerImpl method fetchEntityValues.

/**
 * Method loads entity values for CategoryAttributeValues of entity type and sets entity values to the corresponding
 * property of the {@code CategoryAttributeValue} entity.
 */
@SuppressWarnings("unchecked")
protected void fetchEntityValues(Collection<AccessConstraint<?>> accessConstraints, List<CategoryAttributeValue> values) {
    Multimap<MetaClass, Object> entityIds = HashMultimap.create();
    Multimap<MetaClass, CategoryAttributeValue> valuesByType = HashMultimap.create();
    for (CategoryAttributeValue value : values) {
        String className = value.getCategoryAttribute().getEntityClass();
        try {
            Class<?> aClass = ReflectionHelper.loadClass(className);
            MetaClass metaClass = metadata.getClass(aClass);
            CrudEntityContext crudEntityContext = new CrudEntityContext(metaClass);
            accessManager.applyConstraints(crudEntityContext, accessConstraints);
            if (crudEntityContext.isReadPermitted()) {
                entityIds.put(metaClass, value.getObjectEntityValueId());
                valuesByType.put(metaClass, value);
            }
        } catch (ClassNotFoundException e) {
            log.error("Class {} not found", className);
        }
    }
    EntityManager entityManager = storeAwareLocator.getEntityManager(dynamicAttributesStore);
    for (Map.Entry<MetaClass, Collection<Object>> entry : entityIds.asMap().entrySet()) {
        MetaClass metaClass = entry.getKey();
        Collection<Object> ids = entry.getValue();
        if (!ids.isEmpty()) {
            String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass);
            List<?> resultList = entityManager.createQuery(String.format("select e from %s e where e.%s in :ids", metaClass.getName(), pkName)).setParameter("ids", ids).setHint(PersistenceHints.FETCH_PLAN, fetchPlanRepository.getFetchPlan(metaClass, FetchPlan.INSTANCE_NAME)).getResultList();
            Map<Object, Object> entityById = new LinkedHashMap<>();
            for (Object entity : resultList) {
                entityById.put(EntityValues.getId(entity), entity);
            }
            for (CategoryAttributeValue value : valuesByType.get(metaClass)) {
                value.setTransientEntityValue(entityById.get(value.getObjectEntityValueId()));
            }
        }
    }
}
Also used : CategoryAttributeValue(io.jmix.dynattr.model.CategoryAttributeValue) EntityManager(javax.persistence.EntityManager) MetaClass(io.jmix.core.metamodel.model.MetaClass) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 2 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class AttributeEnumerationScreen method initLocalizationFragment.

protected void initLocalizationFragment() {
    if (coreProperties.getAvailableLocales().size() > 1) {
        localizationBox.setVisible(true);
        CrudEntityContext crudEntityContext = new CrudEntityContext(localizedEnumValuesDc.getEntityMetaClass());
        accessManager.applyRegisteredConstraints(crudEntityContext);
        localizationFragment = fragments.create(this, AttributeLocalizationFragment.class);
        localizationFragment.setEnabled(crudEntityContext.isUpdatePermitted());
        Fragment fragment = localizationFragment.getFragment();
        fragment.setWidth(Component.FULL_SIZE);
        fragment.setHeight(Component.FULL_SIZE);
        fragment.setEnabled(false);
        localizationBox.add(fragment);
        localizationBox.expand(fragment);
    }
}
Also used : AttributeLocalizationFragment(io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) AttributeLocalizationFragment(io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment)

Example 3 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class CategoryAttrsEdit method initLocalizationTab.

protected void initLocalizationTab() {
    if (coreProperties.getAvailableLocales().size() > 1) {
        TabSheet.Tab localizationTab = tabSheet.getTab("localizationTab");
        localizationTab.setVisible(true);
        CrudEntityContext crudEntityContext = new CrudEntityContext(configurationDc.getEntityMetaClass());
        accessManager.applyRegisteredConstraints(crudEntityContext);
        VBoxLayout localizationTabComponent = (VBoxLayout) tabSheet.getTabComponent("localizationTab");
        localizationFragment = fragments.create(this, AttributeLocalizationFragment.class);
        localizationFragment.setNameMsgBundle(getEditedEntity().getNameMsgBundle());
        localizationFragment.setDescriptionMsgBundle(getEditedEntity().getDescriptionsMsgBundle());
        localizationFragment.setEnabled(crudEntityContext.isUpdatePermitted());
        Fragment fragment = localizationFragment.getFragment();
        fragment.setWidth(Component.FULL_SIZE);
        fragment.setHeight("250px");
        localizationTabComponent.add(fragment);
    }
}
Also used : AttributeLocalizationFragment(io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) AttributeLocalizationFragment(io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment)

Example 4 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class CategoryAttrsEdit method initDependsOnAttributesField.

@SuppressWarnings("unchecked")
protected void initDependsOnAttributesField() {
    ValuesSelectAction<CategoryAttribute> selectAction = (ValuesSelectAction<CategoryAttribute>) dependsOnAttributesField.getActionNN("select");
    selectAction.setOptions(new ListEntityOptions<>(getAttributesOptions(), metadata));
    if (getEditedEntity().getConfiguration() != null && getEditedEntity().getConfiguration().getDependsOnAttributeCodes() != null) {
        dependsOnAttributesField.setValue(getAttributesOptions().stream().filter(o -> getEditedEntity().getConfiguration().getDependsOnAttributeCodes().contains(o.getCode())).collect(Collectors.toList()));
    }
    CrudEntityContext crudEntityContext = new CrudEntityContext(configurationDc.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(crudEntityContext);
    if (!crudEntityContext.isUpdatePermitted()) {
        dependsOnAttributesField.setEnabled(false);
        dependsOnAttributesFieldClear.setEnabled(false);
        dependsOnAttributesFieldSelect.setEnabled(false);
    }
}
Also used : ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) CategoryAttribute(io.jmix.dynattr.model.CategoryAttribute) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 5 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class CategoryAttrsEdit method setupFieldsLock.

protected void setupFieldsLock() {
    CrudEntityContext crudEntityContext = new CrudEntityContext(configurationDc.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(crudEntityContext);
    if (!crudEntityContext.isUpdatePermitted()) {
        defaultEntityIdField.setEnabled(false);
        editEnumerationBtn.setEnabled(false);
    }
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Aggregations

CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)26 MetaClass (io.jmix.core.metamodel.model.MetaClass)9 EntityAttributeContext (io.jmix.core.accesscontext.EntityAttributeContext)4 AttributeLocalizationFragment (io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment)4 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)3 ArrayList (java.util.ArrayList)3 CategoryAttrsFragment (io.jmix.dynattrui.screen.categoryattr.CategoryAttrsFragment)2 AttributeLocationFragment (io.jmix.dynattrui.screen.location.AttributeLocationFragment)2 UiSetting (io.jmix.uidata.entity.UiSetting)2 UiTablePresentation (io.jmix.uidata.entity.UiTablePresentation)2 UUID (java.util.UUID)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 AccessManager (io.jmix.core.AccessManager)1 Metadata (io.jmix.core.Metadata)1