private void writeHistoryPerWorksheet(Workspace workspace, IHistorySaver historySaver) throws Exception {
String workspaceId = workspace.getId();
Map<String, JSONArray> comMap = new HashMap<>();
for(ICommand command : _getHistory()) {
if(command.isSavedInHistory() &&
(command.hasTag(CommandTag.Modeling)
|| command.hasTag(CommandTag.Transformation)
|| command.hasTag(CommandTag.Selection)
|| command.hasTag(CommandTag.SemanticType)
)) {
JSONArray json = new JSONArray(command.getInputParameterJson());
String worksheetId = HistoryJsonUtil.getStringValue(HistoryArguments.worksheetId.name(), json);
if(workspace.getWorksheet(worksheetId) != null)
{
try {
if(comMap.get(worksheetId) == null)
comMap.put(worksheetId, new JSONArray());
comMap.get(worksheetId).put(getCommandJSON(workspace, command));
} catch(Exception e) {
logger.error("Error serializing command {} to history, Input:{}", command.getCommandName(), command.getInputParameterJson());
}
}
}
}
for(Map.Entry<String, JSONArray> stringJSONArrayEntry : comMap.entrySet()) {
JSONArray comms = stringJSONArrayEntry.getValue();
historySaver.saveHistory(workspaceId, stringJSONArrayEntry.getKey(), comms);
}
}