/** * Convenience method for getId().getNamespace() */ public final Namespace getNamespace() { return this.id.getNamespace(); }
@GET @Path("alldefinedtypeslocalnames") public List<String> getAllDefinedTypesLocalNames() { return RepositoryFactory.getRepository().getXsdImportManager().getAllDefinedTypesLocalNames().stream() .filter(namespaceAndDefinedLocalNames -> namespaceAndDefinedLocalNames.getNamespace().equals(id.getNamespace())) .flatMap(namespaceAndDefinedLocalNames -> namespaceAndDefinedLocalNames.getDefinedLocalNames().stream()) .sorted() .collect(Collectors.toList()); } }
@GET @Path("alldeclaredelementslocalnames") public List<String> getAllDeclaredElementsLocalNames() { return RepositoryFactory.getRepository().getXsdImportManager().getAllDeclaredElementsLocalNames().stream() .filter(namespaceAndDefinedLocalNames -> namespaceAndDefinedLocalNames.getNamespace().equals(id.getNamespace())) .flatMap(namespaceAndDefinedLocalNames -> namespaceAndDefinedLocalNames.getDefinedLocalNames().stream()) .sorted() .collect(Collectors.toList()); }
/** * @param id the id to determine the namespace of the parent for * @return the namespace of the first DefinitionsChildId found in the ID hierarchy */ public static Namespace getNamespace(ToscaElementId id) { GenericId parent = id.getParent(); while (!(parent instanceof DefinitionsChildId)) { parent = parent.getParent(); } return ((DefinitionsChildId) parent).getNamespace(); }
/** * 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 int compareTo(GenericId o1) { if (o1 instanceof DefinitionsChildId) { int res = this.getClass().getName().compareTo(o1.getClass().getName()); if (res == 0) { DefinitionsChildId o = (DefinitionsChildId) o1; res = VersionUtils.getNameWithoutVersion(this).compareTo(VersionUtils.getNameWithoutVersion(o)); if (res == 0) { res = VersionUtils.getVersion(this).compareTo(VersionUtils.getVersion(o)); } if (res == 0) { res = this.getNamespace().compareTo(o.getNamespace()); } } return res; } else { // comparing TOSCAcomponentIDs with non-TOSCAcomponentIDs is not // possible throw new IllegalStateException(); } } }
public QName getQName() { return new QName(this.getNamespace().getDecoded(), this.getXmlId().getDecoded()); }
@POST @Consumes(MediaType.APPLICATION_JSON) public Response createNewVersion(NewVersionApiData newVersionApiData, @QueryParam("release") String release, @QueryParam("freeze") String freeze) { if (Objects.nonNull(freeze)) { return RestUtils.freezeVersion(this.id).getResponse(); } else if (Objects.nonNull(release)) { return RestUtils.releaseVersion(this.id); } else { String newId = VersionUtils.getNameWithoutVersion(this.id) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersionApiData.version.toString(); DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(this.id.getClass(), this.id.getNamespace().getDecoded(), newId, false); return RestUtils.addNewVersion(this.id, newComponent, newVersionApiData.componentsToUpdate); } }
public QNameApiData(DefinitionsChildId newId) { this.localname = newId.getXmlId().getDecoded(); this.namespace = newId.getNamespace().getDecoded(); } }
@POST @Path("localName") @Consumes(MediaType.APPLICATION_JSON) public Response putId(RenameApiData data) { DefinitionsChildId newId; newId = BackendUtils.getDefinitionsChildId(this.getId().getClass(), this.getId().getNamespace().getDecoded(), data.localname, false); if (data.renameAllComponents) { return RestUtils.renameAllVersionsOfOneDefinition(this.getId(), newId); } else { return RestUtils.rename(this.getId(), newId).getResponse(); } }
/** * Returns a unique name for the given definitions to be used as filename */ private static String getDefinitionsName(IGenericRepository repository, DefinitionsChildId id) { // the prefix is globally unique and the id locally in a namespace // therefore a concatenation of both is also unique return repository.getNamespaceManager().getPrefix(id.getNamespace()) + "__" + id.getXmlId().getEncoded(); }
/** * Collects all the definitions which describe the same component in different versions. * * @param id The {@link DefinitionsChildId} for which all versions should be collected. * @return A set of definitions describing the same component in different versions. */ public static SortedSet<? extends DefinitionsChildId> getOtherVersionDefinitionsFromDefinition(DefinitionsChildId id) { IRepository repository = RepositoryFactory.getRepository(); SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds(id.getClass()); final String componentName = VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()); allDefinitionsChildIds.removeIf(definition -> { if (definition.getNamespace().compareTo(id.getNamespace()) == 0) { String name = VersionUtils.getNameWithoutVersion(definition); return !name.equals(componentName); } return true; }); return allDefinitionsChildIds; }
/** * Persists the given definitions * * @param id the id of the definition child to persist * @param definitions the definitions to persist */ public static void persist(DefinitionsChildId id, Definitions definitions) throws IOException { RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id); NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager(); namespaceManager.addPermanentNamespace(id.getNamespace().getDecoded()); BackendUtils.persist(definitions, ref, MediaTypes.MEDIATYPE_TOSCA_DEFINITIONS); }
/** * Creates a new TDefintions element wrapping a definition child. The namespace of the tosca component is used as * namespace and {@code winery-defs-for-} concatenated with the (unique) ns prefix and idOfContainedElement is used * as id * * @param tcId the id of the element the wrapper is used for * @param defs the definitions to update * @return a definitions element prepared for wrapping a definition child */ public static Definitions updateWrapperDefinitions(DefinitionsChildId tcId, Definitions defs) { // set target namespace // an internal namespace is not possible // a) tPolicyTemplate and tArtfactTemplate do NOT support the "targetNamespace" attribute // b) the imports statement would look bad as it always imported the artificial namespace defs.setTargetNamespace(tcId.getNamespace().getDecoded()); // set a unique id to create a valid definitions element // we do not use UUID to be more human readable and deterministic (for debugging) String prefix = RepositoryFactory.getRepository().getNamespaceManager().getPrefix(tcId.getNamespace()); String elId = tcId.getXmlId().getDecoded(); String id = "winery-defs-for_" + prefix + "-" + elId; defs.setId(id); return defs; }
private List<ComponentId> getListOfIds(SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds, boolean supportsNameAttribute, String full, String includeVersions) { return allDefinitionsChildIds.stream() .sorted() .map(id -> { String name = id.getXmlId().getDecoded(); Definitions definitions = null; WineryVersion version = null; if (supportsNameAttribute) { AbstractComponentInstanceResource componentInstanceResource = AbstractComponentsResource.getComponentInstanceResource(id); name = ((IHasName) componentInstanceResource).getName(); } if (Objects.nonNull(full)) { definitions = getFullComponentData(id); } if (Objects.nonNull(includeVersions)) { version = VersionUtils.getVersion(id.getXmlId().getDecoded()); } return new ComponentId(id.getXmlId().getDecoded(), name, id.getNamespace().getDecoded(), id.getQName(), definitions, version); }) .collect(Collectors.toList()); }
/** * Used by children to implement getListOfAllInstances() */ protected SortedSet<Select2OptGroup> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) throws RepositoryCorruptException { Select2DataWithOptGroups data = new Select2DataWithOptGroups(); Collection<? extends DefinitionsChildId> instanceIds = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(clazz, this.id.getQName()); for (DefinitionsChildId instanceId : instanceIds) { String groupText = instanceId.getNamespace().getDecoded(); String text = BackendUtils.getName(instanceId); data.add(groupText, instanceId.getQName().toString(), text); } return data.asSortedSet(); }
/** * @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())); } } }
/** * Copies the given id resource to the appropriate fields in the element. * <p> * For instance, the id is put in the "name" field for EntityTypes */ public static void copyIdToFields(HasIdInIdOrNameField element, DefinitionsChildId id) { element.setId(id.getXmlId().getDecoded()); if (element instanceof HasTargetNamespace) { ((HasTargetNamespace) element).setTargetNamespace(id.getNamespace().getDecoded()); } // Required for creating a new version in order to also update the name if (element instanceof HasName) { ((HasName) element).setName(id.getXmlId().getDecoded()); } }
public static Response releaseVersion(DefinitionsChildId releasableComponent) { ResourceResult result = new ResourceResult(); WineryVersion version = BackendUtils.getCurrentVersionWithAllFlags(releasableComponent); if (version.isReleasable()) { if (RepositoryFactory.getRepository() instanceof GitBasedRepository) { try { freezeVersion(releasableComponent); version.setWorkInProgressVersion(0); String newId = VersionUtils.getNameWithoutVersion(releasableComponent) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version.toString(); DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(releasableComponent.getClass(), releasableComponent.getNamespace().getDecoded(), newId, false); result = duplicate(releasableComponent, newComponent); BackendUtils.commit(newComponent, "Release"); } catch (GitAPIException e) { result.setStatus(Status.INTERNAL_SERVER_ERROR); } } else { result.setStatus(Status.INTERNAL_SERVER_ERROR); } } else { result.setStatus(Status.BAD_REQUEST); } return result.getResponse(); }
public VisualsApiData(GenericVisualAppearanceResource visuals) { IRepository repository = RepositoryFactory.getRepository(); DefinitionsChildId parent = (DefinitionsChildId) visuals.getId().getParent(); this.color = visuals.getColor(); this.typeId = parent.getQName(); this.pattern = repository.getNamespaceManager().isPatternNamespace(parent.getNamespace().getDecoded()); RepositoryFileReference iconRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_SMALL_ICON); if (repository.exists(iconRef)) { iconUrl = visuals.getAbsoluteURL() + "16x16"; } RepositoryFileReference imageRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_BIG_ICON); if (repository.exists(imageRef)) { imageUrl = visuals.getAbsoluteURL() + "50x50"; } }