Skip to content

Commit

Permalink
SAK-50756 - Tags new endpoint to get from item
Browse files Browse the repository at this point in the history
  • Loading branch information
jumarub committed Dec 13, 2024
1 parent 1e038f4 commit 49096d1
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ public JSONObject getTagsPaginatedByPrefixInLabel(EntityView view, Map<String, O
}
}

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

List<Tag> tagList = tagService().getAssociatedTagsForItem(siteId, assignmentId);

return buildtagJsonOject(tagList, tagList.size());
} catch (Exception e) {
log.error("Error calling getTagsByAssignmentId:", 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 49096d1

Please sign in to comment.