Commit ced92a3b authored by Hando Lukats's avatar Hando Lukats
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Martin Õunap

See merge request teis/admin-service!88
parents a7851d27 32e0666f
......@@ -4,6 +4,8 @@ stages:
- deploy
- cve-test
image: docker.repo.tehik.ee/gradle:jdk17
variables:
USE_POSTGRES: "true"
USE_RABBIT: "true"
......
# Changelog
## [2.0.0] - 2022-07-20
* TEIS-2525: added functionality to compose accident case paths
## [1.27.0] - 2022-05-20
* TEIS-3118: added DDD to allowed extensions for file upload
......
......@@ -44,3 +44,4 @@ Run [integration](service/src/integTest) and [unit tests](service/src/test) via
```jshelllanguage
./gradlew test
```
......@@ -19,32 +19,24 @@ buildscript {
}
}
apply plugin: 'ee.sm.ti.teis'
allprojects {
group = "${theGroup}"
version = "${theVersion}"
apply from: this.getClass().getClassLoader().getResource('teis.sonarqube.gradle')
}
subprojects {
apply plugin: 'ee.sm.ti.teis'
functionalities {
base
}
repositories {
mavenLocal()
maven {
url "${gradle.ext.artifactoryUrl}/${gradle.ext.artifactoryRepoKey}"
credentials {
username = "${gradle.ext.artifactoryUser}"
password = "${gradle.ext.artifactoryPass}"
}
}
jcenter()
}
group = "${theGroup}"
version = "${theVersion}"
sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
manifest {
attributes('Implementation-Title': project.name,
......@@ -52,11 +44,6 @@ allprojects {
}
}
apply from: this.getClass().getClassLoader().getResource('teis.test-sonar.gradle')
apply from: this.getClass().getClassLoader().getResource('teis.test-jacoco.gradle')
dependencies {
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:domain-request-lib:${commonsVersion}"
compile "ee.sm.ti.teis:common-api-gateway-lib:${commonApiGatewayVersion}"
}
}
\ No newline at end of file
}
theGroup=ee.sm.ti.teis
theVersion=1.27.0
pluginVersion=1.5.0
commonsVersion=1.37.0
commonApiGatewayVersion=1.37.0
theVersion=2.0.0
pluginVersion=2.2.0
commonsVersion=2.4.0
commonApiGatewayVersion=2.3.0
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://repo.tehik.ee/artifactory/gradle-distributions/gradle-5.6.4-bin.zip
distributionUrl=https\://repo.tehik.ee/artifactory/gradle-distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
description = """admin-service"""
functionalities {
base
microservice
database
}
......@@ -9,12 +8,11 @@ functionalities {
apply from: this.getClass().getClassLoader().getResource('teis.integrationTest.gradle')
apply from: this.getClass().getClassLoader().getResource('teis.microservice.gradle')
// Define the main class for the application
mainClassName = 'ee.sm.ti.teis.AdminServiceApp'
test {
testLogging {
events "passed", "skipped", "failed"
}
dependencies {
implementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:domain-request-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:common-api-gateway-lib:${commonApiGatewayVersion}"
}
// Define the main class for the application
mainClassName = 'ee.sm.ti.teis.AdminServiceApp'
......@@ -10,8 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static org.apache.commons.lang3.RandomStringUtils.random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.random;
class GetFeatureFlagGwListenerTest extends AdminAppTestBase {
......
......@@ -16,8 +16,8 @@ import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PARAMETERS;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_VIOLATION;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static org.apache.commons.lang3.RandomStringUtils.random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.random;
@Transactional
class UpdateFeatureFlagGwListenerTest extends AdminAppTestBase {
......
......@@ -38,10 +38,13 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void proceedingsPath() {
void getPath_proceedings_success() {
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
......@@ -50,10 +53,13 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void claimsPath() {
void getPath_claims_success() {
UUID claimId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(CLAIM_PAYMENT).id(claimId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(CLAIM_PAYMENT)
.id(claimId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
......@@ -62,52 +68,70 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void proceduralActsPath() {
void getPath_proceduralActs_success() {
UUID actId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEDURAL_ACT).id(actId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEDURAL_ACT)
.id(actId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/acts/" +
actId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/acts/" + actId + "/" + PATH_END);
}
@Test
void violationsPath() {
void getPath_violations_success() {
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(VIOLATION).id(violationId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violations/" +
violationId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violations/" + violationId + "/" + PATH_END);
}
@Test
void violationActsPath() {
void getPath_violationActs_success() {
UUID violationActId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(VIOLATION_ACT).id(violationActId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(VIOLATION_ACT)
.id(violationActId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violationAct/" +
violationActId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violationAct/" + violationActId + "/" + PATH_END);
}
@Test
void riskAssessmentPath_success() {
void getPath_riskAssessments_success() {
UUID riskAssessmentId = UUID.randomUUID();
UUID riskFactorAssessmentId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
......@@ -123,8 +147,23 @@ class PathListenerTest extends AdminAppTestBase {
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId +
"/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId
+ "/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
}
@Test
void getPath_accidentCases_success() {
UUID accidentCaseId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(ACCIDENT_CASE)
.id(accidentCaseId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo("/auth/accidents/" + accidentCaseId + "/" + PATH_END);
}
}
......@@ -6,7 +6,6 @@ import ee.sm.ti.teis.adminservice.config.AdminQueueConfig.GetPathMsResponse;
import ee.sm.ti.teis.domain.admin.GetUrlPath;
import ee.sm.ti.teis.domain.admin.PathDataObjectReference;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.classifier.ObjectType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,15 +13,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.*;
import static org.assertj.core.api.Assertions.assertThat;
class PathMsListenerTest extends AdminAppTestBase {
private static final String PATH_END = "general";
private static final String AUTH_PROCEEDINGS_URL = "/auth/proceedings/";
private static final String AUTH_RISK_ASSESSMENT_URL = "/auth/risk-assessments/";
@Autowired
PathMsListener pathMsListener;
PathMsListener listener;
GetPathMsRequest request;
GetUrlPath payload;
......@@ -37,71 +38,137 @@ class PathMsListenerTest extends AdminAppTestBase {
}
@Test
void proceedingsPath() {
void getPath_proceedings_success() {
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/" + PATH_END);
}
@Test
void claimsPath() {
void getPath_claims_success() {
UUID claimId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.CLAIM_PAYMENT).id(claimId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(CLAIM_PAYMENT)
.id(claimId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo("/auth/claims/" + claimId + "/" + PATH_END);
}
@Test
void proceduralActsPath() {
void getPath_proceduralActs_success() {
UUID actId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEDURAL_ACT).id(actId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEDURAL_ACT)
.id(actId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/acts/" + actId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/acts/" + actId + "/" + PATH_END);
}
@Test
void violationsPath() {
void getPath_violations_success() {
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION).id(violationId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violations/" + violationId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violations/" + violationId + "/" + PATH_END);
}
@Test
void violationActsPath() {
void getPath_violationActs_success() {
UUID violationActId = UUID.randomUUID();
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION).id(violationId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION_ACT).id(violationActId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION_ACT)
.id(violationActId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violationAct/" + violationActId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violationAct/" + violationActId + "/" + PATH_END);
}
@Test
void getPath_riskAssessments_success() {
UUID riskAssessmentId = UUID.randomUUID();
UUID riskFactorAssessmentId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(RISK_ASSESSMENT)
.id(riskAssessmentId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(RISK_FACTOR_ASSESSMENT)
.id(riskFactorAssessmentId)
.build());
payload.setPathEnd(PATH_END);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId
+ "/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
}
@Test
void getPath_accidentCases_success() {
UUID accidentCaseId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(ACCIDENT_CASE)
.id(accidentCaseId)
.build());
payload.setPathEnd(PATH_END);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo("/auth/accidents/" + accidentCaseId + "/" + PATH_END);
}
}
......@@ -7,7 +7,7 @@ import static ee.sm.ti.teis.errors.CommonErrorCode.BAD_REQUEST;
import static ee.sm.ti.teis.types.enums.DataType.INT;
import static org.apache.commons.lang3.BooleanUtils.isTrue;
import static org.apache.commons.lang3.StringUtils.isNumeric;
import static org.springframework.util.StringUtils.isEmpty;
import static org.springframework.util.StringUtils.hasText;
public class ParameterValidationService {
......@@ -16,7 +16,7 @@ public class ParameterValidationService {
}
static void validateUpdateParameterValue(Boolean mandatory, DataType dataType, String value) {
if (isTrue(mandatory) && isEmpty(value)) {
if (isTrue(mandatory) && !hasText(value)) {
throw new TeisBusinessException(BAD_REQUEST, "Value is required");
}
......@@ -24,4 +24,5 @@ public class ParameterValidationService {
throw new TeisBusinessException(BAD_REQUEST, "Value must be numeric");
}
}
}
......@@ -26,6 +26,7 @@ public class PathComposeService {
private static final String CLAIM_PAYMENT_PATH = "claims";
private static final String RISK_ASSESSMENT_PATH = "risk-assessments";
private static final String ASSESSMENT_PATH = "assessment";
private static final String ACCIDENT_CASE_PATH = "accidents";
private static final String PATH_DELIMITER = "/";
......@@ -48,6 +49,7 @@ public class PathComposeService {
if (!isValidData(pathDto)) {
throw new TeisIllegalArgumentException("Path validation error");
}
// IMPORTANT: do not change if ordering, they are ordered based on business logic
if (hasType(pathDto, VIOLATION_ACT)) {
path = PATH_DELIMITER + PROCEEDING_PATH + PATH_DELIMITER + getRefWithType(pathDto, PROCEEDING).getId();
......@@ -65,10 +67,14 @@ public class PathComposeService {
} else if (hasType(pathDto, RISK_ASSESSMENT) || hasType(pathDto, RISK_FACTOR_ASSESSMENT)) {
path = PATH_DELIMITER + RISK_ASSESSMENT_PATH + PATH_DELIMITER + getRefWithType(pathDto, RISK_ASSESSMENT).getId();
path += PATH_DELIMITER + ASSESSMENT_PATH + PATH_DELIMITER + getRefWithType(pathDto, RISK_FACTOR_ASSESSMENT).getId();
} else if (hasType(pathDto, ACCIDENT_CASE)) {
path = PATH_DELIMITER + ACCIDENT_CASE_PATH + PATH_DELIMITER + getRefWithType(pathDto, ACCIDENT_CASE).getId();
}
if (path.length() > 0) {
path = appendUrl(pathDto, path);
}
return path;
}
......
......@@ -8,7 +8,6 @@ spring:
url: jdbc:postgresql://${DB_HOST}:5432/admin_service
username: ${DB_APP_USERNAME}
password: ${DB_APP_PASSWORD}
initialization-mode: never
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
user: ${DB_OWNER_USERNAME}
......
......@@ -5,6 +5,21 @@ gradle.ext.artifactoryUser = hasProperty('ARTIFACTORY_USER') ? ARTIFACTORY_USER
gradle.ext.artifactoryPass = hasProperty('ARTIFACTORY_PASS') ? ARTIFACTORY_PASS : System.getenv('ARTIFACTORY_PASS')
gradle.ext.artifactoryRepoKey = hasProperty('ARTIFACTORY_REPO_KEY') ? ARTIFACTORY_REPO_KEY : System.getenv('ARTIFACTORY_REPO_KEY')
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
mavenLocal()
maven {
url "${gradle.ext.artifactoryUrl}/${gradle.ext.artifactoryRepoKey}"
credentials {
username = "${gradle.ext.artifactoryUser}"
password = "${gradle.ext.artifactoryPass}"
}
}
mavenCentral()
}
}
include 'service'
rootProject.name = 'admin-service'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please