Skip to content

Commit ff28173

Browse files
committed
Refactoring ACTION READ_HTML_FILE in rest resource ReadHtmlFileResource
1 parent b0e6d92 commit ff28173

8 files changed

Lines changed: 124 additions & 412 deletions

File tree

knowage-core/src/main/java/it/eng/spagobi/commons/serializer/MenuListJSONSerializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,10 @@ public Object serialize(Object o, Locale locale) throws SerializationException {
195195
temp.put(ICON_CLS, menuElem.getIconCls());
196196

197197
String text = "";
198-
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#"))
199-
198+
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#")) {
200199
// text = msgBuild.getI18nMessage(locale, menuElem.getName());
201200
text = menuElem.getName();
202-
else {
201+
} else {
203202
if (menuElem.getName().startsWith("#")) {
204203
String titleCode = menuElem.getName().substring(1);
205204
text = msgBuild.getMessage(titleCode, locale);
@@ -690,7 +689,7 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
690689
} else if (childElem.getStaticPage() != null && !childElem.getStaticPage().equals("")) {
691690
temp2.put(HREF,
692691
"javascript:execDirectUrl('" + contextName
693-
+ "/servlet/AdapterHTTP?ACTION_NAME=READ_HTML_FILE&MENU_ID=" + childElem.getMenuId()
692+
+ "/restful-services/2.0/readHtmlFile?MENU_ID=" + childElem.getMenuId()
694693
+ "', '" + path + "' )");
695694
} else if (StringUtils.isNotEmpty(childElem.getFunctionality())) {
696695
String finalUrl = "javascript:execDirectUrl('"

knowage-core/src/main/java/it/eng/spagobi/commons/serializer/MenuListJSONSerializerForREST.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ public Object serialize(Object o, Locale locale) throws SerializationException {
205205
temp.put(ICON_CLS, menuElem.getIconCls());
206206

207207
String text = "";
208-
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#"))
209-
208+
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#")) {
210209
// text = msgBuild.getI18nMessage(locale, menuElem.getName());
211210
text = menuElem.getName();
212-
else {
211+
} else {
213212
if (menuElem.getName().startsWith("#")) {
214213
String titleCode = menuElem.getName().substring(1);
215214
text = msgBuild.getMessage(titleCode, locale);
@@ -719,10 +718,10 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
719718

720719
MessageBuilder msgBuild = new MessageBuilder();
721720
String text = "";
722-
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#"))
721+
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#")) {
723722
// text = msgBuild.getI18nMessage(locale, childElem.getName());
724723
text = childElem.getName();
725-
else {
724+
} else {
726725
if (childElem.getName().startsWith("#")) {
727726
String titleCode = childElem.getName().substring(1);
728727

@@ -762,10 +761,10 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
762761
temp2.put(TEXT, text);
763762

764763
String descr = "";
765-
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#"))
764+
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#")) {
766765
// text = msgBuild.getI18nMessage(locale, childElem.getName());
767766
descr = childElem.getDescr();
768-
else {
767+
} else {
769768
if (childElem.getName().startsWith("#")) {
770769
String titleCode = childElem.getDescr().substring(1);
771770

@@ -808,10 +807,10 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
808807
} else if (childElem.getStaticPage() != null && !childElem.getStaticPage().equals("")) {
809808
temp2.put(HREF,
810809
"javascript:execDirectUrl('" + contextName
811-
+ "/servlet/AdapterHTTP?ACTION_NAME=READ_HTML_FILE&MENU_ID=" + childElem.getMenuId()
810+
+ "/restful-services/2.0/readHtmlFile?MENU_ID=" + childElem.getMenuId()
812811
+ "', '" + path + "' )");
813812
temp2.put(LINK_TYPE, "execDirectUrl");
814-
temp2.put(SRC, contextName + "/servlet/AdapterHTTP?ACTION_NAME=READ_HTML_FILE&MENU_ID="
813+
temp2.put(SRC, contextName + "/restful-services/2.0/readHtmlFile?MENU_ID="
815814
+ childElem.getMenuId());
816815
} else if (StringUtils.isNotEmpty(childElem.getFunctionality())) {
817816
String finalUrl = "javascript:execDirectUrl('"

knowage-core/src/main/java/it/eng/spagobi/commons/serializer/v3/MenuListJSONSerializerForREST.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ private JSONArray createDynamicUserFunctionalitiesMenu(List filteredMenuList, Lo
258258
// Create custom Menu elements (menu defined by the users)
259259

260260
menuUserList = createUserMenuElement(filteredMenuList, menuElem, locale, 1, menuUserList);
261-
if (menuUserList.length() > 0)
261+
if (menuUserList.length() > 0) {
262262
tempFirstLevelMenuList.put(menuUserList.get(0));
263+
}
263264

264265
if (menuElem.getHasChildren()) {
265266
List lstChildrenLev2 = menuElem.getLstChildren();
@@ -273,9 +274,9 @@ private JSONArray createDynamicUserFunctionalitiesMenu(List filteredMenuList, Lo
273274
temp.put(ICON_CLS, menuElem.getIconCls());
274275

275276
String text = "";
276-
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#"))
277+
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#")) {
277278
text = menuElem.getName();
278-
else {
279+
} else {
279280
if (menuElem.getName().startsWith("#")) {
280281
String titleCode = menuElem.getName().substring(1);
281282
text = msgBuild.getMessage(titleCode, locale);
@@ -410,25 +411,30 @@ private JSONArray createItemsArray(Locale locale, MessageBuilder messageBuilder,
410411
if (isAbleTo(reqFunc[i], funcs)) {
411412
addElement = isGroupItemToAdd(itemSB);
412413
}
413-
if (addElement)
414+
if (addElement) {
414415
break;
416+
}
415417
}
416418
}
417419

418-
if (addElement)
420+
if (addElement) {
419421
addElement &= isUserMenuAuthorized(menuType, itemSB);
422+
}
420423

421-
if (addElement)
424+
if (addElement) {
422425
addElement &= isUserMenuForNotAdmin(menuType, itemSB);
426+
}
423427

424-
if (addElement)
428+
if (addElement) {
425429
addElement &= isMenuForKnowageCurrentType(menuType, itemSB);
430+
}
426431

427432
if (addElement) {
428433
JSONObject menu = createMenuNode(locale, messageBuilder, itemSB, menuType);
429434
items.put(menu);
430-
if (menuType == MenuType.TECHNICAL_USER_FUNCTIONALITIES)
435+
if (menuType == MenuType.TECHNICAL_USER_FUNCTIONALITIES) {
431436
technicalUserMenuIds.add(Integer.valueOf((String) itemSB.getAttribute(ID)));
437+
}
432438
}
433439
}
434440

@@ -466,11 +472,13 @@ private boolean isUserMenuAuthorized(MenuType menuType, SourceBean itemSB) throw
466472

467473
isAuthorized = associatedAuthRoles.stream().anyMatch(x -> x.getSbiAuthorizations().getName().equals(lic));
468474
}
469-
if (isAuthorized)
475+
if (isAuthorized) {
470476
break;
477+
}
471478
}
472-
if (isAuthorized)
479+
if (isAuthorized) {
473480
break;
481+
}
474482

475483
}
476484
}
@@ -530,14 +538,16 @@ private boolean isMenuForKnowageCurrentType(MenuType menuType, SourceBean itemSB
530538
if (menuType == MenuType.TECHNICAL_USER_FUNCTIONALITIES) {
531539
if (technicalMenuCommunityOrEnterprise.containsKey(menuId)) {
532540
isToAdd = !isEnterpriseEdition();
533-
if (!isToAdd)
541+
if (!isToAdd) {
534542
return false;
543+
}
535544
}
536545

537546
if (technicalMenuCommunityOrEnterprise.containsValue(menuId)) {
538547
isToAdd = isEnterpriseEdition();
539-
if (!isToAdd)
548+
if (!isToAdd) {
540549
return false;
550+
}
541551
}
542552
}
543553
}
@@ -582,8 +592,9 @@ private boolean isGroupItemToAdd(SourceBean itemSB) {
582592
List<String> activeProducts = (List<String>) getActiveProductsMethod.invoke(productProfilerEE);
583593
for (String lic : requiredLicenses) {
584594
isLicensed = activeProducts.contains(lic);
585-
if (isLicensed)
595+
if (isLicensed) {
586596
break;
597+
}
587598
}
588599
} catch (Exception e) {
589600
isLicensed = false;
@@ -679,8 +690,9 @@ private JSONObject createMenuNode(Locale locale, MessageBuilder messageBuilder,
679690
for (Object objAttribute : containedAttributes) {
680691
SourceBeanAttribute attribute = (SourceBeanAttribute) objAttribute;
681692

682-
if (isAttributeToIgnore(attribute))
693+
if (isAttributeToIgnore(attribute)) {
683694
continue;
695+
}
684696
String value = String.valueOf(attribute.getValue());
685697
String key = attribute.getKey();
686698
if (!key.equals(ITEM) && StringUtils.isNotBlank(value)) {
@@ -732,9 +744,9 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
732744
}
733745

734746
/* TEXT PROPERTY HANDLING */
735-
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#"))
747+
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#")) {
736748
text = childElem.getName();
737-
else {
749+
} else {
738750
if (childElem.getName().startsWith("#")) {
739751
String titleCode = childElem.getName().substring(1);
740752

@@ -772,9 +784,9 @@ private JSONArray createUserMenuElement(List filteredMenuList, Menu childElem, L
772784

773785
/* DESCR PROPERTY HANDLING */
774786
String descr = "";
775-
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#"))
787+
if (!childElem.isAdminsMenu() || !childElem.getName().startsWith("#")) {
776788
descr = childElem.getDescr();
777-
else if (childElem.getName().startsWith("#")) {
789+
} else if (childElem.getName().startsWith("#")) {
778790
// String titleCode = childElem.getDescr().substring(1);
779791
//
780792
// try {
@@ -889,7 +901,7 @@ private void setPropertiesForFunctionalityMenu(Menu childElem, JSONObject temp2,
889901
}
890902

891903
private void setPropertiesForStaticMenu(Menu childElem, JSONObject temp2, String path) throws JSONException {
892-
temp2.put(TO, contextName + "/servlet/AdapterHTTP?ACTION_NAME=READ_HTML_FILE&MENU_ID=" + childElem.getMenuId());
904+
temp2.put(TO, "/html?id=" + childElem.getMenuId());
893905
}
894906

895907
public IEngUserProfile getUserProfile() {

knowage-core/src/main/java/it/eng/spagobi/wapp/services/ReadHtmlFile.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)