/** * Parse Json Response from Alfresco REST API to create a process Definition Object. * * @param json : json response that contains data from the repository * @return ProcessDefinition Object */ @SuppressWarnings("unchecked") public static Process parseJson(Map<String, Object> json) { ProcessImpl process = new ProcessImpl(); // Public Properties process.identifier = JSONConverter.getString(json, OnPremiseConstant.ID_VALUE); String definitionIdentifier = JSONConverter.getString(json, OnPremiseConstant.DEFINITIONURL_VALUE); process.definitionIdentifier = definitionIdentifier.replace(SUFFIX_WORKFLOW_DEFINITION, ""); process.key = JSONConverter.getString(json, OnPremiseConstant.NAME_VALUE); process.name = JSONConverter.getString(json, OnPremiseConstant.TITLE_VALUE); process.priority = JSONConverter.getInteger(json, OnPremiseConstant.PRIORITY_VALUE).intValue(); process.description = JSONConverter.getString(json, OnPremiseConstant.MESSAGE_VALUE); // PARSE DATES String date = JSONConverter.getString(json, OnPremiseConstant.STARTDATE_VALUE); GregorianCalendar g = new GregorianCalendar(); SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.FORMAT_3, Locale.getDefault()); if (date != null) { g.setTime(DateUtils.parseDate(date, sdf)); process.startedAt = g; } date = JSONConverter.getString(json, OnPremiseConstant.ENDDATE_VALUE); if (date != null) { g = new GregorianCalendar(); g.setTime(DateUtils.parseDate(date, sdf)); process.endedAt = g; } // PARSE INITIATOR Map<String, Object> initiator = (Map<String, Object>) json.get(OnPremiseConstant.INITIATOR_VALUE); Person p = PersonImpl.parseJson(initiator); process.initiatorIdentifier = p.getIdentifier(); // EXTRA PROPERTIES process.data = new HashMap<String, Serializable>(); process.data.put(OnPremiseConstant.INITIATOR_VALUE, p); date = JSONConverter.getString(json, OnPremiseConstant.DUEDATE_VALUE); if (date != null) { g = new GregorianCalendar(); g.setTime(DateUtils.parseDate(date, sdf)); process.dueAt = g; } process.data.put(OnPremiseConstant.DUEDATE_VALUE, g); process.data.put( OnPremiseConstant.DESCRIPTION_VALUE, JSONConverter.getString(json, OnPremiseConstant.DESCRIPTION_VALUE)); process.data.put( OnPremiseConstant.ISACTIVE_VALUE, JSONConverter.getBoolean(json, OnPremiseConstant.ISACTIVE_VALUE)); process.hasAllVariables = true; return process; }
public static Process refreshProcess(Process process, Map<String, Property> properties) { if (process == null) { return null; } if (properties == null) { return process; } ProcessImpl refreshedProcess = new ProcessImpl(); refreshedProcess.identifier = process.getIdentifier(); refreshedProcess.definitionIdentifier = process.getDefinitionIdentifier(); refreshedProcess.key = process.getKey(); refreshedProcess.startedAt = process.getStartedAt(); refreshedProcess.endedAt = process.getEndedAt(); refreshedProcess.description = process.getDescription(); refreshedProcess.priority = process.getPriority(); refreshedProcess.initiatorIdentifier = process.getInitiatorIdentifier(); refreshedProcess.name = process.getName(); refreshedProcess.variables = properties; refreshedProcess.hasAllVariables = true; return refreshedProcess; }