diff --git a/LICENSE b/LICENSE index 8051b1e..a91c3a9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Auto & General Insurance Company Ltd. +Copyright (c) 2016 Auto & General Insurance Company Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f311729..ed323c3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ https://developer.atlassian.com/display/DOCS/Introduction+to+the+Atlassian+Plugi The MIT License (MIT) -Copyright (c) 2015 Auto & General Insurance Company Ltd. +Copyright (c) 2016 Auto & General Insurance Company Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/build/bamboo_mass_deployment.jar b/build/bamboo_mass_deployment.jar index 3b6e6f8..a1bab50 100644 Binary files a/build/bamboo_mass_deployment.jar and b/build/bamboo_mass_deployment.jar differ diff --git a/src/main/java/au/com/agic/DeploymentExecution.java b/src/main/java/au/com/agic/DeploymentExecution.java index 79814af..bd16300 100644 --- a/src/main/java/au/com/agic/DeploymentExecution.java +++ b/src/main/java/au/com/agic/DeploymentExecution.java @@ -14,44 +14,53 @@ import com.atlassian.bamboo.ww2.BambooActionSupport; import com.atlassian.user.User; import com.opensymphony.xwork2.Action; + import org.apache.struts2.ServletActionContext; -import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import javax.servlet.http.HttpServletRequest; + /** * Deployment execution controller *

- * This page controller receives 'params' query parameter with the list of serialized DeploymentObjects, - * parses it and then executes deployments + * This page controller receives 'params' query parameter with the list of serialized + * DeploymentObjects, parses it and then executes deployments *

* Exposes resultsParamString field with the serialized list of DeploymentObjects */ public class DeploymentExecution extends BambooActionSupport { + private static final long serialVersionUID = 7830762978792971693L; + private final DeploymentExecutionService deploymentExecutionService; private final EnvironmentService environmentService; private final DeploymentVersionService deploymentVersionService; private final BambooAuthenticationContext bambooAuthenticationContext; private final DeploymentResultService deploymentResultService; - private final EnvironmentTriggeringActionFactory environmentTriggeringActionFactory; + private final EnvironmentTriggeringActionFactory triggeringActionFactory; /** * String we will return with the list of serialized DeploymentObjects */ private String resultsParamString; - public DeploymentExecution(DeploymentExecutionService deploymentExecutionService, EnvironmentService environmentService, - DeploymentVersionService deploymentVersionService, BambooAuthenticationContext bambooAuthenticationContext, - DeploymentResultService deploymentResultService, EnvironmentTriggeringActionFactory environmentTriggeringActionFactory) { + public DeploymentExecution( + final DeploymentExecutionService deploymentExecutionService, + final EnvironmentService environmentService, + final DeploymentVersionService deploymentVersionService, + final BambooAuthenticationContext bambooAuthenticationContext, + final DeploymentResultService deploymentResultService, + final EnvironmentTriggeringActionFactory triggeringActionFactory) { + this.deploymentExecutionService = deploymentExecutionService; this.environmentService = environmentService; this.deploymentVersionService = deploymentVersionService; this.bambooAuthenticationContext = bambooAuthenticationContext; this.deploymentResultService = deploymentResultService; - this.environmentTriggeringActionFactory = environmentTriggeringActionFactory; + this.triggeringActionFactory = triggeringActionFactory; } /** @@ -62,7 +71,7 @@ public DeploymentExecution(DeploymentExecutionService deploymentExecutionService */ private List getDeploymentInfoFromParams(String serializedString) { final String[] parts = serializedString.split(Pattern.quote(";")); - List result = new ArrayList(); + List result = new ArrayList<>(); for (String part : parts) { String[] param = part.split(Pattern.quote(":")); @@ -81,28 +90,32 @@ private List getDeploymentInfoFromParams(String serializedStri @Override public String doDefault() throws Exception { - HttpServletRequest request = ServletActionContext.getRequest(); - List deploymentObjects = new ArrayList(); - resultsParamString = ""; + List deploymentObjects = null; + final HttpServletRequest request = ServletActionContext.getRequest(); + final String rawParams = request.getParameter("params"); - String rawParams = request.getParameter("params"); if (rawParams != null) { deploymentObjects = getDeploymentInfoFromParams(rawParams); } - if (deploymentObjects == null) return Action.ERROR; + if (deploymentObjects == null) { + return Action.ERROR; + } for (DeploymentObject deploymentObject : deploymentObjects) { // Create deployment context and start deployment User user = bambooAuthenticationContext.getUser(); EnvironmentTriggeringAction environmentTriggeringAction = - environmentTriggeringActionFactory.createManualEnvironmentTriggeringAction(deploymentObject.getTargetEnvironment(), deploymentObject.getVersion(), user); + triggeringActionFactory.createManualEnvironmentTriggeringAction( + deploymentObject.getTargetEnvironment(), deploymentObject.getVersion(), user); - ExecutionRequestResult executionRequestResult = deploymentExecutionService.execute(deploymentObject.getTargetEnvironment(), environmentTriggeringAction); + ExecutionRequestResult executionRequestResult = + deploymentExecutionService.execute(deploymentObject.getTargetEnvironment(), environmentTriggeringAction); if (executionRequestResult.getDeploymentResultId() != null) { - DeploymentResult deploymentResult = deploymentResultService.getDeploymentResult(executionRequestResult.getDeploymentResultId()); + DeploymentResult deploymentResult = + deploymentResultService.getDeploymentResult(executionRequestResult.getDeploymentResultId()); deploymentObject.setResult(deploymentResult); // Generate the response string diff --git a/src/main/java/au/com/agic/DeploymentObject.java b/src/main/java/au/com/agic/DeploymentObject.java index 24bbf38..73be77e 100644 --- a/src/main/java/au/com/agic/DeploymentObject.java +++ b/src/main/java/au/com/agic/DeploymentObject.java @@ -22,7 +22,7 @@ public Environment getTargetEnvironment() { return targetEnvironment; } - public void setTargetEnvironment(Environment targetEnvironment) { + public void setTargetEnvironment(final Environment targetEnvironment) { this.targetEnvironment = targetEnvironment; } @@ -30,7 +30,7 @@ public DeploymentVersion getVersion() { return version; } - public void setVersion(DeploymentVersion version) { + public void setVersion(final DeploymentVersion version) { this.version = version; } @@ -38,7 +38,7 @@ public DeploymentProject getProject() { return project; } - public void setProject(DeploymentProject project) { + public void setProject(final DeploymentProject project) { this.project = project; } @@ -46,7 +46,7 @@ public DeploymentResult getResult() { return result; } - public void setResult(DeploymentResult result) { + public void setResult(final DeploymentResult result) { this.result = result; } @@ -54,14 +54,16 @@ public String getCode() { return code; } - public DeploymentObject(DeploymentProject project, Environment targetEnvironment, DeploymentVersion version, DeploymentResult result) { + public DeploymentObject(final DeploymentProject project, final Environment targetEnvironment, + final DeploymentVersion version, final DeploymentResult result) { + this.project = project; this.targetEnvironment = targetEnvironment; this.version = version; this.result = result; } - private String getSerializedId(BambooIdProvider entity) { + private String getSerializedId(final BambooIdProvider entity) { if (entity != null) { return Long.toString(entity.getId()); } diff --git a/src/main/java/au/com/agic/DeploymentResultsForm.java b/src/main/java/au/com/agic/DeploymentResultsForm.java index 0a9f724..f71b93f 100644 --- a/src/main/java/au/com/agic/DeploymentResultsForm.java +++ b/src/main/java/au/com/agic/DeploymentResultsForm.java @@ -11,19 +11,23 @@ import com.atlassian.bamboo.deployments.versions.service.DeploymentVersionService; import com.atlassian.bamboo.ww2.BambooActionSupport; import com.opensymphony.xwork2.Action; + import org.apache.struts2.ServletActionContext; -import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import javax.servlet.http.HttpServletRequest; + /** * Controller for page with the deployments results * Deserialized list of DeploymentObjects is expected to be a value for 'results' query param */ public class DeploymentResultsForm extends BambooActionSupport { + private static final long serialVersionUID = -5744223337014651509L; + private final DeploymentProjectService deploymentProjectService; private final EnvironmentService environmentService; private final DeploymentVersionService deploymentVersionService; @@ -42,16 +46,19 @@ public List getDeploymentObjects() { return deploymentObjects; } - public DeploymentResultsForm(AdministrationConfigurationAccessor administrationConfigurationAccessor, EnvironmentService environmentService, - DeploymentVersionService deploymentVersionService, DeploymentResultService deploymentResultService, - DeploymentProjectService deploymentProjectService) { + public DeploymentResultsForm( + final AdministrationConfigurationAccessor configurationAccessor, + final EnvironmentService environmentService, + final DeploymentVersionService deploymentVersionService, + final DeploymentResultService deploymentResultService, + final DeploymentProjectService deploymentProjectService) { this.environmentService = environmentService; this.deploymentVersionService = deploymentVersionService; this.deploymentResultService = deploymentResultService; this.deploymentProjectService = deploymentProjectService; - baseUrl = administrationConfigurationAccessor.getAdministrationConfiguration().getBaseUrl(); + baseUrl = configurationAccessor.getAdministrationConfiguration().getBaseUrl(); } /** @@ -60,24 +67,30 @@ public DeploymentResultsForm(AdministrationConfigurationAccessor administrationC * @param serializedString - serialized list of DeploymentObjects * @return list of deserialized DeploymentObjects */ - private List getDeploymentInfoFromParams(String serializedString) { + private List getDeploymentInfoFromParams(final String serializedString) { final String[] parts = serializedString.split(Pattern.quote(";")); - List result = new ArrayList(); + final List result = new ArrayList(); - for (String part : parts) { - String[] param = part.split(Pattern.quote(":")); + for (final String part : parts) { + final String[] param = part.split(Pattern.quote(":")); if (param.length >= 4) { - Environment environment = environmentService.getEnvironment(Long.parseLong(param[1], 10)); - DeploymentVersion deploymentVersion = deploymentVersionService.getDeploymentVersion(Long.parseLong(param[2], 10)); - DeploymentResult deploymentResult = deploymentResultService.getDeploymentResult(Long.parseLong(param[3], 10)); + final Environment environment = + environmentService.getEnvironment(Long.parseLong(param[1], 10)); + final DeploymentVersion deploymentVersion = + deploymentVersionService.getDeploymentVersion(Long.parseLong(param[2], 10)); + final DeploymentResult deploymentResult = + deploymentResultService.getDeploymentResult(Long.parseLong(param[3], 10)); DeploymentProject deploymentProject = null; if (environment != null) { - deploymentProject = deploymentProjectService.getDeploymentProject(environment.getDeploymentProjectId()); + deploymentProject = + deploymentProjectService.getDeploymentProject(environment.getDeploymentProjectId()); } - DeploymentObject deploymentObject = new DeploymentObject(deploymentProject, environment, deploymentVersion, deploymentResult); + DeploymentObject deploymentObject = + new DeploymentObject(deploymentProject, environment, deploymentVersion, deploymentResult); + deploymentObject.serialize(); result.add(deploymentObject); @@ -88,8 +101,8 @@ private List getDeploymentInfoFromParams(String serializedStri @Override public String doDefault() throws Exception { - HttpServletRequest request = ServletActionContext.getRequest(); - String rawParams = request.getParameter("results"); + final HttpServletRequest request = ServletActionContext.getRequest(); + final String rawParams = request.getParameter("results"); if (rawParams != null) { deploymentObjects = getDeploymentInfoFromParams(rawParams); diff --git a/src/main/java/au/com/agic/DeploymentSetupForm.java b/src/main/java/au/com/agic/DeploymentSetupForm.java index 351fcdd..5ac0d0f 100644 --- a/src/main/java/au/com/agic/DeploymentSetupForm.java +++ b/src/main/java/au/com/agic/DeploymentSetupForm.java @@ -10,16 +10,15 @@ import com.atlassian.bamboo.deployments.versions.DeploymentVersion; import com.atlassian.bamboo.ww2.BambooActionSupport; import com.opensymphony.xwork2.Action; - import org.apache.struts2.ServletActionContext; import org.jetbrains.annotations.Nullable; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - -import javax.servlet.http.HttpServletRequest; +import java.util.stream.Collectors; /** * Mass deployment setup form controller @@ -93,7 +92,7 @@ public String doDefault() throws Exception { List deploymentProjectsList = deploymentProjectService.getAllDeploymentProjects(); deploymentObjects = new ArrayList<>(); - for (DeploymentProject deploymentProject : deploymentProjectsList) { + for (final DeploymentProject deploymentProject : deploymentProjectsList) { List environments = environmentService.getEnvironmentsForDeploymentProject(deploymentProject.getId()); @@ -135,7 +134,7 @@ public String doDefault() throws Exception { * @return set of environments names */ private List getAllEnvironments() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); try { Iterable environments = environmentService.getAllEnvironments(); @@ -148,7 +147,7 @@ private List getAllEnvironments() { Collections.sort(list); - return list; + return list.stream().distinct().collect(Collectors.toList()); } /** diff --git a/src/main/java/au/com/agic/DeploymentVersionJSON.java b/src/main/java/au/com/agic/DeploymentVersionJSON.java index 96266b0..c1db353 100644 --- a/src/main/java/au/com/agic/DeploymentVersionJSON.java +++ b/src/main/java/au/com/agic/DeploymentVersionJSON.java @@ -6,8 +6,10 @@ import com.opensymphony.webwork.dispatcher.json.JSONException; import com.opensymphony.webwork.dispatcher.json.JSONObject; import com.opensymphony.xwork2.Action; + import org.apache.struts2.ServletActionContext; import org.jetbrains.annotations.NotNull; + import javax.servlet.http.HttpServletRequest; /** @@ -29,14 +31,15 @@ */ public class DeploymentVersionJSON extends BambooActionSupport { + private static final long serialVersionUID = -122842815102740306L; private final DeploymentResultService deploymentResultService; - private JSONObject jsonObject = new JSONObject(); + private final JSONObject jsonObject = new JSONObject(); - public DeploymentVersionJSON(DeploymentResultService deploymentResultService) { + public DeploymentVersionJSON(final DeploymentResultService deploymentResultService) { this.deploymentResultService = deploymentResultService; } - private void errorResponse(String message) throws JSONException { + private void errorResponse(final String message) throws JSONException { jsonObject.put("status", "error"); jsonObject.put("message", message); } @@ -49,8 +52,8 @@ public JSONObject getJsonObject() throws JSONException { try { versionId = Long.parseLong(request.getParameter("version"), 10); - } catch (NumberFormatException e) { - e.printStackTrace(); + } catch (NumberFormatException ex) { + ex.printStackTrace(); } if (versionId == null) {