Skip to content

Commit 32056ed

Browse files
Merge pull request #3 from com-pas/Fetch_Bay_Typicals
Fetch Bay Typicals
2 parents 6f801b6 + e76f624 commit 32056ed

29 files changed

+769
-127
lines changed

DEVELOPMENT.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2023 Alliander N.V.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
# Development for Sitipe Service
8+
9+
This project uses Java 17 and Quarkus to build and run the application. The project is split into multi modules.
10+
The app module will use Quarkus to expose the services as REST XML and JSON Endpoints. The service module contains all
11+
the logic to retrieve data from a Sitipe database. This module uses no Quarkus dependencies, but mainly standard java. This way the service module can also be used in
12+
other environment as Java library, for instance a Spring project.
13+
14+
## Building the application
15+
16+
You can use Maven to build the application and see if all tests are working using:
17+
18+
```shell script
19+
./mvnw clean verify
20+
```
21+
22+
This should normally be enough to also run the application, but there were cases that we need to build using:
23+
24+
```shell script
25+
./mvnw clean install
26+
```
27+
28+
This to make the local modules available for the app module to run the application.
29+
30+
## Running the application locally in dev mode
31+
32+
You can run your application in dev mode that enables live coding using:
33+
34+
```shell script
35+
./mvnw package io.quarkus:quarkus-maven-plugin::dev
36+
```
37+
38+
### Application depends on a running KeyCloak instance for dev mode
39+
40+
A KeyCloak instance needs to be running on port 8089 by default in dev mode. If a custom KeyCloak instance is used see
41+
[Security](README.md#security) for more details.
42+
43+
There is a preconfigured Demo KeyCloak instance available for CoMPAS in the
44+
[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment). This repository can be cloned and
45+
used to execute the following commands to create a local Docker Image with the CoMPAS Demo configuration.
46+
47+
```shell
48+
cd <CoMPAS Deployment Repository Directory>/compas/keycloak
49+
docker build -t compas_keycloak .
50+
```
51+
52+
A Docker Image `compas_keycloak` is created that can be started using the following command
53+
54+
```shell
55+
docker run --rm --name compas_keycloak \
56+
-p 8089:8080
57+
-d compas_keycloak:latest
58+
```
59+
60+
There are now 3 users available to be used, `scl-data-editor`, `scl-data-reader`, `scd-reader`. See
61+
[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) for more information about the users.
62+
63+
## Testing the application
64+
65+
The application is tested with unit and integration tests, but you can also manually test the application using for
66+
instance Postman. And there is also a way to test this service with the CoMPAS OpenSCD Frontend application.
67+
68+
### Postman
69+
70+
To manually test the application there is a Postman collection in the directory `postman` that can be imported
71+
and used to execute REST XML and JSON Calls.
72+
73+
To make the call work we also need to import an environment and authorisation collection. These files can be found
74+
in [CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) in the directory `postman`
75+
(`auth.collection.json` and `local.environment.json`).
76+
77+
In the authorisation collection there are called for the 3 users known within the Demo KeyCloak instance.
78+
If one of these calls are executed there is a variable `bearer` filled.
79+
80+
Now one of the Sitipe Service calls can be executed, the variable `bearer` is added to the header of the request.
81+
After the call is executed the result should be shown in Postman.
82+
83+
### CoMPAS OpenSCD Frontend application
84+
85+
To test the Sitipe Service with the CoMPAS OpenSCD application just run the application in dev mode, including the
86+
KeyCloak instance. For further instruction how to start the CoMPAS OpenSCD application and use this locally see
87+
the file `DEVELOPMENT.md` in [CoMPAS OpenSCD application](https://github.com/com-pas/compas-open-scd).
88+
89+
## Docker Images
90+
91+
### Creating a Docker image with native executable
92+
93+
The releases created in the repository will create a docker image with a native executable. If you're running a Linux
94+
system it's possible to create and run the executable locally. You can create a Docker image with native executable
95+
using:
96+
97+
```shell script
98+
./mvnw package -Pnative-image
99+
```
100+
101+
You can then execute your native executable with: `./app/target/app-local-SNAPSHOT-runner`
102+
103+
### Creating a Docker image with JVM executable
104+
105+
There is also a profile to create a Docker Image which runs the application using a JVM. You can create a Docker Image
106+
with JVM executable using:
107+
108+
```shell script
109+
./mvnw package -Pjvm-image
110+
```
111+
112+
The JVM Image can also (temporary) be created by the release action if there are problems creating or running the
113+
native executable.

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,40 @@ SPDX-License-Identifier: Apache-2.0
1010
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5925/badge)](https://bestpractices.coreinfrastructure.org/projects/5925)
1111
[![Slack](https://raw.githubusercontent.com/com-pas/compas-architecture/master/public/LFEnergy-slack.svg)](http://lfenergy.slack.com/)
1212

13-
# CoMPAS Sitipe Service
13+
# CoMPAS Sitipe-service
14+
The CoMPAS Sitipe-Service Allows users to integrate Siemens Sitipe within the CoMPAS environment.
1415

15-
### Local Development
16+
## Development
17+
18+
Information about how to run and develop for this project check [Development](./DEVELOPMENT.md).
19+
20+
## Environment Variables
21+
22+
|Environment Variable | Default | Example |
23+
|--|--|--|
24+
| JWT_VERIFY_KEY | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
25+
| JWT_VERIFY_ISSUER | http://localhost/auth/realms/compas | http://localhost/auth/realms/compas |
26+
| JWT_VERIFY_CLIENT | sitipe-service | sitipe-service |
27+
| JWT_GROUPS_PATH | resource_access/sitipe-service/roles | resource_access/sitipe-service/roles |
28+
| SITIPE_FRAMEWORK_ID | - | cf1 |
29+
| SITIPE_VERSION | 1.00 | 1.00 |
30+
| SITIPE_MSSQL_URL | _ | jdbc:sqlserver://localhost:1433;databaseName=DB_2019_IC1;ssl-mode=disabled;trustServerCertificate=true;encrypt=false;integratedSecurity=false;
31+
| SITIPE_MSSQL_USER | sa | sa |
32+
| SITIPE_MSSQL_PASSWORD | - | bigStrongPwd123! |
33+
34+
## Security
35+
36+
To use most of the endpoints the users needs to be authenticated using JWT in the authorization header. There are [4 environment variables](#environment-variables) that can be set in the container to configure the validation/processing of the JWT.
37+
38+
## Local Development
1639
You can start the mssql database by running one of the following commands:
1740

18-
#### Mac M1
41+
### Mac M1
1942
```
2043
docker-compose --env-file docker/.env -f docker/docker-compose-m1.yml up -d --build
2144
```
2245

23-
#### AMD64
46+
### AMD64
2447
```
2548
docker-compose --env-file docker/.env -f docker/docker-compose-amd64.yml up -d --build
2649
```

app/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ SPDX-License-Identifier: Apache-2.0
145145
<artifactId>openpojo</artifactId>
146146
<scope>test</scope>
147147
</dependency>
148+
<dependency>
149+
<groupId>io.quarkus</groupId>
150+
<artifactId>quarkus-jdbc-h2</artifactId>
151+
<version>3.0.0.Alpha5</version>
152+
</dependency>
153+
<dependency>
154+
<groupId>io.quarkus</groupId>
155+
<artifactId>quarkus-flyway</artifactId>
156+
</dependency>
148157
</dependencies>
149158

150159
<build>

app/src/main/docker/Dockerfile.native

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ WORKDIR /work/
1919
RUN chown 1001 /work \
2020
&& chmod "g+rwX" /work \
2121
&& chown 1001:root /work
22-
COPY --chown=1001:root target/quarkus-app/*-runner /work/application
22+
COPY --chown=1001:root target/*-runner /work/application
23+
24+
RUN mkdir -p /data/temp \
25+
&& chown -R 1001 /data \
26+
&& chmod -R "g+rwX" /data
2327

2428
EXPOSE 8080
2529
USER 1001

app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/CompasSitipeResource.java renamed to app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
package org.lfenergy.compas.sitipe.rest.v1;
66

7+
import io.quarkus.security.Authenticated;
78
import io.smallrye.common.annotation.Blocking;
89
import io.smallrye.mutiny.Uni;
9-
import org.lfenergy.compas.sitipe.data.entity.BayTypical;
1010
import org.lfenergy.compas.sitipe.rest.v1.model.BayTypicalResponse;
1111
import org.lfenergy.compas.sitipe.service.BayTypicalService;
1212

@@ -19,41 +19,30 @@
1919
import javax.ws.rs.core.MediaType;
2020
import java.util.stream.Collectors;
2121

22-
// @Authenticated
22+
@Authenticated
2323
@RequestScoped
24-
@Path("/sitipe/v1")
25-
public class CompasSitipeResource {
24+
@Path("/v1/baytypicals")
25+
public class BayTypicalResource {
26+
2627
private final BayTypicalService bayTypicalService;
2728

2829
@Inject
29-
public CompasSitipeResource(final BayTypicalService bayTypicalService) {
30+
public BayTypicalResource(final BayTypicalService bayTypicalService) {
3031
this.bayTypicalService = bayTypicalService;
3132
}
3233

3334
@GET
3435
@Consumes(MediaType.APPLICATION_XML)
3536
@Produces(MediaType.APPLICATION_XML)
3637
@Blocking
37-
public Uni<BayTypicalResponse> getHelloWorld() {
38+
public Uni<BayTypicalResponse> getAssignedBayTypicals() {
3839
var response = new BayTypicalResponse();
3940

4041
response.setBayTypicals(
41-
this.bayTypicalService.getBayTypicals()
42+
this.bayTypicalService.getAssignedBayTypicals()
4243
.stream()
43-
.map(bt -> new BayTypicalResponse.BayTypical(
44-
bt.getId(),
45-
bt.getAccessId(),
46-
bt.getName(),
47-
bt.getVersion(),
48-
bt.getDescription(),
49-
bt.getReleased(),
50-
bt.getLockedBy(),
51-
bt.getLockedOn(),
52-
bt.getModifiedOn(),
53-
bt.getSmrFile(),
54-
bt.getContentVersion(),
55-
bt.getReferenceAccessId()
56-
)).collect(Collectors.toList())
44+
.map(BayTypicalResponse.BayTypicalItem::new)
45+
.collect(Collectors.toList())
5746
);
5847

5948
return Uni.createFrom().item(response);

app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponse.java

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
15
package org.lfenergy.compas.sitipe.rest.v1.model;
26

37
import org.eclipse.microprofile.openapi.annotations.media.Schema;
8+
import org.lfenergy.compas.sitipe.data.entity.BayTypical;
49

5-
import javax.persistence.Column;
6-
import javax.persistence.Id;
710
import javax.xml.bind.annotation.XmlAccessType;
811
import javax.xml.bind.annotation.XmlAccessorType;
912
import javax.xml.bind.annotation.XmlElement;
@@ -19,23 +22,23 @@ public class BayTypicalResponse {
1922

2023
@Schema(description = "List of found BayTypicals in the database.")
2124
@XmlElement(name = "BayTypical", namespace = SITIPE_SERVICE_V1_NS_URI)
22-
private List<BayTypical> bayTypicals;
25+
private List<BayTypicalItem> bayTypicals;
2326

24-
public void setBayTypicals(final List<BayTypical> bayTypicals) {
27+
public void setBayTypicals(final List<BayTypicalItem> bayTypicals) {
2528
this.bayTypicals = bayTypicals;
2629
}
2730

28-
public List<BayTypical> getBayTypicals() {
31+
public List<BayTypicalItem> getBayTypicals() {
2932
return bayTypicals;
3033
}
3134

3235
@Schema(description = "BayTypical found in the database.")
3336
@XmlAccessorType(XmlAccessType.FIELD)
34-
public static class BayTypical {
37+
public static class BayTypicalItem {
3538

3639
@Schema(description = "Id of the BayTypical.", example = "1")
3740
@XmlElement(name = "Id", namespace = SITIPE_SERVICE_V1_NS_URI)
38-
private int id;
41+
private Integer id;
3942

4043
@Schema(description = "Access Id of the BayTypical.", example = "c50b3276-81f6-4bc3-82ab-b8adef829136")
4144
@XmlElement(name = "AccessId", namespace = SITIPE_SERVICE_V1_NS_URI)
@@ -49,7 +52,7 @@ public static class BayTypical {
4952
@XmlElement(name = "Version", namespace = SITIPE_SERVICE_V1_NS_URI)
5053
private String version;
5154

52-
@Schema(description = "Description of the BayTypical.", example = "")
55+
@Schema(description = "Description of the BayTypical.")
5356
@XmlElement(name = "Description", namespace = SITIPE_SERVICE_V1_NS_URI)
5457
private String description;
5558

@@ -81,38 +84,27 @@ public static class BayTypical {
8184
@XmlElement(name = "ReferenceAccessId", namespace = SITIPE_SERVICE_V1_NS_URI)
8285
private String referenceAccessId;
8386

84-
public BayTypical(
85-
final int id,
86-
final String accessId,
87-
final String name,
88-
final String version,
89-
final String description,
90-
final int released,
91-
final String lockedBy,
92-
final Long lockedOn,
93-
final Long modifiedOn,
94-
final String smrFile,
95-
final String contentVersion,
96-
final String referenceAccessId
87+
public BayTypicalItem(
88+
final BayTypical bt
9789
) {
98-
this.id = id;
99-
this.accessId = accessId;
100-
this.name = name;
101-
this.version = version;
102-
this.description = description;
103-
this.released = released;
104-
this.lockedBy = lockedBy;
105-
this.lockedOn = lockedOn;
106-
this.modifiedOn = modifiedOn;
107-
this.smrFile = smrFile;
108-
this.contentVersion = contentVersion;
109-
this.referenceAccessId = referenceAccessId;
110-
}
111-
public int getId() {
90+
this.id = bt.getId();
91+
this.accessId = bt.getAccessId();
92+
this.name = bt.getName();
93+
this.version = bt.getVersion();
94+
this.description = bt.getDescription();
95+
this.released = bt.getReleased();
96+
this.lockedBy = bt.getLockedBy();
97+
this.lockedOn = bt.getLockedOn();
98+
this.modifiedOn = bt.getModifiedOn();
99+
this.smrFile = bt.getSmrFile();
100+
this.contentVersion = bt.getContentVersion();
101+
this.referenceAccessId = bt.getReferenceAccessId();
102+
}
103+
public Integer getId() {
112104
return id;
113105
}
114106

115-
public void setId(int id) {
107+
public void setId(Integer id) {
116108
this.id = id;
117109
}
118110

0 commit comments

Comments
 (0)