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

Use SclFileType from CoMPAS Common. #160

Merged
merged 1 commit into from
Dec 15, 2021
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ configured as needed.
- SED_DELETE
- SED_READ
- SED_UPDATE
- STD_CREATE
- STD_DELETE
- STD_READ
- STD_UPDATE

4 changes: 4 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ SPDX-License-Identifier: Apache-2.0
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>commons</artifactId>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl-extension</artifactId>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>jaxrs-commons</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import io.quarkus.security.Authenticated;
import org.eclipse.microprofile.jwt.JsonWebToken;
import org.lfenergy.compas.scl.data.model.SclType;
import org.lfenergy.compas.scl.data.rest.UserInfoProperties;
import org.lfenergy.compas.scl.data.rest.v1.model.Type;
import org.lfenergy.compas.scl.data.rest.v1.model.TypeListResponse;
import org.lfenergy.compas.scl.data.rest.v1.model.UserInfoResponse;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -49,10 +49,10 @@ public TypeListResponse list(@HeaderParam("Authorization") String authHeader) {

var response = new TypeListResponse();
response.setTypes(
Arrays.stream(SclType.values())
Arrays.stream(SclFileType.values())
// Filter on the type the user has read rights.
.filter(sclType -> roles.contains(sclType.name() + "_" + READ_ROLE))
.map(sclType -> new Type(sclType.name(), sclType.getDescription()))
.filter(sclFileType -> roles.contains(sclFileType.name() + "_" + READ_ROLE))
.map(sclFileType -> new Type(sclFileType.name(), sclFileType.getDescription()))
.sorted(Comparator.comparing(Type::getDescription))
.collect(Collectors.toList()));
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import io.quarkus.security.Authenticated;
import org.eclipse.microprofile.jwt.JsonWebToken;
import org.lfenergy.compas.scl.data.model.SclType;
import org.lfenergy.compas.scl.data.model.Version;
import org.lfenergy.compas.scl.data.rest.UserInfoProperties;
import org.lfenergy.compas.scl.data.rest.v1.model.*;
import org.lfenergy.compas.scl.data.service.CompasSclDataService;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -44,7 +44,7 @@ public CompasSclDataResource(CompasSclDataService compasSclDataService) {
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public CreateResponse create(@PathParam(TYPE_PATH_PARAM) SclType type,
public CreateResponse create(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@Valid CreateRequest request) {
String who = jsonWebToken.getClaim(userInfoProperties.who());
LOGGER.trace("Username used for Who {}", who);
Expand All @@ -58,7 +58,7 @@ public CreateResponse create(@PathParam(TYPE_PATH_PARAM) SclType type,
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_XML)
public ListResponse list(@PathParam(TYPE_PATH_PARAM) SclType type) {
public ListResponse list(@PathParam(TYPE_PATH_PARAM) SclFileType type) {
var response = new ListResponse();
response.setItems(compasSclDataService.list(type));
return response;
Expand All @@ -67,7 +67,7 @@ public ListResponse list(@PathParam(TYPE_PATH_PARAM) SclType type) {
@GET
@Path("/{" + ID_PATH_PARAM + "}/versions")
@Produces(MediaType.APPLICATION_XML)
public VersionsResponse listVersionsByUUID(@PathParam(TYPE_PATH_PARAM) SclType type,
public VersionsResponse listVersionsByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id) {
var response = new VersionsResponse();
response.setItems(compasSclDataService.listVersionsByUUID(type, id));
Expand All @@ -77,7 +77,7 @@ public VersionsResponse listVersionsByUUID(@PathParam(TYPE_PATH_PARAM) SclType t
@GET
@Path("/{" + ID_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_XML)
public GetResponse findByUUID(@PathParam(TYPE_PATH_PARAM) SclType type,
public GetResponse findByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id) {
var response = new GetResponse();
response.setSclData(compasSclDataService.findByUUID(type, id));
Expand All @@ -87,7 +87,7 @@ public GetResponse findByUUID(@PathParam(TYPE_PATH_PARAM) SclType type,
@GET
@Path("/{" + ID_PATH_PARAM + "}/{" + VERSION_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_XML)
public GetResponse findByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclType type,
public GetResponse findByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id,
@PathParam(VERSION_PATH_PARAM) Version version) {
var response = new GetResponse();
Expand All @@ -99,7 +99,7 @@ public GetResponse findByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclType type
@Path("/{" + ID_PATH_PARAM + "}")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public UpdateResponse update(@PathParam(TYPE_PATH_PARAM) SclType type,
public UpdateResponse update(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id,
@Valid UpdateRequest request) {
String who = jsonWebToken.getClaim(userInfoProperties.who());
Expand All @@ -114,15 +114,15 @@ public UpdateResponse update(@PathParam(TYPE_PATH_PARAM) SclType type,
@DELETE
@Path("/{" + ID_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_XML)
public void deleteAll(@PathParam(TYPE_PATH_PARAM) SclType type,
public void deleteAll(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id) {
compasSclDataService.delete(type, id);
}

@DELETE
@Path("/{" + ID_PATH_PARAM + "}/{" + VERSION_PATH_PARAM + "}")
@Produces(MediaType.APPLICATION_XML)
public void deleteVersion(@PathParam(TYPE_PATH_PARAM) SclType type,
public void deleteVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type,
@PathParam(ID_PATH_PARAM) UUID id,
@PathParam(VERSION_PATH_PARAM) Version version) {
compasSclDataService.delete(type, id, version);
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ quarkus.http.auth.policy.ISD_DELETE.roles-allowed=ISD_DELETE
quarkus.http.auth.permission.ISD_DELETE_DELETE.paths=/compas-scl-data-service/scl/v1/ISD/*
quarkus.http.auth.permission.ISD_DELETE_DELETE.policy=ISD_DELETE
quarkus.http.auth.permission.ISD_DELETE_DELETE.methods=DELETE

quarkus.http.auth.policy.STD_READ.roles-allowed=STD_READ
quarkus.http.auth.permission.STD_READ_GET.paths=/compas-scl-data-service/scl/v1/STD/*
quarkus.http.auth.permission.STD_READ_GET.policy=STD_READ
quarkus.http.auth.permission.STD_READ_GET.methods=GET
quarkus.http.auth.policy.STD_CREATE.roles-allowed=STD_CREATE
quarkus.http.auth.permission.STD_CREATE_POST.paths=/compas-scl-data-service/scl/v1/STD
quarkus.http.auth.permission.STD_CREATE_POST.policy=STD_CREATE
quarkus.http.auth.permission.STD_CREATE_POST.methods=POST
quarkus.http.auth.policy.STD_UPDATE.roles-allowed=STD_UPDATE
quarkus.http.auth.permission.STD_UPDATE_PUT.paths=/compas-scl-data-service/scl/v1/STD/*
quarkus.http.auth.permission.STD_UPDATE_PUT.policy=STD_UPDATE
quarkus.http.auth.permission.STD_UPDATE_PUT.methods=PUT
quarkus.http.auth.policy.STD_DELETE.roles-allowed=STD_DELETE
quarkus.http.auth.permission.STD_DELETE_DELETE.paths=/compas-scl-data-service/scl/v1/STD/*
quarkus.http.auth.permission.STD_DELETE_DELETE.policy=STD_DELETE
quarkus.http.auth.permission.STD_DELETE_DELETE.methods=DELETE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import io.quarkus.test.Mock;
import org.lfenergy.compas.scl.data.model.Item;
import org.lfenergy.compas.scl.data.model.SclMetaInfo;
import org.lfenergy.compas.scl.data.model.SclType;
import org.lfenergy.compas.scl.data.model.Version;
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
import org.lfenergy.compas.scl.extensions.model.SclFileType;

import javax.enterprise.context.ApplicationScoped;
import java.util.List;
Expand All @@ -18,42 +18,42 @@
@ApplicationScoped
public class CompasSclDataRepositoryMock implements CompasSclDataRepository {
@Override
public List<Item> list(SclType type) {
public List<Item> list(SclFileType type) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public List<Item> listVersionsByUUID(SclType type, UUID id) {
public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public String findByUUID(SclType type, UUID id) {
public String findByUUID(SclFileType type, UUID id) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public SclMetaInfo findMetaInfoByUUID(SclType type, UUID id) {
public SclMetaInfo findMetaInfoByUUID(SclFileType type, UUID id) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public String findByUUID(SclType type, UUID id, Version version) {
public String findByUUID(SclFileType type, UUID id, Version version) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public void create(SclType type, UUID id, String name, String scl, Version version, String who) {
public void create(SclFileType type, UUID id, String name, String scl, Version version, String who) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public void delete(SclType type, UUID id) {
public void delete(SclFileType type, UUID id) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}

@Override
public void delete(SclType type, UUID id, Version version) {
public void delete(SclFileType type, UUID id, Version version) {
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void list_WhenCalledWithMultipleReadRights_ThenMultipleItemResponseRetrieved() {

var xmlPath = response.xmlPath();
// User has read rights for 2 types, so these types are returned.
var sclTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(2, sclTypes.size());
assertEquals("IID", sclTypes.get(0));
assertEquals("SCD", sclTypes.get(1));
var sclFileTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(2, sclFileTypes.size());
assertEquals("IID", sclFileTypes.get(0));
assertEquals("SCD", sclFileTypes.get(1));
}

@Test
Expand All @@ -48,9 +48,9 @@ void list_WhenCalledWithOneReadRights_ThenOneItemResponseRetrieved() {

var xmlPath = response.xmlPath();
// User has read rights for one type, so this type is returned.
var sclTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(1, sclTypes.size());
assertEquals("SCD", sclTypes.get(0));
var sclFileTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(1, sclFileTypes.size());
assertEquals("SCD", sclFileTypes.get(0));
}

@Test
Expand All @@ -65,8 +65,8 @@ void list_WhenCalledWithNoReadRights_ThenNoItemResponseRetrieved() {

var xmlPath = response.xmlPath();
// User has read rights for no types, so empty list is returned.
var sclTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(0, sclTypes.size());
var sclFileTypes = xmlPath.getList("TypeListResponse.Type.Code");
assertEquals(0, sclFileTypes.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl.data.model.ChangeSetType;
import org.lfenergy.compas.scl.data.model.Item;
import org.lfenergy.compas.scl.data.model.SclType;
import org.lfenergy.compas.scl.data.model.Version;
import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest;
import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest;
import org.lfenergy.compas.scl.data.service.CompasSclDataService;
import org.lfenergy.compas.scl.extensions.model.SclFileType;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -45,7 +45,7 @@ class CompasSclDataResourceAsEditorTest {

@Test
void list_WhenCalled_ThenItemResponseRetrieved() {
var type = SclType.SCD;
var type = SclFileType.SCD;
var uuid = UUID.randomUUID();
var name = "name";
var version = "1.0.0";
Expand All @@ -70,7 +70,7 @@ void list_WhenCalled_ThenItemResponseRetrieved() {

@Test
void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
var type = SclType.SCD;
var type = SclFileType.SCD;
var uuid = UUID.randomUUID();
var name = "Name";
var version = "1.0.0";
Expand All @@ -96,7 +96,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {

@Test
void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException {
var type = SclType.SCD;
var type = SclFileType.SCD;
var uuid = UUID.randomUUID();
var scl = readSCL();

Expand All @@ -119,7 +119,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException {

@Test
void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOException {
var type = SclType.SCD;
var type = SclFileType.SCD;
var uuid = UUID.randomUUID();
var scl = readSCL();
var version = new Version(1, 2, 3);
Expand All @@ -144,7 +144,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti

@Test
void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException {
var type = SclType.SCD;
var type = SclFileType.SCD;
var name = "StationName";
var comment = "Some comments";
var scl = readSCL();
Expand Down Expand Up @@ -173,7 +173,7 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException {
@Test
void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException {
var uuid = UUID.randomUUID();
var type = SclType.SCD;
var type = SclFileType.SCD;
var changeSetType = ChangeSetType.MAJOR;
var comment = "Some comments";
var scl = readSCL();
Expand Down Expand Up @@ -203,7 +203,7 @@ void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException
@Test
void deleteAll_WhenCalled_ThenServiceCalled() {
var uuid = UUID.randomUUID();
var type = SclType.SCD;
var type = SclFileType.SCD;

doNothing().when(compasSclDataService).delete(type, uuid);

Expand All @@ -220,7 +220,7 @@ void deleteAll_WhenCalled_ThenServiceCalled() {
@Test
void deleteVersion_WhenCalled_ThenServiceCalled() {
var uuid = UUID.randomUUID();
var type = SclType.SCD;
var type = SclFileType.SCD;
var version = new Version(1, 2, 3);

doNothing().when(compasSclDataService).delete(type, uuid, version);
Expand Down
Loading