/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.workflow.kaleo.runtime.internal.util;
import com.liferay.portal.kernel.json.JSONFactory;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.workflow.kaleo.model.KaleoInstanceToken;
import com.liferay.portal.workflow.kaleo.model.KaleoTaskInstanceToken;
import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext;
import java.io.Serializable;
import java.util.Map;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Marcellus Tavares
*/
@Component(immediate = true, service = NotificationMessageHelper.class)
public class NotificationMessageHelper {
public JSONObject createMessageJSONObject(
String notificationMessage, ExecutionContext executionContext) {
JSONObject jsonObject = jsonFactory.createJSONObject();
Map<String, Serializable> workflowContext =
executionContext.getWorkflowContext();
jsonObject.put(
WorkflowConstants.CONTEXT_COMPANY_ID,
String.valueOf(
workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID)));
jsonObject.put(
WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME,
(String)workflowContext.get(
WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME));
jsonObject.put(
WorkflowConstants.CONTEXT_ENTRY_CLASS_PK,
String.valueOf(
workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)));
jsonObject.put(
WorkflowConstants.CONTEXT_ENTRY_TYPE,
(String)workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_TYPE));
jsonObject.put(
WorkflowConstants.CONTEXT_GROUP_ID,
String.valueOf(
workflowContext.get(WorkflowConstants.CONTEXT_GROUP_ID)));
KaleoInstanceToken kaleoInstanceToken =
executionContext.getKaleoInstanceToken();
long userId = kaleoInstanceToken.getUserId();
KaleoTaskInstanceToken kaleoTaskInstanceToken =
executionContext.getKaleoTaskInstanceToken();
if (kaleoTaskInstanceToken != null) {
userId = kaleoTaskInstanceToken.getUserId();
}
jsonObject.put(
WorkflowConstants.CONTEXT_USER_ID, String.valueOf(userId));
jsonObject.put("notificationMessage", notificationMessage);
jsonObject.put(
"workflowInstanceId", kaleoInstanceToken.getKaleoInstanceId());
if (kaleoTaskInstanceToken != null) {
jsonObject.put(
"workflowTaskId",
kaleoTaskInstanceToken.getKaleoTaskInstanceTokenId());
}
return jsonObject;
}
@Reference
protected JSONFactory jsonFactory;
}