Reputation: 280
I have a following requirement regarding tags and users.
I have done coding for adding the tags to the users as follows
JSP:
<portlet:actionURL var="addTagsURL" name="addTags"/>
<aui:form action="<%=addTagsURL%>" method="post" name="submit">
<aui:input name="emailAddress" id="emailAddress" label="Email Address">
<aui:validator name="required" />
</aui:input>
<liferay-ui:asset-tags-error />
<aui:input name="tags" type="assetTags" />
<div>
<liferay-ui:asset-tags-selector />
</div>
<aui:input type="Submit" name="Submit" value="Submit"></aui:input>
</aui:form>
Action class:
public void addTags(ActionRequest actionRequest,ActionResponse actionResponse){
String emailAddress=ParamUtil.getString(actionRequest, "emailAddress");
log_.info("user email address from form========>"+emailAddress);
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
User user;
try {
user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
AssetEntryLocalServiceUtil.updateEntry(user.getUserId(), themeDisplay.getScopeGroupId(),"com.liferay.portal.model.User", user.getUserId(),null, serviceContext.getAssetTagNames());
log_.info("user email address========>"+user.getEmailAddress());
log_.info("UserId is=========>"+user.getUserId());
String tags[]=serviceContext.getAssetTagNames();
log_.info("Tags are====>"+tags.toString());
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
By above code i can have UI to add the tags to the users.But if i want to delete the tags for particular user how can i do and if any API or tags are there please guide me.
For retrieval purpose of tags based on the emailAddress specified in the textbox, I just using ServiceBuilder concept by querying form tables AssetEntry_AssetTags.Is it correct way of doing to display tags available for a given emailAddress.
Upvotes: 2
Views: 506
Reputation: 4210
You should be able to get asset tags associated with user entity by below API method.
com.liferay.portlet.asset.service.AssetTagLocalServiceUtil
public static java.util.List<com.liferay.portlet.asset.model.AssetTag> getTags(
long classNameId, long classPK)
Where classpk would be userId and classNameId would be of User class.
Hope this helps.
Upvotes: 1