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()));
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations