Skip to content

Instantly share code, notes, and snippets.

@bryceosterhaus
Created April 17, 2017 23:51
Show Gist options
  • Save bryceosterhaus/ed973066ac32a4a424e9622c42f72c92 to your computer and use it in GitHub Desktop.
Save bryceosterhaus/ed973066ac32a4a424e9622c42f72c92 to your computer and use it in GitHub Desktop.
public void viewLoopDivisionHierarchy() throws Exception {
if (!isRespondingTo("json")) {
return;
}
LoopDivision loopDivision = LoopDivisionUtil.fetchLoopDivision(request, themeDisplay);
_validateView(loopDivision);
JSONArray childLoopDivisionJSONArray = JSONFactoryUtil.createJSONArray();
int type = ParamUtil.getInteger(request, "type");
if (!ArrayUtil.contains(LoopDivisionConstants.TYPES, type)) {
type = loopDivision.getType();
}
List<LoopDivision> childLoopDivisions = alloyServiceInvoker.executeDynamicQuery(new Object[] {"companyId", themeDisplay.getCompanyId(), "parentLoopDivisionId", loopDivision.getLoopDivisionId(), "type", type});
for (LoopDivision childLoopDivision : childLoopDivisions) {
childLoopDivisionJSONArray.put(getHierarchyJSONObject(childLoopDivision, JSONFactoryUtil.createJSONArray()));
}
JSONObject loopDivisionHierarchyJSONObject = getHierarchyJSONObject(loopDivision, childLoopDivisionJSONArray);
while (loopDivision.getType() != LoopDivisionConstants.TYPE_ROOT) {
LoopDivision parentLoopDivision = LoopDivisionLocalServiceUtil.fetchLoopDivision(loopDivision.getParentLoopDivisionId());
loopDivisionHierarchyJSONObject = getHierarchyJSONObject(parentLoopDivision, _getSiblingLoopDivisionCompositeJSONArray(loopDivision, loopDivisionHierarchyJSONObject));
loopDivision = parentLoopDivision;
}
respondWith(loopDivisionHierarchyJSONObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment