Foros de discusión

RE: How to get value from document metadata field in liferay workflow

YOEL LORENZO, modificado hace 10 años.

How to get value from document metadata field in liferay workflow

New Member Mensajes: 3 Fecha de incorporación: 8/01/13 Mensajes recientes
Hi everyone:

I have enabled a workflow for a document type in a Documents and Media folder and I'm trying to write a groovy script in a condition node of the workflow that needs to read the value entered by the user in a field of the document type. This is the script I wrote:

long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
DLFileEntry fe = DLFileEntryLocalServiceUtil.getFileEntry(classPK);
                                
long fileEntryTypeId = fe.getFileEntryTypeId();
long versionId = fe.getLatestFileVersion().getFileVersionId();
                                                              
DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
List<ddmstructure> ddmStructures = dlFileEntryType.getDDMStructures();
DDMStructure ddmStructure = ddmStructures.get(0);                       
                                
DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), versionId);
Fields fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());
String value = fields.get("radio6255").getValue().toString();</ddmstructure>


But I'm getting the following error:

No DLFileEntry exists with the primary key 20258

So, I was wondering if someone can provide a better way of doing this or tell what's the problem with my code. I'm using Liferay 6.1.1-ce-ga2!

Any help will be really appreciated, thanks in advance!
YOEL LORENZO, modificado hace 10 años.

RE: How to get value from document metadata field in liferay workflow

New Member Mensajes: 3 Fecha de incorporación: 8/01/13 Mensajes recientes
Hey guys, this is the code that works:

long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));                                
                                                                                               
long fileEntryTypeId = DLFileVersionLocalServiceUtil.getFileVersion(classPK).getFileEntry().getFileEntryTypeId();                                                              
DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
List<ddmstructure> ddmStructures = dlFileEntryType.getDDMStructures();
DDMStructure ddmStructure = ddmStructures.get(0);                                
                                
DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), classPK);
Fields fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());                                
String value = GetterUtil.getString(fields.get("radio6255").getValue());</ddmstructure>
Jonathan Mattox, modificado hace 10 años.

RE: How to get value from document metadata field in liferay workflow

New Member Mensajes: 13 Fecha de incorporación: 5/11/13 Mensajes recientes
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
thumbnail
Dave Weitzel, modificado hace 9 años.

RE: How to get value from document metadata field in liferay workflow

Regular Member Mensajes: 208 Fecha de incorporación: 18/11/09 Mensajes recientes
did you ever get this sorted out?

I'm trying to develop an Application Display Template (for asset publisher but could be for Document Library) and failing when I try to get the fields:
	            
         structureid=$curStructure.getStructureId(), fvid= $dlFileVersion.getFileVersionId()) <br>
#set ($fileEntryMetadata = $dlFileEntryMetadataLocalService.getFileEntryMetadata($curStructure.getStructureId(), $dlFileVersion.getFileVersionId()) )
    	 DDMStorgageId = ${fileEntryMetadata.getDDMStorageId()}  <br>
#set ($fields = $storageEngineUtil.getFields($fileEntryMetadata.getDDMStorageId()) )
		$fields.size() 	$storageEngineUtil.getClass()  $dlFileVersionService.getClass()    <br>
		$getterUtil.getString($fields.get("Author").getValue());


outputs relevant data upto the #set $fields line

structureid= 23279, fvid= 23281)
DDMStorgageId = 23285
$fields.size() class com.sun.proxy.$Proxy554 class com.sun.proxy.$Proxy552

I assume given the output to the getClass() methods that I have instances of the StorageEngineUtil class but doesnt seem to return anything
thumbnail
Eduardo P. García, modificado hace 3 años.

RE: How to get value from document metadata field in liferay workflow

Regular Member Mensajes: 157 Fecha de incorporación: 16/03/12 Mensajes recientes
Hi Dave,

Instead of using the storageEngineUtil, I'd recommend to use the getFieldsMap method of the DLFileEntry class. Assuming that fileEntry is a DLFileEntry object, then:

&lt;#assign fieldsMap = fileEntry.getFieldsMap(dlFileVersion.getFileVersionId()) /&gt;
  
&lt;#list fieldsMap?keys as structureKey&gt;
    <p>File Entry ${fileEntry.getTitle()} has structure with key ${structureKey} with fields:<b>

	</b></p><ul><b>
	     &lt;#list fieldsMap[structureKey].iterator() as field&gt;
		     </b></ul><b><br>If you still need to use the storageEngineUtil, you can get it through the staticUtil accessor instead of the utilLocator. See <a href="https://issues.liferay.com/browse/LPS-50931">James Folkner's comment in this ticket</a> for more information.<br><br>Thanks!</b><br><table>
	    <tbody><tr>
	        <th>Name</th>
	        <th>Type</th>
	    </tr>
	<tr>
    	    	<td>${field.getName()}</td>
    	        <td>${field.getType()}</td>
    	    </tr>
	     <!--#list-->
	
<!--#list--></tbody></table>
thumbnail
selam Aweke selam, modificado hace 9 años.

RE: How to get value from document metadata field in liferay workflow

Junior Member Mensajes: 60 Fecha de incorporación: 14/11/12 Mensajes recientes
hi Eduardo, how can I get document and Media vedio information in asset publisher like , Video thumbinail, title in Asset publisher ADT template