@Test public void testGetResourcesNoPredicate() throws SystemException, UnsupportedPropertyException, NoSuchParentResourceException, NoSuchResourceException { Request request = createNiceMock(Request.class); BlueprintEntity entity = createEntity(getBlueprintTestProperties().iterator().next()); List<BlueprintEntity> results = new ArrayList<BlueprintEntity>(); results.add(entity); expect(dao.findAll()).andReturn(results); replay(dao, request); Set<Resource> setResults = provider.getResources(request, null); assertEquals(1, setResults.size()); verify(dao); validateResource(setResults.iterator().next(), false); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { List<BlueprintEntity> results = null; boolean applyPredicate = false; if (predicate != null) { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); if (requestProps.size() == 1 ) { String name = (String) requestProps.iterator().next().get( BLUEPRINT_NAME_PROPERTY_ID); if (name != null) { BlueprintEntity entity = blueprintDAO.findByName(name); results = entity == null ? Collections.<BlueprintEntity>emptyList() : Collections.singletonList(entity); } } } if (results == null) { applyPredicate = true; results = blueprintDAO.findAll(); } Set<Resource> resources = new HashSet<Resource>(); for (BlueprintEntity entity : results) { Resource resource = toResource(entity, getRequestPropertyIds(request, predicate)); if (predicate == null || ! applyPredicate || predicate.evaluate(resource)) { resources.add(resource); } } if (predicate != null && resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Blueprint not found, " + predicate); } return resources; }
BlueprintResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { List<BlueprintEntity> results = null; boolean applyPredicate = false; if (predicate != null) { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); if (requestProps.size() == 1 ) { String name = (String) requestProps.iterator().next().get( BLUEPRINT_NAME_PROPERTY_ID); if (name != null) { BlueprintEntity entity = blueprintDAO.findByName(name); results = entity == null ? Collections.<BlueprintEntity>emptyList() : Collections.singletonList(entity); } } } if (results == null) { applyPredicate = true; results = blueprintDAO.findAll(); } Set<Resource> resources = new HashSet<Resource>(); for (BlueprintEntity entity : results) { Resource resource = toResource(entity, getRequestPropertyIds(request, predicate)); if (predicate == null || ! applyPredicate || predicate.evaluate(resource)) { resources.add(resource); } } if (predicate != null && resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Blueprint not found, " + predicate); } return resources; } }
BlueprintResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { List<BlueprintEntity> results = null; boolean applyPredicate = false; if (predicate != null) { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); if (requestProps.size() == 1 ) { String name = (String) requestProps.iterator().next().get( BLUEPRINT_NAME_PROPERTY_ID); if (name != null) { BlueprintEntity entity = blueprintDAO.findByName(name); results = entity == null ? Collections.<BlueprintEntity>emptyList() : Collections.singletonList(entity); } } } if (results == null) { applyPredicate = true; results = blueprintDAO.findAll(); } Set<Resource> resources = new HashSet<Resource>(); for (BlueprintEntity entity : results) { Resource resource = toResource(entity, getRequestPropertyIds(request, predicate)); if (predicate == null || ! applyPredicate || predicate.evaluate(resource)) { resources.add(resource); } } if (predicate != null && resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Blueprint not found, " + predicate); } return resources; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); }
BlueprintResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { List<BlueprintEntity> results = null; boolean applyPredicate = false; if (predicate != null) { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); if (requestProps.size() == 1 ) { String name = (String) requestProps.iterator().next().get( BLUEPRINT_NAME_PROPERTY_ID); if (name != null) { BlueprintEntity entity = blueprintDAO.findByName(name); results = entity == null ? Collections.<BlueprintEntity>emptyList() : Collections.singletonList(entity); } } } if (results == null) { applyPredicate = true; results = blueprintDAO.findAll(); } Set<Resource> resources = new HashSet<Resource>(); for (BlueprintEntity entity : results) { Resource resource = toResource(entity, getRequestPropertyIds(request, predicate)); if (predicate == null || ! applyPredicate || predicate.evaluate(resource)) { resources.add(resource); } } if (predicate != null && resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Blueprint not found, " + predicate); } return resources; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); static void init(BlueprintFactory factory, BlueprintDAO dao, SecurityConfigurationFactory
    securityFactory, Gson gson, AmbariMetaInfo metaInfo); @Override RequestStatus createResources(Request request); @Override //todo: continue to use dao/entity directly or use blueprint factory? Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static List<Map<String, Object>> populateSettingList(
          Collection<? extends BlueprintSettingEntity> settings); }
BlueprintResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { List<BlueprintEntity> results = null; boolean applyPredicate = false; if (predicate != null) { Set<Map<String, Object>> requestProps = getPropertyMaps(predicate); if (requestProps.size() == 1 ) { String name = (String) requestProps.iterator().next().get( BLUEPRINT_NAME_PROPERTY_ID); if (name != null) { BlueprintEntity entity = blueprintDAO.findByName(name); results = entity == null ? Collections.<BlueprintEntity>emptyList() : Collections.singletonList(entity); } } } if (results == null) { applyPredicate = true; results = blueprintDAO.findAll(); } Set<Resource> resources = new HashSet<Resource>(); for (BlueprintEntity entity : results) { Resource resource = toResource(entity, getRequestPropertyIds(request, predicate)); if (predicate == null || ! applyPredicate || predicate.evaluate(resource)) { resources.add(resource); } } if (predicate != null && resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Blueprint not found, " + predicate); } return resources; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); static void init(BlueprintFactory factory, BlueprintDAO dao, SecurityConfigurationFactory
    securityFactory, Gson gson, AmbariMetaInfo metaInfo); @Override RequestStatus createResources(Request request); @Override //todo: continue to use dao/entity directly or use blueprint factory? Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static List<Map<String, Object>> populateSettingList(
          Collection<? extends BlueprintSettingEntity> settings); static final String BLUEPRINT_NAME_PROPERTY_ID; static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; static final String BLUEPRINT_SECURITY_PROPERTY_ID; static final String BLUEPRINTS_PROPERTY_ID; static final String HOST_GROUP_PROPERTY_ID; static final String HOST_GROUP_NAME_PROPERTY_ID; static final String HOST_GROUP_CARDINALITY_PROPERTY_ID; static final String COMPONENT_PROPERTY_ID; static final String COMPONENT_NAME_PROPERTY_ID; static final String COMPONENT_PROVISION_ACTION_PROPERTY_ID; static final String CONFIGURATION_PROPERTY_ID; static final String SETTING_PROPERTY_ID; static final String PROPERTIES_PROPERTY_ID; static final String PROPERTIES_ATTRIBUTES_PROPERTY_ID; static final String SCHEMA_IS_NOT_SUPPORTED_MESSAGE; static final String REQUEST_BODY_EMPTY_ERROR_MESSAGE; static final String CONFIGURATION_LIST_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_SIZE_CHECK_ERROR_MESSAGE; }