use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class ConsistencyCheckerTest method nodeTypeImplementationNamespaceHasNoErrors.
@Test
public void nodeTypeImplementationNamespaceHasNoErrors() {
NodeTypeImplementationId id = new NodeTypeImplementationId("http://winery.opentosca.org/test/nodetypeimplementations/fruits", "baobab_impl", false);
ConsistencyErrorCollector errorLogger = new ConsistencyErrorCollector();
consistencyChecker.checkNamespaceUri(id);
assertEquals(Collections.emptyMap(), errorLogger.getErrorList());
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId 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.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class SelfContainmentPackager method getSelfContainedNodeTypeImplId.
private NodeTypeImplementationId getSelfContainedNodeTypeImplId(TNodeTypeImplementation impl) {
QName implQName = new QName(impl.getTargetNamespace(), impl.getIdFromIdOrNameField());
NodeTypeImplementationId originalId = new NodeTypeImplementationId(implQName);
return new NodeTypeImplementationId(VersionSupport.getSelfContainedVersion(originalId));
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class SelfContainmentPackager method createSelfContainedVersion.
public DefinitionsChildId createSelfContainedVersion(DefinitionsChildId entryId) throws IOException {
ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(VersionSupport.getSelfContainedVersion(entryId));
if (!repository.exists(newServiceTemplateId)) {
repository.duplicate(entryId, newServiceTemplateId);
TServiceTemplate serviceTemplate = repository.getElement(newServiceTemplateId);
Collection<DefinitionsChildId> referencedElements = repository.getReferencedDefinitionsChildIds(newServiceTemplateId);
for (DefinitionsChildId elementId : referencedElements) {
if (elementId instanceof NodeTypeId) {
Collection<NodeTypeImplementationId> nodeTypeImplementationIds = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, elementId.getQName());
if (nodeTypeImplementationIds.stream().noneMatch(DefinitionsChildId::isSelfContained)) {
// self-contained element does not exist yet!
List<TNodeTypeImplementation> nodeTypeImplementations = nodeTypeImplementationIds.stream().map(repository::getElement).filter(element -> element.getImplementationArtifacts() != null).collect(Collectors.toList());
for (TNodeTypeImplementation impl : nodeTypeImplementations) {
Optional<SelfContainmentPlugin> nodeTypeBasedPlugin = this.selfContainmentPlugins.stream().filter(plugin -> plugin.canHandleNodeType(elementId.getQName(), repository)).findFirst();
if (nodeTypeBasedPlugin.isPresent()) {
NodeTypeImplementationId selfContainedNodeTypeImpl = getSelfContainedNodeTypeImplId(impl);
try {
repository.duplicate(new NodeTypeImplementationId(impl.getTargetNamespace(), impl.getIdFromIdOrNameField(), false), selfContainedNodeTypeImpl);
TNodeTypeImplementation selfContained = this.repository.getElement(selfContainedNodeTypeImpl);
nodeTypeBasedPlugin.get().downloadDependenciesBasedOnNodeType(selfContained, this.repository);
repository.setElement(selfContainedNodeTypeImpl, selfContained);
} catch (IOException e) {
logger.error("While creating self-contained Node Type Implementation", e);
}
} else if (impl.getImplementationArtifacts() != null) {
createSelfContainedNodeTypeImplementation(impl);
}
}
}
} else if (elementId instanceof ArtifactTemplateId) {
if (serviceTemplate.getTopologyTemplate() != null) {
TArtifactTemplate artifactTemplate = repository.getElement(elementId);
SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = this.downloadArtifacts(elementId.getQName(), artifactTemplate.getType());
if (generatedArtifacts != null && generatedArtifacts.selfContainedArtifactQName != null) {
// first, we need to identify the element that is referencing the artifact
serviceTemplate.getTopologyTemplate().getNodeTemplates().stream().map(TNodeTemplate::getDeploymentArtifacts).filter(Objects::nonNull).filter(daList -> daList.stream().anyMatch(da -> da.getArtifactRef() != null && da.getArtifactRef().equals(elementId.getQName()))).flatMap(Collection::stream).forEach(da -> da.setArtifactRef(generatedArtifacts.selfContainedArtifactQName));
}
}
}
}
repository.setElement(newServiceTemplateId, serviceTemplate);
} else {
logger.info("Self-contained version already exists! '{}'", newServiceTemplateId.getQName());
}
return newServiceTemplateId;
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class BackendUtils method getArtifactTemplatesOfReferencedDeploymentArtifacts.
public static Collection<QName> getArtifactTemplatesOfReferencedDeploymentArtifacts(TNodeTemplate nodeTemplate, IRepository repo) {
// DAs may be assigned directly to a node template
Collection<QName> allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(nodeTemplate.getDeploymentArtifacts());
List<QName> list = new ArrayList<>(allReferencedArtifactTemplates);
// DAs may be assigned via node type implementations
QName nodeTypeQName = nodeTemplate.getType();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = repo.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
List<TDeploymentArtifact> deploymentArtifacts = repo.getElement(nodeTypeImplementationId).getDeploymentArtifacts();
allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(deploymentArtifacts);
list.addAll(allReferencedArtifactTemplates);
}
return list;
}
Aggregations