-1

I am creating a DMS in Liferay. So far I could upload documents in Liferay in document library. And also I can see documents in document and media portlet. The problem is though status for the document is in pending state, the workflow is not started. Below is my code.

                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();

    } 

I have even used WorkflowHandlerRegistryUtil.startWorkflowInstance(companyId, userId, fileEntry.getClass().getName(), fileEntry.getClassPK, fileEntry, serviceContext); But still i have the same problem

halfer
  • 19,824
  • 17
  • 99
  • 186
Rajkumar
  • 189
  • 5
  • 19

2 Answers2

1

If you are working on DMS service for upload document and media in Liferay Dxp. By default status of the document will be draft.You can use below code,

         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();
        }  

Now if you want to change the status of document and media draft to Approved programmatically.

Use below code It will work as expected

 int workFlowStatus = WorkflowConstants.STATUS_APPROVED;

                        dlFileEntry = DLFileEntryLocalServiceUtil.updateStatus(folder.getUserId(),dlFileEntry.getFileVersion().getFileVersionId(),workFlowStatus, serviceContext,new HashMap<String, Serializable>());
Ravikant
  • 149
  • 1
  • 5
0

This is a piece of code that insert correctly fileentry into document library. Take care the serviceContext settings.

                    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);
Daniele Baggio
  • 2,157
  • 1
  • 14
  • 21
  • I tried with the same thing but I get stackoverflow error. and file is not getting added. – Rajkumar Aug 25 '14 at 17:53
  • serviceContext.setScopeGroupId(10181); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); serviceContext.setAssetEntryVisible(true); serviceContext.setUserId(userId); – Rajkumar Aug 25 '14 at 17:56
  • I dont know how to paste the error log here. Caused by: java.lang.StackOverflowError at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.getConstructor(Unknown Source) this is at com.liferay.portal.json.jabsorb.serializer.LiferaySerializer.canSerialize(LiferaySerializer.java:52) at org.jabsorb.JSONSerializer.getSerializer(JSONSerializer.java:818) at org.jabsorb.JSONSerializer.marshall(JSONSerializer.java:387) at org.jabsorb.serializer.impl.BeanSerializer.marshall(BeanSerializer.java:240) – Rajkumar Aug 26 '14 at 14:18
  • Strange error log, but i need the full stack trace. Use gist.github.com, paste the log, give us the link.. – Daniele Baggio Aug 27 '14 at 06:25
  • sorry the url was wrong. please find the correct url https://gist.github.com/rajilion/c9e48eeed494ac343dc5#file-gistfile1-txt – Rajkumar Aug 28 '14 at 14:30
  • I saw the log with gist. I don't understand what you are doing. Why are you using json Web service? – Daniele Baggio Aug 28 '14 at 18:54
  • I am uploading files using json webservice. It is working fine when I use action_draft, the problem comes only when I use action_publish – Rajkumar Aug 29 '14 at 02:19