use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added<
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
List<TPolicy> policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
if (topology != null) {
if (Objects.nonNull(topology.getPolicies())) {
topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
QName type = p.getPolicyType();
PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
ids.add(policyTypeIdId);
});
}
for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through policies
List<TPolicy> policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
// Crawl RequirementTypes and Capabilities for their references
getReferencedRequirementTypeIds(ids, n);
getCapabilitiesReferences(ids, n);
// TODO: this information is collected differently for YAML and XML modes
// crawl through deployment artifacts
List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
if (da.getArtifactType() != null) {
// This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
// expects an empty artifactType and thus it may be null.
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
if (da.getArtifactRef() != null) {
ids.add(new ArtifactTemplateId(da.getArtifactRef()));
}
}
}
// Store all referenced artifact types
List<TArtifact> artifacts = n.getArtifacts();
if (Objects.nonNull(artifacts)) {
artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
}
TNodeType nodeType = this.getElement(new NodeTypeId(qname));
if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
if (Objects.nonNull(iDef.getType())) {
ids.add(new InterfaceTypeId(iDef.getType()));
}
});
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ConsistencyChecker method checkServiceTemplate.
private void checkServiceTemplate(ServiceTemplateId id) {
TServiceTemplate serviceTemplate;
try {
serviceTemplate = configuration.getRepository().getElement(id);
} catch (IllegalStateException e) {
LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e);
printAndAddError(id, "Reading error " + e.getMessage());
return;
}
if (serviceTemplate.getTopologyTemplate() == null) {
return;
}
@NonNull final List<TNodeTemplate> nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
for (TNodeTemplate nodeTemplate : nodeTemplates) {
NodeTypeId nodeTypeId = new NodeTypeId(nodeTemplate.getType());
TNodeType nodeType;
try {
nodeType = configuration.getRepository().getElement(nodeTypeId);
} catch (IllegalStateException e) {
LOGGER.debug("Illegal State Exception during reading of id {}", nodeTypeId.toReadableString(), e);
printAndAddError(nodeTypeId, "Reading error " + e.getMessage());
return;
}
final WinerysPropertiesDefinition winerysPropertiesDefinition = nodeType.getWinerysPropertiesDefinition();
if (winerysPropertiesDefinition != null) {
List<PropertyDefinitionKV> list = winerysPropertiesDefinition.getPropertyDefinitions();
if (list != null) {
// iterate on all defined properties
for (PropertyDefinitionKV propdef : list) {
String key = propdef.getKey();
if (key == null) {
printAndAddError(id, "key is null");
continue;
}
// assign value, but change "null" to "" if no property is defined
final Map<String, String> propertiesKV = ModelUtilities.getPropertiesKV(nodeTemplate);
if (propertiesKV == null) {
printAndAddError(id, "propertiesKV of node template " + nodeTemplate.getId() + " is null");
}
}
}
}
}
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class VersionSupport method getDefinitionInTheGivenVersion.
public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
if (childId.getVersion().compareTo(otherVersion) == 0) {
return childId;
}
String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
if (childId instanceof RelationshipTypeImplementationId) {
return new RelationshipTypeImplementationId(qName);
} else if (childId instanceof NodeTypeImplementationId) {
return new NodeTypeImplementationId(qName);
} else if (childId instanceof RequirementTypeId) {
return new RequirementTypeId(qName);
} else if (childId instanceof NodeTypeId) {
return new NodeTypeId(qName);
} else if (childId instanceof RelationshipTypeId) {
return new RelationshipTypeId(qName);
} else if (childId instanceof CapabilityTypeId) {
return new CapabilityTypeId(qName);
} else if (childId instanceof ArtifactTypeId) {
return new ArtifactTypeId(qName);
} else if (childId instanceof PolicyTypeId) {
return new PolicyTypeId(qName);
} else if (childId instanceof PolicyTemplateId) {
return new PolicyTemplateId(qName);
} else if (childId instanceof ServiceTemplateId) {
return new ServiceTemplateId(qName);
} else if (childId instanceof ArtifactTemplateId) {
return new ArtifactTemplateId(qName);
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method renameAllVersionNamespacesOfOneComponent.
@Test
public void renameAllVersionNamespacesOfOneComponent() throws Exception {
this.setRevisionTo("origin/plain");
String version = "_0.3.4-w3";
String name = "NodeTypeWith5Versions";
String oldNamespace = "http://opentosca.org/nodetypes";
String newNamespace = "http://example.org/nodetypes";
DefinitionsChildId oldId = new NodeTypeId(oldNamespace, name + version, false);
DefinitionsChildId newId = new NodeTypeId(newNamespace, name + version, false);
Response response = RestUtils.renameAllVersionsOfOneDefinition(oldId, newId);
String expectedEntity = "http://localhost:8080/winery/nodetypes/" + EncodingUtil.URLencode(EncodingUtil.URLencode(newNamespace)) + "/" + name + version + "/";
assertEquals(201, response.getStatus());
assertEquals(expectedEntity, response.getEntity());
assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(oldId, repository).size());
assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(newId, repository).size());
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method releaseComponentWhichDoesNotHaveChanges.
@Test
public void releaseComponentWhichDoesNotHaveChanges() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
DefinitionsChildId releasedId = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2", false);
int formerVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository).size();
Response response = RestUtils.releaseVersion(id);
int finalVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(releasedId, repository).size();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasedId, repository);
assertEquals(201, response.getStatus());
assertEquals(formerVersionCount + 1, finalVersionCount);
assertFalse(version.isReleasable());
assertEquals(0, version.getWorkInProgressVersion());
}
Aggregations