Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from opfab/develop
Browse files Browse the repository at this point in the history
1.1.0.RELEASE
  • Loading branch information
woueslati authored Oct 30, 2020
2 parents 905402d + bce473b commit 9cf106a
Show file tree
Hide file tree
Showing 45 changed files with 614 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/letsco-common/letsco-common.iml
/letsco-core.iml
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- SPDX-License-Identifier: CC-BY-4.0 -->

# Let's Coordinate - Getting started
<br/>

## 1. Prerequisites

Expand All @@ -30,12 +31,14 @@ git clone https://github.com/opfab/letscoordinate.git

#### 2.2. Run Operator Fabric

> /!\ The minimal required version of OperatorFabric is: **1.7.0.RELEASE**
Clone the *operatorfabric-getting-started* git project:
```
git clone https://github.com/opfab/operatorfabric-getting-started.git
```

Copy files "*web-ui.json*", "*docker-compose.yml*" and "*favicon.ico*" from "*letscoordinate/test/prepare-opfab-env/opfab-config*" directory and past them into "*operatorfabric-getting-started/server*". Overwrite the existing files when asked!
Copy files "*docker-compose.yml*", "*favicon.ico*", "*ngnix.conf*" and "*web-ui.json*" from "*letscoordinate/test/prepare-opfab-env/opfab-config*" directory and past them into "*operatorfabric-getting-started/server*". Overwrite the existing files when asked!

In the directory "*operatorfabric-getting-started/server*" launch the following command:
```
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

version: '3.7'
version: '3.3'

services:
zookeeper:
Expand Down
22 changes: 22 additions & 0 deletions dockerfiles/front/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2020, RTE (https://www.rte-france.com)
# Copyright (c) 2020 RTE international (https://www.rte-international.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

FROM nginx

RUN rm /etc/nginx/nginx.conf
RUN mkdir /var/www
RUN mkdir /var/www/letsco

COPY ./nginx.conf /etc/nginx
COPY ./letsco-front /var/www/letsco

RUN rm /var/www/letsco/letsco-env/env.js

EXPOSE 80
EXPOSE 8080
20 changes: 20 additions & 0 deletions dockerfiles/front/Dockerfile-with-envjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2020, RTE (https://www.rte-france.com)
# Copyright (c) 2020 RTE international (https://www.rte-international.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

FROM nginx

RUN rm /etc/nginx/nginx.conf
RUN mkdir /var/www
RUN mkdir /var/www/letsco

COPY ./nginx.conf /etc/nginx
COPY ./letsco-front /var/www/letsco

EXPOSE 80
EXPOSE 8080
50 changes: 50 additions & 0 deletions dockerfiles/front/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2020, RTE (https://www.rte-france.com)
# Copyright (c) 2020 RTE international (https://www.rte-international.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

server {
listen 8080;
server_name localhost;
location / {
root /var/www/letsco;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}
30 changes: 30 additions & 0 deletions dockerfiles/front/run_locally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Copyright (c) 2020, RTE (https://www.rte-france.com)
# Copyright (c) 2020 RTE international (https://www.rte-international.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

if [ ! -z $1 ]; then
tag=$1
echo "Tag: $tag"
else
echo "You must specify a tag"
exit 1
fi

cd ../../letsco-front
ng build --prod --base-href /letsco --deploy-url /letsco/
cd -
rm -rf ./letsco-front
cp -r ../../letsco-front/dist/letsco-front .
JS_FILES=$(ls letsco-front/ | grep -E '(\.js|\.css|assets)' | xargs echo)
cd letsco-front/ && mv $JS_FILES letsco && cd -

docker build --tag=nginx-letsco-front -f ./Dockerfile-with-envjs . && \
docker stop nginx-letsco ; docker rm nginx-letsco ; \
docker run -d -p 4200:8080 --name nginx-letsco nginx-letsco-front
37 changes: 37 additions & 0 deletions dockerfiles/front/todo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Copyright (c) 2020, RTE (https://www.rte-france.com)
# Copyright (c) 2020 RTE international (https://www.rte-international.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of the Let’s Coordinate project.

if [ ! -z $1 ]; then
tag=$1
echo "Tag: $tag"
else
echo "You must specify a tag"
exit 1
fi

cd ../../letsco-front
ng build --prod --base-href /letsco --deploy-url /letsco/
cd -
rm -rf ./letsco-front
cp -r ../../letsco-front/dist/letsco-front .
JS_FILES=$(ls letsco-front/ | grep -E '(\.js|\.css|assets)' | xargs echo)
cd letsco-front/ && mv $JS_FILES letsco && cd -
docker build --tag=letscoordinate/frontend:latest .
docker build --tag=letscoordinate/frontend:${tag} .
docker push letscoordinate/frontend:latest
docker push letscoordinate/frontend:${tag}

if [ ! -z $runLocally ]; then
docker build --tag=nginx-letsco-front -f ./Dockerfile-with-env.js . && \
docker stop nginx-letsco ; sudo docker rm nginx-letsco ; \
docker run -d -p 4200:8080 --name nginx-letsco nginx-letsco-front
fi

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.lfenergy.letscoordinate.backend.config.OpfabConfig;
import org.lfenergy.letscoordinate.backend.dto.eventmessage.EventMessageDto;
import org.lfenergy.letscoordinate.backend.dto.eventmessage.header.BusinessDataIdentifierDto;
import org.lfenergy.letscoordinate.backend.dto.eventmessage.payload.ValidationDto;
import org.lfenergy.letscoordinate.backend.dto.eventmessage.payload.ValidationMessageDto;
import org.lfenergy.letscoordinate.backend.enums.ValidationSeverityEnum;
import org.lfenergy.letscoordinate.backend.model.opfab.ValidationData;
Expand Down Expand Up @@ -70,6 +71,21 @@ public Card generateOpfabCard(EventMessageDto eventMessageDto, Long id) {
return card;
}

String getValidationName(EventMessageDto eventMessageDto) {
ValidationSeverityEnum result = eventMessageDto.getPayload().getValidation().getResult();

switch (result) {
case OK:
return POSITIVE_ACK;
case WARNING:
return POSITIVE_ACK_WITH_WARNINGS;
case ERROR:
return NEGATIVE_ACK;
default:
return "";
}
}

void setCardHeadersAndTags(Card card, EventMessageDto eventMessageDto, Long id) {

String source = eventMessageDto.getHeader().getSource();
Expand All @@ -93,7 +109,21 @@ public void setOpfabCardDates(Card card, EventMessageDto eventMessageDto) {
Instant businessDayTo = businessDataIdentifierDto.getBusinessDayTo()
.orElse(businessDayFrom.plus(Duration.ofHours(24)));

card.setTimeSpans(Collections.singletonList(new TimeSpan().start(businessDayFrom).end(businessDayTo)));
List<TimeSpan> timeSpans = new ArrayList<>();
ValidationDto validation = eventMessageDto.getPayload().getValidation();
if (validation != null && validation.getValidationMessages().isPresent() && !validation.getValidationMessages().get().isEmpty()) {
// LC-208 MR-1: If the card contains validation errors and/or warnings, we display a bubble in the timeline
// for each error and/or warning found. No bubble to display for the card’s arrival time in this case.
timeSpans = validation.getValidationMessages().get().stream()
.map(validationMessage -> new TimeSpan().start(validationMessage.getTimestamp()))
.collect(Collectors.toList());
} else {
// LC-207 MR-1 & LC-208 MR-2: If the card does not contain any validation error or warning, we display only
// one bubble for the card’s arrival time in feed
timeSpans.add(new TimeSpan().start(timestamp));
}

card.setTimeSpans(timeSpans);
card.setPublishDate(timestamp);
card.setStartDate(businessDayFrom);
card.setEndDate(businessDayTo);
Expand All @@ -111,21 +141,28 @@ void setCardRecipients(Card card, EventMessageDto eventMessageDto) {

card.setRecipient(new Recipient().type(RecipientEnum.GROUP).identity(source));

Set<String> entityRecipients = new HashSet<>();
tso.ifPresent(entityRecipients::add);
if (opfabConfig.getEntityRecipientsNotAllowed().containsKey(processKey)) {
List<String> recipientsNotAllowed = opfabConfig.getEntityRecipientsNotAllowed().get(processKey);
if (!recipientsNotAllowed.contains("sendingUser")) {
sendingUser.ifPresent(entityRecipients::add);
Set<String> entityRecipientList = new HashSet<>();
tso.ifPresent(entityRecipientList::add);
if (opfabConfig.getEntityRecipients().containsKey(processKey)) {
OpfabConfig.OpfabEntityRecipients entityRecipients = opfabConfig.getEntityRecipients().get(processKey);
if (!entityRecipients.getNotAllowed().equals("sendingUser")) {
sendingUser.ifPresent(entityRecipientList::add);
}
if (!recipientsNotAllowed.contains("recipient")) {
recipient.ifPresent(entityRecipients::addAll);
if (!entityRecipients.getNotAllowed().equals("recipient")) {
recipient.ifPresent(entityRecipientList::addAll);
}
} else {
sendingUser.ifPresent(entityRecipients::add);
recipient.ifPresent(entityRecipients::addAll);
if (entityRecipients.isAddRscs()) {
entityRecipientList.addAll(tsos.entrySet().stream()
.filter(t -> entityRecipientList.contains(t.getKey()))
.map(Map.Entry::getValue)
.map(CoordinationConfig.Tso::getRsc).collect(Collectors.toList()));
}
}else {
sendingUser.ifPresent(entityRecipientList::add);
recipient.ifPresent(entityRecipientList::addAll);
}
card.setEntityRecipients(new ArrayList<>(entityRecipients));
card.setEntityRecipients(new ArrayList<>(entityRecipientList));

}

void specificCardTreatment(Card opfabCard, EventMessageDto eventMessageDto, Long cardId) {
Expand Down Expand Up @@ -184,7 +221,7 @@ void specificCardTreatment(Card opfabCard, EventMessageDto eventMessageDto, Long
}

private String generateFeedTitle(String source, String messageTypeName, String titleProcessType,
Optional<String> processStep, EventMessageDto eventMessageDto) {
Optional<String> processStep, EventMessageDto eventMessageDto) {

String key = source + "_" + messageTypeName;
if (opfabConfig.getFeed().containsKey(key)) {
Expand Down Expand Up @@ -232,7 +269,7 @@ String replacePlaceholders(String title, EventMessageDto eventMessageDto) {
while (m.find()) {
allMatches.put(m.group(), null);
}
allMatches = allMatches.entrySet().stream().map(e -> generatePlaceholderValue(e, bdiMap))
allMatches = allMatches.entrySet().stream().map(e -> generatePlaceholderValue(e, bdiMap,eventMessageDto))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

for (Map.Entry<String, String> entry : allMatches.entrySet())
Expand All @@ -242,7 +279,7 @@ String replacePlaceholders(String title, EventMessageDto eventMessageDto) {
}
}

Map.Entry<String, String> generatePlaceholderValue(Map.Entry<String, String> entry, Map<String, Object> bdiMap) {
Map.Entry<String, String> generatePlaceholderValue(Map.Entry<String, String> entry, Map<String, Object> bdiMap, EventMessageDto eventMessageDto) {

String placeholder = entry.getKey();
String placeholderValue = null;
Expand All @@ -266,7 +303,10 @@ Map.Entry<String, String> generatePlaceholderValue(Map.Entry<String, String> ent
} if ("eicToName".equals(formatMethod)) {
placeholderValue = tsos.get(bdiMap.get(placeholderNoDelimiters)).getName();
return new AbstractMap.SimpleEntry(placeholder, placeholderValue);
} else {
} else if ("notificationTitle".equals(formatMethod)) {
placeholderValue = getValidationName(eventMessageDto);
return new AbstractMap.SimpleEntry(placeholder, placeholderValue);
}else{
log.error("The placeholder method " + formatMethod + "is not valid!");
placeholderValue = bdiMap.get(placeholderNoDelimiters) != null ?
bdiMap.get(placeholderNoDelimiters).toString() : "";
Expand Down Expand Up @@ -304,6 +344,13 @@ private void messageValidatedTreatment(Card card, EventMessageDto eventMessageDt
data.setWarnings(warnings);
data.setErrors(errors);
});
if (eventMessageDto != null && eventMessageDto.getHeader() != null && eventMessageDto.getHeader().getProperties() != null
&& eventMessageDto.getHeader().getProperties().getBusinessDataIdentifier() != null
&& eventMessageDto.getHeader().getProperties().getBusinessDataIdentifier().getSendingUser().isPresent()) {
String sendingUserEicCode = eventMessageDto.getHeader().getProperties().getBusinessDataIdentifier().getSendingUser().get();
if (tsos.get(sendingUserEicCode) != null)
data.setSendingUser(tsos.get(sendingUserEicCode).getName());
}
card.setData(data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ public class OpfabConfig {
private String publisher;
private OpfabUrls url;
private Map<String, OpfabFeed> feed = new HashMap<>();
private Map<String, List<String>> entityRecipientsNotAllowed = new HashMap<>();
private Map<String, OpfabEntityRecipients> entityRecipients = new HashMap<>();

@Getter
@Setter
public static class OpfabUrls {
private String cardsPub;
}

@Getter
@Setter
public static class OpfabEntityRecipients {
private boolean addRscs;
private String notAllowed;
}

@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ValidationData extends EventMessageDto {

List<ValidationMessageDto> warnings;
List<ValidationMessageDto> errors;
String sendingUser;

public ValidationData(EventMessageDto eventMessageDto) {
super(eventMessageDto.getXmlns(), eventMessageDto.getHeader(), eventMessageDto.getPayload());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public final class StringUtil {
public static final String PROCESS_INFORMATION = "ProcessInformation";
public static final String MESSAGE_VALIDATED = "DfgMessageValidated";

public static final String POSITIVE_ACK = "Positive ACK";
public static final String POSITIVE_ACK_WITH_WARNINGS = "Positive ACK with warnings";
public static final String NEGATIVE_ACK = "Negative ACK";

/**
* <p>This function allows to split an input string according to a separator after removing all spaces from it
* if and only if the input string contains the separator</p>
Expand Down
Loading

0 comments on commit 9cf106a

Please sign in to comment.