Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactored exim-api #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ExportImportRestControllerV1 implements ThemesExportImportApi {
ExportImportMapperV1 mapper;

@Override
public Response exportThemes(EximExportRequestDTOV1 request) {
public Response exportThemes(ExportThemeRequestDTOV1 request) {
var themes = dao.findThemeByNames(request.getNames());

var data = themes.collect(Collectors.toMap(Theme::getName, theme -> theme));
Expand All @@ -48,12 +48,12 @@ public Response exportThemes(EximExportRequestDTOV1 request) {

@Override
@Transactional(Transactional.TxType.REQUIRES_NEW)
public Response importThemes(EximImportRequestDTOV1 request) {
public Response importThemes(ThemeSnapshotDTOV1 request) {
var keys = request.getThemes().keySet();
var themes = dao.findThemeByNames(keys);
var map = themes.collect(Collectors.toMap(Theme::getName, theme -> theme));

Map<String, EximThemeResultDTOV1> items = new HashMap<>();
Map<String, ImportThemeResponseStatusDTOV1> items = new HashMap<>();

request.getThemes().forEach((name, dto) -> {

Expand All @@ -63,13 +63,13 @@ public Response importThemes(EximImportRequestDTOV1 request) {
theme = mapper.create(dto);
theme.setName(name);
dao.create(theme);
items.put(name, mapper.create(EximThemeResultStatusDTOV1.CREATED));
items.put(name, ImportThemeResponseStatusDTOV1.CREATED);

} else {

mapper.update(dto, theme);
dao.update(theme);
items.put(name, mapper.create(EximThemeResultStatusDTOV1.UPDATE));
items.put(name, ImportThemeResponseStatusDTOV1.UPDATE);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

import org.tkit.quarkus.log.cdi.LogParam;

import gen.io.github.onecx.theme.rs.exim.v1.model.EximExportRequestDTOV1;
import gen.io.github.onecx.theme.rs.exim.v1.model.EximImportRequestDTOV1;
import gen.io.github.onecx.theme.rs.exim.v1.model.ExportThemeRequestDTOV1;
import gen.io.github.onecx.theme.rs.exim.v1.model.ThemeSnapshotDTOV1;

@ApplicationScoped
public class ExportImportLogParam implements LogParam {

@Override
public List<Item> getClasses() {
return List.of(
item(10, EximExportRequestDTOV1.class, x -> x.getClass().getSimpleName()),
item(10, EximImportRequestDTOV1.class,
x -> x.getClass().getSimpleName() + ":" + ((EximImportRequestDTOV1) x).getId()));
item(10, ExportThemeRequestDTOV1.class, x -> x.getClass().getSimpleName()),
item(10, ThemeSnapshotDTOV1.class,
x -> x.getClass().getSimpleName() + ":" + ((ThemeSnapshotDTOV1) x).getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ public abstract class ExportImportMapperV1 {

@Mapping(target = "id", source = "request.id")
@Mapping(target = "themes", source = "themes")
public abstract EximImportResultDTOV1 create(EximImportRequestDTOV1 request, Map<String, EximThemeResultDTOV1> themes);
public abstract ImportThemeResponseDTOV1 create(ThemeSnapshotDTOV1 request,
Map<String, ImportThemeResponseStatusDTOV1> themes);

public abstract EximThemeResultDTOV1 create(EximThemeResultStatusDTOV1 status);

public EximImportRequestDTOV1 create(Map<String, Theme> data) {
public ThemeSnapshotDTOV1 create(Map<String, Theme> data) {
if (data == null) {
return null;
}
EximImportRequestDTOV1 result = new EximImportRequestDTOV1();
ThemeSnapshotDTOV1 result = new ThemeSnapshotDTOV1();
result.setCreated(OffsetDateTime.now());
result.setThemes(map(data));
return result;
Expand Down
55 changes: 21 additions & 34 deletions src/main/openapi/onecx-theme-exim-v1-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/EximExportRequest'
$ref: '#/components/schemas/ExportThemeRequest'
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/EximImportRequest'
$ref: '#/components/schemas/ThemeSnapshot'
"404":
description: No themes founds
/exim/v1/themes/import:
Expand All @@ -42,14 +40,14 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/EximImportRequest'
$ref: '#/components/schemas/ThemeSnapshot'
responses:
"200":
description: Import result
content:
application/json:
schema:
$ref: '#/components/schemas/EximImportResult'
$ref: '#/components/schemas/ImportThemeResponse'
"400":
description: Bad request
content:
Expand All @@ -58,55 +56,44 @@ paths:
$ref: '#/components/schemas/EximProblemDetailResponse'
components:
schemas:
EximExportRequest:
ExportThemeRequest:
type: object
properties:
names:
type: array
uniqueItems: true
items:
type: string
EximImportResult:
ThemeSnapshot:
type: object
properties:
id:
type: string
minLength: 10
description: ID of the request
created:
$ref: '#/components/schemas/OffsetDateTime'
themes:
$ref: '#/components/schemas/EximImportResultThemes'
EximImportResultThemes:
type: object
nullable: false
additionalProperties:
$ref: '#/components/schemas/EximThemeResult'
EximThemeResult:
type: object
properties:
status:
$ref: '#/components/schemas/EximThemeResultStatus'
EximThemeResultStatus:
type: string
enum:
- UPDATE
- CREATED
- SKIP
EximImportRequest:
type: object
nullable: false
additionalProperties:
$ref: '#/components/schemas/EximTheme'
ImportThemeResponse:
type: object
properties:
id:
type: string
minLength: 10
description: ID of the request
created:
$ref: '#/components/schemas/OffsetDateTime'
themes:
$ref: '#/components/schemas/EximImportThemes'
EximImportThemes:
type: object
nullable: false
additionalProperties:
$ref: '#/components/schemas/EximTheme'
additionalProperties:
$ref: '#/components/schemas/ImportThemeResponseStatus'
ImportThemeResponseStatus:
type: string
enum:
- UPDATE
- CREATED
- SKIP
EximTheme:
type: object
properties:
Expand Down
118 changes: 59 additions & 59 deletions src/main/resources/application.properties
HenryT-CG marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
# DEFAULT
quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.max-size=30
quarkus.datasource.jdbc.min-size=10
quarkus.hibernate-orm.database.generation=validate
quarkus.hibernate-orm.multitenant=DISCRIMINATOR
quarkus.liquibase.migrate-at-start=true
quarkus.liquibase.validate-on-migrate=true
tkit.dataimport.enabled=false
tkit.dataimport.configurations.theme.file=dev-data.import.json
tkit.dataimport.configurations.theme.metadata.operation=CLEAN_INSERT
tkit.dataimport.configurations.theme.enabled=false
tkit.dataimport.configurations.theme.stop-at-error=true
# enable or disable multi-tenancy support
tkit.rs.context.tenant-id.enabled=true
# PROD
%prod.quarkus.datasource.jdbc.url=${DB_URL:jdbc:postgresql://postgresdb:5432/onecx-theme?sslmode=disable}
%prod.quarkus.datasource.username=${DB_USER:onecx-theme}
%prod.quarkus.datasource.password=${DB_PWD:onecx-theme}
# DEV
%dev.tkit.rs.context.tenant-id.enabled=true
%dev.tkit.rs.context.tenant-id.mock.enabled=true
%dev.tkit.rs.context.tenant-id.mock.default-tenant=test
%dev.tkit.rs.context.tenant-id.mock.data.org1=tenant100
# TEST
%test.tkit.dataimport.enabled=true
%test.tkit.dataimport.configurations.theme.enabled=true
%test.tkit.dataimport.configurations.theme.file=./src/test/resources/import/theme-import.json
%test.tkit.dataimport.configurations.theme.metadata.operation=CLEAN_INSERT
%test.tkit.dataimport.configurations.theme.stop-at-error=true
%test.tkit.rs.context.tenant-id.enabled=true
%test.tkit.rs.context.tenant-id.mock.enabled=true
%test.tkit.rs.context.tenant-id.mock.default-tenant=default
%test.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test.tkit.rs.context.tenant-id.mock.data.org2=tenant-200
# TEST-IT
quarkus.test.integration-test-profile=test-it
%test-it.tkit.log.json.enabled=false
%test-it.tkit.rs.context.tenant-id.mock.enabled=true
%test-it.tkit.rs.context.tenant-id.mock.default-tenant=default
%test-it.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test-it.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test-it.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test-it.tkit.rs.context.tenant-id.mock.data.org2=tenant-200
# PIPE CONFIG
# DEFAULT
quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.max-size=30
quarkus.datasource.jdbc.min-size=10

quarkus.hibernate-orm.database.generation=validate
quarkus.hibernate-orm.multitenant=DISCRIMINATOR
quarkus.liquibase.migrate-at-start=true
quarkus.liquibase.validate-on-migrate=true

tkit.dataimport.enabled=false
tkit.dataimport.configurations.theme.file=dev-data.import.json
tkit.dataimport.configurations.theme.metadata.operation=CLEAN_INSERT
tkit.dataimport.configurations.theme.enabled=false
tkit.dataimport.configurations.theme.stop-at-error=true

tkit.log.json.enabled=false
tkit.log.json.pretty-print=false
tkit.log.json.print-details=false

# enable or disable multi-tenancy support
tkit.rs.context.tenant-id.enabled=true

# PROD
%prod.quarkus.datasource.jdbc.url=${DB_URL:jdbc:postgresql://postgresdb:5432/onecx-theme?sslmode=disable}
%prod.quarkus.datasource.username=${DB_USER:onecx-theme}
%prod.quarkus.datasource.password=${DB_PWD:onecx-theme}


# DEV
%dev.tkit.rs.context.tenant-id.enabled=true
%dev.tkit.rs.context.tenant-id.mock.enabled=true
%dev.tkit.rs.context.tenant-id.mock.default-tenant=test
%dev.tkit.rs.context.tenant-id.mock.data.org1=tenant100

# TEST
%test.tkit.dataimport.enabled=true
%test.tkit.dataimport.configurations.theme.enabled=true
%test.tkit.dataimport.configurations.theme.file=./src/test/resources/import/theme-import.json
%test.tkit.dataimport.configurations.theme.metadata.operation=CLEAN_INSERT
%test.tkit.dataimport.configurations.theme.stop-at-error=true

%test.tkit.rs.context.tenant-id.enabled=true
%test.tkit.rs.context.tenant-id.mock.enabled=true
%test.tkit.rs.context.tenant-id.mock.default-tenant=default
%test.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test.tkit.rs.context.tenant-id.mock.data.org2=tenant-200
# TEST-IT
quarkus.test.integration-test-profile=test-it
%test-it.tkit.log.json.enabled=false
%test-it.tkit.rs.context.tenant-id.mock.enabled=true
%test-it.tkit.rs.context.tenant-id.mock.default-tenant=default
%test-it.tkit.rs.context.tenant-id.mock.claim-org-id=orgId
%test-it.tkit.rs.context.tenant-id.mock.token-header-param=apm-principal-token
%test-it.tkit.rs.context.tenant-id.mock.data.org1=tenant-100
%test-it.tkit.rs.context.tenant-id.mock.data.org2=tenant-200
# PIPE CONFIG
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.mockito.Mockito;
import org.tkit.quarkus.jpa.exceptions.DAOException;

import gen.io.github.onecx.theme.rs.exim.v1.model.EximExportRequestDTOV1;
import gen.io.github.onecx.theme.rs.exim.v1.model.ExportThemeRequestDTOV1;
import io.github.onecx.theme.domain.daos.ThemeDAO;
import io.github.onecx.theme.test.AbstractTest;
import io.quarkus.test.InjectMock;
Expand All @@ -34,7 +34,7 @@ void beforeAll() {
@Test
void exportThemesExceptionTest() {

var request = new EximExportRequestDTOV1();
var request = new ExportThemeRequestDTOV1();

given()
.when()
Expand Down
Loading
Loading