use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final TDefinitions definitions = createWrapperDefinitions(id, repository);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof DataTypeId) {
element = new TDataType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof ComplianceRuleId) {
element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
} else if (id instanceof PatternRefinementModelId) {
element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TopologyFragmentRefinementModelId) {
element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TestRefinementModelId) {
element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
} else if (id instanceof InterfaceTypeId) {
element = new TInterfaceType();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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.ServiceTemplateId 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");
}
}
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResourceTest method farmTopologyTemplateCanBeCreatedAsJson.
@Test
public void farmTopologyTemplateCanBeCreatedAsJson() throws Exception {
this.setRevisionTo("1e2054315f18e80c466c26e6918d6506ce53f7f7");
// Quick hack to ensure that the service template containing the topology template exists
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/fruits", "farm", false);
RepositoryFactory.getRepository().flagAsExisting(id);
this.assertPut("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Ffruits/farm/topologytemplate/", "servicetemplates/farm_topologytemplate.json");
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class RestUtils method getCsarOfSelectedResource.
/**
* @param options the set of options that are applicable for exporting a csar
*/
public static Response getCsarOfSelectedResource(final AbstractComponentInstanceResource resource, CsarExportOptions options) {
long start = System.currentTimeMillis();
final CsarExporter exporter = new CsarExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
// check which options are chosen
if (options.isAddToProvenance()) {
// We wait for the accountability layer to confirm the transaction
String result = exporter.writeCsarAndSaveManifestInProvenanceLayer(resource.getId(), output).get();
LOGGER.debug("Stored state in accountability layer in transaction " + result);
} else if (options.isIncludeDependencies() && resource.getId() instanceof ServiceTemplateId) {
SelfContainmentPackager packager = new SelfContainmentPackager(RepositoryFactory.getRepository());
DefinitionsChildId selfContainedVersion = packager.createSelfContainedVersion(resource.getId());
exporter.writeSelfContainedCsar(RepositoryFactory.getRepository(), selfContainedVersion, output, exportConfiguration);
} else {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
}
long duration = (System.currentTimeMillis() - start) / 1000;
LOGGER.debug("CSAR export lasted {} min {} s", (int) duration / 60, duration % 60);
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Aggregations