Skip to content

Commit b702065

Browse files
committed
#12 Add an ability to choose estimation scale. Add support for the two new scales: "Classic", "T-shirt size".
1 parent 456dd1c commit b702065

28 files changed

+661
-111
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2021 Andriy Preizner
3+
*
4+
* This file is a part of Open Poker jira plugin
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.aprey.jira.plugin.openpoker;
21+
22+
import java.util.List;
23+
24+
public interface Deck {
25+
26+
List<EstimationGrade> getGrades();
27+
28+
EstimationGrade getGrade(int gradeId);
29+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2021 Andriy Preizner
3+
*
4+
* This file is a part of Open Poker jira plugin
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.aprey.jira.plugin.openpoker;
21+
22+
import java.util.Arrays;
23+
import java.util.List;
24+
import java.util.Optional;
25+
import java.util.stream.Collectors;
26+
import lombok.Getter;
27+
28+
@Getter
29+
public enum EstimationScale {
30+
CLASSIC_PLANNING("Classic", EstimationUnit.CLASSIC_PLANNING),
31+
FIBONACCI("Fibonacci", EstimationUnit.FIBONACCI),
32+
T_SHIRT_SIZE("T-shirt size", EstimationUnit.T_SHIRT_SIZE);
33+
34+
private final String name;
35+
private EstimationUnit estimationUnit;
36+
37+
EstimationScale(String name, EstimationUnit estimationUnit) {
38+
this.name = name;
39+
this.estimationUnit = estimationUnit;
40+
}
41+
42+
public static Optional<EstimationUnit> findByName(String name) {
43+
return Arrays.stream(values())
44+
.filter(e -> e.name.equals(name))
45+
.map(EstimationScale::getEstimationUnit)
46+
.findFirst();
47+
}
48+
49+
public static List<EstimationScale> getValues() {
50+
return Arrays.stream(values()).collect(Collectors.toList());
51+
}
52+
}

src/main/java/com/aprey/jira/plugin/openpoker/EstimationUnit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
package com.aprey.jira.plugin.openpoker;
2121

2222
public enum EstimationUnit {
23-
FIBONACCI
23+
FIBONACCI, CLASSIC_PLANNING, T_SHIRT_SIZE;
2424
}

src/main/java/com/aprey/jira/plugin/openpoker/IssueServiceFacade.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
3030
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
3131
import java.text.DecimalFormat;
32+
import java.util.Objects;
3233
import java.util.Optional;
3334
import javax.inject.Inject;
3435
import javax.inject.Named;
@@ -56,7 +57,7 @@ public IssueServiceFacade(CustomFieldManager customFieldManager, IssueService is
5657
this.issueManager = issueManager;
5758
}
5859

59-
public void applyEstimate(int estimate, ApplicationUser user, String issueId) {
60+
public void applyEstimate(String estimate, ApplicationUser user, String issueId) {
6061
Issue issue = issueManager.getIssueObject(issueId);
6162
Optional<CustomField> field = getField(issue);
6263
if (!field.isPresent()) {
@@ -82,9 +83,9 @@ public void applyEstimate(int estimate, ApplicationUser user, String issueId) {
8283
log.info("The issue {} has been updated with a new story point value", issueId);
8384
}
8485

85-
private IssueInputParameters buildInputParams(long fieldId, int estimate) {
86+
private IssueInputParameters buildInputParams(long fieldId, String estimate) {
8687
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
87-
issueInputParameters.addCustomFieldValue(fieldId, String.valueOf(estimate));
88+
issueInputParameters.addCustomFieldValue(fieldId, estimate);
8889
issueInputParameters.setSkipScreenCheck(true);
8990
issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true, true);
9091

@@ -104,7 +105,8 @@ public Optional<String> getStoryPoints(String issueId) {
104105
.stream()
105106
.filter(f -> f.getFieldName().equals(STORY_POINT_FILED_NAME))
106107
.map(f -> f.getValue(issue))
107-
.findFirst();
108+
.filter(Objects::nonNull)
109+
.findAny();
108110
if (!value.isPresent()) {
109111
return Optional.empty();
110112
}

src/main/java/com/aprey/jira/plugin/openpoker/PokerSession.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public class PokerSession {
3333
private final long completionDate;
3434
private final List<EstimationGrade> estimationGrades;
3535
private final List<Estimate> estimates;
36+
private final EstimationUnit estimationUnit;
3637
}

src/main/java/com/aprey/jira/plugin/openpoker/api/ActionProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ default Optional<Integer> getParam(HttpServletRequest request, String paramName)
3838
}
3939
}
4040

41+
//TODO: persistanceService should be injected to prcossors instead of passing as parameter
4142
void process(PersistenceService persistenceService, HttpServletRequest request, String issueId);
4243
}

src/main/java/com/aprey/jira/plugin/openpoker/api/ApplyVoteProcessor.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package com.aprey.jira.plugin.openpoker.api;
2121

22-
import com.aprey.jira.plugin.openpoker.IssueServiceFacade;
2322
import com.aprey.jira.plugin.openpoker.persistence.PersistenceService;
2423
import com.atlassian.jira.user.ApplicationUser;
2524
import com.atlassian.jira.user.util.UserManager;
@@ -35,31 +34,28 @@
3534
@Scanned
3635
@Slf4j
3736
public class ApplyVoteProcessor implements ActionProcessor {
38-
private static final String ESTIMATE_FILED = "resultingEstimate";
37+
38+
private static final String ESTIMATE_FILED = "finalEstimateId";
3939
private static final String USER_ID_FIELD = "userId";
4040

4141
@ComponentImport
4242
private final UserManager userManager;
43-
private final IssueServiceFacade issueServiceFacade;
4443

4544
@Inject
46-
public ApplyVoteProcessor(UserManager userManager,
47-
IssueServiceFacade issueServiceFacade) {
45+
public ApplyVoteProcessor(UserManager userManager) {
4846
this.userManager = userManager;
49-
this.issueServiceFacade = issueServiceFacade;
5047
}
5148

5249
@Override
5350
public void process(PersistenceService persistenceService, HttpServletRequest request, String issueId) {
5451
final long userId = Long.parseLong(request.getParameter(USER_ID_FIELD));
55-
final int estimate = Integer.parseInt(request.getParameter(ESTIMATE_FILED));
52+
final int estimateId = Integer.parseInt(request.getParameter(ESTIMATE_FILED));
5653
Optional<ApplicationUser> applicationUser = userManager.getUserById(userId);
5754
if (!applicationUser.isPresent()) {
5855
log.error("Application user is not found by {} id", userId);
5956
return;
6057
}
6158

62-
issueServiceFacade.applyEstimate(estimate, applicationUser.get(), issueId);
63-
persistenceService.deleteSessions(issueId);
59+
persistenceService.applyFinalEstimate(issueId, estimateId, applicationUser.get());
6460
}
6561
}

src/main/java/com/aprey/jira/plugin/openpoker/api/EstimationViewDTO.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
@Builder
3434
public class EstimationViewDTO {
3535
private final List<EstimateDTO> estimates;
36-
private final List<EstimationGrade> gradesToChoose;
37-
private final List<EstimationGrade> gradesToApply;
36+
private final List<EstimationGrade> estimationGrades;
3837
private final boolean alreadyVoted;
3938
private final boolean applicableGrades;
4039

src/main/java/com/aprey/jira/plugin/openpoker/api/PlanningPokerWebPanelProvider.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
package com.aprey.jira.plugin.openpoker.api;
2121

2222
import com.aprey.jira.plugin.openpoker.Estimate;
23-
import com.aprey.jira.plugin.openpoker.EstimationGrade;
24-
import com.aprey.jira.plugin.openpoker.IssueServiceFacade;
23+
import com.aprey.jira.plugin.openpoker.EstimationScale;
2524
import com.aprey.jira.plugin.openpoker.PokerSession;
2625
import com.aprey.jira.plugin.openpoker.persistence.PersistenceService;
2726
import com.atlassian.jira.issue.Issue;
@@ -47,14 +46,12 @@ public class PlanningPokerWebPanelProvider extends AbstractJiraContextProvider {
4746

4847
private final PersistenceService sessionService;
4948
private final UserConverter userConverter;
50-
private final IssueServiceFacade issueServiceFacade;
5149

5250
@Inject
5351
public PlanningPokerWebPanelProvider(PersistenceService sessionService,
54-
UserConverter userConverter, IssueServiceFacade issueServiceFacade) {
52+
UserConverter userConverter) {
5553
this.sessionService = sessionService;
5654
this.userConverter = userConverter;
57-
this.issueServiceFacade = issueServiceFacade;
5855
}
5956

6057
@Override
@@ -66,7 +63,8 @@ public Map<String, Object> getContextMap(ApplicationUser applicationUser, JiraHe
6663
contextMap.put("contextPath", jiraHelper.getRequest().getContextPath());
6764
contextMap.put("issueId", issueId);
6865
contextMap.put("userId", applicationUser.getId());
69-
issueServiceFacade.getStoryPoints(issueId).ifPresent(v -> contextMap.put("currentEstimate", v));
66+
contextMap.put("estimationUnits", EstimationScale.getValues());
67+
sessionService.getFinaleEstimate(issueId).ifPresent(v -> contextMap.put("currentEstimate", v));
7068
return contextMap;
7169
}
7270

@@ -93,11 +91,8 @@ private EstimationViewDTO buildEstimationView(PokerSession session, ApplicationU
9391

9492
return EstimationViewDTO.builder()
9593
.alreadyVoted(alreadyVoted)
96-
.gradesToChoose(session.getEstimationGrades())
94+
.estimationGrades(session.getEstimationGrades())
9795
.estimates(estimates)
98-
.gradesToApply(session.getEstimationGrades().stream()
99-
.filter(EstimationGrade::isApplicable)
100-
.collect(Collectors.toList()))
10196
.build();
10297
}
10398

src/main/java/com/aprey/jira/plugin/openpoker/api/StartSessionProcessor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.aprey.jira.plugin.openpoker.api;
2121

22+
import com.aprey.jira.plugin.openpoker.EstimationScale;
23+
import com.aprey.jira.plugin.openpoker.EstimationUnit;
2224
import com.aprey.jira.plugin.openpoker.persistence.PersistenceService;
2325
import javax.servlet.http.HttpServletRequest;
2426

@@ -27,7 +29,10 @@ public class StartSessionProcessor implements ActionProcessor {
2729
@Override
2830
public void process(PersistenceService persistenceService, HttpServletRequest request, String issueId) {
2931
final long userId = Long.parseLong(request.getParameter("userId"));
32+
final String estimationScale = request.getParameter("estimationScale");
33+
EstimationUnit estimationUnit = EstimationScale.findByName(estimationScale)
34+
.orElse(EstimationUnit.CLASSIC_PLANNING);
3035

31-
persistenceService.startSession(issueId, userId);
36+
persistenceService.startSession(issueId, userId, estimationUnit);
3237
}
3338
}

0 commit comments

Comments
 (0)