protected void addVariable(JSONArray array, TaskQueryVariableValue variable) {
array.put(variableValueConverter.toJsonObject(variable));
}
public TaskQuery toObject(JSONObject json) {
TaskQueryImpl query = new TaskQueryImpl();
if (json.has(TASK_ID)) {
query.taskId(json.getString(TASK_ID));
}
if (json.has(NAME)) {
query.taskName(json.getString(NAME));
}
if (json.has(NAME_LIKE)) {
query.taskNameLike(json.getString(NAME_LIKE));
}
if (json.has(DESCRIPTION)) {
query.taskDescription(json.getString(DESCRIPTION));
}
if (json.has(DESCRIPTION_LIKE)) {
query.taskDescriptionLike(json.getString(DESCRIPTION_LIKE));
}
if (json.has(PRIORITY)) {
query.taskPriority(json.getInt(PRIORITY));
}
if (json.has(MIN_PRIORITY)) {
query.taskMinPriority(json.getInt(MIN_PRIORITY));
}
if (json.has(MAX_PRIORITY)) {
query.taskMaxPriority(json.getInt(MAX_PRIORITY));
}
if (json.has(ASSIGNEE)) {
query.taskAssignee(json.getString(ASSIGNEE));
}
if (json.has(ASSIGNEE_LIKE)) {
query.taskAssigneeLike(json.getString(ASSIGNEE_LIKE));
}
if (json.has(INVOLVED_USER)) {
query.taskInvolvedUser(json.getString(INVOLVED_USER));
}
if (json.has(OWNER)) {
query.taskOwner(json.getString(OWNER));
}
if (json.has(UNASSIGNED) && json.getBoolean(UNASSIGNED)) {
query.taskUnassigned();
}
if (json.has(DELEGATION_STATE)) {
query.taskDelegationState(DelegationState.valueOf(json.getString(DELEGATION_STATE)));
}
if (json.has(CANDIDATE_USER)) {
query.taskCandidateUser(json.getString(CANDIDATE_USER));
}
if (json.has(CANDIDATE_GROUP)) {
query.taskCandidateGroup(json.getString(CANDIDATE_GROUP));
}
if (json.has(CANDIDATE_GROUPS) && !json.has(CANDIDATE_USER) && !json.has(CANDIDATE_GROUP)) {
query.taskCandidateGroupIn(getList(json.getJSONArray(CANDIDATE_GROUPS)));
}
if (json.has(PROCESS_INSTANCE_ID)) {
query.processInstanceId(json.getString(PROCESS_INSTANCE_ID));
}
if (json.has(EXECUTION_ID)) {
query.executionId(json.getString(EXECUTION_ID));
}
if (json.has(ACTIVITY_INSTANCE_ID_IN)) {
query.activityInstanceIdIn(getArray(json.getJSONArray(ACTIVITY_INSTANCE_ID_IN)));
}
if (json.has(CREATED)) {
query.taskCreatedOn(new Date(json.getLong(CREATED)));
}
if (json.has(CREATED_BEFORE)) {
query.taskCreatedBefore(new Date(json.getLong(CREATED_BEFORE)));
}
if (json.has(CREATED_AFTER)) {
query.taskCreatedAfter(new Date(json.getLong(CREATED_AFTER)));
}
if (json.has(KEY)) {
query.taskDefinitionKey(json.getString(KEY));
}
if (json.has(KEY_LIKE)) {
query.taskDefinitionKeyLike(json.getString(KEY_LIKE));
}
if (json.has(PROCESS_DEFINITION_KEY)) {
query.processDefinitionKey(json.getString(PROCESS_DEFINITION_KEY));
}
if (json.has(PROCESS_DEFINITION_ID)) {
query.processDefinitionId(json.getString(PROCESS_DEFINITION_ID));
}
if (json.has(PROCESS_DEFINITION_NAME)) {
query.processDefinitionName(json.getString(PROCESS_DEFINITION_NAME));
}
if (json.has(PROCESS_DEFINITION_NAME_LIKE)) {
query.processDefinitionNameLike(json.getString(PROCESS_DEFINITION_NAME_LIKE));
}
if (json.has(PROCESS_INSTANCE_BUSINESS_KEY)) {
query.processInstanceBusinessKey(json.getString(PROCESS_INSTANCE_BUSINESS_KEY));
}
if (json.has(PROCESS_INSTANCE_BUSINESS_KEY_LIKE)) {
query.processInstanceBusinessKeyLike(json.getString(PROCESS_INSTANCE_BUSINESS_KEY_LIKE));
}
if (json.has(TASK_VARIABLES)) {
addVariables(query, json.getJSONArray(TASK_VARIABLES), true, false);
}
if (json.has(PROCESS_VARIABLES)) {
addVariables(query, json.getJSONArray(PROCESS_VARIABLES), false, true);
}
if (json.has(CASE_INSTANCE_VARIABLES)) {
addVariables(query, json.getJSONArray(CASE_INSTANCE_VARIABLES), false, false);
}
if (json.has(DUE)) {
query.dueDate(new Date(json.getLong(DUE)));
}
if (json.has(DUE_BEFORE)) {
query.dueBefore(new Date(json.getLong(DUE_BEFORE)));
}
if (json.has(DUE_AFTER)) {
query.dueAfter(new Date(json.getLong(DUE_AFTER)));
}
if (json.has(FOLLOW_UP)) {
query.followUpDate(new Date(json.getLong(FOLLOW_UP)));
}
if (json.has(FOLLOW_UP_BEFORE)) {
query.followUpBefore(new Date(json.getLong(FOLLOW_UP_BEFORE)));
}
if (json.has(FOLLOW_UP_AFTER)) {
query.followUpAfter(new Date(json.getLong(FOLLOW_UP_AFTER)));
}
if (json.has(FOLLOW_UP_NULL_ACCEPTED)) {
query.setFollowUpNullAccepted(json.getBoolean(FOLLOW_UP_NULL_ACCEPTED));
}
if (json.has(EXCLUDE_SUBTASKS) && json.getBoolean(EXCLUDE_SUBTASKS)) {
query.excludeSubtasks();
}
if (json.has(SUSPENDED) && json.getBoolean(SUSPENDED)) {
query.suspended();
}
if (json.has(ACTIVE) && json.getBoolean(ACTIVE)) {
query.active();
}
if (json.has(CASE_DEFINITION_KEY)) {
query.caseDefinitionKey(json.getString(CASE_DEFINITION_KEY));
}
if (json.has(CASE_DEFINITION_ID)) {
query.caseDefinitionId(json.getString(CASE_DEFINITION_ID));
}
if (json.has(CASE_DEFINITION_NAME)) {
query.caseDefinitionName(json.getString(CASE_DEFINITION_NAME));
}
if (json.has(CASE_DEFINITION_NAME_LIKE)) {
query.caseDefinitionNameLike(json.getString(CASE_DEFINITION_NAME_LIKE));
}
if (json.has(CASE_INSTANCE_ID)) {
query.caseInstanceId(json.getString(CASE_INSTANCE_ID));
}
if (json.has(CASE_INSTANCE_BUSINESS_KEY)) {
query.caseInstanceBusinessKey(json.getString(CASE_INSTANCE_BUSINESS_KEY));
}
if (json.has(CASE_INSTANCE_BUSINESS_KEY_LIKE)) {
query.caseInstanceBusinessKeyLike(json.getString(CASE_INSTANCE_BUSINESS_KEY_LIKE));
}
if (json.has(CASE_EXECUTION_ID)) {
query.caseExecutionId(json.getString(CASE_EXECUTION_ID));
}
if (json.has(ORDER_BY)) {
query.setOrderBy(json.getString(ORDER_BY));
}
if (json.has(SORT_BY)) {
setSortBy(query, json.getString(SORT_BY));
}
if (json.has(SORT_ORDER)) {
String sortOrder = json.getString(SORT_ORDER);
if (Direction.ASCENDING.getName().equals(sortOrder)) {
query.asc();
}
else if (Direction.DESCENDING.getName().equals(sortOrder)) {
query.desc();
}
else {
throw new NotValidException("Unknown sort ordering '" + sortOrder + "' in query");
}
}
// expressions
Iterator jsonIterator = json.keys();
while (jsonIterator.hasNext()) {
String key = (String) jsonIterator.next();
if (key.endsWith("Expression")) {
String expression = json.getString(key);
query.addExpression(key.substring(0, key.length() - "Expression".length()), expression);
}
}
return query;
}