Result<ActionPlan> result = createActionPlanResult(parameters);
if (result.ok()) {
- result.setObject(actionPlanService.create(result.get()));
+ result.set(actionPlanService.create(result.get()));
}
return result;
}
DefaultActionPlan existingActionPlan = (DefaultActionPlan) actionPlanService.findByKey(key);
if (existingActionPlan == null) {
- Result<ActionPlan> result = new Result<ActionPlan>();
+ Result<ActionPlan> result = Result.of();
result.addError("issues_action_plans.errors.action_plan_does_not_exists", key);
return result;
} else {
DefaultActionPlan actionPlan = (DefaultActionPlan) result.get();
actionPlan.setKey(existingActionPlan.key());
actionPlan.setUserLogin(existingActionPlan.userLogin());
- result.setObject(actionPlanService.update(actionPlan));
+ result.set(actionPlanService.update(actionPlan));
}
return result;
}
// TODO verify authorization
Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
if (result.ok()) {
- result.setObject(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_CLOSED));
+ result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_CLOSED));
}
return result;
}
// TODO verify authorization
Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
if (result.ok()) {
- result.setObject(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN));
+ result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN));
}
return result;
}
@VisibleForTesting
Result<ActionPlan> createActionPlanResult(Map<String, String> parameters, @Nullable String oldName) {
- Result<ActionPlan> result = new Result<ActionPlan>();
+ Result<ActionPlan> result = Result.of();
String name = parameters.get("name");
String description = parameters.get("description");
.setDescription(description)
.setUserLogin(UserSession.get().login())
.setDeadLine(deadLine);
- result.setObject(actionPlan);
+ result.set(actionPlan);
}
return result;
}
private Result<ActionPlan> createResultForExistingActionPlan(String actionPlanKey) {
- Result<ActionPlan> result = new Result<ActionPlan>();
+ Result<ActionPlan> result = Result.of();
if (findActionPlan(actionPlanKey) == null) {
result.addError("issues_action_plans.errors.action_plan_does_not_exists", actionPlanKey);
}
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
package org.sonar.server.issue;
+import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @since 3.6
+ */
public class Result<T> {
- private T object;
- private List<Message> errors;
+ private T object = null;
+ private List<Message> errors = newArrayList();
+ ;
+
+ private Result(@Nullable T object) {
+ this.object = object;
+ }
- public Result() {
- errors = newArrayList();
+ public static <T> Result<T> of(@Nullable T t) {
+ return new Result<T>(t);
}
- public Result(T object) {
- this();
- this.object = object;
+ public static <T> Result<T> of() {
+ return new Result<T>(null);
}
- public void setObject(T object){
+ public Result<T> set(@Nullable T object) {
this.object = object;
+ return this;
}
public T get() {
return object;
}
- public void addError(String text, Object... params){
+ public Result<T> addError(String text, Object... params) {
Message message = new Message(text, params);
errors.add(message);
+ return this;
}
- public List<Message> errors(){
+ public List<Message> errors() {
return errors;
}
- public boolean ok(){
+ public boolean ok() {
return errors.isEmpty();
}
SECTION=Navigation::SECTION_RESOURCE
before_filter :load_resource
- verify :method => :post, :only => [:save, :delete, :change_status], :redirect_to => {:action => :index}
def index
load_action_plans()
end
def save
- @action_plan = ActionPlan.find params[:plan_id] unless params[:plan_id].blank?
+ verify_post_request
+ @action_plan = ActionPlan.find params[:plan_id] if params[:plan_id].present?
unless @action_plan
@action_plan = ActionPlan.new(
:kee => Java::JavaUtil::UUID.randomUUID().toString(),
end
def delete
+ verify_post_request
action_plan = ActionPlan.find params[:plan_id]
action_plan.destroy
redirect_to :action => 'index', :id => @resource.id
end
def change_status
+ verify_post_request
action_plan = ActionPlan.find params[:plan_id]
if action_plan
action_plan.status = action_plan.open? ? ActionPlan::STATUS_CLOSED : ActionPlan::STATUS_OPEN
class Api::ActionPlansController < Api::ApiController
- before_filter :admin_required, :only => [ :create, :delete, :update, :close, :open ]
-
#
# GET /api/action_plans/search?project=<project>
#
# POST /api/action_plans/create
#
# -- Mandatory parameters
- # 'name' is the action plan name
- # 'project' is the project key to link the action plan to
+ # 'name' is the name of the action plan
+ # 'project' is the key of the project to link the action plan to
#
# -- Optional parameters
# 'description' is the plain-text description
#
def create
verify_post_request
+ access_denied unless has_role?(:admin)
require_parameters :project, :name
result = Internal.issues.createActionPlan(params)
#
def delete
verify_post_request
+ access_denied unless has_role?(:admin)
require_parameters :key
result = Internal.issues.deleteActionPlan(params[:key])
#
def update
verify_post_request
+ access_denied unless has_role?(:admin)
require_parameters :key
result = Internal.issues.updateActionPlan(params[:key], params)
#
def close
verify_post_request
+ access_denied unless has_role?(:admin)
require_parameters :key
result = Internal.issues.closeActionPlan(params[:key])
#
def open
verify_post_request
+ access_denied unless has_role?(:admin)
require_parameters :key
result = Internal.issues.openActionPlan(params[:key])