Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishanth authored and imesh committed May 11, 2015
1 parent ea8fce5 commit 2fdac39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,18 @@ public Response addServiceGroup(
if (e.getCause().getMessage().contains("already exists")) {
return Response.status(Response.Status.CONFLICT).entity(new StatusResponseBean(
Response.Status.CONFLICT.getStatusCode(), "Cartridge group not found")).build();
} else if(e.getCause().getMessage().contains("duplicate cartridges")) {
} else if (e.getCause().getMessage().contains("duplicate cartridges")) {
return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
Response.Status.BAD_REQUEST.getStatusCode(), "Cartridges duplicated in the group definition")).build();
} else if(e.getCause().getMessage().contains("duplicate groups")) {
Response.Status.BAD_REQUEST.getStatusCode(), "Cartridges duplicated in the group " +
"definition")).build();
} else if (e.getCause().getMessage().contains("duplicate groups")) {
return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
Response.Status.BAD_REQUEST.getStatusCode(), "Groups duplicated in the group definition")).build();
} else if(e.getCause().getMessage().contains("cyclic group")) {
Response.Status.BAD_REQUEST.getStatusCode(), "Groups duplicated in the group " +
"definition")).build();
} else if (e.getCause().getMessage().contains("cyclic group")) {
return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
Response.Status.BAD_REQUEST.getStatusCode(), "Cyclic group behaviour identified in the group definition")).build();
Response.Status.BAD_REQUEST.getStatusCode(), "Cyclic group behaviour identified in the group " +
"definition")).build();
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ public static void notifyArtifactUpdatedEvent(GitNotificationPayloadBean payload

/**
* Add a Service Group
*
* @param serviceGroupDefinition serviceGroupDefinition
* @throws RestAPIException
*/
Expand All @@ -980,11 +981,11 @@ public static void addServiceGroup(GroupBean serviceGroupDefinition) throws Rest
List<String> groupNames;
String[] cartridgeGroupNames;

if (log.isDebugEnabled()) {
log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
}
if (log.isDebugEnabled()) {
log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
}

findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);
findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);

//validate the group definition to check if cartridges duplicate in any groups defined
validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
Expand All @@ -993,7 +994,7 @@ public static void addServiceGroup(GroupBean serviceGroupDefinition) throws Rest
//validate the group definition to check for cyclic group behaviour
validateGroupDuplicationInGroupDefinition(serviceGroupDefinition, new ArrayList<String>());

CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();
CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();

cartridgeNames = new String[cartridgeTypes.size()];
int j = 0;
Expand Down Expand Up @@ -3230,7 +3231,7 @@ public static List<UserInfoBean> getUsers() throws RestAPIException {
* @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{
private static void validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean) throws RestAPIException {
if (groupBean == null) {
return;
}
Expand All @@ -3248,19 +3249,19 @@ private static void validateCartridgeDuplicationInGroupDefinition(GroupBean grou
}
}
}

/**
* 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{
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 {
} else {
if (log.isDebugEnabled()) {
log.debug("duplicate cartridges defined: " + cartridge);
}
Expand All @@ -3269,15 +3270,16 @@ private static void validateCartridgeDuplicationInGroup(List<String> cartridges)
}
}
}

/**
* This method is to validate the group duplication in the group definition recursively for group within groups
*
* @param groupBean - cartridge group definition
* @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{
throws RestAPIException {
if (groupBean == null) {
return;
}
Expand All @@ -3299,21 +3301,21 @@ private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBea
}
}
}

/**
* 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 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{
throws RestAPIException {
List<String> checkList = new ArrayList<String>();
for (String group : groups) {
if (!checkList.contains(group)) {
checkList.add(group);
}
else {
} else {
if (log.isDebugEnabled()) {
log.debug("duplicate group defined: " + group);
}
Expand All @@ -3329,5 +3331,4 @@ private static void validateGroupDuplicationInGroup(List<String> groups, List<St
}
}
}

}

0 comments on commit 2fdac39

Please sign in to comment.