简体   繁体   English

在DLFileEntryLocalServiceUtil.addFileEntry之后,Liferay给我一个NoSuchEntryException

[英]Liferay throw me a NoSuchEntryException after DLFileEntryLocalServiceUtil.addFileEntry

I'm trying to add images programmatically to liferay Documents Library. 我正在尝试以编程方式将图像添加到liferay文档库中。 I'm using liferay portal 6.1.30 ee. 我正在使用liferay门户网站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. 我尝试使用DLFileEntryLocalServiceUtil.addFileEntry,但它没有正确创建我的文档,因为我在这篇文章中红了没有创建assetEntry记录。

So I tried DLFileEntryLocalServiceUtil.updateStatus (commented here) but i got this error, still no assetEntry: 所以我尝试了DLFileEntryLocalServiceUtil.updateStatus(这里评论),但是我收到了这个错误,仍然没有assetEntry:

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

and i tried calling methods DLFileEntryLocalServiceUtil.updateDLFileEntry or updateFileEntry but it make no difference 我尝试调用方法DLFileEntryLocalServiceUtil.updateDLFileEntry或updateFileEntry但它没有区别

edit: 编辑:

I found a solution using this code after addFileEntry: 我在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);

You could try with the methods in DLFileAppLocalServiceUtil. 您可以尝试使用DLFileAppLocalServiceUtil中的方法。 They generate file's metadata and others required fields like file version. 它们生成文件的元数据,其他需要文件版本等字段。

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM