use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel 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.tosca.extensions.OTTopologyFragmentRefinementModel in project winery by eclipse.
the class PermutationGeneratorTest method checkSimpleMutabilityTest.
@Test
void checkSimpleMutabilityTest() {
setUp();
PermutationGenerator permutationGenerator = new PermutationGenerator();
OTTopologyFragmentRefinementModel refinementModel = (OTTopologyFragmentRefinementModel) candidateForTopology3WithDa.getRefinementModel();
assertTrue(permutationGenerator.checkMutability(refinementModel));
List<OTStringList> options = refinementModel.getPermutationOptions();
assertNotNull(options);
assertEquals(2, options.size());
options.forEach(permutationOption -> assertEquals(1, permutationOption.getValues().size()));
}
use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel in project winery by eclipse.
the class PermutationGenerator method chekMutabilityOfDetectorRelations.
private List<String> chekMutabilityOfDetectorRelations(OTTopologyFragmentRefinementModel refinementModel) {
List<String> unmappableRelationIds = new ArrayList<>();
// try to generate permutation maps.
for (TNodeTemplate detectorNode : refinementModel.getDetector().getNodeTemplates()) {
List<TRelationshipTemplate> unMappableRelations = ModelUtilities.getIncomingRelationshipTemplates(refinementModel.getDetector(), detectorNode).stream().filter(relation -> !permutabilityMappingExistsForDetectorElement(relation, refinementModel)).collect(Collectors.toList());
for (TRelationshipTemplate unmappable : unMappableRelations) {
logger.info("Checking unmapped relation \"{}\"", unmappable.getId());
// If the relation exists between two components in a component set we ignore it, as there is no
// case in which the relation has to be redirected while creating a permutation.
boolean unmappableRelationExists = refinementModel.getComponentSets().stream().noneMatch(componentSet -> componentSet.getValues().containsAll(Arrays.asList(unmappable.getSourceElement().getRef().getId(), unmappable.getTargetElement().getRef().getId())));
if (unmappableRelationExists) {
// If there is only one permutation mapping sourcing from the current detector node,
// the relation can be redirected directly to the corresponding refinement node.
// If there are multiple permutations mappings sourcing from the relation's source detector node,
// do crazy shit: If the corresponding refinement nodes of the relation's source have relations
// that point to the same node that can be mapped to the current detector node (except for
// relations among each other), the relation can be redirected to this node.
TNodeTemplate source = (TNodeTemplate) unmappable.getSourceElement().getRef();
List<TNodeTemplate> nodesTheSourceRefinesTo = getStayAndPermutationMappings(refinementModel).stream().filter(pm -> pm.getDetectorElement().getId().equals(source.getId())).map(OTPrmMapping::getRefinementElement).filter(element -> element instanceof TNodeTemplate).map(element -> (TNodeTemplate) element).distinct().collect(Collectors.toList());
Set<TNodeTemplate> nodesTheRefinementNodesAreDependingOn = new HashSet<>();
nodesTheSourceRefinesTo.forEach(node -> nodesTheRefinementNodesAreDependingOn.addAll(ModelUtilities.getOutgoingRelationshipTemplates(refinementModel.getRefinementStructure(), node).stream().map(outgoing -> outgoing.getTargetElement().getRef()).filter(target -> target instanceof TNodeTemplate).map(target -> (TNodeTemplate) target).filter(target -> refinementModel.getPermutationMappings().stream().anyMatch(pm -> pm.getRefinementElement().getId().equals(target.getId()) && pm.getDetectorElement().getId().equals(detectorNode.getId()))).collect(Collectors.toList())));
// respective target of the relation automatically.
if (nodesTheRefinementNodesAreDependingOn.size() == 1) {
TNodeTemplate target = nodesTheRefinementNodesAreDependingOn.iterator().next();
logger.info("Found possibility to redirect relation \"{}\" to refinement node \"{}\"", unmappable.getId(), target.getId());
addMutabilityMapping(unmappable, target, refinementModel);
unmappableRelationExists = false;
}
} else {
logger.info("Relation \"{}\" is part of a component set", unmappable.getId());
}
if (unmappableRelationExists) {
unmappableRelationIds.add(unmappable.getId());
}
}
}
return unmappableRelationIds;
}
use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel in project winery by eclipse.
the class PermutationGeneratorTestWithGitBackedRepository method simplePrmTest.
@Test
void simplePrmTest() throws Exception {
this.setRevisionTo("origin/plain");
OTPatternRefinementModel refinementModel = generatePrmWithoutPermutationMaps();
PatternRefinementModelId id = new PatternRefinementModelId(refinementModel.getTargetNamespace(), refinementModel.getIdFromIdOrNameField(), false);
RepositoryFactory.getRepository().setElement(id, refinementModel);
PermutationGenerator generator = new PermutationGenerator();
Map<String, OTTopologyFragmentRefinementModel> permutations = generator.generatePermutations(refinementModel);
assertEquals(6, permutations.size());
OTTopologyFragmentRefinementModel permutation_1 = permutations.get("SimplePrm_permutation-1-w1-wip1");
assertNotNull(permutation_1);
assertEquals(4, permutation_1.getDetector().getNodeTemplates().size());
assertEquals(4, permutation_1.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_2 = permutations.get("SimplePrm_permutation-2-w1-wip1");
assertNotNull(permutation_2);
assertEquals(3, permutation_2.getDetector().getNodeTemplates().size());
assertEquals(2, permutation_2.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_3 = permutations.get("SimplePrm_permutation-3-w1-wip1");
assertNotNull(permutation_3);
assertEquals(4, permutation_3.getDetector().getNodeTemplates().size());
assertEquals(3, permutation_3.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_1_2 = permutations.get("SimplePrm_permutation-1-2-w1-wip1");
assertNotNull(permutation_1_2);
assertEquals(4, permutation_1_2.getDetector().getNodeTemplates().size());
assertEquals(4, permutation_1_2.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_1_3 = permutations.get("SimplePrm_permutation-1-3-w1-wip1");
assertNotNull(permutation_1_3);
assertEquals(5, permutation_1_3.getDetector().getNodeTemplates().size());
assertEquals(5, permutation_1_3.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_2_3 = permutations.get("SimplePrm_permutation-2-3-w1-wip1");
assertNotNull(permutation_2_3);
assertEquals(4, permutation_2_3.getDetector().getNodeTemplates().size());
assertEquals(3, permutation_2_3.getDetector().getRelationshipTemplates().size());
}
use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel in project winery by eclipse.
the class PatternDetectionUtilsTest method toPdrms.
@Test
public void toPdrms() {
List<OTRefinementModel> refinementModels = new ArrayList<>();
refinementModels.add(new OTTestRefinementModel());
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
refinementModels.add(new OTTopologyFragmentRefinementModel());
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
OTPatternRefinementModel prm = new OTPatternRefinementModel();
refinementModels.add(prm);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
prm.setIsPdrm(true);
refinementModels.add(prm);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 1);
prm.setIsPdrm(false);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
}
Aggregations