Skip to content

Commit b76352d

Browse files
Merge pull request #61 from aquality-automation/develop
Develop
2 parents 08b86ae + 9f6a114 commit b76352d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1534
-415
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## 0.3.8 (2020-03-11)
4+
5+
Features:
6+
- Update Swagger with Statistic endpoints -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/76)
7+
- Mark import as failed when import is failed -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/79)
8+
9+
Bugfixes:
10+
- Import was finished with Error! You are trying to edit entity which is locked -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/44)
11+
- Incorrect "Duration" count if import several *.json's -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/37)
12+
313
## 0.3.7 (2020-03-02)
414

515
Features:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>unifi_reporting_api</groupId>
77
<artifactId>api</artifactId>
88
<packaging>war</packaging>
9-
<version>0.3.7</version>
9+
<version>0.3.8</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main.annotations;
2+
3+
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
@Target(value= ElementType.FIELD)
10+
@Retention(value= RetentionPolicy.RUNTIME)
11+
public @interface OverrideIDName {
12+
}

src/main/java/main/controllers/AuditController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private List<AuditCommentDto> completeComments(List<AuditCommentDto> comments) t
292292

293293
private UserDto getUser(UserDto template) throws AqualityUserException {
294294
try {
295-
return userDao.getEntityById(template);
295+
return userDao.getEntityById(template.getId());
296296
} catch (AqualityException e) {
297297
throw new AqualityUserException("Cannot get Author for the audit comment.");
298298
}

src/main/java/main/controllers/Project/TestRunController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ public List<TestRunLabelDto> get(TestRunLabelDto template) throws AqualityExcept
6262
}
6363

6464
public List<TestRunStatisticDto> get(TestRunStatisticDto template) throws AqualityException {
65-
return testRunStatisticDao.searchAll(template);
65+
TestRunDto testRunDto = new TestRunDto();
66+
testRunDto.setId(template.getId());
67+
Integer projectId = template.getId() != null
68+
? testRunDto.getProjectIdById()
69+
: template.getProject_id();
70+
if (baseUser.isFromGlobalManagement() || baseUser.getProjectUser(projectId).isViewer()) {
71+
return testRunStatisticDao.searchAll(template);
72+
} else {
73+
throw new AqualityPermissionsException("Account is not allowed to view Test Run Statistic", baseUser);
74+
}
6675
}
6776

6877
public TestRunDto getLastSuiteTestRun(Integer suiteId, Integer projectId) throws AqualityException {

src/main/java/main/model/db/dao/DAO.java

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main.model.db.dao;
22

33
import com.mysql.cj.core.conf.url.ConnectionUrlParser.Pair;
4+
import main.exceptions.AqualityParametersException;
45
import main.exceptions.AqualitySQLException;
56
import main.exceptions.AqualityException;
67
import main.model.db.RS_Converter;
@@ -82,30 +83,58 @@ public List<T> searchAll(T entity) throws AqualityException {
8283

8384
/**
8485
* Get single entity by id
85-
* @param entity entity id
86+
* @param id entity id
8687
* @return entity
8788
*/
88-
public T getEntityById(T entity) throws AqualityException {
89-
List<T> all = searchAll(entity);
90-
if(all.size() > 0) {
91-
return all.get(0);
92-
}
93-
else{
94-
throw new AqualityException("No Entities was found by %s", entity.getIDParameters());
89+
public T getEntityById(Integer id) throws AqualityException {
90+
T entity;
91+
try {
92+
entity = type.newInstance();
93+
} catch (InstantiationException | IllegalAccessException e) {
94+
throw new AqualityException("Cannot Create new Instance of entity");
9595
}
96+
97+
List<Pair<String, String>> parameters = entity.getIdSearchParameters(id);
98+
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());
99+
100+
return getSingleResult(all, id);
96101
}
97102

103+
/**
104+
* Get single entity by id and project_id
105+
* @param entity entity with id and project_id
106+
* @return entity
107+
*/
108+
public T getEntityById(T entity) throws AqualityException {
109+
List<Pair<String, String>> parameters = entity.getIdAndProjectIdSearchParameters();
110+
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());
111+
112+
return getSingleResult(all, entity.getIdOrOverrideId());
113+
}
98114

99115
/**
100116
* Update entity
101117
* @param entity with fields that should be updated (id is required)
102118
* @return Updated entity
103119
*/
104120
public T update(T entity) throws AqualityException {
105-
if(entity.getIDParameters().size() > 0){
106-
return create(entity);
121+
try {
122+
if(entity.hasProjectId()){
123+
getEntityById(entity);
124+
} else {
125+
getEntityById(entity.getIdOrOverrideId());
126+
}
127+
} catch (AqualityException e) {
128+
throw new AqualityParametersException("Entity with specified '%s' id does not exist!", entity.getIdOrOverrideId());
129+
}
130+
131+
List<Pair<String, String>> parameters = entity.getParameters();
132+
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
133+
if (!results.isEmpty()) {
134+
return results.get(0);
107135
}
108-
throw new AqualityException("Cannot update entity without id!");
136+
137+
throw new AqualityException("Was not able to update entity!");
109138
}
110139

111140
/**
@@ -114,7 +143,7 @@ public T update(T entity) throws AqualityException {
114143
* @return true if was able to remove entity
115144
*/
116145
public boolean delete(T entity) throws AqualityException {
117-
List<Pair<String, String>> parameters = entity.getIDParameters();
146+
List<Pair<String, String>> parameters = entity.getDataBaseIDParameters();
118147

119148
CallStoredProcedure(remove, parameters);
120149
return true;
@@ -126,10 +155,22 @@ public boolean delete(T entity) throws AqualityException {
126155
* @return created entity
127156
*/
128157
public T create(T entity) throws AqualityException {
129-
List<Pair<String, String>> parameters = entity.getParameters();
130-
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
131-
if(results.size() > 0){
132-
return results.get(0);
158+
Integer id = null;
159+
try {
160+
id = entity.getIdOrOverrideId();
161+
} catch (AqualityException e) {
162+
// entity has no id
163+
}
164+
165+
if(id == null){
166+
List<Pair<String, String>> parameters = entity.getParameters();
167+
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
168+
if(!results.isEmpty()){
169+
return results.get(0);
170+
}
171+
}
172+
else {
173+
return update(entity);
133174
}
134175

135176
throw new AqualitySQLException(new SQLException("Possible duplicate error.", "23505"));
@@ -176,6 +217,15 @@ protected JSONArray CallStoredProcedure(String sql, List<Pair<String, String>> p
176217
return json;
177218
}
178219

220+
private T getSingleResult(List<T> allResults, Integer id) throws AqualityException {
221+
if(!allResults.isEmpty()) {
222+
return allResults.get(0);
223+
}
224+
else{
225+
throw new AqualityException("No Entities was found by '%s' id", id);
226+
}
227+
}
228+
179229
private void getConnection() throws AqualityException {
180230
InitialContext initialContext;
181231
try {
@@ -220,13 +270,22 @@ private CallableStatement executeCallableStatement(String sql, List<Pair<String,
220270
}
221271
}
222272

223-
try {
224-
callableStatement.execute();
225-
} catch (SQLException e) {
226-
throw new AqualitySQLException(e);
227-
}
273+
return tryExecute(callableStatement);
274+
}
228275

229-
return callableStatement;
276+
private CallableStatement tryExecute(CallableStatement callableStatement) throws AqualitySQLException {
277+
int counter = 0;
278+
SQLException lastException = null;
279+
while(counter < 5) {
280+
try {
281+
callableStatement.execute();
282+
return callableStatement;
283+
} catch (SQLException e) {
284+
counter++;
285+
lastException = e;
286+
}
287+
}
288+
throw new AqualitySQLException(lastException);
230289
}
231290

232291
private CallableStatement getCallableStatement(String sql) throws AqualityException {
@@ -261,4 +320,14 @@ private String getSqlName(String storedProcedure){
261320
}
262321
return "";
263322
}
323+
324+
private boolean areParametersEmpty(List<Pair<String, String>> parameters) {
325+
for (Pair<String, String> pair : parameters) {
326+
if(!pair.right.equals("")){
327+
return false;
328+
}
329+
}
330+
331+
return true;
332+
}
264333
}

src/main/java/main/model/db/dao/audit/AuditorsDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class AuditorsDao extends DAO<AuditorDto> {
1212
public AuditorsDao() {
1313
super(AuditorDto.class);
14-
select = "{call SELECT_AUDITOR(?,?)}";
14+
select = "{call SELECT_AUDITOR(?,?,?)}";
1515
insert = "{call INSERT_AUDITOR(?,?)}";
1616
remove = "{call REMOVE_AUDITOR(?)}";
1717
}

src/main/java/main/model/db/dao/settings/AppSettingsDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class AppSettingsDao extends DAO<AppSettingsDto> {
88
public AppSettingsDao(){
99
super(AppSettingsDto.class);
1010
insert = "{call INSERT_APP_SETTINGS(?,?,?,?)}";
11-
select = "{call SELECT_APP_SETTINGS()}";
11+
select = "{call SELECT_APP_SETTINGS(?)}";
1212
}
1313
}

src/main/java/main/model/db/dao/settings/LdapDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class LdapDao extends DAO<LdapDto>{
77
public LdapDao() {
88
super(LdapDto.class);
9-
select = "{call SELECT_LDAP_SETTING()}";
9+
select = "{call SELECT_LDAP_SETTING(?)}";
1010
insert = "{call INSERT_LDAP_SETTING(?,?,?,?,?,?,?,?,?,?,?,?)}";
1111
}
1212
}

src/main/java/main/model/db/imports/BaseImporter.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private void updateImportTestRun() throws AqualityException {
8888
}
8989

9090
void logToImport(String log) throws AqualityException {
91+
importDto.setProject_id(this.projectId);
9192
importDto.addToLog(log);
9293
importDto = importDao.create(importDto);
9394
}
@@ -105,22 +106,15 @@ private void createTestRun() throws AqualityException {
105106
}
106107
}
107108
else{
108-
createTestRun((testRun.getBuild_name() != null && !testRun.getBuild_name().equals(""))
109-
? testRun.getBuild_name()
110-
: file.getName().substring(0, file.getName().lastIndexOf(".")));
109+
setTestRunStartDate();
110+
setTestRunFinishDate();
111+
testRun.setTest_suite_id(testSuite.getId());
112+
testRun.setId(controllerFactory.getHandler(testRun).create(testRun).getId());
111113
}
112114
updateImportTestRun();
113115
logToImport("Test Run is updated.");
114116
}
115117

116-
private void createTestRun(String buildName) throws AqualityException {
117-
testRun.setBuild_name(buildName);
118-
setTestRunStartDate();
119-
setTestRunFinishDate();
120-
testRun.setTest_suite_id(testSuite.getId());
121-
testRun.setId(controllerFactory.getHandler(testRun).create(testRun).getId());
122-
}
123-
124118
private void setTestRunStartDate(){
125119
Comparator<TestResultDto> startDate = Comparator.comparing(TestResultDto::getStart_date);
126120
if(testRun.getStart_time() == null){
@@ -229,7 +223,7 @@ private void updateResultWithSimilarError(TestResultDto result) throws AqualityE
229223
try{
230224
ProjectDto project = new ProjectDto();
231225
project.setId(result.getProject_id());
232-
project = projectDao.getEntityById(project);
226+
project = projectDao.getEntityById(project.getId());
233227

234228
TestResultDto testResultTemplate = new TestResultDto();
235229
testResultTemplate.setProject_id(result.getProject_id());

src/main/java/main/model/db/imports/Handler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
public abstract class Handler extends DefaultHandler {
1818
protected SAXParser parser;
19+
protected TestRunDto testRun = new TestRunDto();
1920
public Handler() throws AqualityException {
2021
try {
2122
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
@@ -33,4 +34,7 @@ public Handler() throws AqualityException {
3334
public abstract TestRunDto getTestRun();
3435
public abstract List<TestDto> getTests();
3536
public abstract List<TestResultDto> getTestResults();
37+
public void setTestRun(TestRunDto testRun){
38+
this.testRun = testRun;
39+
}
3640
}

src/main/java/main/model/db/imports/HandlerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import main.model.db.imports.ImportHandlers.*;
55

66
import java.io.File;
7+
import java.util.Date;
78

89
class HandlerFactory {
9-
Handler getHandler(File file, String type, TestNameNodeType testNameNodeType) throws AqualityException {
10+
Handler getHandler(File file, String type, TestNameNodeType testNameNodeType, Date finishTime) throws AqualityException {
1011
switch (ImportTypes.valueOf(type)){
1112
case MSTest:
1213
if(testNameNodeType == null){
@@ -23,7 +24,7 @@ Handler getHandler(File file, String type, TestNameNodeType testNameNodeType) th
2324
return new JavaTestNG(file, testNameNodeType);
2425
case Cucumber:
2526
case TestNGCucumber:
26-
return new Cucumber(file);
27+
return new Cucumber(file, finishTime);
2728
case PHPCodeception:
2829
return new PHPCodeception(file);
2930
case NUnit_v2:

0 commit comments

Comments
 (0)