Forums de discussion

How do you create DLFileEntryMetadata object?

Gwowen Fu, modifié il y a 12 années.

How do you create DLFileEntryMetadata object?

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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
thumbnail
jelmer kuperus, modifié il y a 12 années.

RE: How do you create DLFileEntryMetadata object?

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
long id = CounterLocalServiceUtil.increment();
DLFileEntryMetadataLocalServiceUtil.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, modifié il y a 12 années.

RE: How do you create DLFileEntryMetadata object?

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
Thanks!
Gwowen Fu, modifié il y a 12 années.

RE: How do you create DLFileEntryMetadata object?

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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, modifié il y a 12 années.

RE: How do you create DLFileEntryMetadata object?

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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, modifié il y a 12 années.

RE: How do you create DLFileEntryMetadata object? (Réponse)

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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, modifié il y a 11 années.

RE: How do you create DLFileEntryMetadata object?

New Member Envoyer: 1 Date d'inscription: 24/09/12 Publications récentes
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, modifié il y a 11 années.

RE: How do you create DLFileEntryMetadata object?

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
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.
thumbnail
python shi, modifié il y a 11 années.

RE: How do you create DLFileEntryMetadata object?

New Member Publications: 11 Date d'inscription: 03/07/12 Publications récentes
List<ddmstructure> ddmStructures = fileEntryType.getDDMStructures();
			Map<string, fields> fieldsMap = new HashMap<string, fields>();
		
			for(DDMStructure ddmStructure : ddmStructures)
			{
				Set<string> fieldNames = ddmStructure.getFieldNames();
				
				Fields fields = new Fields();
	            for (String name : fieldNames) 
	            {
	                Field field = new Field();
	
	                field.setName(name);
	                
	                /*if current filed metadata is null, continue*/
	                Object value = metadata.get(name);
	      
	                if(value == null) {
	                	
	                	continue;
	                }
	                else {
	                	field.setValue(value.toString());
	                	fields.put(field);
	                }
	                
	                System.out.println("name=" + name + " value=" + value);
	                
	                
	            }
				fieldsMap.put(ddmStructure.getStructureKey(), fields);	
			}</string></string,></string,></ddmstructure>
Jonathan Mattox, modifié il y a 10 années.

RE: How do you create DLFileEntryMetadata object?

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
thumbnail
Neha Goyal, modifié il y a 8 années.

RE: How do you create DLFileEntryMetadata object?

Regular Member Publications: 121 Date d'inscription: 14/05/13 Publications récentes
Hi Guys ,
I used following code to set document meta data like effective date,expiry date,categories and tags:
private void genericFileUploader(String docType, DLFolder folder,
DocumentAssets documentAssets, TextField docTitle,
TextArea description, DateField effectiveDate,
DateField expirationDate, Window subWindow) {

// checking expiration date should be after effective date
boolean allowUpload = compareDates(effectiveDate, expirationDate);
if (allowUpload) {
try {
String[] tagsAssetSelected = documentAssets.getSelectedTagsAsset();
List<Long> categoriessAssetSelected = documentAssets.getSelectedCategoriessAsset();
Field expDateValue;
Field effDateValue;
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLAppService.class.getName(), this.request);
Fields docMetadataFields = new Fields();

DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(themeDisplay.getLayout().getGroupId(), docType);
List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

for (DDMStructure ddmStructure : ddmStructures) {
Set<String> fieldNames = ddmStructure.getFieldNames();
for (Iterator<String> iterator = fieldNames.iterator(); iterator.hasNext();) {
String fieldName = (String) iterator.next();
if (fieldName.equalsIgnoreCase("ExpirationDate")) {
if (expirationDate.getValue() != null) {
Date v_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH).parse(expirationDate.getValue().toString());
String sDate = formatter.format(v_date);
Date date = new SimpleDateFormat("MM/dd/yyyy",Locale.ENGLISH).parse(sDate);
expDateValue = new Field(ddmStructure.getStructureId(),fieldName, date);
docMetadataFields.put(expDateValue);
}
}

if (fieldName.equalsIgnoreCase("EffectiveDate")) {
if (effectiveDate.getValue() != null) {
Date v_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH).parse(effectiveDate.getValue().toString());
String sDate = formatter.format(v_date);
Date date = new SimpleDateFormat("MM/dd/yyyy",Locale.ENGLISH).parse(sDate);
effDateValue = new Field(ddmStructure.getStructureId(),fieldName, date);
docMetadataFields.put(effDateValue);
}
}
}

serviceContext.setAttribute("fileEntryTypeId",dlFileEntryType.getFileEntryTypeId());
String metadataName = Fields.class.getName()+ ddmStructure.getStructureId();
serviceContext.setAttribute(metadataName, docMetadataFields);
}

serviceContext.setAssetTagNames(tagsAssetSelected);
if (categoriessAssetSelected != null) {
long[] categoriessAssetSelectedIds = new long[categoriessAssetSelected.size()];
for (int i = 0; i < categoriessAssetSelected.size(); i++) {
categoriessAssetSelectedIds = categoriessAssetSelected.get(i);
}
serviceContext.setAssetCategoryIds(categoriessAssetSelectedIds);
}
DLAppLocalServiceUtil.addFileEntry(user.getUserId(),
themeDisplay.getLayout().getGroupId(),
folder.getFolderId(), priceFile.getName(),
MimeTypesUtil.getContentType(priceFile),
docTitle.getValue().toString(),
description.getValue().toString(), "", priceFile, serviceContext);

logger.info("Document: " + "[" + priceFile.getName() + "]"+ " uploaded successfully");
final DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(themeDisplay.getLayout().getGroupId(),
folder.getFolderId(), docTitle.getValue().toString());
}


Hope this might help any one.

Regards:
Neha Goyal
thumbnail
Aditya Bhardwaj, modifié il y a 8 années.

RE: How do you create DLFileEntryMetadata object?

Junior Member Publications: 78 Date d'inscription: 08/01/15 Publications récentes
Hi try this;


@Override
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
String name =ParamUtil.getString(uploadPortletRequest, "name");
String description = ParamUtil.getString(uploadPortletRequest, "description");
String title = ParamUtil.getString(uploadPortletRequest, "title");
String experience = ParamUtil.getString(uploadPortletRequest, "experience");

File file = uploadPortletRequest.getFile("uploadedFile");
String mimeType = uploadPortletRequest.getContentType("uploadedFile");
InputStream is = new FileInputStream( file );
String fileName=uploadPortletRequest.getFileName("uploadedFile");
DLFolder folder = null;
ServiceContext serviceContext=null;
try {

folder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), PARENT_FOLDER_ID, ROOT_FOLDER_NAME);
serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);
} catch (Exception e) {
System.out.println(e.getMessage());
}

try {

Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
DDMStructure structure = getDDMStructureByName(themeDisplay);
Fields fields = new Fields();
fields.put(new Field("Name",name ));
fields.put(new Field("Experience", experience));
fieldsMap.put(structure.getStructureKey(), fields);



DLFileEntry dlFileEntry=null;
try {
dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(),
themeDisplay.getScopeGroupId(), folder.getFolderId(),fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK,
folder.getDefaultFileEntryTypeId(),fieldsMap, file, null, file.length(), serviceContext);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

DLFileEntryLocalServiceUtil.updateFileEntry(folder.getUserId(), dlFileEntry.getFileEntryId(), file.getName(), mimeType,
title, description, "Draft to save",true, dlFileEntry.getFileEntryTypeId(), fieldsMap, file, is, file.getTotalSpace(), serviceContext);



}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

public DDMStructure getDDMStructureByName(ThemeDisplay themeDisplay)
{
DDMStructure structure = null;
try {
List<DDMStructure> structures = DDMStructureLocalServiceUtil.getStructures(themeDisplay.getScopeGroupId());

for (DDMStructure struct : structures) {
if (struct.getName((Locale.ROOT)).equalsIgnoreCase(DOCUMENT_TYPE_NAME)) {
structure = struct;
}
}
} catch (SystemException e) {
e.printStackTrace();
}
return structure;
}

Hope this will help