Skip to content

Commit

Permalink
feat: added operator flag and exception handling (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored May 16, 2024
1 parent 3d893f6 commit 2b2b736
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface TemplateMapper {
@Mapping(target = "persisted", ignore = true)
Application createApplication(String productName, String appId, String name, String description);

@Mapping(target = "operator", constant = "false")
@Mapping(target = "mandatory", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public class Permission extends TraceableEntity {
@Column(name = "MANDATORY")
private Boolean mandatory;

/**
* Flag to identify permissions created by an operator
*/
@Column(name = "OPERATOR")
private Boolean operator;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.tkit.onecx.permission.domain.services.PermissionService;
import org.tkit.onecx.permission.rs.internal.mappers.ExceptionMapper;
import org.tkit.onecx.permission.rs.internal.mappers.PermissionMapper;
import org.tkit.quarkus.jpa.exceptions.ConstraintException;
import org.tkit.quarkus.log.cdi.LogService;

import gen.org.tkit.onecx.permission.rs.internal.PermissionInternalApi;
Expand Down Expand Up @@ -86,4 +87,9 @@ public Response updatePermission(String id, UpdatePermissionRequestDTO updatePer
public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationException ex) {
return exceptionMapper.constraint(ex);
}

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintException ex) {
return exceptionMapper.exception(ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public interface PermissionMapper {

PermissionDTO map(Permission data);

@Mapping(target = "mandatory", ignore = true)
@Mapping(target = "mandatory", constant = "false")
@Mapping(target = "operator", constant = "false")
@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "creationUser", ignore = true)
Expand All @@ -31,6 +32,7 @@ public interface PermissionMapper {
@Mapping(target = "persisted", ignore = true)
Permission create(CreatePermissionRequestDTO dto);

@Mapping(target = "operator", ignore = true)
@Mapping(target = "mandatory", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ default List<Permission> map(List<PermissionDTOV1> list, String appId, String pr
return data;
}

@Mapping(target = "operator", constant = "true")
@Mapping(target = "mandatory", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
Expand Down
3 changes: 3 additions & 0 deletions src/main/openapi/onecx-permission-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ components:
mandatory:
type: boolean
default: false
operator:
type: boolean
default: false
CreatePermissionRequest:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<include relativeToChangelogFile="true" file="v1/2024-01-10-data-import-log.xml" />
<include relativeToChangelogFile="true" file="v1/2024-04-09-constraint-and-index-fix.xml" />
<include relativeToChangelogFile="true" file="v1/2024-05-13-mandatory-flags.xml" />
<include relativeToChangelogFile="true" file="v1/2024-05-16-operator-flag.xml" />

</databaseChangeLog>
13 changes: 13 additions & 0 deletions src/main/resources/db/v1/2024-05-16-operator-flag.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">

<changeSet author="dev (generated)" id="1715590921446-1">
<addColumn tableName="permission">
<column name="operator" type="bool"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void searchTest() {
.as(PermissionPageResultDTO.class);

assertThat(data).isNotNull();
assertThat(data.getTotalElements()).isEqualTo(7);
assertThat(data.getStream()).isNotNull().hasSize(7);
assertThat(data.getTotalElements()).isEqualTo(8);
assertThat(data.getStream()).isNotNull().hasSize(8);

criteria.setAppId(" ");

Expand All @@ -54,8 +54,8 @@ void searchTest() {
.as(PermissionPageResultDTO.class);

assertThat(data).isNotNull();
assertThat(data.getTotalElements()).isEqualTo(7);
assertThat(data.getStream()).isNotNull().hasSize(7);
assertThat(data.getTotalElements()).isEqualTo(8);
assertThat(data.getStream()).isNotNull().hasSize(8);
}

@Test
Expand Down Expand Up @@ -90,8 +90,8 @@ void searchCriteriaTest() {
.as(PermissionPageResultDTO.class);

assertThat(output).isNotNull();
assertThat(output.getTotalElements()).isEqualTo(7);
assertThat(output.getStream()).isNotNull().hasSize(7);
assertThat(output.getTotalElements()).isEqualTo(8);
assertThat(output.getStream()).isNotNull().hasSize(8);

}

Expand Down Expand Up @@ -170,6 +170,16 @@ void deletePermissionTest() {

}

@Test
void deletePermissionWithAssignmentByDifferentTenantTest() {

given()
.contentType(APPLICATION_JSON)
.delete("p23")
.then()
.statusCode(BAD_REQUEST.getStatusCode());
}

@Test
void updatePermissionTest() {
var criteria = new UpdatePermissionRequestDTO();
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/data/test-internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<PERMISSION guid="p21" optlock="0" app_id="app2" resource="o1" action="a1" product_name="test1" mandatory="false"/>
<PERMISSION guid="p22" optlock="0" app_id="app2" resource="o1" action="a2" product_name="test1" mandatory="false"/>
<PERMISSION guid="p23" optlock="0" app_id="app2" resource="o1" action="a3" product_name="test1" mandatory="false"/>

<ROLE guid="r11" optlock="0" name="n1" description="d1" tenant_id="default" mandatory="false"/>
<ROLE guid="r12" optlock="0" name="n2" description="d1" tenant_id="default" mandatory=""/>
Expand All @@ -29,6 +30,7 @@
<ASSIGNMENT guid="a12" optlock="0" permission_id="p13" role_id="r14" tenant_id="default" mandatory="false"/>

<ASSIGNMENT guid="a13" optlock="0" permission_id="p21" role_id="r14" tenant_id="default" mandatory="true"/>
<ASSIGNMENT guid="a14" optlock="0" permission_id="p23" role_id="r24" tenant_id="100" mandatory="false"/>


</dataset>

0 comments on commit 2b2b736

Please sign in to comment.