use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class StandardCacheLoader method updateData.
@Override
public void updateData(CacheSet cacheSet, Map<String, Object> params) throws CacheException {
if (configuration.getConfig(GlobalConfig.class).getPerformanceTestMode())
return;
Collection<Object> items = cacheSet.getItems();
List updateItems = (List) params.get("items");
if ((updateItems != null) && (updateItems.size() > 0)) {
MetaClass metaClass = metadata.getSession().getClass(metaClassName);
View view = metadata.getViewRepository().getView(metaClass, viewName);
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
for (Object item : updateItems) {
Entity entity = (Entity) item;
entity = em.find(entity.getClass(), entity.getId(), view);
items.remove(item);
if (entity != null)
items.add(entity);
}
tx.commit();
} catch (Exception e) {
throw new CacheException(e);
} finally {
tx.end();
}
} else {
log.debug("Nothing to update");
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class DomainDescriptionServiceBean method getDomainDescription.
@Override
public String getDomainDescription() {
List<View> views = ((AbstractViewRepository) viewRepository).getAll();
List<MetaClassRepresentation> classes = new ArrayList<>();
List<TemplateHashModel> enums = new ArrayList<>();
Set<String> addedEnums = new HashSet<>();
Set<MetaClass> metas = new HashSet<>(metadataTools.getAllPersistentMetaClasses());
metas.addAll(metadataTools.getAllEmbeddableMetaClasses());
for (MetaClass meta : metas) {
if (metadata.getExtendedEntities().getExtendedClass(meta) != null)
continue;
if (!readPermitted(meta))
continue;
List<View> metaClassViews = new ArrayList<>();
for (View view : views) {
if (view.getEntityClass().equals(meta.getJavaClass())) {
metaClassViews.add(view);
}
}
MetaClassRepresentation rep = new MetaClassRepresentation(meta, metaClassViews);
classes.add(rep);
for (MetaClassRepresentation.MetaClassRepProperty metaProperty : rep.getProperties()) {
TemplateHashModel enumValues = metaProperty.getEnumValues();
if (enumValues != null) {
if (!addedEnums.contains(metaProperty.getJavaType())) {
addedEnums.add(metaProperty.getJavaType());
enums.add(enumValues);
}
}
}
}
Collections.sort(classes, new Comparator<MetaClassRepresentation>() {
@Override
public int compare(MetaClassRepresentation o1, MetaClassRepresentation o2) {
return o1.getName().compareTo(o2.getName());
}
});
Collections.sort(enums, new Comparator<TemplateHashModel>() {
@Override
public int compare(TemplateHashModel o1, TemplateHashModel o2) {
try {
return o1.get("name").toString().compareTo(o2.get("name").toString());
} catch (TemplateModelException e) {
return 0;
}
}
});
Map<String, Object> values = new HashMap<>();
values.put("knownEntities", classes);
String[] availableTypes = getAvailableBasicTypes();
values.put("availableTypes", availableTypes);
values.put("enums", enums);
String template = resources.getResourceAsString("/com/haulmont/cuba/core/app/domain/DomainDescription.ftl");
return TemplateHelper.processTemplate(template, values);
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class MetaClassRepresentation method viewAccessPermitted.
private static boolean viewAccessPermitted(View view) {
Class clazz = view.getEntityClass();
MetaClass meta = getMetaClass(clazz);
return MetaClassRepresentation.readPermitted(meta);
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class DynamicAttributesManager method loadEntityValues.
/**
* 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 loadEntityValues(List<CategoryAttributeValue> cavsOfEntityType) {
HashMultimap<MetaClass, Object> entitiesIdsToBeLoaded = HashMultimap.create();
HashMultimap<MetaClass, CategoryAttributeValue> cavByType = HashMultimap.create();
cavsOfEntityType.forEach(cav -> {
String className = cav.getCategoryAttribute().getEntityClass();
try {
Class<?> aClass = Class.forName(className);
MetaClass metaClass = metadata.getClass(aClass);
entitiesIdsToBeLoaded.put(metaClass, cav.getObjectEntityValueId());
cavByType.put(metaClass, cav);
} catch (ClassNotFoundException e) {
log.error("Class {} not found", className);
}
});
EntityManager em = persistence.getEntityManager();
for (Map.Entry<MetaClass, Collection<Object>> entry : entitiesIdsToBeLoaded.asMap().entrySet()) {
Map<Object, BaseGenericIdEntity> idToEntityMap = new HashMap<>();
MetaClass metaClass = entry.getKey();
Collection<Object> ids = entry.getValue();
if (!ids.isEmpty()) {
String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass);
List<BaseGenericIdEntity> entitiesValues = em.createQuery(format("select e from %s e where e.%s in :ids", metaClass.getName(), pkName)).setParameter("ids", ids).setView(metaClass.getJavaClass(), View.MINIMAL).getResultList();
for (BaseGenericIdEntity entity : entitiesValues) {
idToEntityMap.put(entity.getId(), entity);
}
}
for (CategoryAttributeValue cav : cavByType.get(metaClass)) {
cav.setTransientEntityValue(idToEntityMap.get(cav.getObjectEntityValueId()));
}
}
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class CategoryEditor method initEntityTypeField.
protected void initEntityTypeField() {
final ExtendedEntities extendedEntities = metadata.getExtendedEntities();
// the map sorts meta classes by the string key
Map<String, Object> options = new TreeMap<>();
for (MetaClass metaClass : metadata.getTools().getAllPersistentMetaClasses()) {
if (metadata.getTools().hasCompositePrimaryKey(metaClass) && !HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) {
continue;
}
options.put(messageTools.getDetailedEntityCaption(metaClass), metaClass);
}
entityType.setOptionsMap(options);
if (category.getEntityType() != null) {
entityType.setValue(extendedEntities.getEffectiveMetaClass(extendedEntities.getEffectiveClass(category.getEntityType())));
}
entityType.addValueChangeListener(e -> {
MetaClass metaClass = (MetaClass) e.getValue();
MetaClass originalClass = extendedEntities.getOriginalMetaClass(metaClass);
category.setEntityType(originalClass == null ? metaClass.getName() : originalClass.getName());
});
}
Aggregations