Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Jakub Liska
It should be easier to get FileEntry metadata fields
13 septembre 2011 16:01
Réponse

Jakub Liska

Rang: Regular Member

Publications: 187

Date d'inscription: 25 mars 2010

Publications Récentes

Hey,

I was just writing a workflow script with condition where I needed to get metadata of the FileEntry that is being 'workflowed' and the shortest path to do that seems to be

 1
 2        String className = (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);
 3        long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
 4
 5        DLFileEntry fe;
 6        if (className.equals(DLFileEntryWorkflowHandler.CLASS_NAME))
 7            fe = DLFileEntryLocalServiceUtil.getFileEntry(classPK);
 8
 9        long fileEntryTypeId = fe.getFileEntryTypeId();
10        long versionId = fe.getLatestFileVersion().getFileVersionId();
11       
12        Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
13        List<DDMStructure> ddmStructures = null;
14       
15        if (fileEntryTypeId > 0) {
16            DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
17
18            ddmStructures = dlFileEntryType.getDDMStructures();
19
20            for (DDMStructure ddmStructure : ddmStructures) {
21                try {
22                    DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), versionId);
23
24                    Fields fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());
25
26                    fieldsMap.put(ddmStructure.getStructureKey(), fields);
27                } catch (NoSuchFileEntryMetadataException nsfeme) {
28                    throw new SystemException("Type : " + dlFileEntryType.getName() + " should have metadata of structure : " + ddmStructure.getName());
29                }
30            }
31        }
32    }


It took me 10 minutes to do that, then I went to edit_file_entry.jsp to look how it is done and there is almost exactly the same piece of code.

What about a DLFileEntryMetadataServiceImpl method for getting FileEntry's metadata fields ?
Jorge Ferrer
RE: We should get FileEntry metadata fields more easily
13 septembre 2011 07:38
Réponse

Jorge Ferrer

LIFERAY STAFF

Rang: Liferay Legend

Publications: 2764

Date d'inscription: 31 août 2006

Publications Récentes

Hi Jakub,

This is a good point. I think that the best solution is to add a method to DLFileEntryImpl (which would propagate to its interface with service builder) that would look something like this:

1
2public Map<String, Fields> getMetadataFieldsMap() {
3   // Your code
4}


What do you think? Do you want to give it try and attach a patch to a JIRA ticket?

Jorge
Jakub Liska
RE: We should get FileEntry metadata fields more easily
13 septembre 2011 08:03
Réponse

Jakub Liska

Rang: Regular Member

Publications: 187

Date d'inscription: 25 mars 2010

Publications Récentes

Hi Jorge,

I already sent a github pull request LPS-21095 to Ray. I added the method to DLFileEntryMetadataService in that patch. I'll tell him.
Jorge Ferrer
RE: We should get FileEntry metadata fields more easily
14 septembre 2011 10:00
Réponse

Jorge Ferrer

LIFERAY STAFF

Rang: Liferay Legend

Publications: 2764

Date d'inscription: 31 août 2006

Publications Récentes

Thanks Jakub,

Can you also add a link to the pull request in the JIRA ticket and change the status of the ticket to "Community resolved"? (you will also need to accept the contributor agreement, which is just a checkbox when changing the status)
Alexander Chow
RE: It should be easier to get FileEntry metadata fields
16 septembre 2011 05:59
Réponse

Alexander Chow

LIFERAY STAFF

Rang: Liferay Master

Publications: 518

Date d'inscription: 19 juillet 2005

Publications Récentes

Thanks for the pull request Jakub. I've made some updates and have made a pull request for Brian Chan.
Ivano Carrara
RE: It should be easier to get FileEntry metadata fields
24 juillet 2013 10:02
Réponse

Ivano Carrara

Rang: Expert

Publications: 280

Date d'inscription: 2 juillet 2005

Publications Récentes

Hi Jakub, please could you help me to apply your method to a FileEntry object instead to a DLFileEntry object as in the method you contribued ?

At first I'm not able to get the FileEntryType of the FileEntry... so I can't test your method using a FileEntry to retireve the custom metadata ....

Please, could you help me ?

Thank you in advance !

Ivano C.
Jonathan Mattox
RE: It should be easier to get FileEntry metadata fields
29 janvier 2014 09:33
Réponse

Jonathan Mattox

Rang: New Member

Publications: 13

Date d'inscription: 5 novembre 2013

Publications Récentes

Hello, I am trying to pull values from a custom metadata set and display it as an additional column on the view/gridview along with Title, Size, Created Date. And I am having a hard time figuring out exactly what to do in my hook. I see bits and pieces of code all over the place, but I'm not sure exactly how to extend the classes to add this. I've been able to add a column to be seen on the gridview by adding an entry to the init.jsp file by adding the following around line number 151:

Before:
String defaultEntryColumns = "name,size";

After:
String defaultEntryColumns = "name,size,myNewColumn";

Then I found where you add a condition for it in view_entries.jsp, but when I output fileEntryTypeId in this if statement, I keep getting a "-1"

if (columnName.equals("myNewColumn")) {
//Logic code here
}

Also in view_entries.jsp I see the following code which gets the fileEntryTypeId, which is one of the keys I need to tap into getting the metadata since the DLFileEntry doesn't have a property for this, but I'm not sure how to tap into this to get what I need and post in in the view/gridview:

List results = null;
//List metaDataresults = null;
int total = 0;

if (fileEntryTypeId >= 0) {
Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

if (fileEntryTypeId > 0) {
DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

dlFileEntryTypeName = dlFileEntryType.getName();
}

Also, in edit_file_entry, I see the following code which looks like it pertains, but I don't understand how to use it (starting at line 334):

<%
if (fileEntryTypeId > 0) {
try {
List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

for (DDMStructure ddmStructure : ddmStructures) {
Fields fields = null;

try {
DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersionId);

fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());
}
catch (Exception e) {
}
%>

<%= DDMXSDUtil.getHTML(pageContext, ddmStructure.getXsd(), fields, String.valueOf(ddmStructure.getPrimaryKey()), locale) %>

I also see that the table "DDMContent" gets populated with two rows when you add a document that has metadata fields. One row is for the automatically extracted data, and the other has the custom data from my custom metadata set.

I am trying to implement the following class solutions:

public class MyDLAppLocalService implements DLAppLocalService {}

and

public class MyDLFileEntryMetadataLocalService implements
DLFileEntryMetadataLocalService {}

and

public class MyDLAppLocalServiceImpl extends DLAppLocalServiceWrapper {

public MyDLAppLocalServiceImpl(DLAppLocalService dlAppLocalService) {
super(dlAppLocalService);
// TODO Auto-generated constructor stub
}
}

and

public MyDLAppLocalServiceWrapper(FileEntry fileEntry){
super((DLAppService) fileEntry);
}
}
Here is my liferay-hook.xml:

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<service>
<service-type>com.liferay.portlet.documentlibrary.service.DLAppLocalService</service-type>
<service-impl>com.liferay.sample.hook.MyDLAppLocalServiceImpl</service-impl>
</service>
</hook>


I find all this stuff very confusing. I don't know what to do to which class and where. I see a lot of tutorials about modifying the User's classes, but not much about this and what posts I do find, they only give a tiny snippet of code. I have no idea where that snippet came from (which file and where in that file). I'm trying to figure out all this java and liferay stuff. I've been to the liferay training classes and I'm working through the books, along with Liferay In Action. I just don't see a very clear explanation from start to finish of how to do something like this can anyone please help me?

Thanks in advance emoticon