Exemplo n.º 1
0
  private MenuSchema serializeMenuTree(final MenuItem rootMenuItem) {
    final MenuSchema menuSchema = new MenuSchema();
    menuSchema.setDescription(rootMenuItem.getDescription());
    if (isReport(rootMenuItem) || isView(rootMenuItem) || isDashboard(rootMenuItem)) {
      menuSchema.setId(rootMenuItem.getReferencedElementId().intValue());
    } else if (rootMenuItem.getId() != null) {
      menuSchema.setId(rootMenuItem.getId().intValue());
    }
    menuSchema.setMenuType(rootMenuItem.getType().getValue().toLowerCase());

    if (isClass(rootMenuItem)
        || (isProcess(rootMenuItem) && isProcessUsable(rootMenuItem.getReferedClassName()))) {
      final CMClass menuEntryClass = dataAccessLogic.findClass(rootMenuItem.getReferedClassName());
      menuSchema.setId(menuEntryClass.getId().intValue());
      menuSchema.setDefaultToDisplay(isStartingClass(menuEntryClass));
      menuSchema.setClassname(menuEntryClass.getIdentifier().getLocalName());
      final PrivilegeType privilege = getPrivilegeFor(menuEntryClass);
      menuSchema.setPrivilege(privilege.toString());
    }

    final List<MenuSchema> children = new ArrayList<MenuSchema>();
    MenuSchema childMenuSchema = new MenuSchema();
    for (final MenuItem childMenuItem : rootMenuItem.getChildren()) {
      childMenuSchema = serializeMenuTree(childMenuItem);
      children.add(childMenuSchema);
    }

    menuSchema.setChildren(children.toArray(new MenuSchema[children.size()]));
    return menuSchema;
  }
Exemplo n.º 2
0
  public List<PrivilegeInfo> fetchClassPrivilegesForGroup(final Long groupId) {
    final List<PrivilegeInfo> fetchedClassPrivileges =
        fetchStoredPrivilegesForGroup( //
            groupId, //
            PrivilegedObjectType.CLASS //
            );

    final Iterable<CMClass> nonReservedActiveClasses = filterNonReservedAndNonBaseClasses();

    for (final CMClass clazz : nonReservedActiveClasses) {
      final Long classId = clazz.getId();
      if (!isPrivilegeAlreadyStored(classId, fetchedClassPrivileges)) {
        final PrivilegeInfo pi = new PrivilegeInfo(groupId, clazz, PrivilegeMode.NONE);

        final List<String> attributesPrivileges = new ArrayList<String>();
        for (final CMAttribute attribute : clazz.getAttributes()) {
          final String mode = attribute.getMode().name().toLowerCase();
          attributesPrivileges.add(String.format("%s:%s", attribute.getName(), mode));
        }

        pi.setAttributesPrivileges( //
            attributesPrivileges.toArray(new String[attributesPrivileges.size()]) //
            );

        fetchedClassPrivileges.add(pi);
      }
    }
    return fetchedClassPrivileges;
  }
Exemplo n.º 3
0
 @SuppressWarnings("unchecked")
 private Iterable<CMClass> filterNonReservedAndNonBaseClasses() {
   final Iterable<CMClass> classes = (Iterable<CMClass>) view.findClasses();
   final List<CMClass> nonReservedClasses = Lists.newArrayList();
   for (final CMClass clazz : classes) {
     if (!clazz.isSystem() && !clazz.isBaseClass()) {
       nonReservedClasses.add(clazz);
     }
   }
   return nonReservedClasses;
 }
Exemplo n.º 4
0
  public MenuSchema serializeVisibleClassesFromRoot(final CMClass root) {
    final MenuSchema menuSchema = new MenuSchema();
    menuSchema.setId(root.getId().intValue());
    menuSchema.setDescription(root.getDescription());
    menuSchema.setClassname(root.getIdentifier().getLocalName());
    // FIXME: add metadata serialization... wth are metadata for a class?
    setMenuTypeFromTypeAndChildren(menuSchema, false, root.isSuperclass());
    menuSchema.setPrivilege(getPrivilegeFor(root).getGrantType());
    menuSchema.setDefaultToDisplay(isStartingClass(root));

    final List<MenuSchema> children = new ArrayList<MenuSchema>();
    if (Iterables.size(root.getChildren()) > 0) {
      for (final CMClass childClass : root.getChildren()) {
        children.add(serializeVisibleClassesFromRoot(childClass));
      }
    }
    menuSchema.setChildren(children.toArray(new MenuSchema[children.size()]));
    return menuSchema;
  }
Exemplo n.º 5
0
 private boolean isStartingClass(final CMClass cmClass) {
   final Long startingClassId = operationUser.getPreferredGroup().getStartingClassId();
   return (startingClassId == null) ? false : startingClassId.equals(cmClass.getId());
 }