public Definitions build() { return new Definitions(this); } }
default TRequirementType getElement(RequirementTypeId id) { return (TRequirementType) this.getDefinitions(id).getElement(); }
@PUT @Path("/fileextension") public Response setAssociatedFileExtension(String fileExtension) { this.getDefinitions().getOtherAttributes().put(this.qnameFileExtension, fileExtension); return RestUtils.persist(this); }
public Map<Path, TServiceTemplate> convert(Definitions node, Path outPath) throws MultiException { return convert(node, outPath, new QName(node.getTargetNamespace(), node.getIdFromIdOrNameField())); }
QName tmpName = name; LOGGER.debug("Convert TServiceTemplate: {}", node.getIdFromIdOrNameField()); .setDescription(convertDocumentation(node.getDocumentation())) .setArtifactTypes(convert(node.getArtifactTypes())) .setCapabilityTypes(convert(node.getCapabilityTypes())) .setRelationshipTypes(convert(node.getRelationshipTypes())) .setNodeTypes(convert(node.getNodeTypes())) .setPolicyTypes(convert(node.getPolicyTypes())); if (node.getServiceTemplates().size() == 1) { builder.setTopologyTemplate(convert(node.getServiceTemplates().get(0))); if (Objects.nonNull(node.getServiceTemplates().get(0).getName())) { tmpName = new QName(node.getServiceTemplates().get(0).getName()); builder.addMetadata("targetNamespace", node.getTargetNamespace()); new TImportDefinition.Builder( this.path.relativize(key).toString()) .setNamespaceUri(entry.getValue().getTargetNamespace()) .setNamespacePrefix(getNamespacePrefix(entry.getValue().getTargetNamespace())) .build()
@Override public Definitions getDefinitions(DefinitionsChildId id) { for (WebResource wr: this.repositoryResources) { String path = Util.getUrlPath(id); Definitions definitions = WineryRepositoryClient.getDefinitions(wr.path(path)); if (definitions == null) { // in case of an error, just try the next one continue; } TExtensibleElements element = definitions.getElement(); if (element instanceof TEntityType) { this.cache((TEntityType) element, id.getQName()); return definitions; } } return new Definitions(); }
if (definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().isEmpty()) { theImport = definitions.getImport().get(0); } else { theImport = (TImport) definitions.getElement(); definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().clear(); definitions.getImport().add(theImport);
TExtensibleElements tExtensibleElements = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0); if (!tExtensibleElements.getClass().equals(this.createNewElement().getClass())) { return Response.status(Status.BAD_REQUEST).entity("First type in Definitions is not matching the type modeled by this resource").build(); this.element = this.definitions.getElement();
if (uri != null) { for (TImport i : entryDefinitions.getImport()) { String loc = i.getLocation(); if (!loc.startsWith("../")) { for (TImport i : entryDefinitions.getImport()) { String loc = i.getLocation(); if (Util.isRelativeURI(loc)) { entryDefinitions.getImport().addAll(imports); if (entryDefinitions.getElement() instanceof TEntityType) { exportEntityType(entryDefinitions, uri, tcId);
e.printStackTrace(); LOGGER.debug("Store definition: {}", definitions.getId()); saveDefinitions(definitions, path, definitions.getTargetNamespace(), definitions.getId()); Definitions cleanDefinitions = loadDefinitions(path, definitions.getTargetNamespace(), definitions.getId()); cleanDefinitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().forEach(entry -> { String namespace = csarImporter.getNamespace(entry, definitions.getTargetNamespace()); csarImporter.setNamespace(entry, namespace); part.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(entry);
defs.setId(newName + "Definitions"); defs.setName(newName + "Definitions generated from Artifact " + artifactName); for (TExtensibleElements el : defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) { if (el instanceof TServiceTemplate) { oldSTModel = (TServiceTemplate) el;
newDefs.getImport().addAll(imports); newDefs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(ci);
/** * Creates a new instance of the object represented by this resource */ private void createNew() { this.definitions = BackendUtils.createWrapperDefinitions(this.getId()); // create empty element this.element = this.createNewElement(); // add the element to the definitions this.definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(this.element); // copy ns + id BackendUtils.copyIdToFields((HasIdInIdOrNameField) this.element, this.getId()); // ensure that the definitions is persisted. Ensures that export works. RestUtils.persist(this); }
/** * 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 void exportEntityType(Definitions entryDefinitions, URI uri, DefinitionsChildId tcId) { TEntityType entityType = (TEntityType) entryDefinitions.getElement(); entryDefinitions.getImport().add(imp);
/** * @param directoryId DirectoryID of the TArtifactTemplate that should be returned. * @return The TArtifactTemplate corresponding to the directoryId. */ public static TArtifactTemplate getTArtifactTemplate(DirectoryId directoryId) { RepositoryFileReference ref = BackendUtils.getRefOfDefinitions((ArtifactTemplateId) directoryId.getParent()); try (InputStream is = RepositoryFactory.getRepository().newInputStream(ref)) { Unmarshaller u = JAXBSupport.createUnmarshaller(); Definitions defs = ((Definitions) u.unmarshal(is)); for (TExtensibleElements elem : defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) { if (elem instanceof TArtifactTemplate) { return (TArtifactTemplate) elem; } } } catch (IOException e) { LOGGER.error("Error reading definitions of " + directoryId.getParent() + " at " + ref.getFileName(), e); } catch (JAXBException e) { LOGGER.error("Error in XML in " + ref.getFileName(), e); } return null; }
default TComplianceRule getElement(ComplianceRuleId id) { return (TComplianceRule) this.getDefinitions(id).getElement(); }
public static Definitions createWrapperDefinitions(DefinitionsChildId tcId) { Definitions defs = new Definitions(); return updateWrapperDefinitions(tcId, defs); }
Unmarshaller u = JAXBSupport.createUnmarshaller(); Definitions defs = ((Definitions) u.unmarshal(is)); Map<QName, String> atts = defs.getOtherAttributes(); String src = atts.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "gitsrc")); String branch = atts.get(new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "gitbranch"));
default TServiceTemplate getElement(ServiceTemplateId id) { return (TServiceTemplate) this.getDefinitions(id).getElement(); }