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())); }
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())); }
/** * * @param relation * @param property * @param relevantContexts * @return a List containing all properties which would be overridden by setting the property on the relation. */ private List<DifferingProperty> getPropertyOverviewForConsumedRelation(ResourceEditRelation relation, ResourceEditProperty property, List<ContextEntity> relevantContexts) { if (relevantContexts.isEmpty()) { return Collections.EMPTY_LIST; } List<Integer> relevantContextIds = buildRelevantContextIdsList(relevantContexts); Query query = queries.getPropertyOverviewForConsumedRelatedResourceQuery(property.getTechnicalKey(), relation.getResRelId(), relevantContextIds); List<DifferingProperty> differingProperties = getDifferingProperties(property, query, Origin.RELATION); // obtain property values defined on the (slave) resource, which would be overwritten by defining one on the relation - global context is relevant here relevantContextIds.add(contextHierarchy.getContextWithParentIds(relevantContexts.get(0)).get(0)); differingProperties.addAll(getPropertyDefinedOnResource(relation, property, relevantContextIds, Origin.INSTANCE)); return differingProperties; }
/** * Ensures that - when not adding any additional properties to the relation - only the control property is returned */ @Test public void shouldReturnPropertyDescriptorOnResourceOnly() { //given ResourceContextEntity globalResourceContext = slave.getOrCreateContext(contextEntity); globalResourceContext.addPropertyDescriptor(controlPropertyDescriptorEntity); entityManager.flush(); //when Query result = queries .getPropertyValueForConsumedRelationQuery(consumedResourceRelationEntity.getId(), slave.getId(), Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(1, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); }
/** * Add a property to the type relation and ensure that it's part of the result */ @Test public void shouldReturnPropertyDescriptorOnResourceTypeRelationForProvidedResourceRelation() { //given ResourceTypeContextEntity globalResourceTypeContext = slaveType.getOrCreateContext(contextEntity); ResourceRelationTypeContextEntity globalResourceRelationTypeContext = resourceRelationTypeEntity.getOrCreateContext( contextEntity); globalResourceTypeContext.addPropertyDescriptor(controlPropertyDescriptorEntity); globalResourceRelationTypeContext.addPropertyDescriptor(propertyDescriptorEntity); entityManager.flush(); //when Query result = queries .getPropertyValueForProvidedRelationQuery(providedResourceRelationEntity.getId(), provided.getId(), Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(2, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); Assert.assertTrue(propertyNames.contains(propertyDescriptorEntity.getPropertyName())); }
private List<DifferingProperty> getPropertyDefinedOnResource(ResourceEditRelation relation, ResourceEditProperty property, List<Integer> relevantContextIds, Origin origin) { Query query = queries.getPropertyOverviewForResourceQuery(property.getTechnicalKey(), relation.getSlaveId(), relevantContextIds); return getDifferingProperties(property, query, origin); }
public Query getPropertyValueForResource(int resourceId, List<Integer> resourceTypeIds, List<Integer> contextIds) { String template = loadPropertyDescriptorQuery(); Query query = entityManager.createNativeQuery(template); query.setParameter("loadedFor", Origin.INSTANCE.name()) .setParameter("resourceId", resourceId) .setParameter("resourceTypeIds", resourceTypeIds) .setParameter("contextIds", contextIds) .setParameter("resourceRelationId", -1) .setParameter("masterResourceTypeIds", Arrays.asList(-1)); return query; }
/** * 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())); }
/** * * @param relation * @param property * @param relevantContexts * @return a List containing all properties which would be overridden by setting the property on the relation. */ private List<DifferingProperty> getPropertyOverviewForProvidedRelation(ResourceEditRelation relation, ResourceEditProperty property, List<ContextEntity> relevantContexts) { if (relevantContexts.isEmpty()) { return Collections.EMPTY_LIST; } List<Integer> relevantContextIds = buildRelevantContextIdsList(relevantContexts); Query query = queries.getPropertyOverviewForProvidedRelatedResourceQuery(property.getTechnicalKey(), relation.getResRelId(), relevantContextIds); List<DifferingProperty> differingProperties = getDifferingProperties(property, query, Origin.RELATION); // obtain property values defined on the (slave) resource, which would be overwritten by defining one on the relation - global context is relevant here relevantContextIds.add(contextHierarchy.getContextWithParentIds(relevantContexts.get(0)).get(0)); differingProperties.addAll(getPropertyDefinedOnResource(relation, property, relevantContextIds, Origin.INSTANCE)); return differingProperties; }
/** * * @param resourceType * @param property * @param relevantContexts * @return a List containing all properties which override the value of its parent context. */ public List<DifferingProperty> getPropertyOverviewForResourceType(ResourceTypeEntity resourceType, ResourceEditProperty property, List<ContextEntity> relevantContexts) { if (relevantContexts.isEmpty()) { return Collections.EMPTY_LIST; } List<Integer> contextIds = buildRelevantContextIdsList(relevantContexts); Query query = queries.getPropertyOverviewForResourceTypeQuery(property.getTechnicalKey(), resourceType.getId(), contextIds); return getDifferingProperties(property, query, Origin.INSTANCE); }
/** * 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())); }
/** * Add a property to the type relation and ensure that it's part of the result */ @Test public void shouldReturnPropertyDescriptorOnResourceTypeRelationForConsumedResourceRelation() { //given ResourceTypeContextEntity globalResourceTypeContext = slaveType.getOrCreateContext(contextEntity); ResourceRelationTypeContextEntity globalResourceRelationTypeContext = resourceRelationTypeEntity.getOrCreateContext( contextEntity); globalResourceTypeContext.addPropertyDescriptor(controlPropertyDescriptorEntity); globalResourceRelationTypeContext.addPropertyDescriptor(propertyDescriptorEntity); entityManager.flush(); //when Query result = queries .getPropertyValueForConsumedRelationQuery(consumedResourceRelationEntity.getId(), slave.getId(), Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(2, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); Assert.assertTrue(propertyNames.contains(propertyDescriptorEntity.getPropertyName())); }
/** * Add a property to the relation and ensure that it's part of the result */ @Test public void shouldReturnPropertyDescriptorOnProvidedResourceRelation() { //given ResourceContextEntity globalResourceContext = provided.getOrCreateContext(contextEntity); globalResourceContext.addPropertyDescriptor(controlPropertyDescriptorEntity); ResourceRelationContextEntity globalRelationContext = providedResourceRelationEntity .getOrCreateContext( contextEntity); globalRelationContext.addPropertyDescriptor(propertyDescriptorEntity); entityManager.flush(); //when Query result = queries .getPropertyValueForProvidedRelationQuery(providedResourceRelationEntity.getId(), provided.getId(), Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(2, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); Assert.assertTrue(propertyNames.contains(propertyDescriptorEntity.getPropertyName())); }
/** * * @param resource * @param property * @param relevantContexts * @return a List containing all properties which override the value of its parent context. */ public List<DifferingProperty> getPropertyOverviewForResource(ResourceEntity resource, ResourceEditProperty property, List<ContextEntity> relevantContexts) { if (relevantContexts.isEmpty()) { return Collections.EMPTY_LIST; } List<Integer> contextIds = buildRelevantContextIdsList(relevantContexts); Query query = queries.getPropertyOverviewForResourceQuery(property.getTechnicalKey(), resource.getId(), contextIds); return getDifferingProperties(property, query, Origin.INSTANCE); }
/** * Ensures that - when not adding any additional properties to the relation - only the control property is returned */ @Test public void shouldReturnPropertyDescriptorOnResourceTypeOnly() { //given ResourceTypeContextEntity globalResourceTypeContext = slaveType.getOrCreateContext(contextEntity); globalResourceTypeContext.addPropertyDescriptor(controlPropertyDescriptorEntity); entityManager.flush(); //when Query result = queries.getPropertyValueForResourceTypeRelationQuery(Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(1, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); }
/** * Add a property to the relation and ensure that it's part of the result */ @Test public void shouldReturnPropertyDescriptorOnConsumedResourceRelation() { //given ResourceContextEntity globalResourceContext = slave.getOrCreateContext(contextEntity); globalResourceContext.addPropertyDescriptor(controlPropertyDescriptorEntity); ResourceRelationContextEntity globalRelationContext = consumedResourceRelationEntity .getOrCreateContext( contextEntity); globalRelationContext.addPropertyDescriptor(propertyDescriptorEntity); entityManager.flush(); //when Query result = queries .getPropertyValueForConsumedRelationQuery(consumedResourceRelationEntity.getId(), slave.getId(), Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(2, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); Assert.assertTrue(propertyNames.contains(propertyDescriptorEntity.getPropertyName())); }
/** * Add a property to the type relation and ensure that it's part of the result */ @Test public void shouldReturnPropertyDescriptorOnResourceTypeRelation() { //given ResourceTypeContextEntity globalResourceTypeContext = slaveType.getOrCreateContext(contextEntity); ResourceRelationTypeContextEntity globalResourceRelationTypeContext = resourceRelationTypeEntity.getOrCreateContext( contextEntity); globalResourceTypeContext.addPropertyDescriptor(controlPropertyDescriptorEntity); globalResourceRelationTypeContext.addPropertyDescriptor(propertyDescriptorEntity); entityManager.flush(); //when Query result = queries.getPropertyValueForResourceTypeRelationQuery(Arrays.asList(masterType.getId()), Arrays.asList(slaveType.getId()), Arrays.asList(contextEntity.getId())); List<String> propertyNames = getPropertyNames(result.getResultList()); //then Assert.assertEquals(2, propertyNames.size()); Assert.assertTrue(propertyNames.contains(controlPropertyDescriptorEntity.getPropertyName())); Assert.assertTrue(propertyNames.contains(propertyDescriptorEntity.getPropertyName())); }