user3049882
user3049882

Reputation: 31

Liferay throw me a NoSuchEntryException after DLFileEntryLocalServiceUtil.addFileEntry

I'm trying to add images programmatically to liferay Documents Library. I'm using liferay portal 6.1.30 ee.

Here is my code:

    protected void addDocument(long userId, Group group, InputStream inputStream, DLFolder dlFolder, String name) throws IOException {
    long fileEntryTypeId;
    try {
        fileEntryTypeId = DLFileEntryTypeLocalServiceUtil.getDefaultFileEntryTypeId(dlFolder.getFolderId());
    } catch (NestableException e) {
        if(LOGGER.isWarningEnabled())LOGGER.warn("unable to get fileEntryType ",e);
        return;
    }

    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setCompanyId(group.getCompanyId());
    serviceContext.setScopeGroupId(group.getGroupId());
    serviceContext.setAssetEntryVisible(true);

    try {
        DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, group.getGroupId(), dlFolder.getRepositoryId(),
                dlFolder.getFolderId(), name, MimeTypesUtil.getContentType(name), name,
                StringPool.BLANK, StringPool.BLANK, fileEntryTypeId, null, null,
                inputStream, inputStream.available(), new ServiceContext());


        //fileEntry = DLFileEntryLocalServiceUtil.updateDLFileEntry(fileEntry);
        //fileEntry = DLFileEntryLocalServiceUtil.updateFileEntry(fileEntry.getUserId(),fileEntry.getFileEntryTypeId(),name,MimeTypesUtil.getContentType(name),name,StringPool.BLANK,StringPool.BLANK,false, fileEntryTypeId, new HashMap<String, Fields>(), null, fileEntry.getContentStream(), fileEntry.getSize(),serviceContext);
        //fileEntry = DLFileEntryLocalServiceUtil.updateStatus(fileEntry.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, new HashMap<String, Serializable>(), serviceContext);

        if(LOGGER.isTraceEnabled()) LOGGER.trace("file "+name+" added");
    } catch (NestableException e) {
        if(LOGGER.isWarningEnabled())LOGGER.warn("error adding file "+name+" ",e);
    }
}

I try using DLFileEntryLocalServiceUtil.addFileEntry but it doesn't create my documents properly, as I red in this post no assetEntry record is created.

So I tried DLFileEntryLocalServiceUtil.updateStatus (commented here) but i got this error, still no assetEntry:

com.liferay.portlet.asset.NoSuchEntryException: No AssetEntry exists with the key {classNameId=10076, classPK=42954}
at com.liferay.portlet.asset.service.persistence.AssetEntryPersistenceImpl.findByC_C(AssetEntryPersistenceImpl.java:2933)
at sun.reflect.GeneratedMethodAccessor1937.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.security.lang.DoPrivilegedHandler.doInvoke(DoPrivilegedHandler.java:88)
at com.liferay.portal.security.lang.DoPrivilegedHandler.invoke(DoPrivilegedHandler.java:56)
at com.sun.proxy.$Proxy689.findByC_C(Unknown Source)
at com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.updateVisible(AssetEntryLocalServiceImpl.java:866)
at sun.reflect.GeneratedMethodAccessor1936.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:117)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:52)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:218)
at com.liferay.portal.security.pacl.PACLInvocationHandler.doInvoke(PACLInvocationHandler.java:62)
at com.liferay.portal.security.pacl.PACLInvocationHandler.invoke(PACLInvocationHandler.java:51)
at com.sun.proxy.$Proxy394.updateVisible(Unknown Source)
at com.liferay.portlet.documentlibrary.service.impl.DLAppHelperLocalServiceImpl.updateStatus(DLAppHelperLocalServiceImpl.java:584)
at sun.reflect.GeneratedMethodAccessor1935.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:117)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:52)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:218)
at com.liferay.portal.security.pacl.PACLInvocationHandler.doInvoke(PACLInvocationHandler.java:62)
at com.liferay.portal.security.pacl.PACLInvocationHandler.invoke(PACLInvocationHandler.java:51)
at com.sun.proxy.$Proxy466.updateStatus(Unknown Source)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.updateStatus(DLFileEntryLocalServiceImpl.java:1298)
at com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceWrapper.updateStatus(DLFileEntryLocalServiceWrapper.java:624)
at sun.reflect.GeneratedMethodAccessor1933.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at com.sun.proxy.$Proxy782.updateStatus(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1933.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:117)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:52)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:113)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:218)
at com.liferay.portal.security.pacl.PACLInvocationHandler.doInvoke(PACLInvocationHandler.java:62)
at com.liferay.portal.security.pacl.PACLInvocationHandler.invoke(PACLInvocationHandler.java:51)
at com.sun.proxy.$Proxy468.updateStatus(Unknown Source)
at com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(DLFileEntryLocalServiceUtil.java:626)
at xxx.addDocument()

and i tried calling methods DLFileEntryLocalServiceUtil.updateDLFileEntry or updateFileEntry but it make no difference

edit:

I found a solution using this code after addFileEntry:

    fileEntry = DLFileEntryLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),name, MimeTypesUtil.getContentType(name), name,"", "", true, fileEntryTypeId, null, null, null, 0, serviceContext);
    Map<String, Serializable> workflowContext = new HashMap<String, Serializable>();
    workflowContext.put("event",DLSyncConstants.EVENT_UPDATE);
    fileEntry = DLFileEntryLocalServiceUtil.updateStatus(fileEntry.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext);

Upvotes: 3

Views: 2486

Answers (1)

Jorge
Jorge

Reputation: 141

You could try with the methods in DLFileAppLocalServiceUtil. They generate file's metadata and others required fields like file version.

HTH.

Upvotes: 1

Related Questions