test_class.file: org.eclipse.winery.model.adaptation/src/test/java/org/eclipse/winery/model/adaptation/substitution/refinement/PermutationGeneratorTest.java
test_class.identifier: PermutationGeneratorTest
test_class.superclass: extends AbstractRefinementTest
test_case.body: @Test
      void checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping() {
          OTPatternRefinementModel refinementModel = generatePrmWithComplexRelationMaps();
  
          PermutationGenerator permutationGenerator = new PermutationGenerator();
          assertTrue(permutationGenerator.checkMutability(refinementModel));
  
          assertEquals(2, refinementModel.getPermutationOptions().size());
  
          List<OTPermutationMapping> mappings = refinementModel.getPermutationMappings();
          assertEquals(5, mappings.size());
          assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
              permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("11")
          ));
          assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
              permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("12")
          ));
          assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
              permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("13")
          ));
          assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
              permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("14")
          ));
          assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
              permutationMap.getDetectorElement().getId().equals("1--2") && permutationMap.getRefinementElement().getId().equals("13")
          ));
      }
test_case.class_method_signature: PermutationGeneratorTest.checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping()
test_case.full_signature: @Test void checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping()
test_case.identifier: checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping
test_case.invocations: generatePrmWithComplexRelationMaps assertTrue checkMutability assertEquals size getPermutationOptions getPermutationMappings assertEquals size assertTrue removeIf getPermutationMappings equals getId getDetectorElement equals getId getRefinementElement assertTrue removeIf getPermutationMappings equals getId getDetectorElement equals getId getRefinementElement assertTrue removeIf getPermutationMappings equals getId getDetectorElement equals getId getRefinementElement assertTrue removeIf getPermutationMappings equals getId getDetectorElement equals getId getRefinementElement assertTrue removeIf getPermutationMappings equals getId getDetectorElement equals getId getRefinementElement
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping()
focal_class.declarator: logger = LoggerFactory.getLogger(PermutationGenerator.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(PermutationGenerator.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: relationshipTypes = new HashMap<>()
focal_class.modifier: protected final
focal_class.original_string: protected final Map<QName, TRelationshipType> relationshipTypes = new HashMap<>();
focal_class.type: Map<QName, TRelationshipType>
focal_class.var_name: relationshipTypes
focal_class.declarator: nodeTypes = new HashMap<>()
focal_class.modifier: protected final
focal_class.original_string: protected final Map<QName, TNodeType> nodeTypes = new HashMap<>();
focal_class.type: Map<QName, TNodeType>
focal_class.var_name: nodeTypes
focal_class.declarator: errorMessage = "Permutations cannot be determined automatically! Reason: {}."
focal_class.modifier: protected final
focal_class.original_string: protected final String errorMessage = "Permutations cannot be determined automatically! Reason: {}.";
focal_class.type: String
focal_class.var_name: errorMessage
focal_class.declarator: mutabilityErrorReason = ""
focal_class.modifier: protected
focal_class.original_string: protected String mutabilityErrorReason = "";
focal_class.type: String
focal_class.var_name: mutabilityErrorReason
focal_class.file: org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/substitution/refinement/PermutationGenerator.java
focal_class.identifier: PermutationGenerator
focal_class.class_method_signature: PermutationGenerator.PermutationGenerator()
focal_class.full_signature: public  PermutationGenerator()
focal_class.identifier: PermutationGenerator
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  PermutationGenerator()
focal_class.class_method_signature: PermutationGenerator.checkMutability(OTTopologyFragmentRefinementModel refinementModel)
focal_class.full_signature: public boolean checkMutability(OTTopologyFragmentRefinementModel refinementModel)
focal_class.identifier: checkMutability
focal_class.modifiers: public
focal_class.parameters: (OTTopologyFragmentRefinementModel refinementModel)
focal_class.return: boolean
focal_class.signature: boolean checkMutability(OTTopologyFragmentRefinementModel refinementModel)
focal_class.class_method_signature: PermutationGenerator.checkComponentMutability(TNodeTemplate refinementNode,
                                            TNodeTemplate detectorNode,
                                            OTTopologyFragmentRefinementModel refinementModel)
focal_class.full_signature: private void checkComponentMutability(TNodeTemplate refinementNode,
                                            TNodeTemplate detectorNode,
                                            OTTopologyFragmentRefinementModel refinementModel)
focal_class.identifier: checkComponentMutability
focal_class.modifiers: private
focal_class.parameters: (TNodeTemplate refinementNode,
                                            TNodeTemplate detectorNode,
                                            OTTopologyFragmentRefinementModel refinementModel)
focal_class.return: void
focal_class.signature: void checkComponentMutability(TNodeTemplate refinementNode,
                                            TNodeTemplate detectorNode,
                                            OTTopologyFragmentRefinementModel refinementModel)
focal_class.class_method_signature: PermutationGenerator.chekMutabilityOfDetectorRelations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.full_signature: private List<String> chekMutabilityOfDetectorRelations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.identifier: chekMutabilityOfDetectorRelations
focal_class.modifiers: private
focal_class.parameters: (OTTopologyFragmentRefinementModel refinementModel)
focal_class.return: List<String>
focal_class.signature: List<String> chekMutabilityOfDetectorRelations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.class_method_signature: PermutationGenerator.generatePermutations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.full_signature: public Map<String, OTTopologyFragmentRefinementModel> generatePermutations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.identifier: generatePermutations
focal_class.modifiers: public
focal_class.parameters: (OTTopologyFragmentRefinementModel refinementModel)
focal_class.return: Map<String, OTTopologyFragmentRefinementModel>
focal_class.signature: Map<String, OTTopologyFragmentRefinementModel> generatePermutations(OTTopologyFragmentRefinementModel refinementModel)
focal_class.class_method_signature: PermutationGenerator.getMutabilityErrorReason()
focal_class.full_signature: public String getMutabilityErrorReason()
focal_class.identifier: getMutabilityErrorReason
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getMutabilityErrorReason()
focal_class.class_method_signature: PermutationGenerator.addNodeFromRefinementStructureToDetector(TNodeTemplate refinementElement,
                                                                     OTTopologyFragmentRefinementModel permutation,
                                                                     Map<String, String> alreadyAdded)
focal_class.full_signature: private TNodeTemplate addNodeFromRefinementStructureToDetector(TNodeTemplate refinementElement,
                                                                     OTTopologyFragmentRefinementModel permutation,
                                                                     Map<String, String> alreadyAdded)
focal_class.identifier: addNodeFromRefinementStructureToDetector
focal_class.modifiers: private
focal_class.parameters: (TNodeTemplate refinementElement,
                                                                     OTTopologyFragmentRefinementModel permutation,
                                                                     Map<String, String> alreadyAdded)
focal_class.return: TNodeTemplate
focal_class.signature: TNodeTemplate addNodeFromRefinementStructureToDetector(TNodeTemplate refinementElement,
                                                                     OTTopologyFragmentRefinementModel permutation,
                                                                     Map<String, String> alreadyAdded)
focal_method.body: public boolean checkMutability(OTTopologyFragmentRefinementModel refinementModel) {
          logger.info("Starting mutability check of {}", refinementModel.getIdFromIdOrNameField());
          this.mutabilityErrorReason = "";
  
          List<TNodeTemplate> detectorNodeTemplates = refinementModel.getDetector().getNodeTemplates();
          Set<TNodeTemplate> mutableNodes = detectorNodeTemplates.stream()
              .filter(nodeTemplate -> !isStayPlaceholder(nodeTemplate, refinementModel))
              .collect(Collectors.toSet());
  
          List<OTStringList> permutationOptions = new ArrayList<>();
          refinementModel.setPermutationOptions(permutationOptions);
          Sets.powerSet(mutableNodes).stream()
              .filter(set -> !(
                  set.size() == 0 || set.size() == mutableNodes.size()
              )).forEach(permutation -> permutationOptions.add(
              new OTStringList(
                  permutation.stream()
                      .map(HasId::getId)
                      .collect(Collectors.toList())
              )
          ));
  
          refinementModel.setComponentSets(new ArrayList<>());
  
          for (TNodeTemplate detectorNode : detectorNodeTemplates) {
              getAllMappingsForDetectorNode(detectorNode, refinementModel).stream()
                  .filter(mapping -> mapping.getRefinementElement() instanceof TNodeTemplate)
                  .map(mapping -> (TNodeTemplate) mapping.getRefinementElement())
                  .forEach(refinementNode ->
                      this.checkComponentMutability(refinementNode, detectorNode, refinementModel)
                  );
  
              ModelUtilities.getIncomingRelationshipTemplates(refinementModel.getDetector(), detectorNode)
                  .forEach(relation -> {
                      TNodeTemplate dependantNode = (TNodeTemplate) relation.getSourceElement().getRef();
                      if (refinementModel.getRelationMappings() != null) {
                          refinementModel.getRelationMappings().stream()
                              .filter(relMap -> relMap.getDetectorElement().equals(dependantNode))
                              .filter(relMap -> RefinementUtils.canRedirectRelation(relMap, relation, this.relationshipTypes, this.nodeTypes))
                              .findFirst()
                              .ifPresent(relMap ->
                                  addMutabilityMapping(relMap.getDetectorElement(), relMap.getRefinementElement(), refinementModel)
                              );
                      }
                  });
          }
  
          if (refinementModel.getPermutationMappings() == null) {
              this.mutabilityErrorReason = "No permutation mappings could be identified";
              logger.info(this.errorMessage, this.mutabilityErrorReason);
              return false;
          }
  
          List<String> unmappedDetectorNodes = refinementModel.getDetector().getNodeTemplates().stream()
              .filter(detectorNode -> !isStayPlaceholder(detectorNode, refinementModel))
              .filter(detectorNode -> !permutabilityMappingExistsForDetectorElement(detectorNode, refinementModel))
              .map(HasId::getId)
              .collect(Collectors.toList());
  
          if (unmappedDetectorNodes.size() > 0) {
              this.mutabilityErrorReason = "There are detector nodes which could not be mapped to a refinement node: "
                  + String.join(", ", unmappedDetectorNodes);
              logger.info(this.errorMessage, this.mutabilityErrorReason);
              return false;
          }
  
          List<String> unmappedRefinementNodes = refinementModel.getRefinementStructure().getNodeTemplates().stream()
              .filter(refinementNode -> !isStayingRefinementElement(refinementNode, refinementModel))
              .filter(refinementNode -> !permutabilityMappingExistsForRefinementNode(refinementNode, refinementModel))
              .map(HasId::getId)
              .collect(Collectors.toList());
  
          if (unmappedRefinementNodes.size() > 0) {
              this.mutabilityErrorReason = "There are refinement nodes which could not be mapped to a detector node: "
                  + String.join(", ", unmappedRefinementNodes);
              logger.info(this.errorMessage, this.mutabilityErrorReason);
              return false;
          }
  
          List<String> unmappableRelationIds = chekMutabilityOfDetectorRelations(refinementModel);
  
          if (unmappableRelationIds.size() > 0) {
              this.mutabilityErrorReason = "There are relations that cannot be redirected during the generation: "
                  + String.join(", ", unmappableRelationIds);
              logger.info(this.errorMessage, this.mutabilityErrorReason);
              return false;
          }
  
          return true;
      }
focal_method.class_method_signature: PermutationGenerator.checkMutability(OTTopologyFragmentRefinementModel refinementModel)
focal_method.full_signature: public boolean checkMutability(OTTopologyFragmentRefinementModel refinementModel)
focal_method.identifier: checkMutability
focal_method.invocations: info getIdFromIdOrNameField getNodeTemplates getDetector collect filter stream isStayPlaceholder toSet setPermutationOptions forEach filter stream powerSet size size size add collect map stream toList setComponentSets forEach map filter stream getAllMappingsForDetectorNode getRefinementElement getRefinementElement checkComponentMutability forEach getIncomingRelationshipTemplates getDetector getRef getSourceElement getRelationMappings ifPresent findFirst filter filter stream getRelationMappings equals getDetectorElement canRedirectRelation addMutabilityMapping getDetectorElement getRefinementElement getPermutationMappings info collect map filter filter stream getNodeTemplates getDetector isStayPlaceholder permutabilityMappingExistsForDetectorElement toList size join info collect map filter filter stream getNodeTemplates getRefinementStructure isStayingRefinementElement permutabilityMappingExistsForRefinementNode toList size join info chekMutabilityOfDetectorRelations size join info
focal_method.modifiers: public
focal_method.parameters: (OTTopologyFragmentRefinementModel refinementModel)
focal_method.return: boolean
focal_method.signature: boolean checkMutability(OTTopologyFragmentRefinementModel refinementModel)