@Test public void testSetResourceProperty() { Set<String> propertyIds = new HashSet<String>(); propertyIds.add("p1"); propertyIds.add("foo"); propertyIds.add("cat1/foo"); propertyIds.add("cat2/bar"); propertyIds.add("cat2/baz"); propertyIds.add("cat3/sub1/bam"); propertyIds.add("cat4/sub2/sub3/bat"); propertyIds.add("cat5/sub5"); Resource resource = new ResourceImpl(Resource.Type.Service); assertNull(resource.getPropertyValue("foo")); BaseProvider.setResourceProperty(resource, "foo", "value1", propertyIds); assertEquals("value1", resource.getPropertyValue("foo")); BaseProvider.setResourceProperty(resource, "cat2/bar", "value2", propertyIds); assertEquals("value2", resource.getPropertyValue("cat2/bar")); assertNull(resource.getPropertyValue("unsupported")); BaseProvider.setResourceProperty(resource, "unsupported", "valueX", propertyIds); assertNull(resource.getPropertyValue("unsupported")); BaseProvider.setResourceProperty(resource, "cat5/sub5/prop5", "value5", propertyIds); assertEquals("value5", resource.getPropertyValue("cat5/sub5/prop5")); BaseProvider.setResourceProperty(resource, "cat5/sub5/sub5a/prop5a", "value5", propertyIds); assertEquals("value5", resource.getPropertyValue("cat5/sub5/sub5a/prop5a")); BaseProvider.setResourceProperty(resource, "cat5/sub7/unsupported", "valueX", propertyIds); assertNull(resource.getPropertyValue("cat5/sub7/unsupported")); }
protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) { boolean contains = requestedIds.contains(propertyId) || isPropertyCategoryRequested(propertyId, requestedIds); if (contains) { if (LOG.isDebugEnabled()) { LOG.debug("Setting property for resource" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } if (!setResourceMapProperty(resource, propertyId, value)){ resource.setProperty(propertyId, value); } } else { if (value instanceof Map<?, ?>) { Map<?, ?> mapValue = (Map) value; for (Map.Entry entry : mapValue.entrySet()) { String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString()); Object entryValue = entry.getValue(); contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains; } } if (!contains && LOG.isDebugEnabled()) { LOG.debug("Skipping property for resource as not in requestedIds" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } } return contains; }
BaseProvider { protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) { boolean contains = requestedIds.contains(propertyId) || isPropertyCategoryRequested(propertyId, requestedIds); if (contains) { if (LOG.isDebugEnabled()) { LOG.debug("Setting property for resource" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } if (!setResourceMapProperty(resource, propertyId, value)){ resource.setProperty(propertyId, value); } } else { if (value instanceof Map<?, ?>) { Map<?, ?> mapValue = (Map) value; for (Map.Entry entry : mapValue.entrySet()) { String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString()); Object entryValue = entry.getValue(); contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains; } } if (!contains && LOG.isDebugEnabled()) { LOG.debug("Skipping property for resource as not in requestedIds" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } } return contains; } }
BaseProvider { protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) { boolean contains = requestedIds.contains(propertyId) || isPropertyCategoryRequested(propertyId, requestedIds); if (contains) { if (LOG.isDebugEnabled()) { LOG.debug("Setting property for resource" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } if (!setResourceMapProperty(resource, propertyId, value)){ resource.setProperty(propertyId, value); } } else { if (value instanceof Map<?, ?>) { Map<?, ?> mapValue = (Map) value; for (Map.Entry entry : mapValue.entrySet()) { String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString()); Object entryValue = entry.getValue(); contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains; } } if (!contains && LOG.isDebugEnabled()) { LOG.debug("Skipping property for resource as not in requestedIds" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } } return contains; } BaseProvider(Set<String> propertyIds); }
BaseProvider { protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) { boolean contains = requestedIds.contains(propertyId) || isPropertyCategoryRequested(propertyId, requestedIds); if (contains) { if (LOG.isDebugEnabled()) { LOG.debug("Setting property for resource" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } if (!setResourceMapProperty(resource, propertyId, value)){ resource.setProperty(propertyId, value); } } else { if (value instanceof Map<?, ?>) { Map<?, ?> mapValue = (Map) value; for (Map.Entry entry : mapValue.entrySet()) { String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString()); Object entryValue = entry.getValue(); contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains; } } if (!contains && LOG.isDebugEnabled()) { LOG.debug("Skipping property for resource as not in requestedIds" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } } return contains; } BaseProvider(Set<String> propertyIds); Set<String> checkPropertyIds(Set<String> propertyIds); Set<String> getPropertyIds(); Set<String> getCategoryIds(); }
BaseProvider { protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) { boolean contains = requestedIds.contains(propertyId) || isPropertyCategoryRequested(propertyId, requestedIds); if (contains) { if (LOG.isDebugEnabled()) { LOG.debug("Setting property for resource" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } if (!setResourceMapProperty(resource, propertyId, value)){ resource.setProperty(propertyId, value); } } else { if (value instanceof Map<?, ?>) { Map<?, ?> mapValue = (Map) value; for (Map.Entry entry : mapValue.entrySet()) { String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString()); Object entryValue = entry.getValue(); contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains; } } if (!contains && LOG.isDebugEnabled()) { LOG.debug("Skipping property for resource as not in requestedIds" + ", resourceType=" + resource.getType() + ", propertyId=" + propertyId + ", value=" + value); } } return contains; } BaseProvider(Set<String> propertyIds); Set<String> checkPropertyIds(Set<String> propertyIds); Set<String> getPropertyIds(); Set<String> getCategoryIds();  }