@Test public void testGetJoinedResourceProperties() throws Exception { ResourceDefinition resourceDefinition = new StackResourceDefinition(); Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); mapIds.put(Resource.Type.Stack, "HDP"); QueryImpl instance = new TestQuery(mapIds, resourceDefinition); instance.addProperty("versions/*", null); instance.addProperty("versions/operating_systems/*", null); instance.addProperty("versions/operating_systems/repositories/*", null); instance.execute(); Set<String> propertyIds = new HashSet<String>(); propertyIds.add("versions/operating_systems/repositories/Repositories/repo_id"); propertyIds.add("versions/operating_systems/OperatingSystems/os_type"); Map<Resource, Set<Map<String, Object>>> resourcePropertiesMap = instance.getJoinedResourceProperties(propertyIds, null, null); Set<Map<String, Object>> propertyMaps = null; for (Map.Entry<Resource, Set<Map<String, Object>>> resourceSetEntry : resourcePropertiesMap.entrySet()) { Assert.assertEquals(Resource.Type.Stack, resourceSetEntry.getKey().getType()); propertyMaps = resourceSetEntry.getValue(); } if (propertyMaps == null) { fail("No property maps found!"); } Assert.assertEquals(6, propertyMaps.size()); for (Map<String, Object> map : propertyMaps) { Assert.assertEquals(2, map.size()); Assert.assertTrue(map.containsKey("versions/operating_systems/OperatingSystems/os_type")); Assert.assertTrue(map.containsKey("versions/operating_systems/repositories/Repositories/repo_id")); } }
protected Map<Resource, Set<Map<String, Object>>> getJoinedResourceProperties(Set<String> propertyIds, Resource parentResource, String category) throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Map<Resource, Set<Map<String, Object>>> resourcePropertyMaps = new HashMap<Resource, Set<Map<String, Object>>>(); Map<String, String> categoryPropertyIdMap = getPropertyIdsForCategory(propertyIds, category); for (Map.Entry<Resource, QueryResult> queryResultEntry : populatedQueryResults.entrySet()) { QueryResult queryResult = queryResultEntry.getValue(); Resource queryParentResource = queryResultEntry.getKey(); if (queryParentResource == parentResource) { Iterable<Resource> iterResource = clusterController.getIterable( resourceDefinition.getType(), queryResult.getQueryResponse(), queryResult.getRequest(), queryResult.getPredicate(), null, null); for (Resource resource : iterResource) { Map<String, Object> resourcePropertyMap = new HashMap<String, Object>(); for (Map.Entry<String, String> categoryPropertyIdEntry : categoryPropertyIdMap.entrySet()) { Object value = resource.getPropertyValue(categoryPropertyIdEntry.getValue()); if (value != null) { resourcePropertyMap.put(categoryPropertyIdEntry.getKey(), value); } } Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>(); for (Map.Entry<String, QueryImpl> entry : requestedSubResources.entrySet()) { String subResourceCategory = category == null ? entry.getKey() : category + "/" + entry.getKey(); QueryImpl subResource = entry.getValue(); Map<Resource, Set<Map<String, Object>>> subResourcePropertyMaps = subResource.getJoinedResourceProperties(propertyIds, resource, subResourceCategory); Set<Map<String, Object>> combinedSubResourcePropertyMaps = new HashSet<Map<String, Object>>(); for (Set<Map<String, Object>> maps : subResourcePropertyMaps.values()) { combinedSubResourcePropertyMaps.addAll(maps); } propertyMaps = joinPropertyMaps(propertyMaps, combinedSubResourcePropertyMaps); } if (!resourcePropertyMap.isEmpty()) { if (propertyMaps.isEmpty()) { propertyMaps.add(resourcePropertyMap); } else { for (Map<String, Object> propertyMap : propertyMaps) { propertyMap.putAll(resourcePropertyMap); } } } resourcePropertyMaps.put(resource, propertyMaps); } } } return resourcePropertyMaps; }
QueryImpl implements Query, ResourceInstance { protected Map<Resource, Set<Map<String, Object>>> getJoinedResourceProperties(Set<String> propertyIds, Resource parentResource, String category) throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Map<Resource, Set<Map<String, Object>>> resourcePropertyMaps = new HashMap<Resource, Set<Map<String, Object>>>(); Map<String, String> categoryPropertyIdMap = getPropertyIdsForCategory(propertyIds, category); for (Map.Entry<Resource, QueryResult> queryResultEntry : populatedQueryResults.entrySet()) { QueryResult queryResult = queryResultEntry.getValue(); Resource queryParentResource = queryResultEntry.getKey(); if (queryParentResource == parentResource) { Iterable<Resource> iterResource = clusterController.getIterable( resourceDefinition.getType(), queryResult.getQueryResponse(), queryResult.getRequest(), queryResult.getPredicate(), null, null); for (Resource resource : iterResource) { Map<String, Object> resourcePropertyMap = new HashMap<String, Object>(); for (Map.Entry<String, String> categoryPropertyIdEntry : categoryPropertyIdMap.entrySet()) { Object value = resource.getPropertyValue(categoryPropertyIdEntry.getValue()); if (value != null) { resourcePropertyMap.put(categoryPropertyIdEntry.getKey(), value); } } Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>(); for (Map.Entry<String, QueryImpl> entry : requestedSubResources.entrySet()) { String subResourceCategory = category == null ? entry.getKey() : category + "/" + entry.getKey(); QueryImpl subResource = entry.getValue(); Map<Resource, Set<Map<String, Object>>> subResourcePropertyMaps = subResource.getJoinedResourceProperties(propertyIds, resource, subResourceCategory); Set<Map<String, Object>> combinedSubResourcePropertyMaps = new HashSet<Map<String, Object>>(); for (Set<Map<String, Object>> maps : subResourcePropertyMaps.values()) { combinedSubResourcePropertyMaps.addAll(maps); } propertyMaps = joinPropertyMaps(propertyMaps, combinedSubResourcePropertyMaps); } if (!resourcePropertyMap.isEmpty()) { if (propertyMaps.isEmpty()) { propertyMaps.add(resourcePropertyMap); } else { for (Map<String, Object> propertyMap : propertyMaps) { propertyMap.putAll(resourcePropertyMap); } } } resourcePropertyMaps.put(resource, propertyMaps); } } } return resourcePropertyMaps; } }
QueryImpl implements Query, ResourceInstance { protected Map<Resource, Set<Map<String, Object>>> getJoinedResourceProperties(Set<String> propertyIds, Resource parentResource, String category) throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Map<Resource, Set<Map<String, Object>>> resourcePropertyMaps = new HashMap<Resource, Set<Map<String, Object>>>(); Map<String, String> categoryPropertyIdMap = getPropertyIdsForCategory(propertyIds, category); for (Map.Entry<Resource, QueryResult> queryResultEntry : populatedQueryResults.entrySet()) { QueryResult queryResult = queryResultEntry.getValue(); Resource queryParentResource = queryResultEntry.getKey(); if (queryParentResource == parentResource) { Iterable<Resource> iterResource = clusterController.getIterable( resourceDefinition.getType(), queryResult.getQueryResponse(), queryResult.getRequest(), queryResult.getPredicate(), null, null); for (Resource resource : iterResource) { Map<String, Object> resourcePropertyMap = new HashMap<String, Object>(); for (Map.Entry<String, String> categoryPropertyIdEntry : categoryPropertyIdMap.entrySet()) { Object value = resource.getPropertyValue(categoryPropertyIdEntry.getValue()); if (value != null) { resourcePropertyMap.put(categoryPropertyIdEntry.getKey(), value); } } Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>(); for (Map.Entry<String, QueryImpl> entry : requestedSubResources.entrySet()) { String subResourceCategory = category == null ? entry.getKey() : category + "/" + entry.getKey(); QueryImpl subResource = entry.getValue(); Map<Resource, Set<Map<String, Object>>> subResourcePropertyMaps = subResource.getJoinedResourceProperties(propertyIds, resource, subResourceCategory); Set<Map<String, Object>> combinedSubResourcePropertyMaps = new HashSet<Map<String, Object>>(); for (Set<Map<String, Object>> maps : subResourcePropertyMaps.values()) { combinedSubResourcePropertyMaps.addAll(maps); } propertyMaps = joinPropertyMaps(propertyMaps, combinedSubResourcePropertyMaps); } if (!resourcePropertyMap.isEmpty()) { if (propertyMaps.isEmpty()) { propertyMaps.add(resourcePropertyMap); } else { for (Map<String, Object> propertyMap : propertyMaps) { propertyMap.putAll(resourcePropertyMap); } } } resourcePropertyMaps.put(resource, propertyMaps); } } } return resourcePropertyMaps; } QueryImpl(Map<Resource.Type, String> keyValueMap,
                   ResourceDefinition resourceDefinition,
                   ClusterController clusterController); }
QueryImpl implements Query, ResourceInstance { protected Map<Resource, Set<Map<String, Object>>> getJoinedResourceProperties(Set<String> propertyIds, Resource parentResource, String category) throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Map<Resource, Set<Map<String, Object>>> resourcePropertyMaps = new HashMap<Resource, Set<Map<String, Object>>>(); Map<String, String> categoryPropertyIdMap = getPropertyIdsForCategory(propertyIds, category); for (Map.Entry<Resource, QueryResult> queryResultEntry : populatedQueryResults.entrySet()) { QueryResult queryResult = queryResultEntry.getValue(); Resource queryParentResource = queryResultEntry.getKey(); if (queryParentResource == parentResource) { Iterable<Resource> iterResource = clusterController.getIterable( resourceDefinition.getType(), queryResult.getQueryResponse(), queryResult.getRequest(), queryResult.getPredicate(), null, null); for (Resource resource : iterResource) { Map<String, Object> resourcePropertyMap = new HashMap<String, Object>(); for (Map.Entry<String, String> categoryPropertyIdEntry : categoryPropertyIdMap.entrySet()) { Object value = resource.getPropertyValue(categoryPropertyIdEntry.getValue()); if (value != null) { resourcePropertyMap.put(categoryPropertyIdEntry.getKey(), value); } } Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>(); for (Map.Entry<String, QueryImpl> entry : requestedSubResources.entrySet()) { String subResourceCategory = category == null ? entry.getKey() : category + "/" + entry.getKey(); QueryImpl subResource = entry.getValue(); Map<Resource, Set<Map<String, Object>>> subResourcePropertyMaps = subResource.getJoinedResourceProperties(propertyIds, resource, subResourceCategory); Set<Map<String, Object>> combinedSubResourcePropertyMaps = new HashSet<Map<String, Object>>(); for (Set<Map<String, Object>> maps : subResourcePropertyMaps.values()) { combinedSubResourcePropertyMaps.addAll(maps); } propertyMaps = joinPropertyMaps(propertyMaps, combinedSubResourcePropertyMaps); } if (!resourcePropertyMap.isEmpty()) { if (propertyMaps.isEmpty()) { propertyMaps.add(resourcePropertyMap); } else { for (Map<String, Object> propertyMap : propertyMaps) { propertyMap.putAll(resourcePropertyMap); } } } resourcePropertyMaps.put(resource, propertyMaps); } } } return resourcePropertyMaps; } QueryImpl(Map<Resource.Type, String> keyValueMap,
                   ResourceDefinition resourceDefinition,
                   ClusterController clusterController); @Override void addProperty(String propertyId, TemporalInfo temporalInfo); @Override void addLocalProperty(String property); @Override Result execute(); @Override Predicate getPredicate(); @Override Set<String> getProperties(); @Override void setUserPredicate(Predicate predicate); @Override void setPageRequest(PageRequest pageRequest); @Override void setSortRequest(SortRequest sortRequest); @Override void setRenderer(Renderer renderer); @Override void setRequestInfoProps(Map<String, String> requestInfoProperties); @Override Map<String, String> getRequestInfoProps(); @Override void setKeyValueMap(Map<Resource.Type, String> keyValueMap); @Override Map<Resource.Type, String> getKeyValueMap(); @Override Query getQuery(); @Override ResourceDefinition getResourceDefinition(); @Override boolean isCollectionResource(); @Override Map<String, ResourceInstance> getSubResources(); @Override boolean equals(Object o); @Override int hashCode(); }
QueryImpl implements Query, ResourceInstance { protected Map<Resource, Set<Map<String, Object>>> getJoinedResourceProperties(Set<String> propertyIds, Resource parentResource, String category) throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Map<Resource, Set<Map<String, Object>>> resourcePropertyMaps = new HashMap<Resource, Set<Map<String, Object>>>(); Map<String, String> categoryPropertyIdMap = getPropertyIdsForCategory(propertyIds, category); for (Map.Entry<Resource, QueryResult> queryResultEntry : populatedQueryResults.entrySet()) { QueryResult queryResult = queryResultEntry.getValue(); Resource queryParentResource = queryResultEntry.getKey(); if (queryParentResource == parentResource) { Iterable<Resource> iterResource = clusterController.getIterable( resourceDefinition.getType(), queryResult.getQueryResponse(), queryResult.getRequest(), queryResult.getPredicate(), null, null); for (Resource resource : iterResource) { Map<String, Object> resourcePropertyMap = new HashMap<String, Object>(); for (Map.Entry<String, String> categoryPropertyIdEntry : categoryPropertyIdMap.entrySet()) { Object value = resource.getPropertyValue(categoryPropertyIdEntry.getValue()); if (value != null) { resourcePropertyMap.put(categoryPropertyIdEntry.getKey(), value); } } Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>(); for (Map.Entry<String, QueryImpl> entry : requestedSubResources.entrySet()) { String subResourceCategory = category == null ? entry.getKey() : category + "/" + entry.getKey(); QueryImpl subResource = entry.getValue(); Map<Resource, Set<Map<String, Object>>> subResourcePropertyMaps = subResource.getJoinedResourceProperties(propertyIds, resource, subResourceCategory); Set<Map<String, Object>> combinedSubResourcePropertyMaps = new HashSet<Map<String, Object>>(); for (Set<Map<String, Object>> maps : subResourcePropertyMaps.values()) { combinedSubResourcePropertyMaps.addAll(maps); } propertyMaps = joinPropertyMaps(propertyMaps, combinedSubResourcePropertyMaps); } if (!resourcePropertyMap.isEmpty()) { if (propertyMaps.isEmpty()) { propertyMaps.add(resourcePropertyMap); } else { for (Map<String, Object> propertyMap : propertyMaps) { propertyMap.putAll(resourcePropertyMap); } } } resourcePropertyMaps.put(resource, propertyMaps); } } } return resourcePropertyMaps; } QueryImpl(Map<Resource.Type, String> keyValueMap,
                   ResourceDefinition resourceDefinition,
                   ClusterController clusterController); @Override void addProperty(String propertyId, TemporalInfo temporalInfo); @Override void addLocalProperty(String property); @Override Result execute(); @Override Predicate getPredicate(); @Override Set<String> getProperties(); @Override void setUserPredicate(Predicate predicate); @Override void setPageRequest(PageRequest pageRequest); @Override void setSortRequest(SortRequest sortRequest); @Override void setRenderer(Renderer renderer); @Override void setRequestInfoProps(Map<String, String> requestInfoProperties); @Override Map<String, String> getRequestInfoProps(); @Override void setKeyValueMap(Map<Resource.Type, String> keyValueMap); @Override Map<Resource.Type, String> getKeyValueMap(); @Override Query getQuery(); @Override ResourceDefinition getResourceDefinition(); @Override boolean isCollectionResource(); @Override Map<String, ResourceInstance> getSubResources(); @Override boolean equals(Object o); @Override int hashCode();  }