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,15 @@ 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
+ @ Override
52
+ public List <TestDto > get (TestDto template ) throws AqualityException {
49
53
if (baseUser .isFromGlobalManagement () || baseUser .getProjectUserByTest (template ).isViewer ()){
50
- return fillTests (testDao .searchAll (template ), withChildren );
54
+ return fillTests (testDao .searchAll (template ));
51
55
}else {
52
56
throw new AqualityPermissionsException ("Account is not allowed to view Tests" , baseUser );
53
57
}
54
58
}
55
59
56
- @ Override
57
- public List <TestDto > get (TestDto template ) throws AqualityException {
58
- return get (template , false );
59
- }
60
-
61
60
@ Override
62
61
public boolean delete (TestDto template ) throws AqualityException {
63
62
if (baseUser .isManager () || baseUser .getProjectUser (template .getProject_id ()).isEditor ()){
@@ -93,13 +92,16 @@ private TestDto getTestForMovement(int id, int projectId) throws AqualityExcepti
93
92
TestDto test = new TestDto ();
94
93
test .setId (id );
95
94
test .setProject_id (projectId );
96
-
97
- return get (test , true ).get (0 );
95
+ test = get (test ).get (0 );
96
+ TestResultDto resultSearchTemplate = new TestResultDto ();
97
+ resultSearchTemplate .setTest_id (test .getId ());
98
+ test .setResults (resultDao .searchAll (resultSearchTemplate ));
99
+ return test ;
98
100
}
99
101
100
102
private void executeResultsMovement (List <TestResultDto > resultsToMove ) throws AqualityException {
101
103
for (TestResultDto result : resultsToMove ) {
102
- resultController .create (result );
104
+ resultDao .create (result );
103
105
}
104
106
}
105
107
@@ -118,7 +120,7 @@ protected List<TestResultDto> getResultsToMove (TestDto from, TestDto to){
118
120
}
119
121
120
122
//TODO Refactoring
121
- private List <TestDto > fillTests (List <TestDto > tests , boolean withChildren ) throws AqualityException {
123
+ private List <TestDto > fillTests (List <TestDto > tests ) throws AqualityException {
122
124
List <TestDto > filledTests = new ArrayList <>();
123
125
if (tests .size () > 0 ) {
124
126
ProjectUserDto projectUserDto = new ProjectUserDto ();
@@ -128,6 +130,10 @@ private List<TestDto> fillTests(List<TestDto> tests, boolean withChildren) throw
128
130
testSuiteDto .setProject_id (tests .get (0 ).getProject_id ());
129
131
List <TestSuiteDto > testSuites = suiteDao .searchAll (testSuiteDto );
130
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
+
131
137
for (TestSuiteDto testSuite : testSuites ){
132
138
Test2SuiteDto test2Suite = new Test2SuiteDto ();
133
139
test2Suite .setSuite_id (testSuite .getId ());
@@ -140,16 +146,12 @@ private List<TestDto> fillTests(List<TestDto> tests, boolean withChildren) throw
140
146
test .setDeveloper (projectUsers .stream ().filter (x -> x .getUser ().getId ().equals (test .getDeveloper_id ())).findFirst ().orElse (null ));
141
147
}
142
148
149
+ if (projectDto .getStability_count () != null ) {
150
+ test .setLastResultColors (testDao .getLastColors (test .getId (), projectDto .getStability_count ()));
151
+ }
152
+
143
153
List <Test2SuiteDto > testSuiteLinks = test2Suites .stream ().filter (x -> x .getTest_id ().equals (test .getId ())).collect (Collectors .toList ());
144
154
test .setSuites (test2SuiteController .convertToSuites (testSuiteLinks , testSuites ));
145
-
146
- if (withChildren ) {
147
- TestResultDto testResultTemplate = new TestResultDto ();
148
- testResultTemplate .setTest_id (test .getId ());
149
- testResultTemplate .setProject_id (test .getProject_id ());
150
- testResultTemplate .setLimit (0 );
151
- test .setResults (resultController .get (testResultTemplate ));
152
- }
153
155
filledTests .add (test );
154
156
}
155
157
}
0 commit comments