Program: 88415
Project: 88415
Buggy source:
@Override public void run(ProgressStatus progressStatus){
  progressStatus.init("String_Node_Str",6);
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  Map<String,Pair<ObjectNode,InstanceSpecification>> instanceSpecificationMap=new LinkedHashMap<>();
  Map<String,Pair<ObjectNode,Slot>> slotMap=new LinkedHashMap<>();
  Map<String,ViewMapping> viewMap=new LinkedHashMap<>();
  for (  Element rootView : rootViews) {
    if (MDUtils.isDeveloperMode()) {
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(1);
    DocumentValidator dv=new DocumentValidator(rootView);
    dv.validateDocument();
    if (dv.isFatal()) {
      dv.printErrors(false);
      return;
    }
    DocumentGenerator dg=new DocumentGenerator(rootView,dv,null,false);
    Document dge=dg.parseDocument(true,recurse,false);
    new PostProcessor().process(dge);
    DocBookOutputVisitor docBookOutputVisitor=new DocBookOutputVisitor(true);
    dge.accept(docBookOutputVisitor);
    DBBook book=docBookOutputVisitor.getBook();
    if (book == null) {
      return;
    }
    ViewHierarchyVisitor viewHierarchyVisitor=new ViewHierarchyVisitor();
    dge.accept(viewHierarchyVisitor);
    for (    Element view : viewHierarchyVisitor.getView2ViewElements().keySet()) {
      if (processedElements.contains(view)) {
        Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
        continue;
      }
      ViewMapping viewMapping=viewMap.containsKey(Converters.getElementToIdConverter().apply(view)) ? viewMap.get(Converters.getElementToIdConverter().apply(view)) : new ViewMapping();
      viewMapping.setElement(view);
      viewMapping.setDbBook(book);
      viewMap.put(Converters.getElementToIdConverter().apply(view),viewMapping);
    }
  }
  Map<Element,Constraint> viewConstraintHashMap=new HashMap<>(0);
  for (  ViewMapping viewMapping : viewMap.values()) {
    Element view=viewMapping.getElement();
    if (view == null) {
      continue;
    }
    Constraint constraint=Utils.getViewConstraint(view);
    if (constraint == null) {
      Element element=Converters.getIdToElementConverter().apply(Converters.getElementToIdConverter().apply(view) + MDKConstants.VIEW_CONSTRAINT_SYSML_ID_SUFFIX,project);
      if (element instanceof Constraint) {
        constraint=(Constraint)element;
      }
    }
    if (constraint != null) {
      viewConstraintHashMap.put(view,constraint);
    }
  }
  if (!viewConstraintHashMap.isEmpty()) {
    try {
      SessionManager.getInstance().createSession(project,"String_Node_Str");
      if (!SessionManager.getInstance().isSessionCreated(project)) {
        Application.getInstance().getGUILog().log("String_Node_Str");
        failure=true;
        return;
      }
      for (      Map.Entry<Element,Constraint> entry : viewConstraintHashMap.entrySet()) {
        Constraint constraint=entry.getValue();
        if (!constraint.isEditable()) {
          updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str" + constraint.getLocalID() + "String_Node_Str"));
          failure=true;
          continue;
        }
        Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(constraint));
        try {
          ModelElementsManager.getInstance().removeElement(constraint);
        }
 catch (        ReadOnlyElementException e) {
          updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str" + constraint.getLocalID() + "String_Node_Str"));
          failure=true;
        }
      }
    }
  finally {
      if (SessionManager.getInstance().isSessionCreated(project)) {
        SessionManager.getInstance().closeSession(project);
      }
    }
  }
  if (failure) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
    return;
  }
  if (handleCancel(progressStatus)) {
    return;
  }
  LocalSyncTransactionCommitListener localSyncTransactionCommitListener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  Set<Element> elementsToDelete=new HashSet<>();
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  SessionManager.getInstance().createSession(project,"String_Node_Str");
  if (!SessionManager.getInstance().isSessionCreated(project)) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    failure=true;
    return;
  }
  if (localSyncTransactionCommitListener != null) {
    localSyncTransactionCommitListener.setDisabled(true);
  }
  List<String> viewIDs=new ArrayList<>();
  if (!viewMap.isEmpty()) {
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(2);
    ObjectNode viewResponse;
    try {
      File responseFile=MMSUtils.getElements(project,viewMap.keySet(),progressStatus);
      try (JsonParser jsonParser=JacksonUtils.getJsonFactory().createParser(responseFile)){
        viewResponse=JacksonUtils.parseJsonObject(jsonParser);
      }
     }
 catch (    ServerException|IOException|URISyntaxException e) {
      failure=true;
      Application.getInstance().getGUILog().log("String_Node_Str");
      e.printStackTrace();
      return;
    }
    JsonNode viewElementsJsonArray;
    if (viewResponse != null && (viewElementsJsonArray=viewResponse.get("String_Node_Str")) != null && viewElementsJsonArray.isArray()) {
      Queue<String> instanceIDs=new LinkedList<>();
      Queue<String> slotIDs=new LinkedList<>();
      Property generatedFromViewProperty=Utils.getGeneratedFromViewProperty(project), generatedFromElementProperty=Utils.getGeneratedFromElementProperty(project);
      for (      JsonNode elementJsonNode : viewElementsJsonArray) {
        if (!elementJsonNode.isObject()) {
          continue;
        }
        ObjectNode elementObjectNode=(ObjectNode)elementJsonNode;
        JsonNode viewOperandJsonNode=JacksonUtils.getAtPath(elementObjectNode,"String_Node_Str" + MDKConstants.CONTENTS_KEY + "String_Node_Str"), sysmlIdJson=elementObjectNode.get(MDKConstants.ID_KEY);
        String sysmlId;
        if (sysmlIdJson != null && sysmlIdJson.isTextual() && !(sysmlId=sysmlIdJson.asText()).isEmpty()) {
          viewIDs.add(sysmlId);
          if (viewOperandJsonNode != null && viewOperandJsonNode.isArray()) {
            List<String> viewInstanceIDs=new ArrayList<>(viewOperandJsonNode.size());
            for (            JsonNode viewOperandJson : viewOperandJsonNode) {
              JsonNode instanceIdJsonNode=viewOperandJson.get(MDKConstants.INSTANCE_ID_KEY);
              String instanceId;
              if (instanceIdJsonNode != null && instanceIdJsonNode.isTextual() && !(instanceId=instanceIdJsonNode.asText()).isEmpty()) {
                if (generatedFromViewProperty != null) {
                  slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromViewProperty));
                }
                if (generatedFromElementProperty != null) {
                  slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromElementProperty));
                }
                instanceIDs.add(instanceId);
                viewInstanceIDs.add(instanceId);
              }
            }
            ViewMapping viewMapping=viewMap.containsKey(sysmlId) ? viewMap.get(sysmlId) : new ViewMapping();
            viewMapping.setObjectNode(elementObjectNode);
            viewMapping.setInstanceIDs(viewInstanceIDs);
            viewMap.put(sysmlId,viewMapping);
          }
        }
      }
      List<ObjectNode> instanceObjectNodes=new ArrayList<>();
      List<ObjectNode> slotObjectNodes=new ArrayList<>();
      while (!instanceIDs.isEmpty() && !slotIDs.isEmpty()) {
        if (handleCancel(progressStatus)) {
          return;
        }
        List<String> elementIDs=new ArrayList<>(instanceIDs);
        elementIDs.addAll(slotIDs);
        ObjectNode instanceAndSlotResponse;
        try {
          File responseFile=MMSUtils.getElements(project,elementIDs,progressStatus);
          try (JsonParser jsonParser=JacksonUtils.getJsonFactory().createParser(responseFile)){
            instanceAndSlotResponse=JacksonUtils.parseJsonObject(jsonParser);
          }
         }
 catch (        ServerException|IOException|URISyntaxException e) {
          failure=true;
          Application.getInstance().getGUILog().log("String_Node_Str");
          e.printStackTrace();
          SessionManager.getInstance().cancelSession(project);
          return;
        }
        instanceIDs.clear();
        slotIDs.clear();
        JsonNode instanceAndSlotElementsJsonArray;
        if (instanceAndSlotResponse != null && (instanceAndSlotElementsJsonArray=instanceAndSlotResponse.get("String_Node_Str")) != null && instanceAndSlotElementsJsonArray.isArray()) {
          for (          JsonNode elementJson : instanceAndSlotElementsJsonArray) {
            JsonNode instanceOperandJsonArray=JacksonUtils.getAtPath(elementJson,"String_Node_Str");
            if (instanceOperandJsonArray != null && instanceOperandJsonArray.isArray()) {
              for (              JsonNode instanceOperandJson : instanceOperandJsonArray) {
                JsonNode instanceIdJson=instanceOperandJson.get(MDKConstants.INSTANCE_ID_KEY);
                String instanceId;
                if (instanceIdJson != null && instanceIdJson.isTextual() && !(instanceId=instanceIdJson.asText()).isEmpty()) {
                  if (generatedFromViewProperty != null) {
                    slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromViewProperty));
                  }
                  if (generatedFromElementProperty != null) {
                    slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromElementProperty));
                  }
                  instanceIDs.add(instanceId);
                }
              }
            }
            JsonNode typeJson=elementJson.get(MDKConstants.TYPE_KEY);
            if (typeJson.isTextual() && elementJson.isObject()) {
              (typeJson.asText().equalsIgnoreCase("String_Node_Str") ? slotObjectNodes : instanceObjectNodes).add((ObjectNode)elementJson);
            }
          }
        }
      }
      progressStatus.setDescription("String_Node_Str");
      progressStatus.setCurrent(3);
      EMFImporter emfImporter=new EMFImporter(){
        @Override public List<PreProcessor> getPreProcessors(){
          if (preProcessors == null) {
            preProcessors=new ArrayList<>(super.getPreProcessors());
            preProcessors.remove(PreProcessor.SYSML_ID_VALIDATION);
          }
          return preProcessors;
        }
        @Override public List<EStructuralFeatureOverride> getEStructuralFeatureOverrides(){
          if (eStructuralFeatureOverrides == null) {
            eStructuralFeatureOverrides=new ArrayList<>(super.getEStructuralFeatureOverrides());
            eStructuralFeatureOverrides.remove(EStructuralFeatureOverride.OWNER);
            eStructuralFeatureOverrides.add(new EStructuralFeatureOverride(EStructuralFeatureOverride.OWNER.getPredicate(),(objectNode,eStructuralFeature,project,strict,element) -> {
              if (element instanceof InstanceSpecification) {
                element.setOwner(project.getPrimaryModel());
                return element;
              }
              return EStructuralFeatureOverride.OWNER.getFunction().apply(objectNode,eStructuralFeature,project,strict,element);
            }
));
          }
          return eStructuralFeatureOverrides;
        }
      }
;
      for (      Boolean strict : Arrays.asList(false,true)) {
        ListIterator<ObjectNode> instanceObjectNodesIterator=instanceObjectNodes.listIterator(instanceObjectNodes.size());
        while (instanceObjectNodesIterator.hasPrevious()) {
          if (handleCancel(progressStatus)) {
            return;
          }
          ObjectNode instanceObjectNode=instanceObjectNodesIterator.previous();
          try {
            Changelog.Change<Element> change=emfImporter.apply(instanceObjectNode,project,strict);
            Element element=change != null ? change.getChanged() : null;
            if (element instanceof InstanceSpecification) {
              instanceSpecificationMap.put(Converters.getElementToIdConverter().apply(element),new Pair<>(instanceObjectNode,(InstanceSpecification)element));
            }
          }
 catch (          ImportException|ReadOnlyElementException e) {
            Application.getInstance().getGUILog().log("String_Node_Str" + instanceObjectNode.get(MDKConstants.ID_KEY) + "String_Node_Str"+ e.getMessage());
            instanceObjectNodesIterator.remove();
          }
        }
        ListIterator<ObjectNode> slotObjectNodesIterator=slotObjectNodes.listIterator();
        while (slotObjectNodesIterator.hasNext()) {
          if (handleCancel(progressStatus)) {
            return;
          }
          ObjectNode slotObjectNode=slotObjectNodesIterator.next();
          try {
            Changelog.Change<Element> change=emfImporter.apply(slotObjectNode,project,strict);
            Element element=change != null ? change.getChanged() : null;
            if (element instanceof Slot) {
              slotMap.put(Converters.getElementToIdConverter().apply(element),new Pair<>(slotObjectNode,(Slot)element));
            }
          }
 catch (          ImportException|ReadOnlyElementException e) {
            Application.getInstance().getGUILog().log("String_Node_Str" + slotObjectNode.get(MDKConstants.ID_KEY) + "String_Node_Str"+ e.getMessage());
            slotObjectNodesIterator.remove();
          }
        }
      }
      for (      ViewMapping viewMapping : viewMap.values()) {
        Element view=viewMapping.getElement();
        ObjectNode viewObjectNode=viewMapping.getObjectNode();
        if (viewObjectNode == null) {
          continue;
        }
        JsonNode viewContentsJsonNode=viewObjectNode.get(MDKConstants.CONTENTS_KEY);
        if (viewContentsJsonNode == null || !viewContentsJsonNode.isObject()) {
          continue;
        }
        try {
          Changelog.Change<Element> change=Converters.getJsonToElementConverter().apply((ObjectNode)viewContentsJsonNode,project,false);
          if (change.getChanged() != null && change.getChanged() instanceof Expression) {
            Expression expression=(Expression)change.getChanged();
            expression.getOperand().stream().filter(vs -> !(vs instanceof InstanceValue) || ((InstanceValue)vs).getInstance() == null).collect(Collectors.toList()).forEach(vs -> {
              elementsToDelete.add(vs);
              expression.getOperand().remove(vs);
            }
);
            presentationElementUtils.getOrCreateViewConstraint(view).setSpecification(expression);
          }
        }
 catch (        ImportException|ReadOnlyElementException e) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
        }
      }
    }
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(4);
  Set<Element> views=new LinkedHashSet<>();
  Map<Element,List<PresentationElementInstance>> view2pe=new LinkedHashMap<>();
  Map<Element,List<PresentationElementInstance>> view2unused=new LinkedHashMap<>();
  Map<Element,JSONArray> view2elements=new LinkedHashMap<>();
  Map<String,ObjectNode> images=new LinkedHashMap<>();
  Set<Element> skippedViews=new HashSet<>();
  for (  Element rootView : rootViews) {
    DBAlfrescoVisitor dbAlfrescoVisitor=new DBAlfrescoVisitor(recurse,true);
    try {
      viewMap.get(Converters.getElementToIdConverter().apply(rootView)).getDbBook().accept(dbAlfrescoVisitor);
    }
 catch (    Exception e) {
      Utils.printException(e);
      e.printStackTrace();
    }
    views.addAll(presentationElementUtils.getViewProcessOrder(rootView,dbAlfrescoVisitor.getHierarchyElements()));
    view2pe.putAll(dbAlfrescoVisitor.getView2Pe());
    view2unused.putAll(dbAlfrescoVisitor.getView2Unused());
    view2elements.putAll(dbAlfrescoVisitor.getView2Elements());
    images.putAll(dbAlfrescoVisitor.getImages());
    views.removeAll(processedElements);
  }
  for (  Element view : views) {
    if (ProjectUtilities.isElementInAttachedProject(view)) {
      ValidationRuleViolation violation=new ValidationRuleViolation(view,"String_Node_Str");
      viewInProject.addViolation(violation);
      skippedViews.add(view);
    }
    if (!viewIDs.contains(Converters.getElementToIdConverter().apply(view))) {
      ValidationRuleViolation violation=new ValidationRuleViolation(view,"String_Node_Str");
      viewDoesNotExist.addViolation(violation);
      skippedViews.add(view);
    }
  }
  if (failure) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
    SessionManager.getInstance().cancelSession(project);
    return;
  }
  try {
    for (    Element view : views) {
      if (skippedViews.contains(view)) {
        continue;
      }
      handlePes(view2pe.get(view),null);
      presentationElementUtils.updateOrCreateConstraintFromPresentationElements(view,view2pe.get(view));
    }
    LinkedList<ObjectNode> elementsToCommit=new LinkedList<>();
    Queue<Pair<InstanceSpecification,Element>> instanceToView=new LinkedList<>();
    for (    Element view : views) {
      if (skippedViews.contains(view)) {
        continue;
      }
      ObjectNode clientViewJson=Converters.getElementToJsonConverter().apply(view,project);
      if (clientViewJson == null) {
        skippedViews.add(view);
        continue;
      }
      if (view2elements.get(view) != null) {
        ArrayNode displayedElements=clientViewJson.putArray(MDKConstants.DISPLAYED_ELEMENT_IDS_KEY);
        for (        Object id : view2elements.get(view)) {
          displayedElements.add((String)id);
        }
      }
      Object o;
      ObjectNode serverViewJson=(o=viewMap.get(Converters.getElementToIdConverter().apply(view))) != null ? ((ViewMapping)o).getObjectNode() : null;
      if (!JsonEquivalencePredicate.getInstance().test(clientViewJson,serverViewJson)) {
        if (MDUtils.isDeveloperMode()) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientViewJson,serverViewJson).toString());
        }
        elementsToCommit.add(clientViewJson);
      }
      for (      PresentationElementInstance presentationElementInstance : view2pe.get(view)) {
        if (presentationElementInstance.getInstance() != null) {
          instanceToView.add(new Pair<>(presentationElementInstance.getInstance(),view));
        }
      }
    }
    String viewInstanceBinId=MDKConstants.VIEW_INSTANCES_BIN_PREFIX + Converters.getIProjectToIdConverter().apply(project.getPrimaryProject());
    while (!instanceToView.isEmpty()) {
      Pair<InstanceSpecification,Element> pair=instanceToView.remove();
      InstanceSpecification instance=pair.getKey();
      List<InstanceSpecification> subInstances=presentationElementUtils.getCurrentInstances(instance,pair.getValue()).getAll();
      for (      InstanceSpecification subInstance : subInstances) {
        instanceToView.add(new Pair<>(subInstance,pair.getValue()));
      }
      ObjectNode clientInstanceSpecificationJson=Converters.getElementToJsonConverter().apply(instance,project);
      if (clientInstanceSpecificationJson == null) {
        continue;
      }
      clientInstanceSpecificationJson.put(MDKConstants.OWNER_ID_KEY,viewInstanceBinId);
      ObjectNode serverInstanceSpecificationJson=instanceSpecificationMap.containsKey(Converters.getElementToIdConverter().apply(instance)) ? instanceSpecificationMap.get(Converters.getElementToIdConverter().apply(instance)).getKey() : null;
      if (!JsonEquivalencePredicate.getInstance().test(clientInstanceSpecificationJson,serverInstanceSpecificationJson)) {
        if (MDUtils.isDeveloperMode()) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(instance) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientInstanceSpecificationJson,serverInstanceSpecificationJson).toString());
        }
        elementsToCommit.add(clientInstanceSpecificationJson);
      }
      for (      Slot slot : instance.getSlot()) {
        ObjectNode clientSlotJson=Converters.getElementToJsonConverter().apply(slot,project);
        if (clientSlotJson == null) {
          continue;
        }
        JsonNode serverSlotJson=slotMap.containsKey(Converters.getElementToIdConverter().apply(slot)) ? slotMap.get(Converters.getElementToIdConverter().apply(slot)).getKey() : null;
        if (!JsonEquivalencePredicate.getInstance().test(clientSlotJson,serverSlotJson)) {
          elementsToCommit.add(clientSlotJson);
          if (MDUtils.isDeveloperMode()) {
            Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(slot) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientSlotJson,serverSlotJson).toString());
          }
        }
      }
    }
    boolean changed=false;
    if (elementsToCommit.size() > 0) {
      progressStatus.setDescription("String_Node_Str");
      progressStatus.setCurrent(5);
      Application.getInstance().getGUILog().log("String_Node_Str" + elementsToCommit.size() + "String_Node_Str"+ (elementsToCommit.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
      URIBuilder requestUri=MMSUtils.getServiceProjectsRefsElementsUri(project);
      File sendData=MMSUtils.createEntityFile(this.getClass(),ContentType.APPLICATION_JSON,elementsToCommit,MMSUtils.JsonBlobType.ELEMENT_JSON);
      OutputQueue.getInstance().offer(new Request(project,MMSUtils.HttpRequestType.POST,requestUri,sendData,ContentType.APPLICATION_JSON,elementsToCommit.size(),"String_Node_Str"));
      changed=true;
    }
    Set<String> mmsElementsToDelete=new HashSet<>();
    for (    List<PresentationElementInstance> presentationElementInstances : view2unused.values()) {
      for (      PresentationElementInstance presentationElementInstance : presentationElementInstances) {
        if (presentationElementInstance.getInstance() == null) {
          continue;
        }
        String id=Converters.getElementToIdConverter().apply(presentationElementInstance.getInstance());
        if (id == null) {
          continue;
        }
        mmsElementsToDelete.add(id);
      }
    }
    if (elementsToCommit.size() > 0) {
      Application.getInstance().getGUILog().log("String_Node_Str" + mmsElementsToDelete.size() + "String_Node_Str"+ (mmsElementsToDelete.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
      URIBuilder requestUri=MMSUtils.getServiceProjectsRefsElementsUri(project);
      File sendData=MMSUtils.createEntityFile(this.getClass(),ContentType.APPLICATION_JSON,mmsElementsToDelete,MMSUtils.JsonBlobType.ELEMENT_ID);
      OutputQueue.getInstance().offer(new Request(project,MMSUtils.HttpRequestType.DELETE,requestUri,sendData,ContentType.APPLICATION_JSON,elementsToCommit.size(),"String_Node_Str"));
      changed=true;
    }
    if (!changed) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(6);
    for (    Pair<ObjectNode,Slot> pair : slotMap.values()) {
      if (pair.getValue() != null) {
        elementsToDelete.add(pair.getValue());
      }
    }
    for (    Pair<ObjectNode,InstanceSpecification> pair : instanceSpecificationMap.values()) {
      if (pair.getValue() != null) {
        elementsToDelete.add(pair.getValue());
      }
    }
    for (    Element element : views) {
      Constraint constraint=Utils.getViewConstraint(element);
      if (constraint == null) {
        continue;
      }
      elementsToDelete.add(constraint);
      ValueSpecification valueSpecification=constraint.getSpecification();
      if (valueSpecification == null) {
        continue;
      }
      elementsToDelete.add(valueSpecification);
      List<ValueSpecification> operands;
      if (!(valueSpecification instanceof Expression) || (operands=((Expression)valueSpecification).getOperand()) == null) {
        continue;
      }
      for (      ValueSpecification operand : operands) {
        elementsToDelete.add(operand);
        InstanceSpecification instanceSpecification;
        if (!(operand instanceof InstanceValue) || (instanceSpecification=((InstanceValue)operand).getInstance()) == null) {
          continue;
        }
        elementsToDelete.add(instanceSpecification);
        for (        Slot slot : instanceSpecification.getSlot()) {
          elementsToDelete.add(slot);
          elementsToDelete.addAll(slot.getValue());
        }
      }
    }
    for (    Element element : elementsToDelete) {
      try {
        ModelElementsManager.getInstance().removeElement(element);
      }
 catch (      ReadOnlyElementException ignored) {
        System.out.println("String_Node_Str" + element.getLocalID());
      }
    }
    processedElements.addAll(views);
  }
 catch (  Exception e) {
    failure=true;
    Utils.printException(e);
  }
 finally {
    if (SessionManager.getInstance().isSessionCreated(project)) {
      SessionManager.getInstance().cancelSession(project);
    }
    if (localSyncTransactionCommitListener != null) {
      localSyncTransactionCommitListener.setDisabled(false);
    }
  }
  ImageValidator iv=new ImageValidator(images,images);
  iv.validate(project);
  for (  ValidationRule validationRule : iv.getSuite().getValidationRules()) {
    for (    ValidationRuleViolation validationRuleViolation : validationRule.getViolations()) {
      if (!validationRuleViolation.getActions().isEmpty()) {
        validationRuleViolation.getActions().get(0).actionPerformed(null);
      }
    }
  }
  if (suite.hasErrors()) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void run(ProgressStatus progressStatus){
  progressStatus.init("String_Node_Str",6);
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  Map<String,Pair<ObjectNode,InstanceSpecification>> instanceSpecificationMap=new LinkedHashMap<>();
  Map<String,Pair<ObjectNode,Slot>> slotMap=new LinkedHashMap<>();
  Map<String,ViewMapping> viewMap=new LinkedHashMap<>();
  for (  Element rootView : rootViews) {
    if (MDUtils.isDeveloperMode()) {
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(1);
    DocumentValidator dv=new DocumentValidator(rootView);
    dv.validateDocument();
    if (dv.isFatal()) {
      dv.printErrors(false);
      return;
    }
    DocumentGenerator dg=new DocumentGenerator(rootView,dv,null,false);
    Document dge=dg.parseDocument(true,recurse,false);
    new PostProcessor().process(dge);
    DocBookOutputVisitor docBookOutputVisitor=new DocBookOutputVisitor(true);
    dge.accept(docBookOutputVisitor);
    DBBook book=docBookOutputVisitor.getBook();
    if (book == null) {
      return;
    }
    ViewHierarchyVisitor viewHierarchyVisitor=new ViewHierarchyVisitor();
    dge.accept(viewHierarchyVisitor);
    for (    Element view : viewHierarchyVisitor.getView2ViewElements().keySet()) {
      if (processedElements.contains(view)) {
        Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
        continue;
      }
      ViewMapping viewMapping=viewMap.containsKey(Converters.getElementToIdConverter().apply(view)) ? viewMap.get(Converters.getElementToIdConverter().apply(view)) : new ViewMapping();
      viewMapping.setElement(view);
      viewMapping.setDbBook(book);
      viewMap.put(Converters.getElementToIdConverter().apply(view),viewMapping);
    }
  }
  Map<Element,Constraint> viewConstraintHashMap=new HashMap<>(0);
  for (  ViewMapping viewMapping : viewMap.values()) {
    Element view=viewMapping.getElement();
    if (view == null) {
      continue;
    }
    Constraint constraint=Utils.getViewConstraint(view);
    if (constraint == null) {
      Element element=Converters.getIdToElementConverter().apply(Converters.getElementToIdConverter().apply(view) + MDKConstants.VIEW_CONSTRAINT_SYSML_ID_SUFFIX,project);
      if (element instanceof Constraint) {
        constraint=(Constraint)element;
      }
    }
    if (constraint != null) {
      viewConstraintHashMap.put(view,constraint);
    }
  }
  if (!viewConstraintHashMap.isEmpty()) {
    try {
      SessionManager.getInstance().createSession(project,"String_Node_Str");
      if (!SessionManager.getInstance().isSessionCreated(project)) {
        Application.getInstance().getGUILog().log("String_Node_Str");
        failure=true;
        return;
      }
      for (      Map.Entry<Element,Constraint> entry : viewConstraintHashMap.entrySet()) {
        Constraint constraint=entry.getValue();
        if (!constraint.isEditable()) {
          updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str" + constraint.getLocalID() + "String_Node_Str"));
          failure=true;
          continue;
        }
        Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(constraint));
        try {
          ModelElementsManager.getInstance().removeElement(constraint);
        }
 catch (        ReadOnlyElementException e) {
          updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str" + constraint.getLocalID() + "String_Node_Str"));
          failure=true;
        }
      }
    }
  finally {
      if (SessionManager.getInstance().isSessionCreated(project)) {
        SessionManager.getInstance().closeSession(project);
      }
    }
  }
  if (failure) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
    return;
  }
  if (handleCancel(progressStatus)) {
    return;
  }
  LocalSyncTransactionCommitListener localSyncTransactionCommitListener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  Set<Element> elementsToDelete=new HashSet<>();
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  SessionManager.getInstance().createSession(project,"String_Node_Str");
  if (!SessionManager.getInstance().isSessionCreated(project)) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    failure=true;
    return;
  }
  if (localSyncTransactionCommitListener != null) {
    localSyncTransactionCommitListener.setDisabled(true);
  }
  List<String> viewIDs=new ArrayList<>();
  if (!viewMap.isEmpty()) {
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(2);
    ObjectNode viewResponse;
    try {
      File responseFile=MMSUtils.getElements(project,viewMap.keySet(),progressStatus);
      try (JsonParser jsonParser=JacksonUtils.getJsonFactory().createParser(responseFile)){
        viewResponse=JacksonUtils.parseJsonObject(jsonParser);
      }
     }
 catch (    ServerException|IOException|URISyntaxException e) {
      failure=true;
      Application.getInstance().getGUILog().log("String_Node_Str");
      e.printStackTrace();
      return;
    }
    JsonNode viewElementsJsonArray;
    if (viewResponse != null && (viewElementsJsonArray=viewResponse.get("String_Node_Str")) != null && viewElementsJsonArray.isArray()) {
      Queue<String> instanceIDs=new LinkedList<>();
      Queue<String> slotIDs=new LinkedList<>();
      Property generatedFromViewProperty=Utils.getGeneratedFromViewProperty(project), generatedFromElementProperty=Utils.getGeneratedFromElementProperty(project);
      for (      JsonNode elementJsonNode : viewElementsJsonArray) {
        if (!elementJsonNode.isObject()) {
          continue;
        }
        ObjectNode elementObjectNode=(ObjectNode)elementJsonNode;
        JsonNode viewOperandJsonNode=JacksonUtils.getAtPath(elementObjectNode,"String_Node_Str" + MDKConstants.CONTENTS_KEY + "String_Node_Str"), sysmlIdJson=elementObjectNode.get(MDKConstants.ID_KEY);
        String sysmlId;
        if (sysmlIdJson != null && sysmlIdJson.isTextual() && !(sysmlId=sysmlIdJson.asText()).isEmpty()) {
          viewIDs.add(sysmlId);
          if (viewOperandJsonNode != null && viewOperandJsonNode.isArray()) {
            List<String> viewInstanceIDs=new ArrayList<>(viewOperandJsonNode.size());
            for (            JsonNode viewOperandJson : viewOperandJsonNode) {
              JsonNode instanceIdJsonNode=viewOperandJson.get(MDKConstants.INSTANCE_ID_KEY);
              String instanceId;
              if (instanceIdJsonNode != null && instanceIdJsonNode.isTextual() && !(instanceId=instanceIdJsonNode.asText()).isEmpty()) {
                if (generatedFromViewProperty != null) {
                  slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromViewProperty));
                }
                if (generatedFromElementProperty != null) {
                  slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromElementProperty));
                }
                instanceIDs.add(instanceId);
                viewInstanceIDs.add(instanceId);
              }
            }
            ViewMapping viewMapping=viewMap.containsKey(sysmlId) ? viewMap.get(sysmlId) : new ViewMapping();
            viewMapping.setObjectNode(elementObjectNode);
            viewMapping.setInstanceIDs(viewInstanceIDs);
            viewMap.put(sysmlId,viewMapping);
          }
        }
      }
      List<ObjectNode> instanceObjectNodes=new ArrayList<>();
      List<ObjectNode> slotObjectNodes=new ArrayList<>();
      while (!instanceIDs.isEmpty() && !slotIDs.isEmpty()) {
        if (handleCancel(progressStatus)) {
          return;
        }
        List<String> elementIDs=new ArrayList<>(instanceIDs);
        elementIDs.addAll(slotIDs);
        ObjectNode instanceAndSlotResponse;
        try {
          File responseFile=MMSUtils.getElements(project,elementIDs,progressStatus);
          try (JsonParser jsonParser=JacksonUtils.getJsonFactory().createParser(responseFile)){
            instanceAndSlotResponse=JacksonUtils.parseJsonObject(jsonParser);
          }
         }
 catch (        ServerException|IOException|URISyntaxException e) {
          failure=true;
          Application.getInstance().getGUILog().log("String_Node_Str");
          e.printStackTrace();
          SessionManager.getInstance().cancelSession(project);
          return;
        }
        instanceIDs.clear();
        slotIDs.clear();
        JsonNode instanceAndSlotElementsJsonArray;
        if (instanceAndSlotResponse != null && (instanceAndSlotElementsJsonArray=instanceAndSlotResponse.get("String_Node_Str")) != null && instanceAndSlotElementsJsonArray.isArray()) {
          for (          JsonNode elementJson : instanceAndSlotElementsJsonArray) {
            JsonNode instanceOperandJsonArray=JacksonUtils.getAtPath(elementJson,"String_Node_Str");
            if (instanceOperandJsonArray != null && instanceOperandJsonArray.isArray()) {
              for (              JsonNode instanceOperandJson : instanceOperandJsonArray) {
                JsonNode instanceIdJson=instanceOperandJson.get(MDKConstants.INSTANCE_ID_KEY);
                String instanceId;
                if (instanceIdJson != null && instanceIdJson.isTextual() && !(instanceId=instanceIdJson.asText()).isEmpty()) {
                  if (generatedFromViewProperty != null) {
                    slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromViewProperty));
                  }
                  if (generatedFromElementProperty != null) {
                    slotIDs.add(instanceId + MDKConstants.SLOT_ID_SEPARATOR + Converters.getElementToIdConverter().apply(generatedFromElementProperty));
                  }
                  instanceIDs.add(instanceId);
                }
              }
            }
            JsonNode typeJson=elementJson.get(MDKConstants.TYPE_KEY);
            if (typeJson.isTextual() && elementJson.isObject()) {
              (typeJson.asText().equalsIgnoreCase("String_Node_Str") ? slotObjectNodes : instanceObjectNodes).add((ObjectNode)elementJson);
            }
          }
        }
      }
      progressStatus.setDescription("String_Node_Str");
      progressStatus.setCurrent(3);
      EMFImporter emfImporter=new EMFImporter(){
        @Override public List<PreProcessor> getPreProcessors(){
          if (preProcessors == null) {
            preProcessors=new ArrayList<>(super.getPreProcessors());
            preProcessors.remove(PreProcessor.SYSML_ID_VALIDATION);
          }
          return preProcessors;
        }
        @Override public List<EStructuralFeatureOverride> getEStructuralFeatureOverrides(){
          if (eStructuralFeatureOverrides == null) {
            eStructuralFeatureOverrides=new ArrayList<>(super.getEStructuralFeatureOverrides());
            eStructuralFeatureOverrides.remove(EStructuralFeatureOverride.OWNER);
            eStructuralFeatureOverrides.add(new EStructuralFeatureOverride(EStructuralFeatureOverride.OWNER.getPredicate(),(objectNode,eStructuralFeature,project,strict,element) -> {
              if (element instanceof InstanceSpecification) {
                element.setOwner(project.getPrimaryModel());
                return element;
              }
              return EStructuralFeatureOverride.OWNER.getFunction().apply(objectNode,eStructuralFeature,project,strict,element);
            }
));
          }
          return eStructuralFeatureOverrides;
        }
      }
;
      for (      Boolean strict : Arrays.asList(false,true)) {
        ListIterator<ObjectNode> instanceObjectNodesIterator=instanceObjectNodes.listIterator(instanceObjectNodes.size());
        while (instanceObjectNodesIterator.hasPrevious()) {
          if (handleCancel(progressStatus)) {
            return;
          }
          ObjectNode instanceObjectNode=instanceObjectNodesIterator.previous();
          try {
            Changelog.Change<Element> change=emfImporter.apply(instanceObjectNode,project,strict);
            Element element=change != null ? change.getChanged() : null;
            if (element instanceof InstanceSpecification) {
              instanceSpecificationMap.put(Converters.getElementToIdConverter().apply(element),new Pair<>(instanceObjectNode,(InstanceSpecification)element));
            }
          }
 catch (          ImportException|ReadOnlyElementException e) {
            Application.getInstance().getGUILog().log("String_Node_Str" + instanceObjectNode.get(MDKConstants.ID_KEY) + "String_Node_Str"+ e.getMessage());
            instanceObjectNodesIterator.remove();
          }
        }
        ListIterator<ObjectNode> slotObjectNodesIterator=slotObjectNodes.listIterator();
        while (slotObjectNodesIterator.hasNext()) {
          if (handleCancel(progressStatus)) {
            return;
          }
          ObjectNode slotObjectNode=slotObjectNodesIterator.next();
          try {
            Changelog.Change<Element> change=emfImporter.apply(slotObjectNode,project,strict);
            Element element=change != null ? change.getChanged() : null;
            if (element instanceof Slot) {
              slotMap.put(Converters.getElementToIdConverter().apply(element),new Pair<>(slotObjectNode,(Slot)element));
            }
          }
 catch (          ImportException|ReadOnlyElementException e) {
            Application.getInstance().getGUILog().log("String_Node_Str" + slotObjectNode.get(MDKConstants.ID_KEY) + "String_Node_Str"+ e.getMessage());
            slotObjectNodesIterator.remove();
          }
        }
      }
      for (      ViewMapping viewMapping : viewMap.values()) {
        Element view=viewMapping.getElement();
        ObjectNode viewObjectNode=viewMapping.getObjectNode();
        if (viewObjectNode == null) {
          continue;
        }
        JsonNode viewContentsJsonNode=viewObjectNode.get(MDKConstants.CONTENTS_KEY);
        if (viewContentsJsonNode == null || !viewContentsJsonNode.isObject()) {
          continue;
        }
        try {
          Changelog.Change<Element> change=Converters.getJsonToElementConverter().apply((ObjectNode)viewContentsJsonNode,project,false);
          if (change.getChanged() != null && change.getChanged() instanceof Expression) {
            Expression expression=(Expression)change.getChanged();
            expression.getOperand().stream().filter(vs -> !(vs instanceof InstanceValue) || ((InstanceValue)vs).getInstance() == null).collect(Collectors.toList()).forEach(vs -> {
              elementsToDelete.add(vs);
              expression.getOperand().remove(vs);
            }
);
            presentationElementUtils.getOrCreateViewConstraint(view).setSpecification(expression);
          }
        }
 catch (        ImportException|ReadOnlyElementException e) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
        }
      }
    }
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(4);
  Set<Element> views=new LinkedHashSet<>();
  Map<Element,List<PresentationElementInstance>> view2pe=new LinkedHashMap<>();
  Map<Element,List<PresentationElementInstance>> view2unused=new LinkedHashMap<>();
  Map<Element,JSONArray> view2elements=new LinkedHashMap<>();
  Map<String,ObjectNode> images=new LinkedHashMap<>();
  Set<Element> skippedViews=new HashSet<>();
  for (  Element rootView : rootViews) {
    DBAlfrescoVisitor dbAlfrescoVisitor=new DBAlfrescoVisitor(recurse,true);
    try {
      viewMap.get(Converters.getElementToIdConverter().apply(rootView)).getDbBook().accept(dbAlfrescoVisitor);
    }
 catch (    Exception e) {
      Utils.printException(e);
      e.printStackTrace();
    }
    views.addAll(presentationElementUtils.getViewProcessOrder(rootView,dbAlfrescoVisitor.getHierarchyElements()));
    view2pe.putAll(dbAlfrescoVisitor.getView2Pe());
    view2unused.putAll(dbAlfrescoVisitor.getView2Unused());
    view2elements.putAll(dbAlfrescoVisitor.getView2Elements());
    images.putAll(dbAlfrescoVisitor.getImages());
    views.removeAll(processedElements);
  }
  for (  Element view : views) {
    if (ProjectUtilities.isElementInAttachedProject(view)) {
      ValidationRuleViolation violation=new ValidationRuleViolation(view,"String_Node_Str");
      viewInProject.addViolation(violation);
      skippedViews.add(view);
    }
    if (!viewIDs.contains(Converters.getElementToIdConverter().apply(view))) {
      ValidationRuleViolation violation=new ValidationRuleViolation(view,"String_Node_Str");
      viewDoesNotExist.addViolation(violation);
      skippedViews.add(view);
    }
  }
  if (failure) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
    SessionManager.getInstance().cancelSession(project);
    return;
  }
  try {
    for (    Element view : views) {
      if (skippedViews.contains(view)) {
        continue;
      }
      handlePes(view2pe.get(view),null);
      presentationElementUtils.updateOrCreateConstraintFromPresentationElements(view,view2pe.get(view));
    }
    LinkedList<ObjectNode> elementsToCommit=new LinkedList<>();
    Queue<Pair<InstanceSpecification,Element>> instanceToView=new LinkedList<>();
    for (    Element view : views) {
      if (skippedViews.contains(view)) {
        continue;
      }
      ObjectNode clientViewJson=Converters.getElementToJsonConverter().apply(view,project);
      if (clientViewJson == null) {
        skippedViews.add(view);
        continue;
      }
      if (view2elements.get(view) != null) {
        ArrayNode displayedElements=clientViewJson.putArray(MDKConstants.DISPLAYED_ELEMENT_IDS_KEY);
        for (        Object id : view2elements.get(view)) {
          displayedElements.add((String)id);
        }
      }
      Object o;
      ObjectNode serverViewJson=(o=viewMap.get(Converters.getElementToIdConverter().apply(view))) != null ? ((ViewMapping)o).getObjectNode() : null;
      if (!JsonEquivalencePredicate.getInstance().test(clientViewJson,serverViewJson)) {
        if (MDUtils.isDeveloperMode()) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientViewJson,serverViewJson).toString());
        }
        elementsToCommit.add(clientViewJson);
      }
      for (      PresentationElementInstance presentationElementInstance : view2pe.get(view)) {
        if (presentationElementInstance.getInstance() != null) {
          instanceToView.add(new Pair<>(presentationElementInstance.getInstance(),view));
        }
      }
    }
    String viewInstanceBinId=MDKConstants.VIEW_INSTANCES_BIN_PREFIX + Converters.getIProjectToIdConverter().apply(project.getPrimaryProject());
    while (!instanceToView.isEmpty()) {
      Pair<InstanceSpecification,Element> pair=instanceToView.remove();
      InstanceSpecification instance=pair.getKey();
      List<InstanceSpecification> subInstances=presentationElementUtils.getCurrentInstances(instance,pair.getValue()).getAll();
      for (      InstanceSpecification subInstance : subInstances) {
        instanceToView.add(new Pair<>(subInstance,pair.getValue()));
      }
      ObjectNode clientInstanceSpecificationJson=Converters.getElementToJsonConverter().apply(instance,project);
      if (clientInstanceSpecificationJson == null) {
        continue;
      }
      clientInstanceSpecificationJson.put(MDKConstants.OWNER_ID_KEY,viewInstanceBinId);
      ObjectNode serverInstanceSpecificationJson=instanceSpecificationMap.containsKey(Converters.getElementToIdConverter().apply(instance)) ? instanceSpecificationMap.get(Converters.getElementToIdConverter().apply(instance)).getKey() : null;
      if (!JsonEquivalencePredicate.getInstance().test(clientInstanceSpecificationJson,serverInstanceSpecificationJson)) {
        if (MDUtils.isDeveloperMode()) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(instance) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientInstanceSpecificationJson,serverInstanceSpecificationJson).toString());
        }
        elementsToCommit.add(clientInstanceSpecificationJson);
      }
      for (      Slot slot : instance.getSlot()) {
        ObjectNode clientSlotJson=Converters.getElementToJsonConverter().apply(slot,project);
        if (clientSlotJson == null) {
          continue;
        }
        JsonNode serverSlotJson=slotMap.containsKey(Converters.getElementToIdConverter().apply(slot)) ? slotMap.get(Converters.getElementToIdConverter().apply(slot)).getKey() : null;
        if (!JsonEquivalencePredicate.getInstance().test(clientSlotJson,serverSlotJson)) {
          elementsToCommit.add(clientSlotJson);
          if (MDUtils.isDeveloperMode()) {
            Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(slot) + "String_Node_Str"+ JsonPatchFunction.getInstance().apply(clientSlotJson,serverSlotJson).toString());
          }
        }
      }
    }
    boolean changed=false;
    if (elementsToCommit.size() > 0) {
      progressStatus.setDescription("String_Node_Str");
      progressStatus.setCurrent(5);
      Application.getInstance().getGUILog().log("String_Node_Str" + elementsToCommit.size() + "String_Node_Str"+ (elementsToCommit.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
      URIBuilder requestUri=MMSUtils.getServiceProjectsRefsElementsUri(project);
      File sendData=MMSUtils.createEntityFile(this.getClass(),ContentType.APPLICATION_JSON,elementsToCommit,MMSUtils.JsonBlobType.ELEMENT_JSON);
      OutputQueue.getInstance().offer(new Request(project,MMSUtils.HttpRequestType.POST,requestUri,sendData,ContentType.APPLICATION_JSON,elementsToCommit.size(),"String_Node_Str"));
      changed=true;
    }
    Set<String> mmsElementsToDelete=new HashSet<>();
    for (    List<PresentationElementInstance> presentationElementInstances : view2unused.values()) {
      for (      PresentationElementInstance presentationElementInstance : presentationElementInstances) {
        if (presentationElementInstance.getInstance() == null) {
          continue;
        }
        String id=Converters.getElementToIdConverter().apply(presentationElementInstance.getInstance());
        if (id == null) {
          continue;
        }
        mmsElementsToDelete.add(id);
      }
    }
    if (mmsElementsToDelete.size() > 0) {
      Application.getInstance().getGUILog().log("String_Node_Str" + mmsElementsToDelete.size() + "String_Node_Str"+ (mmsElementsToDelete.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
      URIBuilder requestUri=MMSUtils.getServiceProjectsRefsElementsUri(project);
      File sendData=MMSUtils.createEntityFile(this.getClass(),ContentType.APPLICATION_JSON,mmsElementsToDelete,MMSUtils.JsonBlobType.ELEMENT_ID);
      OutputQueue.getInstance().offer(new Request(project,MMSUtils.HttpRequestType.DELETE,requestUri,sendData,ContentType.APPLICATION_JSON,mmsElementsToDelete.size(),"String_Node_Str"));
      changed=true;
    }
    if (!changed) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(6);
    for (    Pair<ObjectNode,Slot> pair : slotMap.values()) {
      if (pair.getValue() != null) {
        elementsToDelete.add(pair.getValue());
      }
    }
    for (    Pair<ObjectNode,InstanceSpecification> pair : instanceSpecificationMap.values()) {
      if (pair.getValue() != null) {
        elementsToDelete.add(pair.getValue());
      }
    }
    for (    Element element : views) {
      Constraint constraint=Utils.getViewConstraint(element);
      if (constraint == null) {
        continue;
      }
      elementsToDelete.add(constraint);
      ValueSpecification valueSpecification=constraint.getSpecification();
      if (valueSpecification == null) {
        continue;
      }
      elementsToDelete.add(valueSpecification);
      List<ValueSpecification> operands;
      if (!(valueSpecification instanceof Expression) || (operands=((Expression)valueSpecification).getOperand()) == null) {
        continue;
      }
      for (      ValueSpecification operand : operands) {
        elementsToDelete.add(operand);
        InstanceSpecification instanceSpecification;
        if (!(operand instanceof InstanceValue) || (instanceSpecification=((InstanceValue)operand).getInstance()) == null) {
          continue;
        }
        elementsToDelete.add(instanceSpecification);
        for (        Slot slot : instanceSpecification.getSlot()) {
          elementsToDelete.add(slot);
          elementsToDelete.addAll(slot.getValue());
        }
      }
    }
    for (    Element element : elementsToDelete) {
      try {
        ModelElementsManager.getInstance().removeElement(element);
      }
 catch (      ReadOnlyElementException ignored) {
        System.out.println("String_Node_Str" + element.getLocalID());
      }
    }
    processedElements.addAll(views);
  }
 catch (  Exception e) {
    failure=true;
    Utils.printException(e);
  }
 finally {
    if (SessionManager.getInstance().isSessionCreated(project)) {
      SessionManager.getInstance().cancelSession(project);
    }
    if (localSyncTransactionCommitListener != null) {
      localSyncTransactionCommitListener.setDisabled(false);
    }
  }
  ImageValidator iv=new ImageValidator(images,images);
  iv.validate(project);
  for (  ValidationRule validationRule : iv.getSuite().getValidationRules()) {
    for (    ValidationRuleViolation validationRuleViolation : validationRule.getViolations()) {
      if (!validationRuleViolation.getActions().isEmpty()) {
        validationRuleViolation.getActions().get(0).actionPerformed(null);
      }
    }
  }
  if (suite.hasErrors()) {
    Utils.displayValidationWindow(project,vss,"String_Node_Str");
  }
}