Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
eschrewe committed Feb 8, 2024
2 parents 9000072 + ee6375c commit ab73db7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public ResponseEntity<RequestReactionMessageDto> postMapping(@RequestBody ItemSt
return ResponseEntity.status(422).body(new RequestReactionMessageDto(requestMessageDto.getHeader().getMessageId()));
}
switch (requestMessageDto.getContent().getDirection()) {
case INBOUND ->
executorService.submit(() -> itemStockRequestApiService.handleRequestFromCustomer(requestMessageDto, createdRequestMessage));
case OUTBOUND ->
executorService.submit(() -> itemStockRequestApiService.handleRequestFromCustomer(requestMessageDto, createdRequestMessage));
case INBOUND ->
executorService.submit(() -> itemStockRequestApiService.handleRequestFromSupplier(requestMessageDto, createdRequestMessage));
default -> {
log.warn("Missing direction in request \n" + requestMessageDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public class ItemStockRequestApiService {
public void handleRequestFromCustomer(ItemStockRequestMessageDto requestMessageDto, ItemStockRequestMessage requestMessage) {
var requestMessageHeader = requestMessageDto.getHeader();
Partner customerPartner = partnerService.findByBpnl(requestMessageHeader.getSenderBpn());
if (customerPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND) {
if (customerPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND) {
requestMessage.setState(DT_RequestStateEnum.Error);
itemStockRequestMessageService.update(requestMessage);
if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND){
if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND){
log.error("Wrong direction in request from customer \n" + requestMessageDto);
}
if(customerPartner == null) {
Expand Down Expand Up @@ -140,10 +140,10 @@ public void handleRequestFromCustomer(ItemStockRequestMessageDto requestMessageD
public void handleRequestFromSupplier(ItemStockRequestMessageDto requestMessageDto, ItemStockRequestMessage requestMessage) {
var requestMessageHeader = requestMessageDto.getHeader();
Partner supplierPartner = partnerService.findByBpnl(requestMessageHeader.getSenderBpn());
if (supplierPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND) {
if (supplierPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND) {
requestMessage.setState(DT_RequestStateEnum.Error);
itemStockRequestMessageService.update(requestMessage);
if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND){
if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND){
log.error("Wrong direction in request from customer \n" + requestMessageDto);
}
if(supplierPartner == null) {
Expand Down Expand Up @@ -242,7 +242,7 @@ private void sendResponse(Partner partner, ItemStockResponseDto responseDto, Ite
*/
public void doRequestForMaterialItemStocks(Partner supplierPartner, Material... materials) {
ItemStockRequestMessage itemStockRequestMessage = getItemStockRequestMessage(supplierPartner);
itemStockRequestMessage.setDirection(DirectionCharacteristic.INBOUND);
itemStockRequestMessage.setDirection(DirectionCharacteristic.OUTBOUND);
for (var material : materials) {
ItemStockRequestMessage.Request request = new ItemStockRequestMessage.Request();
request.setMaterialGlobalAssetId(material.getMaterialNumberCx());
Expand All @@ -262,7 +262,7 @@ public void doRequestForMaterialItemStocks(Partner supplierPartner, Material...
*/
public void doRequestForProductItemStocks(Partner customerPartner, Material... materials) {
ItemStockRequestMessage itemStockRequestMessage = getItemStockRequestMessage(customerPartner);
itemStockRequestMessage.setDirection(DirectionCharacteristic.OUTBOUND);
itemStockRequestMessage.setDirection(DirectionCharacteristic.INBOUND);
for (var material : materials) {
ItemStockRequestMessage.Request request = new ItemStockRequestMessage.Request();
request.setMaterialGlobalAssetId(material.getMaterialNumberCx());
Expand Down
56 changes: 48 additions & 8 deletions local/INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,79 @@
# Initial Setup
# Creating a local testing and development setup via Docker

## Additional information for Windows users

If you want to use the local setup on a Windows machine, it seems advisable to use the Windows subsystem for Linux (WSL).
An installation guide can be found [here](https://learn.microsoft.com/en-us/windows/wsl/install).

Also see this [additional information about using Docker in combination with WSL2](https://docs.docker.com/desktop/wsl/)

## Initial Setup
In case you had any previous installations of this project on your machine, it is advisable to remove them via the script
(see below in the Notes on debugging section).
(see below in the Notes on debugging section).

Run the following script to generate the necessary keys. It will also create an .env file in the ./local folder.
Make sure to have `openssl` and `jq` installed in your shell.
Make sure to have `openssl` and `jq` installed in your shell. openssl is pre-installed on most operating systems. jq can be
installed via the usual installation repositories, see [here](https://jqlang.github.io/jq/download/)
```shell
cd local
sh generate-keys.sh
```

# Build
## Build
If you are doing a fresh install and everytime you edited the code of the PURIS frontend or backend you have to create a
new build of docker images for the PURIS frontend/backend.

For creating a docker image of the frontend, navigate your shell to the frontend folder and run

```
docker build -t puris-frontend:dev .
```

For creating a docker image of the backend, navigate your shell to the backend folder and run

```
docker build -t puris-backend:dev .
```

Please see the INSTALL.md documents in the [frontend](../frontend/INSTALL.md) and [backend](../backend/INSTALL.md)

The default image tag is 'dev'. Remember to also adjust the tag in the docker-compose.yaml if you want to use different
tags.

# Start
First start the infrastructure:
## Start
First start the infrastructure by navigating your shell to the local folder and running

```shell
docker compose -f docker-compose-infrastructure.yaml up
```
After the MIW container has finished booting, use this script to initialise two wallets for customer and supplier:
After the MIW container has finished booting, use this script (also in the local folder) to initialise two wallets for customer and supplier:
```shell
sh ./init-wallets.sh
sh init-wallets.sh
```
Then start the PURIS demonstrator containers via:
```shell
docker compose up
```
Wait for the startup and visit http://localhost:3000/ for the customer's frontend or http://localhost:3001/ for the supplier side.

Whenever you have edited the source code in the frontend or backend and you want to test these changes, we recommend that you
stop all the containers, which are not part of the infrastructure, by deleting the volumes, i.e. run

```
docker compose down -v
```

Then, build a new docker image for the respective component (frontend and/or backend) as described above and then restart via

```shell
docker compose up
```

In general, it is not necessary to restart the infrastructure, if you had to rebuild frontend or backend.
However, in rare cases there may be issues with the MIW. If this
happens, you should use the cleanup script as mentioned in the debugging section below and then repeat the above-mentioned
steps beginning with the Initial Setup section.

## Notes on debugging

### Vault & Certs
Expand Down
2 changes: 1 addition & 1 deletion local/docker-compose-infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:

postgres:

Check warning on line 34 in local/docker-compose-infrastructure.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Healthcheck Not Set

Check containers periodically to see if they are running properly.
image: postgres:15.4-alpine
container_name: postgres
container_name: postgres-miw
environment:
POSTGRES_DB: edc
POSTGRES_USER: ${PG_USER}
Expand Down
2 changes: 1 addition & 1 deletion local/miw/infrastructure.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AUTH_SERVER_URL=http://keycloak:8080
APPLICATION_PORT=80
MANAGEMENT_PORT=8090
APPLICATION_ENVIRONMENT=dev
DB_HOST=postgres
DB_HOST=postgres-miw
DB_PORT=5432
USE_SSL=false
DB_USER=${PG_USER}
Expand Down

0 comments on commit ab73db7

Please sign in to comment.