Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/296#discussion_r29760927
  
    --- Diff: 
components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
 ---
    @@ -3200,4 +3196,110 @@ public static void updateUser(UserInfoBean 
userInfoBean) throws RestAPIException
             return userList;
         }
     
    +    /**
    +     * This method is to validate the cartridge duplication in the group 
definition recursively for group within groups
    +     *
    +     * @param groupBean - cartridge group definition
    +     * @throws RestAPIException - throws the rest api exception when the 
group definition is invalid
    +     */
    +    private static void 
validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean) throws 
RestAPIException {
    +        if (groupBean == null) {
    +            return;
    +        }
    +        List<String> cartridges = new ArrayList<String>();
    +        if (groupBean.getCartridges() != null) {
    +            if (groupBean.getCartridges().size() > 1) {
    +                cartridges.addAll(groupBean.getCartridges());
    +                validateCartridgeDuplicationInGroup(cartridges);
    +            }
    +        }
    +        if (groupBean.getGroups() != null) {
    +            //Recursive because to check groups inside groups
    +            for (GroupBean group : groupBean.getGroups()) {
    +                validateCartridgeDuplicationInGroupDefinition(group);
    +            }
    +        }
    +    }
    +
    +    /**
    +     * This method is to validate the duplication of cartridges from the 
given list
    +     *
    +     * @param cartridges - list of strings which holds the cartridgeTypes 
values
    +     * @throws RestAPIException - throws the rest api exception when the 
cartridges are duplicated
    +     */
    +    private static void validateCartridgeDuplicationInGroup(List<String> 
cartridges) throws RestAPIException {
    +        List<String> checkList = new ArrayList<String>();
    +        for (String cartridge : cartridges) {
    +            if (!checkList.contains(cartridge)) {
    +                checkList.add(cartridge);
    +            } else {
    +                if (log.isDebugEnabled()) {
    +                    log.debug("duplicate cartridges defined: " + 
cartridge);
    +                }
    +                throw new RestAPIException("Invalid Service Group 
definition, duplicate cartridges defined: " +
    +                        cartridge);
    +            }
    +        }
    +    }
    +
    +    /**
    +     * This method is to validate the group duplication in the group 
definition recursively for group within groups
    +     *
    +     * @param groupBean    - cartridge group definition
    +     * @param parentGroups - list of string which holds the parent group 
names (all parents in the hierarchy)
    +     * @throws RestAPIException - throws the rest api exception when the 
group definition is invalid
    +     */
    +    private static void 
validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> 
parentGroups)
    +            throws RestAPIException {
    +        if (groupBean == null) {
    +            return;
    +        }
    +        List<String> groups = new ArrayList<String>();
    +        parentGroups.add(groupBean.getName());
    +        if (groupBean.getGroups() != null) {
    +            if (!groupBean.getGroups().isEmpty()) {
    +                for (GroupBean g : groupBean.getGroups()) {
    +                    groups.add(g.getName());
    +                }
    +                validateGroupDuplicationInGroup(groups, parentGroups);
    +            }
    +        }
    +        if (groupBean.getGroups() != null) {
    +            //Recursive because to check groups inside groups
    +            for (GroupBean group : groupBean.getGroups()) {
    +                validateGroupDuplicationInGroupDefinition(group, 
parentGroups);
    +                parentGroups.remove(group.getName());
    +            }
    +        }
    +    }
    +
    +    /**
    +     * This method is to validate the duplication of groups in the same 
level and to validate cyclic behaviour of groups
    +     *
    +     * @param groups       - cartridge group definition
    +     * @param parentGroups - list of string which holds the parent group 
names (all parents in the hierarchy)
    +     * @throws RestAPIException - throws the rest api exception when group 
duplicate or when cyclic behaviour occurs
    +     */
    +    private static void validateGroupDuplicationInGroup(List<String> 
groups, List<String> parentGroups)
    +            throws RestAPIException {
    +        List<String> checkList = new ArrayList<String>();
    +        for (String group : groups) {
    +            if (!checkList.contains(group)) {
    +                checkList.add(group);
    +            } else {
    +                if (log.isDebugEnabled()) {
    +                    log.debug("duplicate group defined: " + group);
    +                }
    +                throw new RestAPIException("Invalid Service Group 
definition, duplicate groups defined: " +
    --- End diff --
    
    I think we have now changed the term "service group" to "cartridge group". 
Might be better to use lower case letters inside the sentence.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to