Skip to content

Commit cbdba6d

Browse files
DmitryBogatkod.bogatko
andauthored
Added feature to integrate aq entities with 3rd party systems (#83)
* added different reference types * added DataBaseRequired annotation. Allows to mark some fields as required and they will always be sent (for UPDATE especially). refactored method getIdAndProjectIdSearchParameters * created common class ProjectEntityController to be base for most of the Controllers related to the project as result, SystemController and ReferenceController were refactored added Roles policies and implemented RoleValidator class to check roles added Procedure to remove references ReferenceType was extended by adding a method that creates empty DTO ReferenceServlet has been extended by the support of get and delete methods * added URL to the table with a list of systems * generified controllers to use the same for different servlets added ControlType class to manage a list of supported controllers extended ProjectEntityController by the new logic of processing permissions and by new additional methods (createTable, deleteInProject) ReadonlyController has been unified to use Generics added TestTrackingTypes and TestTrackingStatus tables added REMOVE_INT_SYSTEMS procedure DAO extended by new projects added new interface IEntity added 3 servlets that provide necessary methods for almost any concrete servlet * changed the structure of the DB by replacing the int_system_statuses table. useless classes and methods were removed. added new tables for storing system workflow statuses * added publishing controller and related classes * added triggers on deleting tests, test_runs, issues * updated trigger on removing resolution refactored TtsType and SystemType to re-use common logic * get changed to post in RefStatusServlet as we are going to consume data in this method added support of options method to be able to support CORS policies * fixed and removed todos * CORS policies reverted in BaseServlet updated version and changelog Co-authored-by: d.bogatko <[email protected]>
1 parent 7b9a75c commit cbdba6d

File tree

99 files changed

+5884
-128
lines changed

Some content is hidden

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

99 files changed

+5884
-128
lines changed

CHANGELOG.md

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

3+
## 1.3.0 (2021-02-26)
4+
- Added feature that allows to link aquality entities (tests, issues and test runs) with 3rd party systems like Jira, Xray, TestRail and etc.
5+
In this version only Jira and Xray support has been added.
6+
- Improved and generified work with controllers
7+
38
## 1.1.1 (2020-12-15)
49
Bugfixes:
510
- Added handling of non utf-8 body in the request

pom.xml

Lines changed: 23 additions & 15 deletions
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>1.1.1</version>
9+
<version>1.3.0</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -93,20 +93,21 @@
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>
9595
<artifactId>maven-war-plugin</artifactId>
96-
<version>3.2.0</version><configuration>
97-
<webResources>
98-
<resource>
99-
<filtering>true</filtering>
100-
<directory>src/main/webapp</directory>
101-
<includes>
102-
<include>**/META-INF/context.xml</include>
103-
</includes>
104-
</resource>
105-
</webResources>
106-
<warSourceDirectory>src/main/webapp</warSourceDirectory>
107-
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
108-
<warName>api</warName>
109-
</configuration>
96+
<version>3.2.0</version>
97+
<configuration>
98+
<webResources>
99+
<resource>
100+
<filtering>true</filtering>
101+
<directory>src/main/webapp</directory>
102+
<includes>
103+
<include>**/META-INF/context.xml</include>
104+
</includes>
105+
</resource>
106+
</webResources>
107+
<warSourceDirectory>src/main/webapp</warSourceDirectory>
108+
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
109+
<warName>api</warName>
110+
</configuration>
110111
</plugin>
111112
</plugins>
112113
</build>
@@ -215,5 +216,12 @@
215216
<artifactId>javax.ws.rs-api</artifactId>
216217
<version>2.0</version>
217218
</dependency>
219+
220+
<!-- JIRA client -->
221+
<dependency>
222+
<groupId>org.apache.httpcomponents</groupId>
223+
<artifactId>httpclient</artifactId>
224+
<version>4.5.8</version>
225+
</dependency>
218226
</dependencies>
219227
</project>
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 DataBaseRequired {
12+
}

src/main/java/main/controllers/ControllerFactory.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,113 @@
44
import main.controllers.Administration.StepTypeController;
55
import main.controllers.Administration.UserController;
66
import main.controllers.Project.*;
7+
import main.model.db.dao.DAO;
8+
import main.model.dto.BaseDto;
9+
import main.model.dto.interfaces.IProjectEntity;
710
import main.model.dto.project.*;
811
import main.model.dto.settings.EmailSettingsDto;
912
import main.model.dto.settings.UserDto;
1013

1114
public class ControllerFactory {
1215
private UserDto user;
1316

14-
public ControllerFactory(UserDto user){
17+
public ControllerFactory(UserDto user) {
1518
this.user = user;
1619
}
1720

1821
public ProjectController getHandler(ProjectDto entity) {
1922
return new ProjectController(user);
2023
}
24+
2125
public BodyPatternController getHandler(BodyPatternDto entity) {
2226
return new BodyPatternController(user);
2327
}
28+
2429
public FinalResultController getHandler(FinalResultDto entity) {
2530
return new FinalResultController(user);
2631
}
32+
2733
public ImportController getHandler(ImportDto entity) {
2834
return new ImportController(user);
2935
}
36+
3037
public APITokenController getHandler(APITokenDto entity) {
3138
return new APITokenController(user);
3239
}
40+
3341
public MilestoneController getHandler(MilestoneDto entity) {
3442
return new MilestoneController(user);
3543
}
44+
3645
public ProjectUserController getHandler(ProjectUserDto entity) {
3746
return new ProjectUserController(user);
3847
}
48+
3949
public ResultController getHandler(TestResultDto entity) {
4050
return new ResultController(user);
4151
}
52+
4253
public ResultResolutionController getHandler(ResultResolutionDto entity) {
4354
return new ResultResolutionController(user);
4455
}
56+
4557
public SuiteController getHandler(TestSuiteDto entity) {
4658
return new SuiteController(user);
4759
}
60+
4861
public SuiteDashboardController getHandler(SuiteDashboardDto entity) {
4962
return new SuiteDashboardController(user);
5063
}
64+
5165
public Test2SuiteController getHandler(Test2SuiteDto entity) {
5266
return new Test2SuiteController(user);
5367
}
68+
5469
public TestController getHandler(TestDto entity) {
5570
return new TestController(user);
5671
}
72+
5773
public TestRunController getHandler(TestRunDto entity) {
5874
return new TestRunController(user);
5975
}
76+
6077
public UserController getHandler(UserDto entity) {
6178
return new UserController(user);
6279
}
80+
6381
public EmailSettingsController getHandler(EmailSettingsDto entity) {
6482
return new EmailSettingsController(user);
6583
}
84+
6685
public StepController getHandler(StepDto entity) {
6786
return new StepController(user);
6887
}
88+
6989
public StepResultController getHandler(StepResultDto entity) {
7090
return new StepResultController(user);
7191
}
92+
7293
public StepTypeController getHandler(StepTypeDto entity) {
7394
return new StepTypeController(user);
7495
}
96+
7597
public PredefinedResolutionController getHandler(PredefinedResolutionDto entity) {
7698
return new PredefinedResolutionController(user);
7799
}
100+
78101
public IssueController getHandler(IssueDto entity) {
79102
return new IssueController(user);
80103
}
104+
81105
public TestResultAttachmentController getHandler(TestResultAttachmentDto entity) {
82106
return new TestResultAttachmentController(user);
83107
}
84-
}
108+
109+
public <T extends BaseDto & IProjectEntity, D extends DAO<T>> ProjectEntityController<T, D> getProjectEntityHandler(ControllerType<T, D> controllerType) {
110+
return new ProjectEntityController<>(user, controllerType.createDao());
111+
}
112+
113+
public <T extends BaseDto, D extends DAO<T>> ReadonlyController<T, D> getReadonlyHandler(ControllerType<T, D> controllerType) {
114+
return new ReadonlyController<>(user, controllerType.createDao());
115+
}
116+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main.controllers;
2+
3+
import main.model.db.dao.DAO;
4+
import main.model.db.dao.integrations.ReferenceDao;
5+
import main.model.db.dao.integrations.PubItemDao;
6+
import main.model.db.dao.integrations.systems.SystemDao;
7+
import main.model.db.dao.integrations.systems.SystemTypeDao;
8+
import main.model.db.dao.integrations.systems.workflow.SystemWorkflowStatusDao;
9+
import main.model.db.dao.integrations.systems.workflow.SystemWorkflowStatusTypeDao;
10+
import main.model.db.dao.integrations.tts.TestTrackingStatusDao;
11+
import main.model.db.dao.integrations.tts.TestTrackingTypeDao;
12+
import main.model.dto.BaseDto;
13+
import main.model.dto.integrations.publishing.PubItemDto;
14+
import main.model.dto.integrations.references.IssueReferenceDto;
15+
import main.model.dto.integrations.references.ReferenceType;
16+
import main.model.dto.integrations.references.TestReferenceDto;
17+
import main.model.dto.integrations.references.TestRunReferenceDto;
18+
import main.model.dto.integrations.systems.SystemDto;
19+
import main.model.dto.integrations.systems.SystemTypeDto;
20+
import main.model.dto.integrations.systems.workflow.SystemWorkflowStatusDto;
21+
import main.model.dto.integrations.systems.workflow.SystemWorkflowStatusTypeDto;
22+
import main.model.dto.integrations.tts.TestTrackingStatusDto;
23+
import main.model.dto.integrations.tts.TestTrackingTypeDto;
24+
25+
import java.util.function.Supplier;
26+
27+
public class ControllerType<T extends BaseDto, D extends DAO<T>> {
28+
29+
public static final ControllerType<TestReferenceDto, ReferenceDao<TestReferenceDto>> REF_TEST_CONTROLLER = new ControllerType<TestReferenceDto, ReferenceDao<TestReferenceDto>>(TestReferenceDto::new, () -> new ReferenceDao<>(ReferenceType.TEST), TestReferenceDto.class);
30+
public static final ControllerType<TestRunReferenceDto, ReferenceDao<TestRunReferenceDto>> REF_TESTRUN_CONTROLLER = new ControllerType<TestRunReferenceDto, ReferenceDao<TestRunReferenceDto>>(TestRunReferenceDto::new, () -> new ReferenceDao<>(ReferenceType.TEST_RUN), TestRunReferenceDto.class);
31+
public static final ControllerType<IssueReferenceDto, ReferenceDao<IssueReferenceDto>> REF_ISSUE_CONTROLLER = new ControllerType<IssueReferenceDto, ReferenceDao<IssueReferenceDto>>(IssueReferenceDto::new, () -> new ReferenceDao<>(ReferenceType.ISSUE), IssueReferenceDto.class);
32+
public static final ControllerType<TestTrackingStatusDto, TestTrackingStatusDao> TTS_STATUS_CONTROLLER = new ControllerType<>(TestTrackingStatusDto::new, TestTrackingStatusDao::new, TestTrackingStatusDto.class);
33+
public static final ControllerType<SystemDto, SystemDao> SYSTEM_CONTROLLER = new ControllerType<>(SystemDto::new, SystemDao::new, SystemDto.class);
34+
public static final ControllerType<SystemTypeDto, SystemTypeDao> SYSTEM_TYPE_CONTROLLER = new ControllerType<>(SystemTypeDto::new, SystemTypeDao::new, SystemTypeDto.class);
35+
public static final ControllerType<SystemWorkflowStatusTypeDto, SystemWorkflowStatusTypeDao> SYSTEM_WORKFLOW_STATUS_TYPE_CONTROLLER = new ControllerType<>(SystemWorkflowStatusTypeDto::new, SystemWorkflowStatusTypeDao::new, SystemWorkflowStatusTypeDto.class);
36+
public static final ControllerType<SystemWorkflowStatusDto, SystemWorkflowStatusDao> SYSTEM_WORKFLOW_STATUS_CONTROLLER = new ControllerType<>(SystemWorkflowStatusDto::new, SystemWorkflowStatusDao::new, SystemWorkflowStatusDto.class);
37+
public static final ControllerType<TestTrackingTypeDto, TestTrackingTypeDao> TTS_TYPE_CONTROLLER = new ControllerType<>(TestTrackingTypeDto::new, TestTrackingTypeDao::new, TestTrackingTypeDto.class);
38+
public static final ControllerType<PubItemDto, PubItemDao> PUBLISHING_CONTROLLER = new ControllerType<>(PubItemDto::new, PubItemDao::new, PubItemDto.class);
39+
40+
private final Supplier<T> dtoSupplier;
41+
private final Supplier<D> daoSupplier;
42+
private final Class<T> dtoClass;
43+
44+
private ControllerType(Supplier<T> dtoSupplier, Supplier<D> daoSupplier, Class<T> dtoClass) {
45+
this.dtoSupplier = dtoSupplier;
46+
this.daoSupplier = daoSupplier;
47+
this.dtoClass = dtoClass;
48+
}
49+
50+
D createDao() {
51+
return daoSupplier.get();
52+
}
53+
54+
public T createDto() {
55+
return dtoSupplier.get();
56+
}
57+
58+
public Class<T> getDtoClass() {
59+
return dtoClass;
60+
}
61+
}

src/main/java/main/controllers/Project/TestController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ protected List<TestResultDto> getResultsToMove(TestDto from, TestDto to) {
155155
return resultsToMove;
156156
}
157157

158-
//TODO Refactoring
159158
private List<TestDto> fillTests(List<TestDto> tests) throws AqualityException {
160159
List<TestDto> filledTests = new ArrayList<>();
161160
if (tests.size() > 0) {
@@ -186,7 +185,6 @@ private List<TestDto> fillTests(List<TestDto> tests) throws AqualityException {
186185
return filledTests;
187186
}
188187

189-
//TODO Refactoring
190188
private void updateSuites(TestDto test) throws AqualityException {
191189
Test2SuiteDto test2SuiteDto = new Test2SuiteDto();
192190
test2SuiteDto.setTest_id(test.getId());
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main.controllers;
2+
3+
import main.exceptions.AqualityException;
4+
import main.exceptions.AqualityPermissionsException;
5+
import main.model.db.dao.DAO;
6+
import main.model.dto.BaseDto;
7+
import main.model.dto.interfaces.IProjectEntity;
8+
import main.model.dto.project.ProjectUserDto;
9+
import main.model.dto.roles.GlobalRole;
10+
import main.model.dto.roles.ProjectRole;
11+
import main.model.dto.roles.RolePair;
12+
import main.model.dto.roles.RoleValidator;
13+
import main.model.dto.settings.UserDto;
14+
15+
import java.util.List;
16+
17+
public class ProjectEntityController<DTO extends BaseDto & IProjectEntity, D extends DAO<DTO>> extends ReadonlyController<DTO, D> {
18+
19+
public ProjectEntityController(UserDto user, D dao) {
20+
super(user, dao);
21+
}
22+
23+
@Override
24+
public DTO create(DTO entity) throws AqualityException {
25+
validateRoles(entity, getRolesPermittedToCreate());
26+
return dao.create(entity);
27+
}
28+
29+
@Override
30+
public List<DTO> get(DTO entity) throws AqualityException {
31+
validateRoles(entity, getRolesPermittedToGet());
32+
return dao.searchAll(entity);
33+
}
34+
35+
@Override
36+
public boolean delete(DTO entity) throws AqualityException {
37+
validateRoles(entity, getRolesPermittedToDelete());
38+
return dao.delete(entity);
39+
}
40+
41+
private RolePair getRolesPermittedToGet() {
42+
return new RolePair(GlobalRole.ADMIN, ProjectRole.VIEWER);
43+
}
44+
45+
private RolePair getRolesPermittedToCreate() {
46+
return new RolePair(GlobalRole.ADMIN, ProjectRole.ENGINEER);
47+
}
48+
49+
protected RolePair getRolesPermittedToDelete() {
50+
return new RolePair(GlobalRole.ADMIN, ProjectRole.ENGINEER);
51+
}
52+
53+
private void validateRoles(DTO entity, RolePair roles) throws AqualityException {
54+
GlobalRole globalRole = roles.getGlobal();
55+
ProjectRole projectRole = roles.getProject();
56+
ProjectUserDto projectUser = baseUser.getProjectUser(entity.getProjectId());
57+
if (!(RoleValidator.atLeastInRole(globalRole, baseUser) || RoleValidator.atLeastInRole(projectRole, projectUser))) {
58+
throw new AqualityPermissionsException(String.format("You should be global '%1$s' or at least project '%2$s' to perform this action",
59+
globalRole.getName(), projectRole.getName()),
60+
baseUser);
61+
}
62+
}
63+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main.controllers;
2+
3+
import main.exceptions.AqualityException;
4+
import main.model.db.dao.DAO;
5+
import main.model.dto.BaseDto;
6+
import main.model.dto.settings.UserDto;
7+
8+
import java.util.List;
9+
10+
public class ReadonlyController<T extends BaseDto, D extends DAO<T>> extends BaseController<T> {
11+
protected D dao;
12+
13+
public ReadonlyController(UserDto user, D dao) {
14+
super(user);
15+
this.dao = dao;
16+
}
17+
18+
@Override
19+
public List<T> get(T entity) throws AqualityException {
20+
return dao.searchAll(entity);
21+
}
22+
23+
@Override
24+
public T create(T entity) throws AqualityException {
25+
throw getUnsupportedException("CREATE");
26+
}
27+
28+
@Override
29+
public boolean delete(T entity) throws AqualityException {
30+
throw getUnsupportedException("DELETE");
31+
}
32+
33+
private AqualityException getUnsupportedException(String operationName) {
34+
return new AqualityException("Operation " + operationName + " is not supported for integration_systems table. This table includes list of constants.");
35+
}
36+
}

0 commit comments

Comments
 (0)