Program: 88606
Project: 88606
Buggy source:
@SuppressWarnings("String_Node_Str") @Override public void run(ProgressStatus progressStatus){
  progressStatus.setDescription("String_Node_Str");
  if (ProjectUtilities.isFromTeamworkServer(project.getPrimaryProject()) && TeamworkUtils.getLoggedUserName() == null) {
    Utils.guilog("String_Node_Str");
    return;
  }
  LocalSyncTransactionCommitListener listener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  if (listener == null) {
    Utils.guilog("String_Node_Str");
    return;
  }
  String url;
  try {
    url=MMSUtils.getServerUrl(project);
  }
 catch (  IllegalStateException e) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  if (url == null || url.isEmpty()) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  String site=MMSUtils.getSiteName(project);
  if (site == null || site.isEmpty()) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  try {
    if (!MMSUtils.isSiteEditable(project,site)) {
      Application.getInstance().getGUILog().log("String_Node_Str");
      return;
    }
  }
 catch (  ServerException e) {
    e.printStackTrace();
    Application.getInstance().getGUILog().log("String_Node_Str" + e.getMessage());
    return;
  }
catch (  URISyntaxException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  listener.setDisabled(true);
  SyncElements.lockSyncFolder(project);
  listener.setDisabled(false);
  JMSSyncProjectEventListenerAdapter.JMSSyncProjectMapping jmsSyncProjectMapping=JMSSyncProjectEventListenerAdapter.getProjectMapping(Application.getInstance().getProject());
  JMSMessageListener jmsMessageListener=jmsSyncProjectMapping.getJmsMessageListener();
  if (jmsMessageListener == null) {
    if (MDKOptionsGroup.getMDKOptions().isChangeListenerEnabled()) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    return;
  }
  Changelog<String,Element> persistedLocalChangelog=new Changelog<>();
  Collection<SyncElement> persistedLocalSyncElements=SyncElements.getAllOfType(project,SyncElement.Type.LOCAL);
  for (  SyncElement syncElement : persistedLocalSyncElements) {
    persistedLocalChangelog=persistedLocalChangelog.and(SyncElements.buildChangelog(syncElement),(key,value) -> Converters.getIdToElementConverter().apply(key,project));
  }
  Changelog<String,Element> localChangelog=persistedLocalChangelog.and(listener.getInMemoryLocalChangelog());
  Map<String,Element> localCreated=localChangelog.get(Changelog.ChangeType.CREATED), localUpdated=localChangelog.get(Changelog.ChangeType.UPDATED), localDeleted=localChangelog.get(Changelog.ChangeType.DELETED);
  Changelog<String,Void> persistedJmsChangelog=new Changelog<>();
  Collection<SyncElement> persistedJmsSyncElements=SyncElements.getAllOfType(project,SyncElement.Type.MMS);
  for (  SyncElement syncElement : persistedJmsSyncElements) {
    persistedJmsChangelog=persistedJmsChangelog.and(SyncElements.buildChangelog(syncElement));
  }
  Changelog<String,Void> jmsChangelog=persistedJmsChangelog.and(jmsMessageListener.getInMemoryJMSChangelog(),(key,objectNode) -> null);
  Map<String,Void> jmsCreated=jmsChangelog.get(Changelog.ChangeType.CREATED), jmsUpdated=jmsChangelog.get(Changelog.ChangeType.UPDATED), jmsDeleted=jmsChangelog.get(Changelog.ChangeType.DELETED);
  Set<String> elementIdsToGet=new HashSet<>(jmsUpdated.keySet());
  elementIdsToGet.addAll(jmsCreated.keySet());
  if (shouldUpdate && !jmsChangelog.isEmpty()) {
    int size=jmsChangelog.flattenedSize();
    Application.getInstance().getGUILog().log("String_Node_Str" + size + "String_Node_Str"+ (size != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
  }
  Map<String,ObjectNode> jmsJsons=new HashMap<>(elementIdsToGet.size());
  if (!elementIdsToGet.isEmpty()) {
    progressStatus.setDescription("String_Node_Str" + elementIdsToGet.size() + "String_Node_Str"+ (elementIdsToGet.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
    ObjectNode response=null;
    try {
      response=MMSUtils.getElementsById(elementIdsToGet,project,progressStatus);
    }
 catch (    ServerException|IOException|URISyntaxException e) {
      if (e instanceof ServerException && ((ServerException)e).getCode() == 404) {
        (response=JacksonUtils.getObjectMapper().createObjectNode()).putArray("String_Node_Str");
      }
 else       if (!progressStatus.isCancel()) {
        Application.getInstance().getGUILog().log("String_Node_Str");
        e.printStackTrace();
        return;
      }
    }
    if (progressStatus.isCancel()) {
      Application.getInstance().getGUILog().log("String_Node_Str");
      return;
    }
    JsonNode elementsArrayNode;
    if (response == null || (elementsArrayNode=response.get("String_Node_Str")) == null || !elementsArrayNode.isArray()) {
      Utils.guilog("String_Node_Str");
      return;
    }
    for (    JsonNode jsonNode : elementsArrayNode) {
      if (!jsonNode.isObject()) {
        continue;
      }
      String webId=jsonNode.get(MDKConstants.SYSML_ID_KEY).asText();
      jmsJsons.put(webId,(ObjectNode)jsonNode);
    }
  }
  progressStatus.setDescription("String_Node_Str");
  Map<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedChanges=new LinkedHashMap<>(), unconflictedChanges=new LinkedHashMap<>();
  localChangelog.findConflicts(jmsChangelog,(change,change2) -> change != null && change2 != null,conflictedChanges,unconflictedChanges);
  Map<String,Element> localElementsToPost=new LinkedHashMap<>(localCreated.size() + localUpdated.size());
  Set<String> localElementsToDelete=new HashSet<>(localDeleted.size());
  Map<String,ObjectNode> jmsElementsToCreateLocally=new LinkedHashMap<>(jmsCreated.size());
  Map<String,Pair<ObjectNode,Element>> jmsElementsToUpdateLocally=new LinkedHashMap<>(jmsUpdated.size());
  Map<String,Element> jmsElementsToDeleteLocally=new LinkedHashMap<>(jmsDeleted.size());
  for (  Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> unconflictedEntry : unconflictedChanges.entrySet()) {
    String id=unconflictedEntry.getKey();
    Changelog.Change<Element> localChange=unconflictedEntry.getValue().getFirst();
    Changelog.Change<ObjectNode> jmsChange=unconflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),unconflictedEntry.getValue().getSecond().getType()) : null;
    if (shouldCommit && localChange != null) {
      Element element=localChange.getChanged();
switch (localChange.getType()) {
case CREATED:
case UPDATED:
        if (element == null) {
          Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
          continue;
        }
      localElementsToPost.put(id,element);
    break;
case DELETED:
  if (element != null && !project.isDisposed(element)) {
    Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
    continue;
  }
localElementsToDelete.add(id);
break;
}
}
 else if (shouldUpdate && jmsChange != null) {
ObjectNode objectNode=jmsChange.getChanged();
Element element=Converters.getIdToElementConverter().apply(id,project);
switch (jmsChange.getType()) {
case CREATED:
if (objectNode == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (element != null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
jmsElementsToCreateLocally.put(id,objectNode);
break;
case UPDATED:
if (objectNode == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (element == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (!element.isEditable()) {
if (MDUtils.isDeveloperMode()) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
}
failedJmsChangelog.addChange(id,null,Changelog.ChangeType.UPDATED);
continue;
}
jmsElementsToUpdateLocally.put(id,new Pair<>(objectNode,element));
break;
case DELETED:
if (element == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (!element.isEditable()) {
if (MDUtils.isDeveloperMode()) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
}
failedJmsChangelog.addChange(id,null,Changelog.ChangeType.DELETED);
continue;
}
jmsElementsToDeleteLocally.put(id,element);
break;
}
}
}
if (progressStatus.isCancel()) {
Application.getInstance().getGUILog().log("String_Node_Str");
return;
}
boolean shouldLogNoLocalChanges=shouldCommit;
if (shouldCommit && !localElementsToPost.isEmpty()) {
progressStatus.setDescription("String_Node_Str");
ArrayNode elementsArrayNode=JacksonUtils.getObjectMapper().createArrayNode();
for (Element element : localElementsToPost.values()) {
ObjectNode elementObjectNode=Converters.getElementToJsonConverter().apply(element,project);
if (elementObjectNode != null) {
elementsArrayNode.add(elementObjectNode);
}
}
if (elementsArrayNode.size() > 0) {
ObjectNode body=JacksonUtils.getObjectMapper().createObjectNode();
body.set("String_Node_Str",elementsArrayNode);
body.put("String_Node_Str","String_Node_Str");
body.put("String_Node_Str",MDKPlugin.VERSION);
Application.getInstance().getGUILog().log("String_Node_Str" + NumberFormat.getInstance().format(elementsArrayNode.size()) + "String_Node_Str"+ (elementsArrayNode.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
try {
OutputQueue.getInstance().offer(new Request(MMSUtils.HttpRequestType.POST,MMSUtils.getServiceWorkspacesSitesElementsUri(project),body,true,elementsArrayNode.size(),"String_Node_Str"));
}
 catch (IOException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
catch (URISyntaxException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
shouldLogNoLocalChanges=false;
}
}
if (shouldCommit && shouldCommitDeletes && !localElementsToDelete.isEmpty()) {
progressStatus.setDescription("String_Node_Str");
ArrayNode elementsArrayNode=JacksonUtils.getObjectMapper().createArrayNode();
for (String id : localElementsToDelete) {
ObjectNode elementObjectNode=JacksonUtils.getObjectMapper().createObjectNode();
elementObjectNode.put(MDKConstants.SYSML_ID_KEY,id);
elementsArrayNode.add(elementObjectNode);
}
ObjectNode body=JacksonUtils.getObjectMapper().createObjectNode();
body.set("String_Node_Str",elementsArrayNode);
body.put("String_Node_Str","String_Node_Str");
body.put("String_Node_Str",MDKPlugin.VERSION);
Application.getInstance().getGUILog().log("String_Node_Str" + NumberFormat.getInstance().format(elementsArrayNode.size()) + "String_Node_Str"+ (elementsArrayNode.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
URIBuilder uri=MMSUtils.getServiceWorkspacesSitesElementsUri(project);
try {
OutputQueue.getInstance().offer(new Request(MMSUtils.HttpRequestType.POST,uri,body,true,elementsArrayNode.size(),"String_Node_Str"));
}
 catch (IOException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
catch (URISyntaxException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
shouldLogNoLocalChanges=false;
}
if (shouldLogNoLocalChanges) {
Application.getInstance().getGUILog().log("String_Node_Str");
}
if (shouldUpdate) {
listener.setDisabled(true);
List<ObjectNode> jmsElementsToCreateOrUpdateLocally=new ArrayList<>(jmsElementsToCreateLocally.size() + jmsElementsToUpdateLocally.size());
jmsElementsToCreateOrUpdateLocally.addAll(jmsElementsToCreateLocally.values());
jmsElementsToUpdateLocally.values().forEach(pair -> jmsElementsToCreateOrUpdateLocally.add(pair.getFirst()));
UpdateClientElementAction updateClientElementAction=new UpdateClientElementAction(project);
updateClientElementAction.setElementsToUpdate(jmsElementsToCreateOrUpdateLocally);
updateClientElementAction.setElementsToDelete(jmsElementsToDeleteLocally.values().stream().map(Converters.getElementToIdConverter()).filter(id -> id != null).collect(Collectors.toList()));
updateClientElementAction.run(progressStatus);
failedJmsChangelog=failedJmsChangelog.and(updateClientElementAction.getFailedChangelog(),(id,objectNode) -> null);
listener.setDisabled(false);
}
progressStatus.setDescription("String_Node_Str");
Set<Element> localConflictedElements=new HashSet<>();
Set<ObjectNode> jmsConflictedElements=new HashSet<>();
for (Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedEntry : conflictedChanges.entrySet()) {
String id=conflictedEntry.getKey();
Changelog.Change<Element> localChange=conflictedEntry.getValue().getFirst();
Changelog.Change<ObjectNode> jmsChange=conflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),conflictedEntry.getValue().getSecond().getType()) : null;
if (localChange != null && localChange.getChanged() != null && !project.isDisposed(localChange.getChanged())) {
localConflictedElements.add(localChange.getChanged());
}
if (jmsChange != null && jmsChange.getChanged() != null) {
jmsConflictedElements.add(jmsChange.getChanged());
}
}
ElementValidator elementValidator=new ElementValidator(ElementValidator.buildElementPairs(localConflictedElements,project),jmsConflictedElements,project);
elementValidator.run(progressStatus);
if (!elementValidator.getInvalidElements().isEmpty()) {
Application.getInstance().getGUILog().log("String_Node_Str" + elementValidator.getInvalidElements().size() + "String_Node_Str"+ (elementValidator.getInvalidElements().size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
vss.add(elementValidator.getValidationSuite());
Utils.displayValidationWindow(elementValidator.getValidationSuite(),"String_Node_Str");
for (Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedEntry : conflictedChanges.entrySet()) {
String id=conflictedEntry.getKey();
if (!elementValidator.getInvalidElements().containsKey(id)) {
continue;
}
Changelog.Change<Element> localChange=conflictedEntry.getValue().getFirst();
Changelog.Change<ObjectNode> jmsChange=conflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),conflictedEntry.getValue().getSecond().getType()) : null;
if (localChange != null && localChange.getChanged() != null || Changelog.ChangeType.DELETED.equals(localChange.getType())) {
failedLocalChangelog.addChange(conflictedEntry.getKey(),localChange.getChanged(),localChange.getType());
}
if (jmsChange != null && jmsChange.getChanged() != null || Changelog.ChangeType.DELETED.equals(jmsChange.getType())) {
failedJmsChangelog.addChange(conflictedEntry.getKey(),null,jmsChange.getType());
}
}
}
listener.getInMemoryLocalChangelog().clear();
jmsMessageListener.getInMemoryJMSChangelog().clear();
listener.setDisabled(true);
if (!SessionManager.getInstance().isSessionCreated()) {
SessionManager.getInstance().createSession("String_Node_Str");
}
Changelog<String,Void> unprocessedLocalChangelog=new Changelog<>();
if (!shouldCommit) {
unprocessedLocalChangelog=unprocessedLocalChangelog.and(localChangelog,(s,element) -> null);
}
if (shouldCommit && !shouldCommitDeletes) {
Map<String,Void> unprocessedLocalDeletedChanges=unprocessedLocalChangelog.get(Changelog.ChangeType.DELETED);
for (String key : localChangelog.get(Changelog.ChangeType.DELETED).keySet()) {
unprocessedLocalDeletedChanges.put(key,null);
}
}
unprocessedLocalChangelog=unprocessedLocalChangelog.and(failedLocalChangelog,(s,element) -> null);
try {
SyncElements.setByType(project,SyncElement.Type.LOCAL,JacksonUtils.getObjectMapper().writeValueAsString(SyncElements.buildJson(unprocessedLocalChangelog)));
}
 catch (JsonProcessingException e) {
e.printStackTrace();
}
Changelog<String,Void> unprocessedJmsChangelog=new Changelog<>();
if (!shouldUpdate) {
unprocessedJmsChangelog=unprocessedJmsChangelog.and(jmsChangelog);
}
unprocessedJmsChangelog=unprocessedJmsChangelog.and(failedJmsChangelog);
try {
SyncElements.setByType(project,SyncElement.Type.MMS,JacksonUtils.getObjectMapper().writeValueAsString(SyncElements.buildJson(unprocessedJmsChangelog)));
}
 catch (JsonProcessingException e) {
e.printStackTrace();
}
SessionManager.getInstance().closeSession();
listener.setDisabled(false);
failure=false;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override public void run(ProgressStatus progressStatus){
  progressStatus.setDescription("String_Node_Str");
  if (ProjectUtilities.isFromTeamworkServer(project.getPrimaryProject()) && TeamworkUtils.getLoggedUserName() == null) {
    Utils.guilog("String_Node_Str");
    return;
  }
  LocalSyncTransactionCommitListener listener=LocalSyncProjectEventListenerAdapter.getProjectMapping(project).getLocalSyncTransactionCommitListener();
  if (listener == null) {
    Utils.guilog("String_Node_Str");
    return;
  }
  String url;
  try {
    url=MMSUtils.getServerUrl(project);
  }
 catch (  IllegalStateException e) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  if (url == null || url.isEmpty()) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  String site=MMSUtils.getSiteName(project);
  if (site == null || site.isEmpty()) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    return;
  }
  try {
    if (!MMSUtils.isSiteEditable(project,site)) {
      Application.getInstance().getGUILog().log("String_Node_Str");
      return;
    }
  }
 catch (  ServerException e) {
    e.printStackTrace();
    Application.getInstance().getGUILog().log("String_Node_Str" + e.getMessage());
    return;
  }
catch (  URISyntaxException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  listener.setDisabled(true);
  SyncElements.lockSyncFolder(project);
  listener.setDisabled(false);
  JMSSyncProjectEventListenerAdapter.JMSSyncProjectMapping jmsSyncProjectMapping=JMSSyncProjectEventListenerAdapter.getProjectMapping(Application.getInstance().getProject());
  JMSMessageListener jmsMessageListener=jmsSyncProjectMapping.getJmsMessageListener();
  if (jmsMessageListener == null) {
    if (MDKOptionsGroup.getMDKOptions().isChangeListenerEnabled()) {
      Application.getInstance().getGUILog().log("String_Node_Str");
    }
    return;
  }
  Changelog<String,Element> persistedLocalChangelog=new Changelog<>();
  Collection<SyncElement> persistedLocalSyncElements=SyncElements.getAllOfType(project,SyncElement.Type.LOCAL);
  for (  SyncElement syncElement : persistedLocalSyncElements) {
    persistedLocalChangelog=persistedLocalChangelog.and(SyncElements.buildChangelog(syncElement),(key,value) -> Converters.getIdToElementConverter().apply(key,project));
  }
  Changelog<String,Element> localChangelog=persistedLocalChangelog.and(listener.getInMemoryLocalChangelog());
  Map<String,Element> localCreated=localChangelog.get(Changelog.ChangeType.CREATED), localUpdated=localChangelog.get(Changelog.ChangeType.UPDATED), localDeleted=localChangelog.get(Changelog.ChangeType.DELETED);
  Changelog<String,Void> persistedJmsChangelog=new Changelog<>();
  Collection<SyncElement> persistedJmsSyncElements=SyncElements.getAllOfType(project,SyncElement.Type.MMS);
  for (  SyncElement syncElement : persistedJmsSyncElements) {
    persistedJmsChangelog=persistedJmsChangelog.and(SyncElements.buildChangelog(syncElement));
  }
  Changelog<String,Void> jmsChangelog=persistedJmsChangelog.and(jmsMessageListener.getInMemoryJMSChangelog(),(key,objectNode) -> null);
  Map<String,Void> jmsCreated=jmsChangelog.get(Changelog.ChangeType.CREATED), jmsUpdated=jmsChangelog.get(Changelog.ChangeType.UPDATED), jmsDeleted=jmsChangelog.get(Changelog.ChangeType.DELETED);
  Set<String> elementIdsToGet=new HashSet<>(jmsUpdated.keySet());
  elementIdsToGet.addAll(jmsCreated.keySet());
  if (shouldUpdate && !jmsChangelog.isEmpty()) {
    int size=jmsChangelog.flattenedSize();
    Application.getInstance().getGUILog().log("String_Node_Str" + size + "String_Node_Str"+ (size != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
  }
  Map<String,ObjectNode> jmsJsons=new HashMap<>(elementIdsToGet.size());
  if (!elementIdsToGet.isEmpty()) {
    progressStatus.setDescription("String_Node_Str" + elementIdsToGet.size() + "String_Node_Str"+ (elementIdsToGet.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
    ObjectNode response=null;
    try {
      response=MMSUtils.getElementsById(elementIdsToGet,project,progressStatus);
    }
 catch (    ServerException|IOException|URISyntaxException e) {
      if (e instanceof ServerException && ((ServerException)e).getCode() == 404) {
        (response=JacksonUtils.getObjectMapper().createObjectNode()).putArray("String_Node_Str");
      }
 else       if (!progressStatus.isCancel()) {
        Application.getInstance().getGUILog().log("String_Node_Str");
        e.printStackTrace();
        return;
      }
    }
    if (progressStatus.isCancel()) {
      Application.getInstance().getGUILog().log("String_Node_Str");
      return;
    }
    JsonNode elementsArrayNode;
    if (response == null || (elementsArrayNode=response.get("String_Node_Str")) == null || !elementsArrayNode.isArray()) {
      Utils.guilog("String_Node_Str");
      return;
    }
    for (    JsonNode jsonNode : elementsArrayNode) {
      if (!jsonNode.isObject()) {
        continue;
      }
      String webId=jsonNode.get(MDKConstants.SYSML_ID_KEY).asText();
      jmsJsons.put(webId,(ObjectNode)jsonNode);
    }
  }
  progressStatus.setDescription("String_Node_Str");
  Map<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedChanges=new LinkedHashMap<>(), unconflictedChanges=new LinkedHashMap<>();
  localChangelog.findConflicts(jmsChangelog,(change,change2) -> change != null && change2 != null,conflictedChanges,unconflictedChanges);
  Map<String,Element> localElementsToPost=new LinkedHashMap<>(localCreated.size() + localUpdated.size());
  Set<String> localElementsToDelete=new HashSet<>(localDeleted.size());
  Map<String,ObjectNode> jmsElementsToCreateLocally=new LinkedHashMap<>(jmsCreated.size());
  Map<String,Pair<ObjectNode,Element>> jmsElementsToUpdateLocally=new LinkedHashMap<>(jmsUpdated.size());
  Map<String,Element> jmsElementsToDeleteLocally=new LinkedHashMap<>(jmsDeleted.size());
  for (  Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> unconflictedEntry : unconflictedChanges.entrySet()) {
    String id=unconflictedEntry.getKey();
    Changelog.Change<Element> localChange=unconflictedEntry.getValue().getFirst();
    Changelog.Change<ObjectNode> jmsChange=unconflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),unconflictedEntry.getValue().getSecond().getType()) : null;
    if (shouldCommit && localChange != null) {
      Element element=localChange.getChanged();
switch (localChange.getType()) {
case CREATED:
case UPDATED:
        if (element == null) {
          Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
          continue;
        }
      localElementsToPost.put(id,element);
    break;
case DELETED:
  if (element != null && !project.isDisposed(element)) {
    Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
    continue;
  }
localElementsToDelete.add(id);
break;
}
}
 else if (shouldUpdate && jmsChange != null) {
ObjectNode objectNode=jmsChange.getChanged();
Element element=Converters.getIdToElementConverter().apply(id,project);
switch (jmsChange.getType()) {
case CREATED:
if (objectNode == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (element != null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
jmsElementsToCreateLocally.put(id,objectNode);
break;
case UPDATED:
if (objectNode == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (element == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (!element.isEditable()) {
if (MDUtils.isDeveloperMode()) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
}
failedJmsChangelog.addChange(id,null,Changelog.ChangeType.UPDATED);
continue;
}
jmsElementsToUpdateLocally.put(id,new Pair<>(objectNode,element));
break;
case DELETED:
if (element == null) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
continue;
}
if (!element.isEditable()) {
if (MDUtils.isDeveloperMode()) {
Application.getInstance().getGUILog().log("String_Node_Str" + id + "String_Node_Str");
}
failedJmsChangelog.addChange(id,null,Changelog.ChangeType.DELETED);
continue;
}
jmsElementsToDeleteLocally.put(id,element);
break;
}
}
}
if (progressStatus.isCancel()) {
Application.getInstance().getGUILog().log("String_Node_Str");
return;
}
boolean shouldLogNoLocalChanges=shouldCommit;
if (shouldCommit && !localElementsToPost.isEmpty()) {
progressStatus.setDescription("String_Node_Str");
ArrayNode elementsArrayNode=JacksonUtils.getObjectMapper().createArrayNode();
for (Element element : localElementsToPost.values()) {
ObjectNode elementObjectNode=Converters.getElementToJsonConverter().apply(element,project);
if (elementObjectNode != null) {
elementsArrayNode.add(elementObjectNode);
}
}
if (elementsArrayNode.size() > 0) {
ObjectNode body=JacksonUtils.getObjectMapper().createObjectNode();
body.set("String_Node_Str",elementsArrayNode);
body.put("String_Node_Str","String_Node_Str");
body.put("String_Node_Str",MDKPlugin.VERSION);
Application.getInstance().getGUILog().log("String_Node_Str" + NumberFormat.getInstance().format(elementsArrayNode.size()) + "String_Node_Str"+ (elementsArrayNode.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
try {
OutputQueue.getInstance().offer(new Request(MMSUtils.HttpRequestType.POST,MMSUtils.getServiceWorkspacesSitesElementsUri(project),body,true,elementsArrayNode.size(),"String_Node_Str"));
}
 catch (IOException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
catch (URISyntaxException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
shouldLogNoLocalChanges=false;
}
}
if (shouldCommit && shouldCommitDeletes && !localElementsToDelete.isEmpty()) {
progressStatus.setDescription("String_Node_Str");
ArrayNode elementsArrayNode=JacksonUtils.getObjectMapper().createArrayNode();
for (String id : localElementsToDelete) {
ObjectNode elementObjectNode=JacksonUtils.getObjectMapper().createObjectNode();
elementObjectNode.put(MDKConstants.SYSML_ID_KEY,id);
elementsArrayNode.add(elementObjectNode);
}
ObjectNode body=JacksonUtils.getObjectMapper().createObjectNode();
body.set("String_Node_Str",elementsArrayNode);
body.put("String_Node_Str","String_Node_Str");
body.put("String_Node_Str",MDKPlugin.VERSION);
Application.getInstance().getGUILog().log("String_Node_Str" + NumberFormat.getInstance().format(elementsArrayNode.size()) + "String_Node_Str"+ (elementsArrayNode.size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
URIBuilder uri=MMSUtils.getServiceWorkspacesSitesElementsUri(project);
try {
OutputQueue.getInstance().offer(new Request(MMSUtils.HttpRequestType.DELETE,uri,body,true,elementsArrayNode.size(),"String_Node_Str"));
}
 catch (IOException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
catch (URISyntaxException e) {
Application.getInstance().getGUILog().log("String_Node_Str");
e.printStackTrace();
}
shouldLogNoLocalChanges=false;
}
if (shouldLogNoLocalChanges) {
Application.getInstance().getGUILog().log("String_Node_Str");
}
if (shouldUpdate) {
listener.setDisabled(true);
List<ObjectNode> jmsElementsToCreateOrUpdateLocally=new ArrayList<>(jmsElementsToCreateLocally.size() + jmsElementsToUpdateLocally.size());
jmsElementsToCreateOrUpdateLocally.addAll(jmsElementsToCreateLocally.values());
jmsElementsToUpdateLocally.values().forEach(pair -> jmsElementsToCreateOrUpdateLocally.add(pair.getFirst()));
UpdateClientElementAction updateClientElementAction=new UpdateClientElementAction(project);
updateClientElementAction.setElementsToUpdate(jmsElementsToCreateOrUpdateLocally);
updateClientElementAction.setElementsToDelete(jmsElementsToDeleteLocally.values().stream().map(Converters.getElementToIdConverter()).filter(id -> id != null).collect(Collectors.toList()));
updateClientElementAction.run(progressStatus);
failedJmsChangelog=failedJmsChangelog.and(updateClientElementAction.getFailedChangelog(),(id,objectNode) -> null);
listener.setDisabled(false);
}
progressStatus.setDescription("String_Node_Str");
Set<Element> localConflictedElements=new HashSet<>();
Set<ObjectNode> jmsConflictedElements=new HashSet<>();
for (Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedEntry : conflictedChanges.entrySet()) {
String id=conflictedEntry.getKey();
Changelog.Change<Element> localChange=conflictedEntry.getValue().getFirst();
Changelog.Change<ObjectNode> jmsChange=conflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),conflictedEntry.getValue().getSecond().getType()) : null;
if (localChange != null && localChange.getChanged() != null && !project.isDisposed(localChange.getChanged())) {
localConflictedElements.add(localChange.getChanged());
}
if (jmsChange != null && jmsChange.getChanged() != null) {
jmsConflictedElements.add(jmsChange.getChanged());
}
}
ElementValidator elementValidator=new ElementValidator(ElementValidator.buildElementPairs(localConflictedElements,project),jmsConflictedElements,project);
elementValidator.run(progressStatus);
if (!elementValidator.getInvalidElements().isEmpty()) {
Application.getInstance().getGUILog().log("String_Node_Str" + elementValidator.getInvalidElements().size() + "String_Node_Str"+ (elementValidator.getInvalidElements().size() != 1 ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str");
vss.add(elementValidator.getValidationSuite());
Utils.displayValidationWindow(elementValidator.getValidationSuite(),"String_Node_Str");
for (Map.Entry<String,Pair<Changelog.Change<Element>,Changelog.Change<Void>>> conflictedEntry : conflictedChanges.entrySet()) {
String id=conflictedEntry.getKey();
if (!elementValidator.getInvalidElements().containsKey(id)) {
continue;
}
Changelog.Change<Element> localChange=conflictedEntry.getValue().getFirst();
Changelog.Change<ObjectNode> jmsChange=conflictedEntry.getValue().getSecond() != null ? new Changelog.Change<>(jmsJsons.get(id),conflictedEntry.getValue().getSecond().getType()) : null;
if (localChange != null && localChange.getChanged() != null || Changelog.ChangeType.DELETED.equals(localChange.getType())) {
failedLocalChangelog.addChange(conflictedEntry.getKey(),localChange.getChanged(),localChange.getType());
}
if (jmsChange != null && jmsChange.getChanged() != null || Changelog.ChangeType.DELETED.equals(jmsChange.getType())) {
failedJmsChangelog.addChange(conflictedEntry.getKey(),null,jmsChange.getType());
}
}
}
listener.getInMemoryLocalChangelog().clear();
jmsMessageListener.getInMemoryJMSChangelog().clear();
listener.setDisabled(true);
if (!SessionManager.getInstance().isSessionCreated()) {
SessionManager.getInstance().createSession("String_Node_Str");
}
Changelog<String,Void> unprocessedLocalChangelog=new Changelog<>();
if (!shouldCommit) {
unprocessedLocalChangelog=unprocessedLocalChangelog.and(localChangelog,(s,element) -> null);
}
if (shouldCommit && !shouldCommitDeletes) {
Map<String,Void> unprocessedLocalDeletedChanges=unprocessedLocalChangelog.get(Changelog.ChangeType.DELETED);
for (String key : localChangelog.get(Changelog.ChangeType.DELETED).keySet()) {
unprocessedLocalDeletedChanges.put(key,null);
}
}
unprocessedLocalChangelog=unprocessedLocalChangelog.and(failedLocalChangelog,(s,element) -> null);
try {
SyncElements.setByType(project,SyncElement.Type.LOCAL,JacksonUtils.getObjectMapper().writeValueAsString(SyncElements.buildJson(unprocessedLocalChangelog)));
}
 catch (JsonProcessingException e) {
e.printStackTrace();
}
Changelog<String,Void> unprocessedJmsChangelog=new Changelog<>();
if (!shouldUpdate) {
unprocessedJmsChangelog=unprocessedJmsChangelog.and(jmsChangelog);
}
unprocessedJmsChangelog=unprocessedJmsChangelog.and(failedJmsChangelog);
try {
SyncElements.setByType(project,SyncElement.Type.MMS,JacksonUtils.getObjectMapper().writeValueAsString(SyncElements.buildJson(unprocessedJmsChangelog)));
}
 catch (JsonProcessingException e) {
e.printStackTrace();
}
SessionManager.getInstance().closeSession();
listener.setDisabled(false);
failure=false;
}