Skip to content

Commit

Permalink
feat(#332): move FCDA parameter csv file management out of compas
Browse files Browse the repository at this point in the history
Signed-off-by: Aliou DIAITE <aliou.diaite@rte-france.com>
  • Loading branch information
AliouDIAITE committed Oct 5, 2023
1 parent 4a14304 commit 5f85824
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 20,296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
import org.lfenergy.compas.sct.commons.exception.ScdException;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public enum FcdaCandidates {
SINGLETON;

private static final String FCDA_CONSTRAINTS_FILE_NAME = "FcdaCandidates.csv";

@Getter
private Set<FcdaCandidate> candidates;

/**
Expand All @@ -27,26 +27,30 @@ public enum FcdaCandidates {
*/
public boolean contains(DataAttributeRef dataAttributeRef) {
return contains(dataAttributeRef.getLnClass(),
dataAttributeRef.getDoName().toStringWithoutInst(),
dataAttributeRef.getDaName().toString(),
dataAttributeRef.getFc().value());
dataAttributeRef.getDoName().toStringWithoutInst(),
dataAttributeRef.getDaName().toString(),
dataAttributeRef.getFc().value());
}

boolean contains(String lnClass, String doName, String daName, String fc) {
if (StringUtils.isBlank(lnClass)
|| StringUtils.isBlank(doName)
|| StringUtils.isBlank(daName)
|| StringUtils.isBlank(fc)) {
if (StringUtils.isBlank(lnClass) || StringUtils.isBlank(doName) || StringUtils.isBlank(daName) || StringUtils.isBlank(fc)) {
throw new IllegalArgumentException("parameters must not be blank");
}

if (candidates == null) {
// using a HashSet because "HashSet.contains" is faster than "ArrayList.contains"
candidates = new HashSet<>(CsvUtils.parseRows(FCDA_CONSTRAINTS_FILE_NAME, StandardCharsets.UTF_8, FcdaCandidate.class));
if (this.candidates == null || this.candidates.isEmpty()) {
throw new ScdException("Accepted FCDAs list is empty, you should set candidates in FcdaCandidates.class before");
}
return candidates.contains(new FcdaCandidate(lnClass, doName, daName, fc));
}

/**
* Allow to set the list of accepted FCDA
*
* @param fcdaWhiteList list of accepted FCDA
*/
public void setCandidates(List<FcdaCandidate> fcdaWhiteList) {
this.candidates = new HashSet<>(fcdaWhiteList);
}

@NoArgsConstructor
@AllArgsConstructor
@Getter
Expand Down
Loading

0 comments on commit 5f85824

Please sign in to comment.