Liferay文档管理系统工作流程

时间:2014-08-24 20:13:12

标签: liferay workflow dms

我在Liferay中创建了一个DMS。到目前为止,我可以在文档库中上传Liferay中的文档。而且我也可以在文档和媒体portlet中看到文档。问题是虽然文档的状态处于暂挂状态,但工作流程未启动。以下是我的代码。

                Folder folder = null;
//  getting folder
                try {

                folder =    DLAppLocalServiceUtil.getFolder(10181, 0, folderName);
                System.out.println("getting folder");
                } catch(NoSuchFolderException e)
                {
//                  creating folder
                    System.out.println("creating folder");
                    try {
                        folder = DLAppLocalServiceUtil.addFolder(userId, 10181, 0, folderName, description, serviceContext);

                    } catch (PortalException e3) {
                        // TODO Auto-generated catch block
                        e3.printStackTrace();
                    } catch (SystemException e3) {
                        // TODO Auto-generated catch block
                        e3.printStackTrace();
                    }

                }

                catch (PortalException e4) {
                    // TODO Auto-generated catch block
                    e4.printStackTrace();
                } catch (SystemException e4) {
                    // TODO Auto-generated catch block
                    e4.printStackTrace();
                }


//                  adding file

                    try {
                        System.out.println("New File");

fileEntry = DLAppLocalServiceUtil.addFileEntry(userId,
                                10181, folder.getFolderId(), sourceFileName,
                                mimeType, title, "testing description",
                                "changeLog", sampleChapter, serviceContext);

Map<String, Serializable> workflowContext = new HashMap<String, Serializable>();
workflowContext.put("event",DLSyncConstants.EVENT_CHECK_IN);

DLFileEntryLocalServiceUtil.updateStatus(userId, fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.ACTION_PUBLISH, workflowContext, serviceContext);
System.out.println("after entry"+ fileEntry.getFileEntryId());

                    } catch (DuplicateFileException e) {

                            } catch (PortalException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            } catch (SystemException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        } catch (PortalException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (SystemException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                    }

            return fileEntry.getFileEntryId();

    } 

我甚至使用过WorkflowHandlerRegistryUtil.startWorkflowInstance(companyId, userId, fileEntry.getClass().getName(), fileEntry.getClassPK, fileEntry, serviceContext); 但我仍有同样的问题

2 个答案:

答案 0 :(得分:1)

如果您正在Liferay Dxp中处理上传文档和媒体的DMS服务。 默认情况下,文档的状态草稿。您可以使用以下代码,

         DLFileEntry dlFileEntry = null;
         String fileName = null;
         long PARENT_FOLDER_ID = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
         DLFolder folder = DLFolderLocalServiceUtil.getFolder(group.getGroupId(), PARENT_FOLDER_ID,
                        "SirswaPartnerDocuments");
                long groupId = folder.getGroupId();
                long repositoryId = folder.getRepositoryId();
                long folderId = folder.getFolderId();
                String sourceFileName = "dummy";
                String mimeType = MimeTypesUtil.getContentType(file);
                String title = file.getName();
                String extension = "Caption";
                fileName = file.getName();

            String uniqueTitle = DLFileEntryLocalServiceUtil.getUniqueTitle(groupId, folderId,
                    folder.getDefaultFileEntryTypeId(), title, extension);

            String changeLog = "SirswaChangeLog";
            String description = folder.getDescription();
            long defaultFileEntryTypeId = folder.getDefaultFileEntryTypeId();
        try
         {
            dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(folder.getUserId(), groupId,
            repositoryId, folder.getFolderId(), sourceFileName, MimeTypesUtil.getContentType(file),
            uniqueTitle, description, changeLog, folder.getDefaultFileEntryTypeId(),
            ddmFormValuesMap, file, is, size, serviceContext);

        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }  

现在,如果您想以编程方式将文档和媒体草稿的状态更改为已批准

使用以下代码它将按预期工作

 int workFlowStatus = WorkflowConstants.STATUS_APPROVED;

                        dlFileEntry = DLFileEntryLocalServiceUtil.updateStatus(folder.getUserId(),dlFileEntry.getFileVersion().getFileVersionId(),workFlowStatus, serviceContext,new HashMap<String, Serializable>());

答案 1 :(得分:0)

这是一段将fileentry正确插入文档库的代码。请注意serviceContext设置。

                    ServiceContext serviceContext = new ServiceContext();
                    serviceContext.setAddGroupPermissions(true);
                    serviceContext.setUserId(userDest.getUserId());
                    serviceContext.setScopeGroupId(userDest.getGroupId());
                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

                    FileEntry newfile =
                        DLAppLocalServiceUtil.addFileEntry(
                            userDest.getUserId(),
                            userDest.getGroupId(),
                            folder.getFolderId(),
                            item.getFileName(),
                            MimeTypesUtil.getContentType(item.getFileName()),
                            item.getFileName(), null, null, bytes,
                            serviceContext);