/** * Returns the fragment of the URL path belonging to the id * <p> * For instance, an Id of type ServiceTemplateId has * <code>servicetemplates/{double encoded ns}/{double encoded name}/</code> * * @param id the element to return the path fragment for * @return the path fragment to be used inside an URL */ public static String getURLPathFragment(GenericId id) { return IdUtil.getPathFragment(id, true); }
@Override public void forceDelete(GenericId id) throws IOException { String pathFragment = IdUtil.getURLPathFragment(id); for (WebResource wr: this.repositoryResources) { ClientResponse response = wr.path(pathFragment).delete(ClientResponse.class); if ((response.getClientResponseStatus() != ClientResponse.Status.NO_CONTENT) || (response.getClientResponseStatus() != ClientResponse.Status.NOT_FOUND)) { LOGGER.debug(String.format("Error %d when deleting id %s from URI %s", response.getStatus(), id.toString(), wr.getURI().toString())); } } }
/** * Returns the namespace where the given Id is nested in. As the id is not a * DefinitionsChildId, it cannot be directly asked for its parent. Merely, the * parent has to be asked for its namespace. The parent, in turn, if it is * no DefinitionsChildId has to ask his parent. * * @param id the id refering to an element, where the namespace has to be * checked for * @return the namespace of the element denoted by id */ public static Namespace getNamespace(GenericId id) { if (id instanceof DefinitionsChildId) { return ((DefinitionsChildId) id).getNamespace(); } else { return IdUtil.getNamespace(id.getParent()); } }
@Override public String getName(GenericId id) { if (this.nameCache.containsKey(id)) { return this.nameCache.get(id); } String name = null; for (WebResource wr: this.repositoryResources) { String pathFragment = IdUtil.getURLPathFragment(id); WebResource resource = wr.path(pathFragment).path("name"); ClientResponse response = resource.accept(MediaType.TEXT_PLAIN_TYPE).get(ClientResponse.class); if (response.getClientResponseStatus() == ClientResponse.Status.OK) { name = response.getEntity(String.class); // break loop as the first match is the final result break; } } // if all resources did not return "OK", "null" is returned if (name != null) { if (this.nameCache.size() > WineryRepositoryClient.MAX_NAME_CACHE_SIZE) { // if cache grew too large, clear it. this.nameCache.clear(); } this.nameCache.put(id, name); } return name; }
/** * Returns the fragment of the path belonging to the id * <p> * For instance, an Id of type ServiceTemplateId has * <code>servicetemplates/{encoded ns}/{encoded name}/</code> * * @param id the element to return the path fragment for * @return the path fragment. This is <em>not</em> intended to be used * inside a URL */ public static String getPathFragment(GenericId id) { return IdUtil.getPathFragment(id, false); }
/** * @param oldId the old id * @param newId the new id */ @Override public void rename(DefinitionsChildId oldId, DefinitionsChildId newId) throws IOException { String pathFragment = IdUtil.getURLPathFragment(oldId); NamespaceAndIdAsString namespaceAndIdAsString = new NamespaceAndIdAsString(); namespaceAndIdAsString.namespace = newId.getNamespace().getDecoded(); namespaceAndIdAsString.id = newId.getXmlId().getDecoded(); for (WebResource wr: this.repositoryResources) { // TODO: Check whether namespaceAndIdAsString is the correct data type expected at the resource ClientResponse response = wr.path(pathFragment).path("id").post(ClientResponse.class, namespaceAndIdAsString); if ((response.getClientResponseStatus() != ClientResponse.Status.NO_CONTENT) || (response.getClientResponseStatus() != ClientResponse.Status.NOT_FOUND)) { LOGGER.debug(String.format("Error %d when renaming DefinitionsChildId %s to %s at %s", response.getStatus(), oldId.toString(), newId.toString(), wr.getURI().toString())); } } }
toInsert = Util.URLencode(toInsert); return IdUtil.getPathFragment(id.getParent()) + toInsert + "/"; } else { throw new IllegalStateException("Unknown subclass of GenericId " + id.getClass());
return res; } else if (id instanceof DefinitionsChildId) { return IdUtil.getPathFragment(id); } else if (id instanceof ToscaElementId) {