/** * loads the properties from the database in a single query and returns them as a transfer object * * @param resourceId * - the resource id of the resource for which the properties should be loaded * @param type * - the resource type of the resource for which the properties should be loaded * @param currentContext * - the context for which the properties should be loaded * @return a list of containers which contain the required property information */ public List<ResourceEditProperty> loadPropertiesForEditResource(Integer resourceId, ResourceTypeEntity type, ContextEntity currentContext) { Map<Integer, ResourceEditProperty> propMap = new HashMap<>(); List<Integer> contextList = contextHierarchy.getContextWithParentIds(currentContext); List<Integer> typeList = getTypeWithParentIds(null, type); Query query = queries.getPropertyValueForResource(resourceId, typeList, contextList); List<ResourceEditProperty> result = JpaSqlResultMapper.list(query, ResourceEditProperty.class); for (ResourceEditProperty prop : result) { // Since we have to load also the properties of the parent contexts (to display the replaced // values) we must find the property of the current context and set parents hierarchical propMap.put(prop.getDescriptorId(), findChildPropAndSetParent(prop, propMap.get(prop.getDescriptorId()), contextList)); } return new ArrayList<>(new TreeSet<>(propMap.values())); }
public List<ResourceEditProperty> loadPropertiesForEditResourceTypeRelation(ResourceTypeEntity masterResourceType, ResourceTypeEntity slaveResourceType, ContextEntity currentContext) { Map<Integer, ResourceEditProperty> propMap = new HashMap<>(); List<Integer> contextList = contextHierarchy.getContextWithParentIds(currentContext); List<Integer> masterResourceTypeList = getTypeWithParentIds(null, masterResourceType); List<Integer> slaveResourceTypeList = getTypeWithParentIds(null, slaveResourceType); Query query = queries.getPropertyValueForResourceTypeRelationQuery(masterResourceTypeList, slaveResourceTypeList, contextList); List<ResourceEditProperty> result = JpaSqlResultMapper.list(query, ResourceEditProperty.class); for (ResourceEditProperty prop : result) { if(!slaveResourceType.getId().equals(prop.getPropertyValueTypeId()) || !masterResourceType.getId().equals(prop.getMasterTypeId())){ prop.setDefinedOnSuperResourceType(true); } // Since we have to load also the properties of the parent contexts (to display the replaced // values) we must find the property of the current context and set parents hierarchical propMap.put(prop.getDescriptorId(), findChildPropAndSetParent(prop, propMap.get(prop.getDescriptorId()), contextList)); } return new ArrayList<>(new TreeSet<>(propMap.values())); }
public List<ResourceEditProperty> loadPropertiesForEditRelation(Mode relationTyp, Integer resourceRelationId, Integer relatedResourceId, ResourceTypeEntity masterResourceType, ResourceTypeEntity slaveResourceType, ContextEntity currentContext) { Map<Integer, ResourceEditProperty> propMap = new HashMap<>(); List<Integer> contextList = contextHierarchy.getContextWithParentIds(currentContext); List<Integer> masterResourceTypeList = getTypeWithParentIds(null, masterResourceType); List<Integer> slaveResourceTypeList = getTypeWithParentIds(null, slaveResourceType); Query query; switch (relationTyp) { case CONSUMED: query = queries.getPropertyValueForConsumedRelationQuery(resourceRelationId, relatedResourceId, masterResourceTypeList, slaveResourceTypeList, contextList); break; case PROVIDED: query = queries.getPropertyValueForProvidedRelationQuery(resourceRelationId, relatedResourceId, masterResourceTypeList, slaveResourceTypeList, contextList); break; default: query = null; } List<ResourceEditProperty> result = JpaSqlResultMapper.list(query, ResourceEditProperty.class); for (ResourceEditProperty prop : result) { // Since we have to load also the properties of the parent contexts (to display the replaced // values) we must find the property of the current context and set parents hierarchical propMap.put(prop.getDescriptorId(), findChildPropAndSetParent(prop, propMap.get(prop.getDescriptorId()), contextList)); } return new ArrayList<>(new TreeSet<>(propMap.values())); }
/** * loads the properties from the database in a single query and returns them as a transfer object * * @param resourceType * - the resourcetype for which the properties should be loaded * @param currentContext * - the context for which the properties should be loaded * @return a list of containers which contain the required property information */ public List<ResourceEditProperty> loadPropertiesForEditResourceType(ResourceTypeEntity resourceType, ContextEntity currentContext) { Map<Integer, ResourceEditProperty> propMap = new HashMap<>(); List<Integer> contextList = contextHierarchy.getContextWithParentIds(currentContext); List<Integer> typeList = getTypeWithParentIds(null, resourceType); Query query = queries.getPropertyValueForResourceType(typeList, contextList); List<ResourceEditProperty> result = JpaSqlResultMapper.list(query, ResourceEditProperty.class); for (ResourceEditProperty prop : result) { // Since we have to load also the properties of the parent contexts (to display the replaced // values) we must find the property of the current context and set parents hierarchical propMap.put(prop.getDescriptorId(), findChildPropAndSetParent(prop, propMap.get(prop.getDescriptorId()), contextList)); if(!resourceType.getId().equals(prop.getTypeId())){ prop.setDescriptorDefinedOnSuperResourceType(true); } if(!resourceType.getId().equals(prop.getPropertyValueTypeId())){ prop.setDefinedOnSuperResourceType(true); } } return new ArrayList<>(new TreeSet<>(propMap.values())); }
ResourceEditProperty bestParentMatch = findChildPropAndSetParent(candidate, existing.getParent(), contextList); existing.setParent(bestParentMatch);