public NamespaceWithPrefix(Namespace ns, String prefix) { Objects.requireNonNull(ns); Objects.requireNonNull(prefix); this.namespace = ns.getDecoded(); this.prefix = prefix; }
public NamespaceAndDefinedLocalNamesForAngular(final Namespace namespace, final List<LocalNameForAngular> localNamesForAngular) { Objects.requireNonNull(namespace); Objects.requireNonNull(localNamesForAngular); this.id = namespace.getEncoded(); this.text = namespace.getDecoded(); this.localNamesForAngular = localNamesForAngular; }
/** * required by artifacts.jsp */ public String getNamespace() { return this.resWithNamespace.getNamespace().getDecoded(); }
default String getPrefix(Namespace namespace) { Objects.requireNonNull(namespace); String ns = namespace.getDecoded(); return this.getPrefix(ns); }
public static List<NamespaceAndDefinedLocalNamesForAngular> convert(List<NamespaceAndDefinedLocalNames> list) { return list.stream().map(namespaceAndDefinedLocalNames -> { List<LocalNameForAngular> names = namespaceAndDefinedLocalNames.getDefinedLocalNames() .stream().map(localName -> { final String id = "{" + namespaceAndDefinedLocalNames.getNamespace().getDecoded() + "}" + localName; return new LocalNameForAngular(id, localName); }).collect(Collectors.toList()); return new NamespaceAndDefinedLocalNamesForAngular( namespaceAndDefinedLocalNames.getNamespace(), names); }).collect(Collectors.toList()); }
public List<ComplianceRuleId> getRuleIds(TServiceTemplate serviceTemplate) { List<ComplianceRuleId> complianceRules = new ArrayList<>(); Namespace namespace = new Namespace(serviceTemplate.getTargetNamespace(), false); Collection<Namespace> componentsNamespaces = RepositoryFactory.getRepository().getComponentsNamespaces(ComplianceRuleId.class); List<Namespace> relevantNamespaces = componentsNamespaces.stream() .filter(ns -> namespace.getDecoded().startsWith( ns.getDecoded().split("/compliancerules")[0] ) ).collect(Collectors.toList()); for (Namespace space : relevantNamespaces) { complianceRules.addAll((Collection<? extends ComplianceRuleId>) ((FilebasedRepository) RepositoryFactory.getRepository()).getAllIdsInNamespace(ComplianceRuleId.class, space)); } return complianceRules; }
public QName getQName() { return new QName(this.getNamespace().getDecoded(), this.getXmlId().getDecoded()); }
public List<TTopologyTemplate> getAllTopologyFragmentsForLocation(String targetLocation) { String namespaceStr; if ("*".equals(targetLocation)) { namespaceStr = NS_NAME_START; } else { namespaceStr = NS_NAME_START + targetLocation.toLowerCase(); } return RepositoryFactory.getRepository().getAllDefinitionsChildIds(ServiceTemplateId.class).stream() // get all service templates in the namespace .filter(id -> id.getNamespace().getDecoded().toLowerCase().startsWith(namespaceStr)) // get all contained node templates .flatMap(id -> { TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(id).getTopologyTemplate(); List<TNodeTemplate> matchedNodeTemplates = topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream() .filter(t -> t instanceof TNodeTemplate) .map(TNodeTemplate.class::cast) .collect(Collectors.toList()); matchedNodeTemplates.forEach(t -> ModelUtilities.setTargetLabel(t, id.getNamespace().getDecoded().replace(NS_NAME_START, ""))); return getAllTopologyFragmentsFromServiceTemplate(topologyTemplate).stream(); }) .collect(Collectors.toList()); }
@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(); } }
private List<ServiceTemplateId> save(ServiceTemplateId originalId, List<TopologyWrapper> allocatedTopologies, String suffix) throws IOException, AllocationException { if (allocatedTopologies.isEmpty()) { throw new AllocationException("No topologies were created"); } List<ServiceTemplateId> allocatedIds = new ArrayList<>(); for (int i = 0; i < allocatedTopologies.size(); i++) { // generate id ServiceTemplateId allocatedId = new ServiceTemplateId( originalId.getNamespace().getDecoded(), originalId.getXmlId().getDecoded() + "-" + suffix + (i + 1), false); repository.forceDelete(allocatedId); repository.flagAsExisting(allocatedId); // generate and save service template TServiceTemplate allocated = createServiceTemplate(allocatedTopologies.get(i)); repository.setElement(allocatedId, allocated); allocatedIds.add(allocatedId); } LOGGER.debug("Saved " + allocatedIds.size() + " allocated topologies"); return allocatedIds; }
/** * Generates a unique and valid name to be used for the generated maven project name, java project name, class name, * port type name. */ private String generateName(EntityTypeId typeId, String interfaceName) { String name = Util.namespaceToJavaPackage(typeId.getNamespace().getDecoded()); name += Util.FORBIDDEN_CHARACTER_REPLACEMENT; // Winery already ensures that this is a valid NCName // getName() returns the id of the nodeType: A nodeType carries the "id" attribute only (and no name attribute) name += VersionUtils.getNameWithoutVersion(typeId.getXmlId().getDecoded()); // Two separators to distinguish node type and interface part name += Util.FORBIDDEN_CHARACTER_REPLACEMENT; name += Util.FORBIDDEN_CHARACTER_REPLACEMENT; name += Util.namespaceToJavaPackage(interfaceName); // In addition we must replace '.', because Java class names must not // contain dots, but for Winery they are fine. return name.replace(".", Util.FORBIDDEN_CHARACTER_REPLACEMENT); }
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()); }
@POST() @Path("createnewstatefulversion") @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response createNewStatefulVersion() { ServiceTemplateId id = (ServiceTemplateId) this.getId(); WineryVersion version = VersionUtils.getVersion(id); WineryVersion newVersion = new WineryVersion("stateful-" + version.toString() + "-" + Instant.now().toString(), 1, 0); ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false); ResourceResult response = RestUtils.duplicate(id, newId); if (response.getStatus() == Status.CREATED) { response.setUri(null); response.setMessage(new QNameApiData(newId)); } return response.getResponse(); }
/** * 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); }
/** * 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 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"; } }