Skip to content

Commit

Permalink
codestyle fixes
Browse files Browse the repository at this point in the history
license year updated
jar updated
  • Loading branch information
idooo-test committed Jul 11, 2016
1 parent e3c3d70 commit 110bb95
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 52 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified build/bamboo_mass_deployment.jar
Binary file not shown.
47 changes: 30 additions & 17 deletions src/main/java/au/com/agic/DeploymentExecution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <p/>
* 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
* <p/>
* 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;
}

/**
Expand All @@ -62,7 +71,7 @@ public DeploymentExecution(DeploymentExecutionService deploymentExecutionService
*/
private List<DeploymentObject> getDeploymentInfoFromParams(String serializedString) {
final String[] parts = serializedString.split(Pattern.quote(";"));
List<DeploymentObject> result = new ArrayList<DeploymentObject>();
List<DeploymentObject> result = new ArrayList<>();

for (String part : parts) {
String[] param = part.split(Pattern.quote(":"));
Expand All @@ -81,28 +90,32 @@ private List<DeploymentObject> getDeploymentInfoFromParams(String serializedStri

@Override
public String doDefault() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
List<DeploymentObject> deploymentObjects = new ArrayList<DeploymentObject>();

resultsParamString = "";
List<DeploymentObject> 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
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/au/com/agic/DeploymentObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,48 @@ public Environment getTargetEnvironment() {
return targetEnvironment;
}

public void setTargetEnvironment(Environment targetEnvironment) {
public void setTargetEnvironment(final Environment targetEnvironment) {
this.targetEnvironment = targetEnvironment;
}

public DeploymentVersion getVersion() {
return version;
}

public void setVersion(DeploymentVersion version) {
public void setVersion(final DeploymentVersion version) {
this.version = version;
}

public DeploymentProject getProject() {
return project;
}

public void setProject(DeploymentProject project) {
public void setProject(final DeploymentProject project) {
this.project = project;
}

public DeploymentResult getResult() {
return result;
}

public void setResult(DeploymentResult result) {
public void setResult(final DeploymentResult result) {
this.result = result;
}

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());
}
Expand Down
45 changes: 29 additions & 16 deletions src/main/java/au/com/agic/DeploymentResultsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,16 +46,19 @@ public List<DeploymentObject> 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();
}

/**
Expand All @@ -60,24 +67,30 @@ public DeploymentResultsForm(AdministrationConfigurationAccessor administrationC
* @param serializedString - serialized list of DeploymentObjects
* @return list of deserialized DeploymentObjects
*/
private List<DeploymentObject> getDeploymentInfoFromParams(String serializedString) {
private List<DeploymentObject> getDeploymentInfoFromParams(final String serializedString) {
final String[] parts = serializedString.split(Pattern.quote(";"));
List<DeploymentObject> result = new ArrayList<DeploymentObject>();
final List<DeploymentObject> result = new ArrayList<DeploymentObject>();

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);
Expand All @@ -88,8 +101,8 @@ private List<DeploymentObject> 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);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/au/com/agic/DeploymentSetupForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +92,7 @@ public String doDefault() throws Exception {
List<DeploymentProject> deploymentProjectsList = deploymentProjectService.getAllDeploymentProjects();
deploymentObjects = new ArrayList<>();

for (DeploymentProject deploymentProject : deploymentProjectsList) {
for (final DeploymentProject deploymentProject : deploymentProjectsList) {
List<Environment> environments =
environmentService.getEnvironmentsForDeploymentProject(deploymentProject.getId());

Expand Down Expand Up @@ -135,7 +134,7 @@ public String doDefault() throws Exception {
* @return set of environments names
*/
private List<String> getAllEnvironments() {
List<String> list = new ArrayList<>();
final List<String> list = new ArrayList<>();

try {
Iterable<Environment> environments = environmentService.getAllEnvironments();
Expand All @@ -148,7 +147,7 @@ private List<String> getAllEnvironments() {

Collections.sort(list);

return list;
return list.stream().distinct().collect(Collectors.toList());
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/au/com/agic/DeploymentVersionJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down

0 comments on commit 110bb95

Please sign in to comment.