protected Object getValueId(Object value) { if (value instanceof EmbeddableEntity) { return null; } else if (value instanceof BaseGenericIdEntity) { return referenceToEntitySupport.getReferenceId((Entity) value); } else { return null; } }
@Nullable protected Entity findEntity(String entityName, Object entityId) { Entity entity = null; if (entityId != null && !Strings.isNullOrEmpty(entityName)) { MetaClass metaClass = metadata.getClass(entityName); if (metaClass != null) { LoadContext ctx = new LoadContext(metaClass).setQuery( LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", entityName, referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass))) .setParameter("entityId", entityId)) .setView(View.MINIMAL); entity = dataManager.load(ctx); } } return entity; }
if (HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) { query = em.createQuery(format("select cav from sys$CategoryAttributeValue cav where cav.entity.%s in :ids and cav.parent is null", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), CategoryAttributeValue.class); } else { query = em.createQuery(format("select cav from sys$CategoryAttributeValue cav where cav.entity.%s in :ids " + "and cav.categoryAttribute.categoryEntityType = :entityType and cav.parent is null", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), CategoryAttributeValue.class); query.setParameter("entityType", metaClass.getName());
@Override public EntitySnapshot getLastEntitySnapshot(Entity entity) { checkCompositePrimaryKey(entity); MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(entity.getMetaClass()); View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse"); LoadContext<EntitySnapshot> lx = LoadContext.create(EntitySnapshot.class).setQuery(LoadContext .createQuery(format("select e from sys$EntitySnapshot e where e.entityMetaClass = :metaClass and" + " e.entity.%s = :entityId order by e.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass))) .setParameter("metaClass", metaClass.getName()) .setParameter("entityId", referenceToEntitySupport.getReferenceId(entity)) .setMaxResults(1)) .setView(view); return dataManager.load(lx); }
@Override public List<EntitySnapshot> getSnapshots(MetaClass metaClass, Object id) { metaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass); Entity entity = dataManager.load(new LoadContext<>(metaClass).setId(id).setView(View.LOCAL)); checkCompositePrimaryKey(entity); List<EntitySnapshot> resultList = null; View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse"); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); TypedQuery<EntitySnapshot> query = em.createQuery(format( "select s from sys$EntitySnapshot s where s.entity.%s = :entityId and s.entityMetaClass = :metaClass " + "order by s.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), EntitySnapshot.class); query.setParameter("entityId", referenceToEntitySupport.getReferenceId(entity)); query.setParameter("metaClass", metaClass.getName()); query.setView(view); resultList = query.getResultList(); tx.commit(); } finally { tx.end(); } return resultList; }
public void search() { int maxRows; try { maxRows = Integer.parseInt(showRowField.getValue().toString()); if (maxRows >= 0) entityLogDs.setMaxResults(maxRows); else throw new NumberFormatException(); } catch (Exception e) { showNotification(messages.getMessage(getClass(), "invalidNumber"), NotificationType.HUMANIZED); return; } Entity entity = instancePicker.getValue(); Map<String, Object> params = new HashMap<>(); if (entity != null) { Object entityId = referenceToEntitySupport.getReferenceId(entity); if (entityId instanceof UUID) { params.put("entityId", entityId); } else if (entityId instanceof String) { params.put("stringEntityId", entityId); } else if (entityId instanceof Integer) { params.put("intEntityId", entityId); } else if (entityId instanceof Long) { params.put("longEntityId", entityId); } } entityLogDs.refresh(params); }
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)
@Override public EntitySnapshot getLastEntitySnapshot(MetaClass metaClass, Object referenceId) { if (referenceId instanceof Entity) { throw new IllegalArgumentException(format("Reference id can not be an entity: %s", referenceId.getClass())); } MetaClass originalMetaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass); View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse"); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); TypedQuery<EntitySnapshot> query = em.createQuery( format("select e from sys$EntitySnapshot e where e.entityMetaClass = :metaClass and" + " e.entity.%s = :entityId order by e.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(originalMetaClass)), EntitySnapshot.class) .setParameter("metaClass", originalMetaClass.getName()) .setParameter("entityId", referenceId) .setMaxResults(1) .setView(view); return query.getFirstResult(); } finally { tx.close(); } }
.map(e -> referenceToEntitySupport.getReferenceId(e)) .collect(Collectors.toList()); Collection<CategoryAttributeValue> entityAttributeValues = allAttributeValues.get(referenceToEntitySupport.getReferenceId(entity)); Map<String, CategoryAttributeValue> map = new HashMap<>(); entity.setDynamicAttributes(map);
@SuppressWarnings("unchecked") protected void fillDefaultEntities(Class entityClass) { MetaClass metaClass = metadata.getClassNN(entityClass); if (attribute.getObjectDefaultEntityId() != null) { LoadContext<Entity> lc = new LoadContext<>(entityClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", metaClass.getName(), pkName)) .setParameter("entityId", attribute.getObjectDefaultEntityId()); Entity entity = dataManager.load(lc); if (entity != null) { defaultEntityField.setValue(entity); } else { defaultEntityField.setValue(null); } } }
paramName = paramBuilder.createParamName(condition); String cavEntityId = referenceToEntitySupport.getReferenceIdPropertyName(condition.getEntityMetaClass()); String valueFieldName = "stringValue"; if (Entity.class.isAssignableFrom(javaClass)) valueFieldName = "entityValue." + referenceToEntitySupport.getReferenceIdPropertyName(metadata.getClassNN(javaClass)) ; else if (String.class.isAssignableFrom(javaClass)) valueFieldName = "stringValue";
@SuppressWarnings("unchecked") protected boolean calculateFilteredData(Entity entity, Set<EntityId> handled, boolean checkPermitted) { if (referenceToEntitySupport.getReferenceId(entity) == null) { return false; return true; EntityId entityId = new EntityId(referenceToEntitySupport.getReferenceId(entity), metaClass.getName()); if (handled.contains(entityId)) { return false; for (Entity item : (Collection<Entity>) value) { if (calculateFilteredData(item, handled, true)) { filtered.add(referenceToEntitySupport.getReferenceId(item)); if (calculateFilteredData(valueEntity, handled, true)) { securityTokenManager.addFiltered(baseGenericIdEntity, property.getName(), referenceToEntitySupport.getReferenceId(valueEntity));
LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", metaClass.getName(), referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass))) .setParameter("entityId", entityId)); Entity entity = dataManager.load(ctx);
@SuppressWarnings("unchecked") protected void applyConstraints(Entity entity, Set<EntityId> handled) { MetaClass metaClass = entity.getMetaClass(); EntityId entityId = new EntityId(referenceToEntitySupport.getReferenceId(entity), metaClass.getName()); if (handled.contains(entityId)) { return; Entity item = iterator.next(); if (filteredData != null && filteredData.containsEntry(property.getName(), referenceToEntitySupport.getReferenceId(item))) { iterator.remove(); } else { referenceToEntitySupport.getReferenceId((Entity) value))) { baseGenericIdEntity.setValue(property.getName(), null); } else {
MetaClass entityMetaClass = metadata.getClassNN(categoryAttribute.getJavaClassForEntity()); LoadContext<Entity> lc = new LoadContext<>(entityMetaClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(entityMetaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", entityMetaClass.getName(), pkName)) .setParameter("entityId", categoryAttribute.getDefaultValue());
/** * @see Initializer#init(String, Entity) */ protected void init(String procCode, Entity entity) { ProcDefinition procDefinition = bpmEntitiesService.findProcDefinitionByCode(procCode, BpmConstants.Views.PROC_DEFINITION_WITH_ROLES); if (procDefinition == null) { log.debug("Process definition with code '{}' not found", procCode); return; } List<ProcInstance> procInstances = bpmEntitiesService.findActiveProcInstancesForEntity(procDefinition.getCode(), entity, BpmConstants.Views.PROC_INSTANCE_FULL); procInstance = procInstances.isEmpty() ? null : procInstances.get(0); if (procInstance == null) { procInstance = metadata.create(ProcInstance.class); procInstance.setProcDefinition(procDefinition); procInstance.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity)); procInstance.setEntityName(entity.getMetaClass().getName()); } init(procInstance); }
CollectionCompare.with() .onCreate(e -> { if (!dstFilteredIds.contains(referenceToEntitySupport.getReferenceId(e))) { Entity result = importEntity(e, null, viewProperty.getView(), regularView, commitContext, referenceInfoList, optimisticLocking); if (!dstFilteredIds.contains(referenceToEntitySupport.getReferenceId(src))) { Entity result = importEntity(src, dst, viewProperty.getView(), regularView, commitContext, referenceInfoList, optimisticLocking); if (!dstFilteredIds.contains(referenceToEntitySupport.getReferenceId(e))) { if (srcFilteredIds.contains(referenceToEntitySupport.getReferenceId(e))) { newCollectionValue.add(e); } else if (viewProperty.getCollectionImportPolicy() == CollectionImportPolicy.KEEP_ABSENT_ITEMS) {
} else if (value instanceof BaseGenericIdEntity) { ReferenceToEntitySupport referenceToEntitySupport = AppBeans.get(ReferenceToEntitySupport.class); Object referenceId = referenceToEntitySupport.getReferenceId((BaseGenericIdEntity) value); entityValue.setObjectEntityId(referenceId); setTransientEntityValue((BaseGenericIdEntity) value);
protected EntitySnapshot createEntitySnapshot(Entity entity, View view, Date snapshotDate, User author) { Preconditions.checkNotNullArgument(entity); Preconditions.checkNotNullArgument(view); Preconditions.checkNotNullArgument(snapshotDate); checkCompositePrimaryKey(entity); Class viewEntityClass = view.getEntityClass(); Class entityClass = entity.getClass(); if (!viewEntityClass.isAssignableFrom(entityClass)) { throw new IllegalStateException("View could not be used with this propertyValue"); } MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(metadata.getClass(entity.getClass())); EntitySnapshot snapshot = metadata.create(EntitySnapshot.class); snapshot.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity)); snapshot.setEntityMetaClass(metaClass.getName()); snapshot.setViewXml(viewSerializationAPI.toJson(view, ViewSerializationOption.COMPACT_FORMAT)); snapshot.setSnapshotXml(entitySerializationAPI.toJson(entity)); snapshot.setSnapshotDate(snapshotDate); snapshot.setAuthor(author); return snapshot; } }
item.setType(type); item.setEntity(metadata.getExtendedEntities().getOriginalOrThisMetaClass(metaClass).getName()); item.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity)); item.setAttributes(entityLogAttrs);