Program: 88576
Project: 88576
Buggy source:
@Override public void run(ProgressStatus progressStatus){
  progressStatus.init("String_Node_Str",6);
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(1);
  DocumentValidator dv=new DocumentValidator(start);
  dv.validateDocument();
  if (dv.isFatal()) {
    dv.printErrors(false);
    return;
  }
  DocumentGenerator dg=new DocumentGenerator(start,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);
  Map<String,Pair<ObjectNode,InstanceSpecification>> instanceSpecificationMap=new LinkedHashMap<>();
  Map<String,Pair<ObjectNode,Slot>> slotMap=new LinkedHashMap<>();
  Map<String,ViewMapping> viewMap=new LinkedHashMap<>(viewHierarchyVisitor.getView2ViewElements().size());
  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);
    viewMap.put(Converters.getElementToIdConverter().apply(view),viewMapping);
  }
  List<Constraint> constraintsToBeDeleted=new ArrayList<>(viewMap.size());
  for (  ViewMapping viewMapping : viewMap.values()) {
    Element view=viewMapping.getElement();
    if (view == null) {
      continue;
    }
    Constraint constraint=Utils.getViewConstraint(view);
    if (constraint != null) {
      constraintsToBeDeleted.add(constraint);
    }
  }
  if (!constraintsToBeDeleted.isEmpty()) {
    SessionManager.getInstance().createSession(project,"String_Node_Str");
    for (    Constraint constraint : constraintsToBeDeleted) {
      if (constraint.isEditable()) {
        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"));
          failure=true;
        }
      }
 else {
        updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str"));
        failure=true;
      }
    }
    SessionManager.getInstance().closeSession(project);
  }
  if (failure) {
    if (showValidation) {
      Utils.displayValidationWindow(project,vss,"String_Node_Str");
    }
    return;
  }
  if (handleCancel(progressStatus)) {
    return;
  }
  LocalSyncTransactionCommitListener localSyncTransactionCommitListener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  if (SessionManager.getInstance().isSessionCreated(project)) {
    SessionManager.getInstance().closeSession(project);
  }
  SessionManager.getInstance().createSession(project,"String_Node_Str");
  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 {
      viewResponse=JacksonUtils.parseJsonObject(MMSUtils.getElements(project,viewMap.keySet(),progressStatus));
    }
 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 {
          instanceAndSlotResponse=JacksonUtils.parseJsonObject(MMSUtils.getElements(project,elementIDs,progressStatus));
        }
 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();
        if (handleCancel(progressStatus)) {
          return;
        }
        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) {
            instanceUtils.getOrCreateViewConstraint(view).setSpecification((Expression)change.getChanged());
          }
        }
 catch (        ImportException|ReadOnlyElementException e) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
          continue;
        }
      }
    }
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(4);
  DBAlfrescoVisitor dbAlfrescoVisitor=new DBAlfrescoVisitor(recurse,true);
  try {
    book.accept(dbAlfrescoVisitor);
  }
 catch (  Exception e) {
    Utils.printException(e);
    e.printStackTrace();
  }
  Map<Element,List<PresentationElementInstance>> view2pe=dbAlfrescoVisitor.getView2Pe();
  Map<Element,List<PresentationElementInstance>> view2unused=dbAlfrescoVisitor.getView2Unused();
  List<Element> views=instanceUtils.getViewProcessOrder(start,dbAlfrescoVisitor.getHierarchyElements());
  views.removeAll(processedElements);
  Set<Element> skippedViews=new HashSet<>();
  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) {
    if (showValidation) {
      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);
      instanceUtils.updateOrCreateConstraintFromPresentationElements(view,view2pe.get(view));
    }
    if (handleCancel(progressStatus)) {
      return;
    }
    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;
      }
      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"+ JsonDiffFunction.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=instanceUtils.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"+ JsonDiffFunction.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"+ JsonDiffFunction.getInstance().apply(clientSlotJson,serverSlotJson).toString());
          }
        }
      }
    }
    if (handleCancel(progressStatus)) {
      return;
    }
    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,true,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,true,elementsToCommit.size(),"String_Node_Str"));
      changed=true;
    }
    if (!changed) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(6);
    Set<Element> elementsToDelete=new HashSet<>();
    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(dbAlfrescoVisitor.getImages(),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 (showValidation) {
    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 (manageSesssions) {
    if (SessionManager.getInstance().isSessionCreated(project)) {
      SessionManager.getInstance().closeSession(project);
    }
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(1);
  DocumentValidator dv=new DocumentValidator(start);
  dv.validateDocument();
  if (dv.isFatal()) {
    dv.printErrors(false);
    return;
  }
  DocumentGenerator dg=new DocumentGenerator(start,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);
  Map<String,Pair<ObjectNode,InstanceSpecification>> instanceSpecificationMap=new LinkedHashMap<>();
  Map<String,Pair<ObjectNode,Slot>> slotMap=new LinkedHashMap<>();
  Map<String,ViewMapping> viewMap=new LinkedHashMap<>(viewHierarchyVisitor.getView2ViewElements().size());
  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);
    viewMap.put(Converters.getElementToIdConverter().apply(view),viewMapping);
  }
  List<Constraint> constraintsToBeDeleted=new ArrayList<>(viewMap.size());
  for (  ViewMapping viewMapping : viewMap.values()) {
    Element view=viewMapping.getElement();
    if (view == null) {
      continue;
    }
    Constraint constraint=Utils.getViewConstraint(view);
    if (constraint != null) {
      constraintsToBeDeleted.add(constraint);
    }
  }
  if (!constraintsToBeDeleted.isEmpty()) {
    if (manageSesssions) {
      SessionManager.getInstance().createSession(project,"String_Node_Str");
    }
    for (    Constraint constraint : constraintsToBeDeleted) {
      if (constraint.isEditable()) {
        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"));
          failure=true;
        }
      }
 else {
        updateFailed.addViolation(new ValidationRuleViolation(constraint,"String_Node_Str"));
        failure=true;
      }
    }
    if (manageSesssions) {
      SessionManager.getInstance().closeSession(project);
    }
  }
  if (failure) {
    if (showValidation) {
      Utils.displayValidationWindow(project,vss,"String_Node_Str");
    }
    return;
  }
  if (handleCancel(progressStatus)) {
    return;
  }
  LocalSyncTransactionCommitListener localSyncTransactionCommitListener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  if (manageSesssions) {
    if (SessionManager.getInstance().isSessionCreated(project)) {
      SessionManager.getInstance().closeSession(project);
    }
    SessionManager.getInstance().createSession(project,"String_Node_Str");
  }
  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 {
      viewResponse=JacksonUtils.parseJsonObject(MMSUtils.getElements(project,viewMap.keySet(),progressStatus));
    }
 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 {
          instanceAndSlotResponse=JacksonUtils.parseJsonObject(MMSUtils.getElements(project,elementIDs,progressStatus));
        }
 catch (        ServerException|IOException|URISyntaxException e) {
          failure=true;
          Application.getInstance().getGUILog().log("String_Node_Str");
          e.printStackTrace();
          if (manageSesssions) {
            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();
        if (handleCancel(progressStatus)) {
          return;
        }
        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) {
            instanceUtils.getOrCreateViewConstraint(view).setSpecification((Expression)change.getChanged());
          }
        }
 catch (        ImportException|ReadOnlyElementException e) {
          Application.getInstance().getGUILog().log("String_Node_Str" + Converters.getElementToIdConverter().apply(view) + "String_Node_Str");
          continue;
        }
      }
    }
  }
  progressStatus.setDescription("String_Node_Str");
  progressStatus.setCurrent(4);
  DBAlfrescoVisitor dbAlfrescoVisitor=new DBAlfrescoVisitor(recurse,true);
  try {
    book.accept(dbAlfrescoVisitor);
  }
 catch (  Exception e) {
    Utils.printException(e);
    e.printStackTrace();
  }
  Map<Element,List<PresentationElementInstance>> view2pe=dbAlfrescoVisitor.getView2Pe();
  Map<Element,List<PresentationElementInstance>> view2unused=dbAlfrescoVisitor.getView2Unused();
  List<Element> views=instanceUtils.getViewProcessOrder(start,dbAlfrescoVisitor.getHierarchyElements());
  views.removeAll(processedElements);
  Set<Element> skippedViews=new HashSet<>();
  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) {
    if (showValidation) {
      Utils.displayValidationWindow(project,vss,"String_Node_Str");
    }
    if (manageSesssions) {
      SessionManager.getInstance().cancelSession(project);
    }
    return;
  }
  try {
    for (    Element view : views) {
      if (skippedViews.contains(view)) {
        continue;
      }
      handlePes(view2pe.get(view),null);
      instanceUtils.updateOrCreateConstraintFromPresentationElements(view,view2pe.get(view));
    }
    if (handleCancel(progressStatus)) {
      return;
    }
    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;
      }
      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"+ JsonDiffFunction.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=instanceUtils.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"+ JsonDiffFunction.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"+ JsonDiffFunction.getInstance().apply(clientSlotJson,serverSlotJson).toString());
          }
        }
      }
    }
    if (handleCancel(progressStatus)) {
      return;
    }
    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,true,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,true,elementsToCommit.size(),"String_Node_Str"));
      changed=true;
    }
    if (!changed) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    progressStatus.setDescription("String_Node_Str");
    progressStatus.setCurrent(6);
    Set<Element> elementsToDelete=new HashSet<>();
    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 (manageSesssions) {
      if (SessionManager.getInstance().isSessionCreated(project)) {
        SessionManager.getInstance().cancelSession(project);
      }
    }
    if (localSyncTransactionCommitListener != null) {
      localSyncTransactionCommitListener.setDisabled(false);
    }
  }
  ImageValidator iv=new ImageValidator(dbAlfrescoVisitor.getImages(),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 (showValidation) {
    if (suite.hasErrors()) {
      Utils.displayValidationWindow(project,vss,"String_Node_Str");
    }
  }
}