Skip to content

Commit

Permalink
Merge pull request #61 from aquality-automation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
VladislavKostyukevich authored Mar 11, 2020
2 parents 08b86ae + 9f6a114 commit b76352d
Show file tree
Hide file tree
Showing 49 changed files with 1,534 additions and 415 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.3.8 (2020-03-11)

Features:
- Update Swagger with Statistic endpoints -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/76)
- Mark import as failed when import is failed -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/79)

Bugfixes:
- 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)
- Incorrect "Duration" count if import several *.json's -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/37)

## 0.3.7 (2020-03-02)

Features:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>unifi_reporting_api</groupId>
<artifactId>api</artifactId>
<packaging>war</packaging>
<version>0.3.7</version>
<version>0.3.8</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/main/annotations/OverrideIDName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main.annotations;


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(value= ElementType.FIELD)
@Retention(value= RetentionPolicy.RUNTIME)
public @interface OverrideIDName {
}
2 changes: 1 addition & 1 deletion src/main/java/main/controllers/AuditController.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private List<AuditCommentDto> completeComments(List<AuditCommentDto> comments) t

private UserDto getUser(UserDto template) throws AqualityUserException {
try {
return userDao.getEntityById(template);
return userDao.getEntityById(template.getId());
} catch (AqualityException e) {
throw new AqualityUserException("Cannot get Author for the audit comment.");
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/main/controllers/Project/TestRunController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ public List<TestRunLabelDto> get(TestRunLabelDto template) throws AqualityExcept
}

public List<TestRunStatisticDto> get(TestRunStatisticDto template) throws AqualityException {
return testRunStatisticDao.searchAll(template);
TestRunDto testRunDto = new TestRunDto();
testRunDto.setId(template.getId());
Integer projectId = template.getId() != null
? testRunDto.getProjectIdById()
: template.getProject_id();
if (baseUser.isFromGlobalManagement() || baseUser.getProjectUser(projectId).isViewer()) {
return testRunStatisticDao.searchAll(template);
} else {
throw new AqualityPermissionsException("Account is not allowed to view Test Run Statistic", baseUser);
}
}

public TestRunDto getLastSuiteTestRun(Integer suiteId, Integer projectId) throws AqualityException {
Expand Down
113 changes: 91 additions & 22 deletions src/main/java/main/model/db/dao/DAO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main.model.db.dao;

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

/**
* Get single entity by id
* @param entity entity id
* @param id entity id
* @return entity
*/
public T getEntityById(T entity) throws AqualityException {
List<T> all = searchAll(entity);
if(all.size() > 0) {
return all.get(0);
}
else{
throw new AqualityException("No Entities was found by %s", entity.getIDParameters());
public T getEntityById(Integer id) throws AqualityException {
T entity;
try {
entity = type.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new AqualityException("Cannot Create new Instance of entity");
}

List<Pair<String, String>> parameters = entity.getIdSearchParameters(id);
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());

return getSingleResult(all, id);
}

/**
* Get single entity by id and project_id
* @param entity entity with id and project_id
* @return entity
*/
public T getEntityById(T entity) throws AqualityException {
List<Pair<String, String>> parameters = entity.getIdAndProjectIdSearchParameters();
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());

return getSingleResult(all, entity.getIdOrOverrideId());
}

/**
* Update entity
* @param entity with fields that should be updated (id is required)
* @return Updated entity
*/
public T update(T entity) throws AqualityException {
if(entity.getIDParameters().size() > 0){
return create(entity);
try {
if(entity.hasProjectId()){
getEntityById(entity);
} else {
getEntityById(entity.getIdOrOverrideId());
}
} catch (AqualityException e) {
throw new AqualityParametersException("Entity with specified '%s' id does not exist!", entity.getIdOrOverrideId());
}

List<Pair<String, String>> parameters = entity.getParameters();
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
if (!results.isEmpty()) {
return results.get(0);
}
throw new AqualityException("Cannot update entity without id!");

throw new AqualityException("Was not able to update entity!");
}

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

CallStoredProcedure(remove, parameters);
return true;
Expand All @@ -126,10 +155,22 @@ public boolean delete(T entity) throws AqualityException {
* @return created entity
*/
public T create(T entity) throws AqualityException {
List<Pair<String, String>> parameters = entity.getParameters();
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
if(results.size() > 0){
return results.get(0);
Integer id = null;
try {
id = entity.getIdOrOverrideId();
} catch (AqualityException e) {
// entity has no id
}

if(id == null){
List<Pair<String, String>> parameters = entity.getParameters();
List<T> results = dtoMapper.mapObjects(CallStoredProcedure(insert, parameters).toString());
if(!results.isEmpty()){
return results.get(0);
}
}
else {
return update(entity);
}

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

private T getSingleResult(List<T> allResults, Integer id) throws AqualityException {
if(!allResults.isEmpty()) {
return allResults.get(0);
}
else{
throw new AqualityException("No Entities was found by '%s' id", id);
}
}

private void getConnection() throws AqualityException {
InitialContext initialContext;
try {
Expand Down Expand Up @@ -220,13 +270,22 @@ private CallableStatement executeCallableStatement(String sql, List<Pair<String,
}
}

try {
callableStatement.execute();
} catch (SQLException e) {
throw new AqualitySQLException(e);
}
return tryExecute(callableStatement);
}

return callableStatement;
private CallableStatement tryExecute(CallableStatement callableStatement) throws AqualitySQLException {
int counter = 0;
SQLException lastException = null;
while(counter < 5) {
try {
callableStatement.execute();
return callableStatement;
} catch (SQLException e) {
counter++;
lastException = e;
}
}
throw new AqualitySQLException(lastException);
}

private CallableStatement getCallableStatement(String sql) throws AqualityException {
Expand Down Expand Up @@ -261,4 +320,14 @@ private String getSqlName(String storedProcedure){
}
return "";
}

private boolean areParametersEmpty(List<Pair<String, String>> parameters) {
for (Pair<String, String> pair : parameters) {
if(!pair.right.equals("")){
return false;
}
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/main/model/db/dao/audit/AuditorsDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class AuditorsDao extends DAO<AuditorDto> {
public AuditorsDao() {
super(AuditorDto.class);
select = "{call SELECT_AUDITOR(?,?)}";
select = "{call SELECT_AUDITOR(?,?,?)}";
insert = "{call INSERT_AUDITOR(?,?)}";
remove = "{call REMOVE_AUDITOR(?)}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class AppSettingsDao extends DAO<AppSettingsDto> {
public AppSettingsDao(){
super(AppSettingsDto.class);
insert = "{call INSERT_APP_SETTINGS(?,?,?,?)}";
select = "{call SELECT_APP_SETTINGS()}";
select = "{call SELECT_APP_SETTINGS(?)}";
}
}
2 changes: 1 addition & 1 deletion src/main/java/main/model/db/dao/settings/LdapDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class LdapDao extends DAO<LdapDto>{
public LdapDao() {
super(LdapDto.class);
select = "{call SELECT_LDAP_SETTING()}";
select = "{call SELECT_LDAP_SETTING(?)}";
insert = "{call INSERT_LDAP_SETTING(?,?,?,?,?,?,?,?,?,?,?,?)}";
}
}
18 changes: 6 additions & 12 deletions src/main/java/main/model/db/imports/BaseImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private void updateImportTestRun() throws AqualityException {
}

void logToImport(String log) throws AqualityException {
importDto.setProject_id(this.projectId);
importDto.addToLog(log);
importDto = importDao.create(importDto);
}
Expand All @@ -105,22 +106,15 @@ private void createTestRun() throws AqualityException {
}
}
else{
createTestRun((testRun.getBuild_name() != null && !testRun.getBuild_name().equals(""))
? testRun.getBuild_name()
: file.getName().substring(0, file.getName().lastIndexOf(".")));
setTestRunStartDate();
setTestRunFinishDate();
testRun.setTest_suite_id(testSuite.getId());
testRun.setId(controllerFactory.getHandler(testRun).create(testRun).getId());
}
updateImportTestRun();
logToImport("Test Run is updated.");
}

private void createTestRun(String buildName) throws AqualityException {
testRun.setBuild_name(buildName);
setTestRunStartDate();
setTestRunFinishDate();
testRun.setTest_suite_id(testSuite.getId());
testRun.setId(controllerFactory.getHandler(testRun).create(testRun).getId());
}

private void setTestRunStartDate(){
Comparator<TestResultDto> startDate = Comparator.comparing(TestResultDto::getStart_date);
if(testRun.getStart_time() == null){
Expand Down Expand Up @@ -229,7 +223,7 @@ private void updateResultWithSimilarError(TestResultDto result) throws AqualityE
try{
ProjectDto project = new ProjectDto();
project.setId(result.getProject_id());
project = projectDao.getEntityById(project);
project = projectDao.getEntityById(project.getId());

TestResultDto testResultTemplate = new TestResultDto();
testResultTemplate.setProject_id(result.getProject_id());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/main/model/db/imports/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

public abstract class Handler extends DefaultHandler {
protected SAXParser parser;
protected TestRunDto testRun = new TestRunDto();
public Handler() throws AqualityException {
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
Expand All @@ -33,4 +34,7 @@ public Handler() throws AqualityException {
public abstract TestRunDto getTestRun();
public abstract List<TestDto> getTests();
public abstract List<TestResultDto> getTestResults();
public void setTestRun(TestRunDto testRun){
this.testRun = testRun;
}
}
5 changes: 3 additions & 2 deletions src/main/java/main/model/db/imports/HandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import main.model.db.imports.ImportHandlers.*;

import java.io.File;
import java.util.Date;

class HandlerFactory {
Handler getHandler(File file, String type, TestNameNodeType testNameNodeType) throws AqualityException {
Handler getHandler(File file, String type, TestNameNodeType testNameNodeType, Date finishTime) throws AqualityException {
switch (ImportTypes.valueOf(type)){
case MSTest:
if(testNameNodeType == null){
Expand All @@ -23,7 +24,7 @@ Handler getHandler(File file, String type, TestNameNodeType testNameNodeType) th
return new JavaTestNG(file, testNameNodeType);
case Cucumber:
case TestNGCucumber:
return new Cucumber(file);
return new Cucumber(file, finishTime);
case PHPCodeception:
return new PHPCodeception(file);
case NUnit_v2:
Expand Down
Loading

0 comments on commit b76352d

Please sign in to comment.