use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.
the class ShortcutDefDOM method getShortcuts.
public Map<String, Shortcut> getShortcuts() {
Map<String, Shortcut> shortcuts = new HashMap<String, Shortcut>();
Element shortcutsElement = this._doc.getRootElement().getChild(SHORTCUTS_ELEMENT_NAME);
if (null == shortcutsElement) {
return shortcuts;
}
List<Element> shortcutElements = shortcutsElement.getChildren();
for (int i = 0; i < shortcutElements.size(); i++) {
Element shortcutElement = shortcutElements.get(i);
String id = shortcutElement.getAttributeValue(SHORTCUT_ID_ATTRIBUTE_NAME);
Shortcut shortcut = new Shortcut(id);
shortcut.setRequiredPermission(shortcutElement.getAttributeValue(SHORTCUT_REQ_PERMISSION_ATTRIBUTE_NAME));
shortcut.setMenuSectionCode(shortcutElement.getAttributeValue(SHORTCUT_MENU_SECTION_ATTRIBUTE_NAME));
shortcut.setSource(shortcutElement.getAttributeValue(SHORTCUT_SOURCE_ATTRIBUTE_NAME));
this.extractDescriptions(shortcutElement, shortcut);
Element urlElement = shortcutElement.getChild(SHORTCUT_URL_ELEMENT_NAME);
if (null != urlElement) {
List<Element> paramElements = urlElement.getChildren(PARAM_ELEMENT_NAME);
for (int j = 0; j < paramElements.size(); j++) {
Element paramElement = paramElements.get(j);
String name = paramElement.getAttributeValue(PARAM_NAME_ATTRIBUTE_NAME);
String value = paramElement.getText();
if (name.equals(NAMESPACE_PARAM_NAME)) {
shortcut.setNamespace(value);
} else if (name.equals(ACTIONNAME_PARAM_NAME)) {
shortcut.setActionName(value);
} else {
if (null == shortcut.getParameters()) {
shortcut.setParameters(new HashMap<String, Object>());
}
shortcut.getParameters().put(name, value);
}
}
}
shortcuts.put(shortcut.getId(), shortcut);
}
return shortcuts;
}
use of org.entando.entando.apsadmin.system.services.shortcut.model.Shortcut in project entando-core by entando.
the class ShortcutListTag method getAllowedShortcutSelectItems.
public List<SelectItem> getAllowedShortcutSelectItems(List<Shortcut> myShortcuts, UserDetails currentUser) {
List<SelectItem> items = new ArrayList<SelectItem>();
if (null == myShortcuts || myShortcuts.isEmpty()) {
_logger.debug("shortcut list null");
return items;
}
try {
Map<String, List<SelectItem>> groups = new HashMap<String, List<SelectItem>>();
for (int i = 0; i < myShortcuts.size(); i++) {
Shortcut shortcut = myShortcuts.get(i);
String groupCode = shortcut.getSource();
String optgroup = shortcut.getSource();
if (groupCode.equals("core")) {
groupCode += " - " + shortcut.getMenuSection().getId();
String sectDescrKey = shortcut.getMenuSection().getDescriptionKey();
String sectDescr = this.getText(sectDescrKey);
if (null == sectDescrKey || sectDescrKey.equals(sectDescr)) {
sectDescr = shortcut.getMenuSection().getDescription();
}
optgroup += " - " + sectDescr;
} else {
String labelCode = optgroup + ".name";
String optgroupDescr = this.getText(labelCode);
if (!optgroupDescr.equals(labelCode)) {
optgroup = optgroupDescr;
}
}
String descrKey = shortcut.getDescriptionKey();
String descr = this.getText(descrKey);
if (null == descrKey || descrKey.equals(descr)) {
descr = shortcut.getDescription();
}
List<SelectItem> itemsByGroup = groups.get(groupCode);
if (null == itemsByGroup) {
itemsByGroup = new ArrayList<SelectItem>();
groups.put(groupCode, itemsByGroup);
}
SelectItem selectItem = new SelectItem(shortcut.getId(), descr, optgroup);
itemsByGroup.add(selectItem);
}
List<String> keys = new ArrayList<String>(groups.keySet());
Collections.sort(keys);
for (int i = 0; i < keys.size(); i++) {
List<SelectItem> itemsByGroup = groups.get(keys.get(i));
BeanComparator comparator = new BeanComparator("value");
Collections.sort(itemsByGroup, comparator);
items.addAll(itemsByGroup);
}
} catch (Throwable t) {
_logger.error("Error extracting allowed shortcut items by user {}", currentUser.getUsername(), t);
throw new RuntimeException("Error extracting allowed shortcut items by user " + currentUser.getUsername(), t);
}
return items;
}
Aggregations