我正在尝试将Liferay动态数据列表集成到Kaleo Workflow(Liferay 6.1 CE GA2)中,但是如何在工作流程中获取ddlRecordId?我做了一些功课,我检查了serviceContext中的所有属性,但是在serviceContext属性中没有“ddlRecordId”,只有一个名为“recordId”的键,它的值总是为0.我还可以在serviceContext属性中得到一些字段值,例如select和textarea。但我想要的是上传文件字段。感谢。
long ddlRecordId = GetterUtil.getLong(serviceContext.getAttribute("ddlRecordId"));
DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(ddlRecordId);
答案 0 :(得分:1)
在Liferay 6.1中, DDLRecordId 等同于工作流上下文变量中的 entryClassPK 。这可能是一个有用的documentation(关于工作流上下文变量的阅读部分)
因此,您可以通过以下方式获取上传文件字段:
import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
import com.liferay.portlet.dynamicdatamapping.storage.Field;
import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.util.GetterUtil;
import java.io.File;
import java.io.Serializable
DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getDDLRecord(GetterUtil.getLong(entryClassPK));
// get the upload field
Field field = ddlRecord.getField("field_attachment");
if (field != null){
DDMStructure structure = field.getDDMStructure();
Serializable fieldValue = field.getValue();
String value = String.valueOf(fieldValue);
if (!value.isEmpty()){
JSONObject fileJSONObject = JSONFactoryUtil.createJSONObject(value);
String fileName = fileJSONObject.getString("name");
String filePath = fileJSONObject.getString("path");
File file = DLStoreUtil.getFile(structure.getCompanyId(), 0L, filePath);
}
}
我希望这会有不止一个......
答案 1 :(得分:0)
我必须恢复列表中的所有DDLRecords并找到一个使用“recordSetId”属性的工作流程与DDLRecord的“recordSetId”相比。
最终代码如下:
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.dynamicdatamapping.storage.Field;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordImpl;
import com.liferay.portlet.dynamicdatalists.service.*;
long companyId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
String uuid = (String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID);
ServiceContext serviceContext = (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
long ddlRecordId = GetterUtil.getLong(serviceContext.getAttribute("recordSetId"));
List ddlRecordList = DDLRecordLocalServiceUtil.getDDLRecords(0,DDLRecordLocalServiceUtil.getDDLRecordsCount());
for(DDLRecord o : ddlRecordList){
if(o.getRecordSetId()==ddlRecordId){
Field field = o.getField("status");
String status = GetterUtil.getString(field.getValue());
if (status.contains("not")) {
returnValue = "No"
}
else {
returnValue = "Yes"
}
}
}