Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gwowen Fu
How do you create DLFileEntryMetadata object?
April 13, 2012 9:47 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Hi,

Since DLFileEntryMetadata is an interface I cannot do new DLFileEntryMetadata ().

How a DLFileEntryMetadata object can be created so that I can call

DLFileEntryMetadataLocalServiceUtil.addDLFileEntryMetadata(DLFileEntryMetadata dlFileEntryMetadata)

to add metadata?

Thanks!
Gwowen
Jelmer Kuperus
RE: How do you create DLFileEntryMetadata object?
April 14, 2012 7:32 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

1long id = CounterLocalServiceUtil.increment();
2DLFileEntryMetadataLocalServiceUtil.createDLFileEntryMetadata(id)


will create a new instance without persisting it

You probably shouldn't be doing what you are trying to do though and instead use DLFileEntryMetadataLocalServiceUtil.updateFileEntryMetadata
Gwowen Fu
RE: How do you create DLFileEntryMetadata object?
April 16, 2012 7:28 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Thanks!
Gwowen Fu
RE: How do you create DLFileEntryMetadata object?
April 16, 2012 8:29 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

jelmer kuperus:
You probably shouldn't be doing what you are trying to do though and instead use DLFileEntryMetadataLocalServiceUtil.updateFileEntryMetadata


Hi Jelmer,

I am going to call updateFileEntryMetadata() to add metedata but couldn't figure it out how to do it.
public static void updateFileEntryMetadata(long fileEntryTypeId,
long fileEntryId,
long fileVersionId,
Map<String,Fields> fieldsMap,
ServiceContext serviceContext)
throws PortalException,
SystemException

Question 1: Which table stores the data I passed in fieldsMap?
Question 2: JavaDoc says "fieldsMap - mapping for fields associated with a custom file entry type". If this is not for metadata, how do I set data for metadata (Metadata Set)?

Do I have to call this method instead?
public static void updateFileEntryMetadata(long companyId,
List<DDMStructure> ddmStructures,
long fileEntryTypeId,
long fileEntryId,
long fileVersionId,
Map<String,Fields> fieldsMap,
ServiceContext serviceContext)
throws PortalException,
SystemException

Thanks!
Gwowen
Gwowen Fu
RE: How do you create DLFileEntryMetadata object?
April 16, 2012 12:12 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Hi,

I am adding a document that will have a user defined document type, this document type is assigned metadata set that is created by user. This metadata set has one property called "OriginalDocumentID".

How can I set the value for "OriginalDocumentID" when adding a document that has the metadata set assigned?

I tried the code below but value for "OriginalDocumentID" is not saved.

-----------------------------------------------------------------------------

// Add document
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, repositoryId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId, fieldsMap, file, is, file.length(), serviceContext);

// Get DDMStructure
DDMStructure structure = DDMStructureLocalServiceUtil.fetchDDMStructure(26906); // Get the metadata set created by user
Map<String, Map<String, String>> fields = structure.getFieldsMap();
Map<String, String> field = fields.get("text11889"); // Get the "OriginalDocumentID" field
field.put("predefinedValue", "12345"); // Set predefinedValue
field.put("values", "12345"); // Set value
fields.put("text11889", field);
structure.setFieldsMap(fields);
DDMStructureLocalServiceUtil.updateDDMStructure(structure, true);

// get List<DDMStructure>
List<DDMStructure> ddmStructures = DDMStructureLocalServiceUtil.getDLFileEntryTypeStructures(fileEntryTypeId);
ddmStructures.set(0, structure);

// Add metadata
DLFileEntryMetadataLocalServiceUtil.updateFileEntryMetadata(serviceContext.getCompanyId(), ddmStructures, fileEntryTypeId, dlFileEntry.getPrimaryKey(), dlFileEntry.getFileVersion()
.getPrimaryKey(), fieldsMap, serviceContext);

-----------------------------------------------------------------------------

Value for predefinedValue and values are not saved.

Thanks!
Gwowen
Gwowen Fu
RE: How do you create DLFileEntryMetadata object?
April 18, 2012 7:37 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Found the solution after looking at Liferay source code. The key is to put the metadata information in the fieldMap.

DDMStructure structure = DDMStructureLocalServiceUtil.fetchDDMStructure(structureID);
Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
Fields targetFields = new Fields();
targetFields.put(new Field(name, value));

fieldsMap.put(structure.getStructureKey(), targetFields);

DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId,
fieldsMap, file, null, file.length(), serviceContext);
Sergio Spadaro
RE: How do you create DLFileEntryMetadata object?
September 24, 2012 4:31 AM
Answer

Sergio Spadaro

Rank: New Member

Posts: 1

Join Date: September 24, 2012

Recent Posts

Gwowen Fu:
Found the solution after looking at Liferay source code. The key is to put the metadata information in the fieldMap.

DDMStructure structure = DDMStructureLocalServiceUtil.fetchDDMStructure(structureID);
Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
Fields targetFields = new Fields();
targetFields.put(new Field(name, value));

fieldsMap.put(structure.getStructureKey(), targetFields);

DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId,
fieldsMap, file, null, file.length(), serviceContext);


Hi Gwowen Fu.
can you please sharing the whole code used?
I've got the same problem when I try to insert a new image with addtional metadata attribute and the risult is that the image has the status 'DRAFT' and I have to publish manually, but more important the addiotional metadata are not set.....
thx in advance
S
Gwowen Fu
RE: How do you create DLFileEntryMetadata object?
November 7, 2012 1:19 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Sergio Spadaro:
the image has the status 'DRAFT' and I have to publish manually
Once it is saved then change the status to published. That's what I did to web content.
python shi
RE: How do you create DLFileEntryMetadata object?
December 3, 2012 11:30 PM
Answer

python shi

Rank: New Member

Posts: 10

Join Date: July 2, 2012

Recent Posts

 1List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();
 2            Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
 3       
 4            for(DDMStructure ddmStructure : ddmStructures)
 5            {
 6                Set<String> fieldNames = ddmStructure.getFieldNames();
 7               
 8                Fields fields = new Fields();
 9                for (String name : fieldNames)
10                {
11                    Field field = new Field();
12   
13                    field.setName(name);
14                   
15                    /*if current filed metadata is null, continue*/
16                    Object value = metadata.get(name);
17         
18                    if(value == null) {
19                        
20                        continue;
21                    }
22                    else {
23                        field.setValue(value.toString());
24                        fields.put(field);
25                    }
26                   
27                    System.out.println("name=" + name + " value=" + value);
28                   
29                   
30                }
31                fieldsMap.put(ddmStructure.getStructureKey(), fields);   
32            }
Jonathan Mattox
RE: How do you create DLFileEntryMetadata object?
January 29, 2014 9:35 AM
Answer

Jonathan Mattox

Rank: New Member

Posts: 9

Join Date: November 5, 2013

Recent Posts

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