Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit ae06604

Browse files
authored
RT-2260 Created OutcomeObject class (#458)
* Created OutcomeObject class * Changed capitalization of severity enum values and removed fatal
1 parent 78a0fbc commit ae06604

6 files changed

Lines changed: 220 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ target/
88
.recommenders
99
.idea/
1010
.factorypath
11+
generic-model/.vscode/settings.json

generic-model/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<version>0.0.9-SNAPSHOT</version>
2424
</parent>
2525
<artifactId>generic-model</artifactId>
26+
<version>0.1.0</version>
2627
<name>Base model for the Generic services</name>
2728
<description>Representation of ServiceRequest and ServiceResponse</description>
29+
<dependencies>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
2836
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.elimu.a2d2.genericmodel;
2+
3+
public class Issue implements java.io.Serializable{
4+
5+
private static final long serialVersionUID = 1L;
6+
7+
public enum IssueSeverity {
8+
INFORMATION,
9+
WARNING,
10+
ERROR
11+
}
12+
13+
public enum IssueType {
14+
INVALID_VALUE,
15+
INVALID_STRUCTURE,
16+
MISSING_ITEM,
17+
SECURITY_EXPIRED,
18+
SECURITY_FORBIDDEN,
19+
PROCESSING_NOT_SUPPORTED,
20+
PROCESSING_DUPLICATE,
21+
PROCESSING_MULTIPLE_MATCHES,
22+
PROCESSING_NOT_FOUND,
23+
PROCESSING_BUSINESS_RULE_VIOLATION,
24+
TRANSIENT_TIMEOUT,
25+
TRANSIENT_EXCEPTION,
26+
INFORMATIONAL
27+
}
28+
private IssueType code;
29+
30+
31+
private IssueSeverity severity;
32+
private String diagnostics;
33+
34+
35+
public Issue() {
36+
}
37+
38+
public IssueSeverity getSeverity() {
39+
return severity;
40+
}
41+
42+
public void setSeverity(IssueSeverity severity) {
43+
this.severity = severity;
44+
}
45+
46+
public IssueType getCode() {
47+
return code;
48+
}
49+
50+
public void setCode(IssueType code) {
51+
this.code = code;
52+
}
53+
54+
public String getDiagnostics() {
55+
return diagnostics;
56+
}
57+
58+
public void setDiagnostics(String diagnostics) {
59+
this.diagnostics = diagnostics;
60+
}
61+
62+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.elimu.a2d2.genericmodel;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
public class OutcomeObject implements java.io.Serializable {
6+
7+
private static final long serialVersionUID = 1L;
8+
9+
private List<Issue> issues;
10+
11+
private void init() {
12+
if (issues == null) {
13+
issues = new ArrayList<>();
14+
}
15+
}
16+
17+
public OutcomeObject() {
18+
init();
19+
}
20+
21+
public List<Issue> getIssues() {
22+
return issues;
23+
}
24+
25+
public void setIssues(List<Issue> issues) {
26+
this.issues = issues;
27+
}
28+
29+
public void addIssue(Issue issue) {
30+
this.issues.add(issue);
31+
}
32+
33+
public void removeIssue(Issue issue) {
34+
this.issues.remove(issue);
35+
}
36+
37+
public void clearIssues() {
38+
this.issues.clear();
39+
}
40+
41+
public boolean hasErrors() {
42+
if (issues == null) {
43+
return false;
44+
}
45+
for (Issue issue : issues) {
46+
if (issue != null && Issue.IssueSeverity.ERROR.equals(issue.getSeverity())) {
47+
return true;
48+
}
49+
}
50+
return false;
51+
}
52+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.elimu.a2d2.genericmodel;
2+
3+
4+
import org.junit.Test;
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class IssueTest {
8+
9+
@Test
10+
public void testSeverityGetterSetter() {
11+
Issue issue = new Issue();
12+
issue.setSeverity(Issue.IssueSeverity.ERROR);
13+
assertEquals(Issue.IssueSeverity.ERROR, issue.getSeverity());
14+
}
15+
16+
@Test
17+
public void testCodeGetterSetter() {
18+
Issue issue = new Issue();
19+
issue.setCode(Issue.IssueType.INVALID_VALUE);
20+
assertEquals(Issue.IssueType.INVALID_VALUE, issue.getCode());
21+
}
22+
23+
@Test
24+
public void testDiagnosticsGetterSetter() {
25+
Issue issue = new Issue();
26+
issue.setDiagnostics("Some diagnostics");
27+
assertEquals("Some diagnostics", issue.getDiagnostics());
28+
}
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.elimu.a2d2.genericmodel;
2+
3+
import java.util.Arrays;
4+
import org.junit.Test;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.junit.Assert.assertFalse;
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class OutcomeObjectTest {
10+
11+
@Test
12+
public void testAddAndGetIssues() {
13+
OutcomeObject outcome = new OutcomeObject();
14+
Issue issue = new Issue();
15+
issue.setSeverity(Issue.IssueSeverity.WARNING);
16+
outcome.addIssue(issue);
17+
assertEquals(1, outcome.getIssues().size());
18+
assertEquals(Issue.IssueSeverity.WARNING, outcome.getIssues().get(0).getSeverity());
19+
}
20+
21+
@Test
22+
public void testSetIssues() {
23+
OutcomeObject outcome = new OutcomeObject();
24+
Issue issue1 = new Issue();
25+
issue1.setSeverity(Issue.IssueSeverity.INFORMATION);
26+
Issue issue2 = new Issue();
27+
issue2.setSeverity(Issue.IssueSeverity.ERROR);
28+
outcome.setIssues(Arrays.asList(issue1, issue2));
29+
assertEquals(2, outcome.getIssues().size());
30+
}
31+
32+
@Test
33+
public void testRemoveIssue() {
34+
OutcomeObject outcome = new OutcomeObject();
35+
Issue issue = new Issue();
36+
outcome.addIssue(issue);
37+
outcome.removeIssue(issue);
38+
assertTrue(outcome.getIssues().isEmpty());
39+
}
40+
41+
@Test
42+
public void testClearIssues() {
43+
OutcomeObject outcome = new OutcomeObject();
44+
outcome.addIssue(new Issue());
45+
outcome.clearIssues();
46+
assertTrue(outcome.getIssues().isEmpty());
47+
}
48+
49+
@Test
50+
public void testHasErrors() {
51+
OutcomeObject outcome = new OutcomeObject();
52+
Issue info = new Issue();
53+
info.setSeverity(Issue.IssueSeverity.INFORMATION);
54+
Issue error = new Issue();
55+
error.setSeverity(Issue.IssueSeverity.ERROR);
56+
outcome.addIssue(info);
57+
assertFalse(outcome.hasErrors());
58+
outcome.addIssue(error);
59+
assertTrue(outcome.hasErrors());
60+
}
61+
62+
@Test
63+
public void testHasErrorsWithNullIssues() {
64+
OutcomeObject outcome = new OutcomeObject();
65+
outcome.setIssues(null);
66+
assertFalse(outcome.hasErrors());
67+
}
68+
}

0 commit comments

Comments
 (0)