2

I am new to liferay. I am using liferay 6.0.5 I want to add "Archive" tag to doc library document through code so latter on I can fetch the document with "Archive" tag. how to do this?

Here is the code being worked upon :

private void addArchive(List<DLFileEntry> fileEntryList) {       
    try
    {
        long groupId=0;
        long userId=0;
        String className=null;
        long classPK=0;
        long categoryIds[]=null;
        String tagNames[]=null;
        String newTagNames[] = new String[20];
        long entryId = 0;
        List<AssetTag> TNames = new ArrayList<AssetTag>();
        int i = 0;
        for(DLFileEntry cur:fileEntryList)
        {
            groupId=cur.getGroupId();
            userId=cur.getUserId();
            className=cur.getClass().getName();
            classPK=cur.getPrimaryKey();
            AssetEntry ae=AssetEntryLocalServiceUtil.getEntry(groupId, cur.getUuid());
            categoryIds=ae.getCategoryIds();
            entryId = ae.getEntryId();
            TNames = ae.getTags();
            System.out.println(cur.getTitle());
            i=0;
            for(AssetTag tag : TNames)
            {
                System.out.println(tag.getName());      
                newTagNames[i]=tag.getName().toString();
                i++;
            }
            newTagNames[i]="NameArchive";
            AssetEntryLocalServiceUtil.updateEntry(userId, groupId, className, classPK, categoryIds, newTagNames);
            System.out.println("------------------------------------------------");
        }
        System.out.println("outside for loop"); 
    }
    catch (Exception e) {
        // TODO: handle exception
    }
}
MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
Rakesh Goswami
  • 205
  • 1
  • 4
  • 21

1 Answers1

0

Firstly you need to find the "entryId" of the File in your Document Library using the DLFileEntryLocalServiceUtil class (and the other associated DL*LocalServiceUtil classes).

The "entryId" relates to the "classPK" field on the assetentry table in the database. Then you can use the following method to update the AssetEntry with the Tag "Archive":

AssetEntryLocalServiceUtil.updateEntry(userId, groupId, DLFileEntry.class.getName(), fileEntryIdYouJustGot, categoryIds, new String[] {"Archive"});

This will remove any other tags though so you may want to retrieve the current tags from the Asset Entry and then add "Archive" to them, then pass the resulting array to the method.

But this is the basis of what you need to do.

~~ EDIT ~~

Amend your getEntryLine to use the following. You're passing in the DLFileEntry UUID, but if you look at the Source Code it's asking for a classUuid which I don't believe are the same thing. Also add logging in your Exception handling to see if a Exception is being thrown.

AssetEntry ae=AssetEntryLocalServiceUtil.getEntry(groupId, classPK);
Jonny
  • 2,663
  • 1
  • 24
  • 24
  • 1
    I have edited the question and included the code also. On running this I am not getting any error but new tag is not there with documents as result. – Rakesh Goswami Mar 21 '12 at 11:44
  • Hi Rakesh, I've updated my answer to include a small change in your source. – Jonny Mar 21 '12 at 14:10