@Test public void testWithParentFromBase64() throws Exception { Authentication authentication = TestAuthenticationFactory.createAdministrator(); SecurityContextHolder.getContext().setAuthentication(authentication); File file = new File("src/test/resources/version_definition_resource_provider.xml"); byte[] bytes = IOUtils.toByteArray(new FileInputStream(file)); String base64Str = Base64.encodeBase64String(bytes); final ResourceProvider versionProvider = new VersionDefinitionResourceProvider(); final ResourceProvider provider = injector.getInstance(ResourceProviderFactory.class) .getRepositoryVersionResourceProvider(); final Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>(); final Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(VersionDefinitionResourceProvider.VERSION_DEF_DEFINITION_BASE64, base64Str); propertySet.add(properties); final Request createRequest = PropertyHelper.getCreateRequest(propertySet, null); RequestStatus status = versionProvider.createResources(createRequest); Assert.assertEquals(1, status.getAssociatedResources().size()); Request getRequest = PropertyHelper.getReadRequest("VersionDefinition"); Set<Resource> results = versionProvider.getResources(getRequest, null); Assert.assertEquals(1, results.size()); final Predicate predicateStackName = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID).equals("HDP").toPredicate(); final Predicate predicateStackVersion = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID).equals("2.2.0").toPredicate(); results = provider.getResources(getRequest, new AndPredicate(predicateStackName, predicateStackVersion)); Assert.assertEquals(1, results.size()); getRequest = PropertyHelper.getReadRequest( RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, RepositoryVersionResourceProvider.REPOSITORY_VERSION_ID_PROPERTY_ID, RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, RepositoryVersionResourceProvider.SUBRESOURCE_REPOSITORIES_PROPERTY_ID, "RepositoryVersions/release", "RepositoryVersions/services", "RepositoryVersions/has_children", "RepositoryVersions/parent_id"); results = provider.getResources(getRequest, new AndPredicate(predicateStackName, predicateStackVersion)); Assert.assertEquals(2, results.size()); Resource r = null; for (Resource result : results) { if (result.getPropertyValue("RepositoryVersions/repository_version").equals("2.2.0.8-5678")) { r = result; break; } } Assert.assertNotNull(r); Map<String, Map<String, Object>> map = r.getPropertiesMap(); Assert.assertTrue(map.containsKey("RepositoryVersions")); Map<String, Object> vals = map.get("RepositoryVersions"); Assert.assertEquals("2.2.0.8-5678", vals.get("repository_version")); Assert.assertNotNull(vals.get("parent_id")); Assert.assertEquals(Boolean.FALSE, vals.get("has_children")); Assert.assertTrue(map.containsKey("RepositoryVersions/release")); vals = map.get("RepositoryVersions/release"); Assert.assertEquals("5678", vals.get("build")); Assert.assertEquals("2.3.4.[1-9]", vals.get("compatible_with")); Assert.assertEquals("http: vals.get("notes")); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String VERSION_DEF; static final String VERSION_DEF_BASE64_PROPERTY; static final String VERSION_DEF_STACK_NAME; static final String VERSION_DEF_STACK_VERSION; static final String DIRECTIVE_SKIP_URL_CHECK; static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID; }