13
13
14
14
public class TestController extends BaseController <TestDto > {
15
15
private TestDao testDao ;
16
+ private ProjectDao projectDao ;
16
17
private TestSuiteDao suiteDao ;
17
- private ResultController resultController ;
18
+ private TestResultDao resultDao ;
18
19
private Test2SuiteController test2SuiteController ;
19
20
private ProjectUserController projectUserController ;
20
21
21
22
public TestController (UserDto user ) {
22
23
super (user );
24
+
23
25
testDao = new TestDao ();
24
26
suiteDao = new TestSuiteDao ();
25
- resultController = new ResultController (user );
27
+ projectDao = new ProjectDao ();
28
+ resultDao = new TestResultDao ();
26
29
test2SuiteController = new Test2SuiteController (user );
27
30
projectUserController = new ProjectUserController (user );
28
31
}
@@ -45,19 +48,14 @@ public TestDto create(TestDto template) throws AqualityException {
45
48
return create (template , false );
46
49
}
47
50
48
- public List <TestDto > get (TestDto template , boolean withChildren ) throws AqualityException {
51
+ public List <TestDto > get (TestDto template ) throws AqualityException {
49
52
if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (template .getProject_id ()).isViewer ()) {
50
- return fillTests (testDao .searchAll (template ), withChildren );
53
+ return fillTests (testDao .searchAll (template ));
51
54
} else {
52
55
throw new AqualityPermissionsException ("Account is not allowed to view Tests" , baseUser );
53
56
}
54
57
}
55
58
56
- @ Override
57
- public List <TestDto > get (TestDto template ) throws AqualityException {
58
- return get (template , false );
59
- }
60
-
61
59
@ Override
62
60
public boolean delete (TestDto template ) throws AqualityException {
63
61
if (baseUser .isManager () || baseUser .getProjectUser (template .getProject_id ()).isEditor ()) {
@@ -93,13 +91,16 @@ private TestDto getTestForMovement(int id, int projectId) throws AqualityExcepti
93
91
TestDto test = new TestDto ();
94
92
test .setId (id );
95
93
test .setProject_id (projectId );
96
-
97
- return get (test , true ).get (0 );
94
+ test = get (test ).get (0 );
95
+ TestResultDto resultSearchTemplate = new TestResultDto ();
96
+ resultSearchTemplate .setTest_id (test .getId ());
97
+ test .setResults (resultDao .searchAll (resultSearchTemplate ));
98
+ return test ;
98
99
}
99
100
100
101
private void executeResultsMovement (List <TestResultDto > resultsToMove ) throws AqualityException {
101
102
for (TestResultDto result : resultsToMove ) {
102
- resultController .create (result );
103
+ resultDao .create (result );
103
104
}
104
105
}
105
106
@@ -118,7 +119,7 @@ protected List<TestResultDto> getResultsToMove(TestDto from, TestDto to) {
118
119
}
119
120
120
121
//TODO Refactoring
121
- private List <TestDto > fillTests (List <TestDto > tests , boolean withChildren ) throws AqualityException {
122
+ private List <TestDto > fillTests (List <TestDto > tests ) throws AqualityException {
122
123
List <TestDto > filledTests = new ArrayList <>();
123
124
if (tests .size () > 0 ) {
124
125
Integer projectId = tests .get (0 ).getProject_id ();
@@ -129,6 +130,10 @@ private List<TestDto> fillTests(List<TestDto> tests, boolean withChildren) throw
129
130
testSuiteDto .setProject_id (projectId );
130
131
List <TestSuiteDto > testSuites = suiteDao .searchAll (testSuiteDto );
131
132
List <Test2SuiteDto > test2Suites = new ArrayList <>();
133
+ ProjectDto projectDto = new ProjectDto ();
134
+ projectDto .setId (tests .get (0 ).getProject_id ());
135
+ projectDto = projectDao .getEntityById (projectDto );
136
+
132
137
for (TestSuiteDto testSuite : testSuites ) {
133
138
Test2SuiteDto test2Suite = new Test2SuiteDto ();
134
139
test2Suite .setSuite_id (testSuite .getId ());
@@ -141,16 +146,12 @@ private List<TestDto> fillTests(List<TestDto> tests, boolean withChildren) throw
141
146
test .setDeveloper (projectUsers .stream ().filter (x -> x .getUser ().getId ().equals (test .getDeveloper_id ())).findFirst ().orElse (null ));
142
147
}
143
148
149
+ if (projectDto .getStability_count () != null ) {
150
+ test .setLastResultColors (testDao .getLastColors (test .getId (), projectDto .getStability_count ()));
151
+ }
152
+
144
153
List <Test2SuiteDto > testSuiteLinks = test2Suites .stream ().filter (x -> x .getTest_id ().equals (test .getId ())).collect (Collectors .toList ());
145
154
test .setSuites (test2SuiteController .convertToSuites (testSuiteLinks , testSuites ));
146
-
147
- if (withChildren ) {
148
- TestResultDto testResultTemplate = new TestResultDto ();
149
- testResultTemplate .setTest_id (test .getId ());
150
- testResultTemplate .setProject_id (test .getProject_id ());
151
- testResultTemplate .setLimit (0 );
152
- test .setResults (resultController .get (testResultTemplate ));
153
- }
154
155
filledTests .add (test );
155
156
}
156
157
}
0 commit comments