view ssdt-jira-plugins-v2/plugins/src/main/java/org/nwoca/ssdt/jira/RequireEstimateValidator.java @ 3:e90b3c5c8df3 tip

Improve validator if work has already been logged.
author smith
date Fri, 20 Jun 2008 12:23:06 -0400
parents 56349dc044f5
children
line wrap: on
line source
/*
 * RequireDocumentIssueValidator.java
 *
 * Created on May 14, 2007, 1:04 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package org.nwoca.ssdt.jira;

import com.atlassian.jira.issue.Issue;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.InvalidInputException;
import com.opensymphony.workflow.Validator;
import com.opensymphony.workflow.WorkflowException;
import java.util.Map;

/**
 * Validator blocks Fixed resolution. Use for Workflow steps where "fixed" is
 *not appropriate.
 *
 * @author SMITH
 */
public class RequireEstimateValidator implements Validator {

    /**
     * Creates a new instance of RequireDocumentIssueValidator.
     */
    public RequireEstimateValidator() {
    }

    public void validate(Map transientVars, Map args, PropertySet ps)
            throws InvalidInputException, WorkflowException {

        Issue issue = (Issue) transientVars.get("issue");

        if (isZero(issue.getTimeSpent())) {
            if (isZero(issue.getOriginalEstimate())) {
                throw new InvalidInputException("Original Estimate is required at this step");
            }
        } else if (isZero(issue.getEstimate())) {
            throw new InvalidInputException("Remaining Estimate is required at this step");

        }
    }

    private boolean isZero(Long value) {
        return value == null || value.longValue() == 0;
    }
}