开发者

How to add file with additional properties into Liferay's Document Library

I'm trying to figure this out, I was asking this question in Liferay's forum here - the last entry.

And only thing I'm able to come up with is creating an Expando for FileEntry, which seems very complicated. Who knows if it makes sense. I don't like the expando feature since I couldn't query them via hibernate properly.

Does anybody know the answer for my question in that Liferay forum ?

The problem is that,

DLAppLocalServiceUtil.addFileEntry(...);
DLLocalServiceUtil.addFile(....);

doesn't let you store any additional information / properties about the file. As a result, one would have to use JackRabbit directly, instead of using Liferay's JCRHook. But you loose all the advantages that Document Library b开发者_开发技巧rings.


Yep, the only option is to use Expando AKA custom properties/fields. In case of fileEntry you don't need to create table and columns programmatically but you can set it up in Control Panel > custom fields.

After that you have a few options how to populate the expando values.

fileEntry.getExpandoBridge().setAttribute("propName", "propValue")

or if you get the properties from view layer

<liferay-ui:custom-attributes-available className="<%= DLFileEntry.class.getName() %>">
    <liferay-ui:custom-attribute-list
        className="<%= DLFileEntry.class.getName() %>"
        classPK="<%= (fileVersion != null) ? fileVersion.getFileVersionId() : 0 %>"
        editable="<%= true %>"
        label="<%= true %>"
        />
</liferay-ui:custom-attributes-available>

and then

ServiceContext serviceContext = ServiceContextFactory.getInstance(
            DLFileEntry.class.getName(), actionRequest);

serviceContext gets populated by parameters in actionRequest and you then just call

fileEntry.getExpandoBridge().setAttributes(serviceContext)

Finally, you may need to query for fileEntries with particular properties

public Hits search() {
     Map<String, Serializable> attributes = new HashMap<String, Serializable>();
     attributes.put("propertyName", "propertyValue");

     SearchContext searchContext = new SearchContext();
     searchContext.setAttributes(attributes);
     Indexer indexer = IndexerRegistryUtil.getIndexer(FileEntry.class);
     return indexer.search(searchContext);
}

Of course, this solution may seem a little complicated, because Liferay Document Library is not a JCR content repository, but it's literally a document library that provides abstraction layer for concrete repo implementations via Hooks, such as JCRHook ( where files are stored into jackrabbit repository ), CMIS support, migration support etc. It also handles permissionChecking, fileVersioning, document workflow and asset management.

So if you intend to do something more complicated and you will have to query the properties/metadata, change them and expand them. You should consider using JCR repository directly...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜