Github user imesh commented on a diff in the pull request: https://github.com/apache/stratos/pull/296#discussion_r30015973 --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java --- @@ -3200,4 +3202,124 @@ 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 InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid + */ + private static void validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean) + throws InvalidCartridgeGroupDefinitionException { + 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 InvalidCartridgeGroupDefinitionException - throws when the cartridges are duplicated + */ + private static void validateCartridgeDuplicationInGroup(List<String> cartridges) + throws InvalidCartridgeGroupDefinitionException { + 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 InvalidCartridgeGroupDefinitionException("Invalid cartridge group definition, " + + "duplicate cartridges defined: " + cartridge); + } + } + } + + + /** + * This is a wrapper method to invoke validateGroupDuplicationInGroupDefinition with a new arraylist of string + * + * @param groupBean - cartridge group definition + * @throws InvalidCartridgeGroupDefinitionException + */ + private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean) + throws InvalidCartridgeGroupDefinitionException { + validateGroupDuplicationInGroupDefinition(groupBean, new ArrayList<String>()); + } + + /** + * This 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 InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid + */ + private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> parentGroups) + throws InvalidCartridgeGroupDefinitionException { + 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 InvalidCartridgeGroupDefinitionException - throws when group duplicate or when cyclic behaviour occurs + */ + private static void validateGroupDuplicationInGroup(List<String> groups, List<String> parentGroups) + throws InvalidCartridgeGroupDefinitionException { + 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 InvalidCartridgeGroupDefinitionException("Invalid cartridge group definition, " + + "duplicate groups defined: " + group); + } + if (parentGroups.contains(group)) { + if (log.isDebugEnabled()) { + log.debug("cyclic group behaviour identified [group-name]: " + group); --- End diff -- Same concern, please change the first letter of this sentence to uppercase.
--- 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. ---