Skip to content

Commit

Permalink
SAK-50756 Tags new endpoint to get tags by id (#13107)
Browse files Browse the repository at this point in the history
Co-authored-by: bgarciaentornos <[email protected]>
  • Loading branch information
jumarub and bgarciaentornos authored Jan 17, 2025
1 parent 5ca4bb2 commit b8e8c8a
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ public JSONObject getTagsPaginatedByPrefixInLabel(EntityView view, Map<String, O
}
}

@EntityCustomAction(action = "getTagsByItemId", viewKey = EntityView.VIEW_LIST)
public JSONObject getTagsByItemId(EntityView view, Map<String, Object> params) {
WrappedParams wp = new WrappedParams(params);
String itemId = wp.getString("itemId");
String siteId = wp.getString("siteId");

try {
List<Tag> tagList = tagService().getAssociatedTagsForItem(siteId, itemId);
return buildtagJsonOject(tagList, tagList.size());
} catch (Exception e) {
log.error("Could not get tag with itemId={} in site={}, {}", itemId, siteId, e);
return null;
}
}

private JSONObject buildtagJsonOject(List<Tag> tagList, int tagCount) {
JSONObject responseDetailsJson = new JSONObject();
JSONArray jsonArray = new JSONArray();

for (Tag p : tagList) {
JSONObject formDetailsJson = new JSONObject();
formDetailsJson.put("tagId", p.getTagId());
formDetailsJson.put("tagLabel", p.getTagLabel());
formDetailsJson.put("collectionName", p.getCollectionName());
formDetailsJson.put("tagCollectionId", p.getTagCollectionId());
jsonArray.add(formDetailsJson);
}
responseDetailsJson.put("total",tagCount );
responseDetailsJson.put("tags", jsonArray);

return responseDetailsJson;
}



private TagService tagService() {
Expand Down

0 comments on commit b8e8c8a

Please sign in to comment.