-1

我正在 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); 但我仍然有同样的问题

4

2 回答 2

1

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

         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>());
于 2018-03-06T05:52:23.107 回答
0

这是一段代码,可以正确地将文件条目插入到文档库中。注意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);
于 2014-08-25T16:16:27.770 回答