Forums de discussion

It should be easier to get FileEntry metadata fields

thumbnail
Jakub Liska, modifié il y a 12 années.

It should be easier to get FileEntry metadata fields

Regular Member Publications: 187 Date d'inscription: 25/03/10 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


		String className = (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);
		long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

		DLFileEntry fe;
		if (className.equals(DLFileEntryWorkflowHandler.CLASS_NAME))
			fe = DLFileEntryLocalServiceUtil.getFileEntry(classPK);

		long fileEntryTypeId = fe.getFileEntryTypeId();
		long versionId = fe.getLatestFileVersion().getFileVersionId();
		
		Map<string, fields> fieldsMap = new HashMap<string, fields>();
		List<ddmstructure> ddmStructures = null;
		
		if (fileEntryTypeId &gt; 0) {
			DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

			ddmStructures = dlFileEntryType.getDDMStructures();

			for (DDMStructure ddmStructure : ddmStructures) {
				try {
					DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), versionId);

					Fields fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());

					fieldsMap.put(ddmStructure.getStructureKey(), fields);
				} catch (NoSuchFileEntryMetadataException nsfeme) {
					throw new SystemException("Type : " + dlFileEntryType.getName() + " should have metadata of structure : " + ddmStructure.getName());
				}
			}
		}
	}
</ddmstructure></string,></string,>


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 ?
thumbnail
Jorge Ferrer, modifié il y a 12 années.

RE: We should get FileEntry metadata fields more easily

Liferay Legend Publications: 2871 Date d'inscription: 31/08/06 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:


public Map<string, fields> getMetadataFieldsMap() {
   // Your code
}
</string,>


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

Jorge
thumbnail
Jakub Liska, modifié il y a 12 années.

RE: We should get FileEntry metadata fields more easily

Regular Member Publications: 187 Date d'inscription: 25/03/10 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.
thumbnail
Jorge Ferrer, modifié il y a 12 années.

RE: We should get FileEntry metadata fields more easily

Liferay Legend Publications: 2871 Date d'inscription: 31/08/06 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)
thumbnail
Alexander Chow, modifié il y a 12 années.

RE: It should be easier to get FileEntry metadata fields

Liferay Master Publications: 518 Date d'inscription: 20/07/05 Publications récentes
Thanks for the pull request Jakub. I've made some updates and have made a pull request for Brian Chan.
thumbnail
Ivano Carrara, modifié il y a 10 années.

RE: It should be easier to get FileEntry metadata fields

Expert Publications: 345 Date d'inscription: 03/07/05 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, modifié il y a 10 années.

RE: It should be easier to get FileEntry metadata fields

New Member Publications: 13 Date d'inscription: 05/11/13 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