Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.thucydides.plugins.jira.requirements;
  
 
 import java.util.List;
 
 public class IssueTagReader {
 
     private final org.slf4j.Logger logger = LoggerFactory.getLogger(IssueTagReader.class);
 
     private final List<RequirementflattenedRequirements;
     private final JerseyJiraClient jiraClient;
     private final String projectKey;
     private List<TestTagtags = Lists.newArrayList();
 
     public IssueTagReader(JerseyJiraClient jiraClientList<RequirementflattenedRequirementsString projectKey) {
         this. = flattenedRequirements;
         this. = jiraClient;
         this. = projectKey;
     }
 
     public IssueTagReader addVersionTags(String issueKey) {
         String decodedIssueKey = decoded(issueKey);
         try {
             Optional<IssueSummaryissue = .findByKey(issueKey);
             if (issue.isPresent()) {
                 addVersionTags(issue.get().getFixVersions());
             }
         } catch (JSONException e) {
             .warn("Could not read versions for issue " + decodedIssueKeye);
         }
         return this;
     }
 
     private void addVersionTags(List<Stringversions) {
         for(String version : versions) {
             TestTag versionTag = TestTag.withName(version).andType("Version");
             .add(versionTag);
         }
     }
 
     public IssueTagReader addRequirementTags(String issueKey) {
         String decodedIssueKey = decoded(issueKey);
         List<RequirementparentRequirements = getAssociatedRequirementsOf(decodedIssueKey);// getParentRequirementsOf(decodedIssueKey);
         for (Requirement parentRequirement : parentRequirements) {
             .add(parentRequirement.asTag());
         }
         return this;
     }
 
     public IssueTagReader addIssueTags(String issueKey) {
         String decodedIssueKey = decoded(issueKey);
         Optional<IssueSummarybehaviourIssue = Optional.absent();
         try {
             behaviourIssue = .findByKey(decodedIssueKey);
         } catch (JSONException e) {
             .warn("Could not read tags for issue " + decodedIssueKeye);
         }
         if (behaviourIssue.isPresent()) {
             .add(TestTag.withName(behaviourIssue.get().getSummary()).andType(behaviourIssue.get().getType()));
         }
         return this;
     }
 
     public List<TestTaggetTags() {
         return ImmutableList.copyOf();
     }
 
     private List<RequirementgetAssociatedRequirementsOf(String issueKey) {
         for (Requirement requirement : ) {
             if (requirement.getCardNumber().equalsIgnoreCase(issueKey)) {
                 List<RequirementassociatedRequirements = Lists.newArrayList(requirement);
                 associatedRequirements.addAll(getParentRequirementsOf(issueKey));
                 return ImmutableList.copyOf(associatedRequirements);
             }
         }
         return ImmutableList.of();
     }
 
     private List<RequirementgetParentRequirementsOf(String issueKey) {
         List<RequirementparentRequirements = Lists.newArrayList();
 
         Optional<RequirementparentRequirement = getParentRequirementOf(issueKey);
         if (parentRequirement.isPresent()) {
             parentRequirements.add(parentRequirement.get());
             parentRequirements.addAll(getParentRequirementsOf(parentRequirement.get().getCardNumber()));
         }
 
         return parentRequirements;
     }
        for (Requirement requirement : ) {
            if (containsRequirementWithId(keyrequirement.getChildren())) {
                return Optional.of(requirement);
            }
        }
        return Optional.absent();
    }
    private boolean containsRequirementWithId(String keyList<Requirementrequirements) {
        for (Requirement requirement : requirements) {
            if (requirement.getCardNumber().equals(key)) {
                return true;
            }
        }
        return false;
    }
    private String decoded(String issueKey) {
        if (issueKey.startsWith("#")) {
            issueKey = issueKey.substring(1);
        }
        if (StringUtils.isNumeric(issueKey)) {
            issueKey =  + "-" + issueKey;
        }
        return issueKey;
    }
New to GrepCode? Check out our FAQ X