use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId 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<>();
OTComplianceRule complianceRule = this.getElement(id);
// TODO extend to required Structure
if (complianceRule.getIdentifier() != null) {
for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
getReferencedRequirementTypeIds(ids, n);
getCapabilitiesReferences(ids, n);
// 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);
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// There may be multiple DAs/IAs referencing the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
final TNodeTypeImplementation element = this.getElement(id);
// DAs
List<TDeploymentArtifact> deploymentArtifacts = element.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
QName qname;
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
}
// IAs
return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(PolicyTemplateId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
final TPolicyTemplate element = this.getElement(id);
ids.add(new PolicyTypeId(element.getType()));
return ids;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ConsistencyChecker method checkAllDefinitions.
private void checkAllDefinitions(IRepository repository) {
final Path tempCsar;
try {
tempCsar = Files.createTempFile("Export", ".csar");
} catch (IOException e) {
LOGGER.debug("Could not create temp CSAR file", e);
errorCollector.error("Could not create temp CSAR file");
return;
}
float elementsChecked = 0;
int size = allDefinitionsChildIds.size();
Map<QName, TDefinitions> allQNameToDefinitionMapping = repository.getAllQNameToDefinitionsMapping();
for (DefinitionsChildId id : allDefinitionsChildIds) {
float progress = ++elementsChecked / size;
if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) {
progressListener.updateProgress(progress, id.toReadableString());
} else {
progressListener.updateProgress(progress);
}
checkId(id, allQNameToDefinitionMapping);
checkXmlSchemaValidation(id);
checkReferencedQNames(id, allQNameToDefinitionMapping);
checkPropertiesValidation(id);
if (id instanceof ServiceTemplateId) {
checkServiceTemplate((ServiceTemplateId) id);
}
if (configuration.isCheckDocumentation()) {
checkDocumentation(id);
}
checkPlainConformance(id, tempCsar);
checkCsar(id, tempCsar, repository);
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ConsistencyChecker method checkNamespaceUri.
public void checkNamespaceUri(@NonNull DefinitionsChildId id) {
Objects.requireNonNull(id);
String uriStr = id.getNamespace().getDecoded();
if (!uriStr.trim().equals(uriStr)) {
printAndAddError(id, "Namespace starts or ends with white spaces");
}
URI uri;
try {
uri = new URI(uriStr);
} catch (URISyntaxException e) {
LOGGER.debug("Invalid URI", e);
printAndAddError(id, "Invalid URI: " + e.getMessage());
return;
}
if (!uri.isAbsolute()) {
printAndAddError(id, "URI is relative");
}
if ((uriStr.startsWith("http://www.opentosca.org/") && (!uriStr.toLowerCase().equals(uriStr)))) {
// URI is not lowercase
// There are some special URIs, which are OK
String[] splitUri = uriStr.split("/");
String lastElement = splitUri[splitUri.length - 1];
String uriStrWithoutLastElement = uriStr.substring(0, (uriStr.length() - lastElement.length()));
if (!(id.getXmlId().toString().startsWith(lastElement)) || (!uriStrWithoutLastElement.toLowerCase().equals(uriStrWithoutLastElement))) {
printAndAddError(id, "opentosca URI is not lowercase");
}
}
if (uriStr.endsWith("/")) {
printAndAddError(id, "URI ends with a slash");
}
if (uriStr.contains(ARTEFACT_BE)) {
printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English");
}
// We could just check OpenTOSCA namespace rule examples. However, this would be too strict
// Here, the idea is to check whether a string of another (!) id class appers in the namespace
// If this is the case, the namespace is not consistent
// For instance, a node type residing in the namespace: http://servicetemplates.example.org should not exist.
boolean namespaceUriContainsDifferentType = DefinitionsChildId.ALL_TOSCA_COMPONENT_ID_CLASSES.stream().filter(definitionsChildIdClass -> !definitionsChildIdClass.isAssignableFrom(id.getClass())).flatMap(definitionsChildIdClass -> {
final String lowerCaseIdClass = IdUtil.getTypeForComponentId(definitionsChildIdClass).toLowerCase();
return Stream.of(lowerCaseIdClass + "s", lowerCaseIdClass + "/");
}).anyMatch(uriStr::contains);
if (namespaceUriContainsDifferentType) {
if ((id instanceof ServiceTemplateId) && (id.getNamespace().getDecoded().contains("compliance"))) {
// special case, because TComplianceRule models a service template, but Compliance Rules are treated as Service Template during modeling
// example: class org.eclipse.winery.common.ids.definitions.ServiceTemplateId / {http://www.compliance.opentosca.org/compliancerules}Satisfied_Compliance_Rule_Example_w1
printAndAddWarning(id, "Cannot perform checks for compliance rules...");
} else {
printAndAddError(id, "Namespace URI contains tosca definitions name from other type. E.g., Namespace is ...servicetemplates..., but the type is an artifact template");
}
}
}
Aggregations