use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class GenericArtifactsResource method storeProperties.
private void storeProperties(ArtifactTemplateId artifactTemplateId, DefinitionsChildId typeId, String name) {
// We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate):
// getAny() does not always return "w3c.dom.element" anymore
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
LOGGER.error(e.getMessage(), e);
return;
}
Document doc = builder.newDocument();
String namespace = QNames.QNAME_ARTIFACT_TYPE_WAR.getNamespaceURI();
Element root = doc.createElementNS(namespace, "WSProperties");
doc.appendChild(root);
Element element = doc.createElementNS(namespace, "ServiceEndpoint");
Text text = doc.createTextNode("/services/" + name + "Port");
element.appendChild(text);
root.appendChild(element);
element = doc.createElementNS(namespace, "PortType");
text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name);
element.appendChild(text);
root.appendChild(element);
element = doc.createElementNS(namespace, "InvocationType");
text = doc.createTextNode("SOAP/HTTP");
element.appendChild(text);
root.appendChild(element);
TEntityTemplate.XmlProperties properties = new TEntityTemplate.XmlProperties();
properties.setAny(root);
final IRepository repository = RepositoryFactory.getRepository();
final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
artifactTemplate.setProperties(properties);
try {
repository.setElement(artifactTemplateId, artifactTemplate);
} catch (IOException e) {
throw new WebApplicationException(e);
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class ToscaExportUtil method specifyImports.
private TDefinitions specifyImports(IRepository repository, DefinitionsChildId tcId, Collection<DefinitionsChildId> referencedDefinitionsChildIds) {
TDefinitions entryDefinitions = repository.getDefinitions(tcId);
// BEGIN: Definitions modification
// the "imports" collection contains the imports of Definitions, not of other definitions
// the other definitions are stored in entryDefinitions.getImport()
// we modify the internal definitions object directly. It is not written back to the storage. Therefore, we do not need to clone it
// the imports (pointing to not-definitions (xsd, wsdl, ...)) already have a correct relative URL. (quick hack)
URI uri = (URI) this.exportConfiguration.get(CsarExportConfiguration.REPOSITORY_URI.name());
if (uri != null) {
// we are in the plain-XML mode, the URLs of the imports have to be adjusted
for (TImport i : entryDefinitions.getImport()) {
String loc = i.getLocation();
if (!loc.startsWith("../")) {
LOGGER.warn("Location is not relative for id " + tcId.toReadableString());
}
loc = loc.substring(3);
loc = uri + loc;
// now the location is an absolute URL
i.setLocation(loc);
}
}
// files of imports have to be added to the CSAR, too
for (TImport i : entryDefinitions.getImport()) {
String loc = i.getLocation();
if (Util.isRelativeURI(loc)) {
// locally stored, add to CSAR
GenericImportId iid = new GenericImportId(i);
String fileName = IdUtil.getLastURIPart(loc);
fileName = EncodingUtil.URLdecode(fileName);
RepositoryFileReference ref = new RepositoryFileReference(iid, fileName);
putRefAsReferencedItemInCsar(repository, ref);
}
}
Set<DefinitionsChildId> collect = referencedDefinitionsChildIds.stream().filter(id -> id instanceof NodeTypeImplementationId).collect(Collectors.toSet());
if (collect.stream().anyMatch(DefinitionsChildId::isSelfContained)) {
if (this.exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name())) {
referencedDefinitionsChildIds.removeAll(collect.stream().filter(id -> !id.isSelfContained()).collect(Collectors.toList()));
} else if (collect.size() > 1 && collect.stream().anyMatch(id -> !id.isSelfContained())) {
referencedDefinitionsChildIds.removeAll(collect.stream().filter(DefinitionsChildId::isSelfContained).collect(Collectors.toList()));
}
}
// adjust imports: add imports of definitions to it
Collection<TImport> imports = new ArrayList<>();
for (DefinitionsChildId id : referencedDefinitionsChildIds) {
this.addToImports(repository, id, imports);
}
entryDefinitions.getImport().addAll(imports);
// END: Definitions modification
return entryDefinitions;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class XmlRepositoryTest method subDirectoryExpandedCorrectly.
@Test
public void subDirectoryExpandedCorrectly() throws Exception {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
final IRepository repository = this.repository;
final Path expected = Paths.get("artifacttemplates", "http%3A%2F%2Fwww.example.org", "at", "source", "dir1", "dir2", "dir3", "test.txt");
assertEquals(expected, repository.getRepositoryRoot().relativize(repository.ref2AbsolutePath(ref)));
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class DataFlowResource method createNodeTemplate.
/**
* Create a NodeTemplate corresponding to the given filter with the given type, properties and artifacts and add it
* to the topology of the incomplete deployment model.
*/
private TTopologyTemplate createNodeTemplate(TTopologyTemplate topology, NodeTypeId nodeTypeId, String templateName, Map<String, String> properties, List<QName> artifacts) {
// get NodeType to access Requirements for the completion and available properties
IRepository repo = RepositoryFactory.getRepository();
TNodeType nodeType = repo.getElement(nodeTypeId);
if (Objects.isNull(nodeType)) {
return null;
}
TNodeTemplate.Builder templateBuilder = new TNodeTemplate.Builder(templateName, nodeTypeId.getQName());
// add the defined properties to the NodeTemplate
if (Objects.nonNull(properties)) {
LinkedHashMap<String, String> propertyList = new LinkedHashMap<>();
if (Objects.nonNull(nodeType.getWinerysPropertiesDefinition())) {
// add empty property for NodeType properties to avoid errors due to missing properties
WinerysPropertiesDefinition def = nodeType.getWinerysPropertiesDefinition();
for (PropertyDefinitionKV prop : def.getPropertyDefinitions()) {
propertyList.put(prop.getKey(), "");
}
}
// add all properties which are defined at the filter
propertyList.putAll(properties);
TEntityTemplate.WineryKVProperties nodeProperties = new TEntityTemplate.WineryKVProperties();
nodeProperties.setKVProperties(propertyList);
templateBuilder.setProperties(nodeProperties);
}
// add all requirements which are defined by the corresponding NodeType
if (nodeType.getRequirementDefinitions() != null) {
for (TRequirementDefinition requirementDef : nodeType.getRequirementDefinitions()) {
String requirementId = templateName + "-" + requirementDef.getName();
templateBuilder.addRequirement(new TRequirement.Builder(requirementId, requirementDef.getName(), requirementDef.getRequirementType()).build());
}
}
// add the DAs to the NodeTemplate
if (Objects.nonNull(artifacts) && !artifacts.isEmpty()) {
LOGGER.debug("{} artifacts specified for filter {}", artifacts.size(), templateName);
// get the IDs of all available ArtifactTemplates
List<ArtifactTemplateId> artifactTemplateIds = repo.getAllDefinitionsChildIds().stream().filter(id -> id.getGroup().equals(ARTIFACT_TEMPLATE_GROUP) && id instanceof ArtifactTemplateId).map(id -> (ArtifactTemplateId) id).collect(Collectors.toList());
for (QName artifactName : artifacts) {
Optional<ArtifactTemplateId> idOptional = artifactTemplateIds.stream().filter(id -> id.getQName().equals(artifactName)).findFirst();
if (idOptional.isPresent()) {
ArtifactTemplateId artifactTemplateId = idOptional.get();
TArtifactTemplate artifactTemplate = repo.getElement(artifactTemplateId);
templateBuilder.addDeploymentArtifact(new TDeploymentArtifact.Builder(artifactName.toString(), artifactTemplate.getType()).setArtifactRef(artifactName).build());
} else {
LOGGER.warn("Filter '{}' specifies DA with name '{}' but no such artifact available in repository!", templateName, artifactName);
}
}
}
topology.addNodeTemplate(templateBuilder.build());
return topology;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class DataFlowResource method createRelationshipTemplate.
private TRelationshipTemplate createRelationshipTemplate(RelationshipTypeId relationshipTypeId, TNodeTemplate source, TNodeTemplate target, String dataTransferType) {
// get ConnectsTo RelationshipType to access available properties
IRepository repo = RepositoryFactory.getRepository();
TRelationshipType relationshipType = repo.getElement(relationshipTypeId);
if (Objects.isNull(relationshipType)) {
return null;
}
String relationId = source.getId() + "-connectsTo-" + target.getId();
TRelationshipTemplate.Builder builder = new TRelationshipTemplate.Builder(relationId, relationshipTypeId.getQName(), source, target).setName(relationId);
// add empty properties to avoid errors due to missing properties
if (Objects.nonNull(relationshipType.getWinerysPropertiesDefinition())) {
LinkedHashMap<String, String> propertyList = new LinkedHashMap<>();
WinerysPropertiesDefinition def = relationshipType.getWinerysPropertiesDefinition();
for (PropertyDefinitionKV prop : def.getPropertyDefinitions()) {
propertyList.put(prop.getKey(), "");
}
TEntityTemplate.WineryKVProperties relationProperties = new TEntityTemplate.WineryKVProperties();
relationProperties.setElementName(def.getElementName());
relationProperties.setNamespace(def.getNamespace());
relationProperties.setKVProperties(propertyList);
builder.setProperties(relationProperties);
}
TRelationshipTemplate relation = builder.build();
// evaluate pipe attribute to determine connectsTo direction
if (Objects.nonNull(dataTransferType) && dataTransferType.equalsIgnoreCase(DATA_TRANSFER_TYPE_PULL)) {
// change connectsTo direction in case the corresponding target filter is pulling
relation.setSourceNodeTemplate(target);
relation.setTargetNodeTemplate(source);
relation.getOtherAttributes().put(ModelUtilities.RELATIONSHIP_TEMPLATE_TRANSFER_TYPE, RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL);
}
return relation;
}
Aggregations