use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionWithNonEditableFlag.
@Test
public void getVersionWithNonEditableFlag() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
versions.forEach(wineryVersion -> assertFalse(wineryVersion.isEditable()));
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ToscaGraphIsomorphismTest method testServiceTemplateComplianceRuleChecker.
@Test
public void testServiceTemplateComplianceRuleChecker() throws Exception {
this.setRevisionTo("origin/plain");
HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE);
ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test2"));
ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test3"));
// create NodeType
NodeTypeId nodeTypeIdA = createNodeTypeId("IDA");
NodeTypeId nodeTypeIdB = createNodeTypeId("IDB");
NodeTypeId nodeTypeIdC = createNodeTypeId("IDC");
NodeTypeId nodeTypeIdD = createNodeTypeId("IDD");
TNodeType nodeTypeA = createTNodeType(nodeTypeIdA);
allEntities.put(nodeTypeIdA, nodeTypeA);
TNodeType nodeTypeB = createTNodeType(nodeTypeIdB);
setDerivedFrom(nodeTypeIdA, nodeTypeB);
allEntities.put(nodeTypeIdB, nodeTypeB);
TNodeType nodeTypeC = createTNodeType(nodeTypeIdC);
setDerivedFrom(nodeTypeIdA, nodeTypeC);
allEntities.put(nodeTypeIdC, nodeTypeC);
TNodeType nodeTypeD = createTNodeType(nodeTypeIdD);
allEntities.put(nodeTypeIdD, nodeTypeD);
TNodeTemplate ruleOneIdentifier = createTNodeTemplate("R1_I", nodeTypeIdA);
TNodeTemplate ruleOneRequiredStructure = createTNodeTemplate("R1_RS", nodeTypeIdB);
TNodeTemplate ruleTwoIdentifier = createTNodeTemplate("R2_I", nodeTypeIdA);
TNodeTemplate ruleTwoRequiredStructure = createTNodeTemplate("R2_RS", nodeTypeIdC);
TNodeTemplate ruleThreeIdentifier = createTNodeTemplate("R3_I", nodeTypeIdA);
TNodeTemplate ruleThreeRequiredStructure = createTNodeTemplate("R3_RS", nodeTypeIdD);
TNodeTemplate serviceTemplateTopology = createTNodeTemplate("ST", nodeTypeIdB);
// satisfied
OTComplianceRule ruleOne = createTComplianceRule(crId1);
ruleOne.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleOneIdentifier), newArrayList()));
ruleOne.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleOneRequiredStructure), newArrayList()));
allEntities.put(crId1, ruleOne);
// unsatisfied
OTComplianceRule ruleTwo = createTComplianceRule(crId2);
ruleTwo.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleTwoIdentifier), newArrayList()));
ruleTwo.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleTwoRequiredStructure), newArrayList()));
allEntities.put(crId2, ruleTwo);
// invalid rule
OTComplianceRule ruleThree = createTComplianceRule(crId3);
ruleThree.setIdentifier(createTTopologyTemplate(Arrays.asList(ruleThreeIdentifier), newArrayList()));
ruleThree.setRequiredStructure(createTTopologyTemplate(Arrays.asList(ruleThreeRequiredStructure), newArrayList()));
allEntities.put(crId3, ruleThree);
tServiceTemplate.setTopologyTemplate(createTTopologyTemplate(Arrays.asList(serviceTemplateTopology), newArrayList()));
persist(allEntities);
ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().count());
assertEquals(3, checker.getRuleIds(tServiceTemplate).stream().filter(id -> id.getQName().getLocalPart().matches("test1|test2|test3")).count());
ServiceTemplateCheckingResult serviceTemplateCheckingResult = checker.checkComplianceRules();
assertEquals(1, serviceTemplateCheckingResult.getSatisfied().size());
assertEquals(1, serviceTemplateCheckingResult.getUnsatisfied().size());
assertEquals(1, serviceTemplateCheckingResult.getException().size());
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(ServiceTemplateCheckingResult.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(serviceTemplateCheckingResult, sw);
System.out.println(sw.toString());
} catch (JAXBException e) {
e.printStackTrace();
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ToscaGraphIsomorphismTest method testTOSCAComplianceRuleMatcher.
@Test
public void testTOSCAComplianceRuleMatcher() throws IOException {
// TNodeTemplateMatching
// by TNodeType
HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
NodeTypeId nodeTypeIdAbstractA = createNodeTypeId("AbstractA");
allEntities.put(nodeTypeIdAbstractA, createTNodeType(nodeTypeIdAbstractA));
NodeTypeId nodeTypeIdAbstractB = createNodeTypeId("AbstractB");
allEntities.put(nodeTypeIdAbstractB, createTNodeType(nodeTypeIdAbstractB));
NodeTypeId nodeTypeIdActualA = createNodeTypeId("ActualA");
TNodeType actualA = createTNodeType(nodeTypeIdActualA);
setDerivedFrom(nodeTypeIdAbstractA, actualA);
allEntities.put(nodeTypeIdActualA, actualA);
NodeTypeId nodeTypeIdActualB = createNodeTypeId("ActualB");
TNodeType actualB = createTNodeType(nodeTypeIdActualB);
setDerivedFrom(nodeTypeIdAbstractB, actualB);
allEntities.put(nodeTypeIdActualB, actualB);
NodeTypeId nodeTypeIdActualB2 = createNodeTypeId("ActualB2");
TNodeType actualB2 = createTNodeType(nodeTypeIdActualB2);
setDerivedFrom(nodeTypeIdAbstractB, actualB2);
allEntities.put(nodeTypeIdActualB2, actualB2);
persist(allEntities);
TNodeTemplate nodeTemplate1 = createTNodeTemplate("01", nodeTypeIdAbstractA);
TNodeTemplate nodeTemplate2 = createTNodeTemplate("02", nodeTypeIdAbstractB);
TNodeTemplate nodeTemplate3 = createTNodeTemplate("03", nodeTypeIdActualA);
TNodeTemplate nodeTemplate4 = createTNodeTemplate("04", nodeTypeIdActualB);
TNodeTemplate nodeTemplate5 = createTNodeTemplate("05", nodeTypeIdActualB);
TNodeTemplate nodeTemplate6 = createTNodeTemplate("06", nodeTypeIdActualB2);
ToscaComplianceRuleMatcher matcher = new ToscaComplianceRuleMatcher();
// same type
assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate1), createTOSCANodeOnlyTypes(nodeTemplate1)));
// "01" is supertype of "03" -> match
assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate1), createTOSCANodeOnlyTypes(nodeTemplate3)));
// "03" is subtype of "01" -> match
assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate3), createTOSCANodeOnlyTypes(nodeTemplate1)));
// different types
assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate4), createTOSCANodeOnlyTypes(nodeTemplate3)));
// different types
assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate3), createTOSCANodeOnlyTypes(nodeTemplate2)));
// same type
assertTrue(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate5), createTOSCANodeOnlyTypes(nodeTemplate4)));
// different types derived from same type
assertFalse(matcher.isTEntityTypesCompatible(createTOSCANodeOnlyTypes(nodeTemplate5), createTOSCANodeOnlyTypes(nodeTemplate6)));
// by TEntityTemplate.Properties
ToscaModelPropertiesBuilder bldrLeft = new ToscaModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "TestProperties");
ToscaModelPropertiesBuilder bldrRight = new ToscaModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "TestProperties");
// test by values
// test simple matching
bldrLeft.addProperty("A", "Something");
bldrRight.addProperty("A", "Something");
assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
bldrRight.addProperty("A", "SomeOtherThing");
assertFalse(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
// testRegex
bldrLeft.addProperty("A", ".*");
assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
// test by property set
// left subset of right
bldrLeft.addProperty("B", ".*");
bldrRight.addProperty("B", ".*");
bldrRight.addProperty("C", ".*");
assertTrue(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrLeft), createTOSCANodeOnlyProperties(bldrRight)));
// other way round
assertFalse(matcher.isPropertiesCompatible(createTOSCANodeOnlyProperties(bldrRight), createTOSCANodeOnlyProperties(bldrLeft)));
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtils method getType.
/**
* This is a quick helper method. The code should be refactored to use HasType on the element directly instead of
* going through the resource. The method was implemented, because it is not that easy to get the id of the element
* belonging to a resource.
*
* @param res a resource, where the associated element has a type. Example: EntityTypeImplementationResource
* @return the QName of the associated type
*/
public static QName getType(IPersistable res) {
DefinitionsChildId id = (DefinitionsChildId) res.getRepositoryFileReference().getParent();
final HasType element = (HasType) RepositoryFactory.getRepository().getDefinitions(id).getElement();
return element.getTypeAsQName();
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtils method releaseVersion.
public static Response releaseVersion(DefinitionsChildId releasableComponent) {
ResourceResult result = new ResourceResult();
final IRepository repository = RepositoryFactory.getRepository();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasableComponent, repository);
if (version.isReleasable()) {
if (repository instanceof GitBasedRepository) {
try {
freezeVersion(releasableComponent);
version.setWorkInProgressVersion(0);
String newId = releasableComponent.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(releasableComponent.getClass(), releasableComponent.getNamespace().getDecoded(), newId, false);
result = duplicate(releasableComponent, newComponent);
BackendUtils.commit(newComponent, "Release", repository);
} catch (GitAPIException e) {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.INTERNAL_SERVER_ERROR);
}
} else {
result.setStatus(Status.BAD_REQUEST);
}
return result.getResponse();
}
Aggregations