Skip to content

Commit

Permalink
Merge pull request #106 from com-pas/fix/70-some-DA-should-not-be-upd…
Browse files Browse the repository at this point in the history
…atable

[#70] : all updatable DA should be returned

Signed-off-by: massifben <105049157+massifben@users.noreply.github.com>
  • Loading branch information
massifben authored Jun 3, 2022
2 parents 51b311d + 9478609 commit cee4f8a
Show file tree
Hide file tree
Showing 24 changed files with 1,116 additions and 372 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -141,4 +141,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

package org.lfenergy.compas.sct.commons.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,12 +15,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class DaTypeName extends DataTypeName{
public static final String VALIDATION_REGEX
= "[a-zA-Z][a-zA-Z0-9]*(\\([0-9]+\\))?(\\.[a-zA-Z][a-zA-Z0-9]*(\\([0-9]+\\))?)*";
Expand All @@ -37,6 +34,10 @@ public DaTypeName(String daName) {
super(daName);
}

public DaTypeName(String name, String names) {
super(name, names);
}

public static DaTypeName from(DaTypeName dataName){
DaTypeName daTypeName = new DaTypeName(dataName.toString());
if(dataName.isDefined()) {
Expand All @@ -50,11 +51,6 @@ public static DaTypeName from(DaTypeName dataName){
return daTypeName;
}


public DaTypeName(String name, String names) {
super(name, names);
}

public boolean isValImport(){
return valImport;
}
Expand Down Expand Up @@ -94,22 +90,6 @@ public void addDaiValue(Long sg, String val) {
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || o.getClass() != getClass()) return false;
if (!super.equals(o)) return false;
DaTypeName that = (DaTypeName) o;
return fc == that.fc &&
Objects.equals(bType, that.bType) &&
Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), fc, bType, type);
}

public void merge(DaTypeName daName) {
if(!isDefined()) return;
fc = daName.fc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,41 @@
package org.lfenergy.compas.sct.commons.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;


@Getter
@Setter
@Slf4j
@NoArgsConstructor
@EqualsAndHashCode
public class DataTypeName {
protected String name = ""; // dataName or DataAttributeName

private List<String> structNames = new ArrayList<>(); // [.DataName[…]] or [.DAComponentName[ ….]]

public DataTypeName(String dataName){
if(dataName == null) return;

String[] tokens = dataName.split("\\.");
name = tokens[0];
if(tokens.length > 1){
int idx = dataName.indexOf(".");
tokens = dataName.substring(idx + 1).split("\\.");
structNames = Stream.of(tokens).collect(Collectors.toList());
structNames.addAll(List.of(tokens).subList(1, tokens.length));
}
}

public DataTypeName(String name, String names){
if(name == null) return;
this.name = name;
if (StringUtils.isNotBlank(names)){
structNames.addAll(List.of(names.split("\\.")));
}
}

Expand All @@ -49,12 +51,6 @@ public boolean isDefined(){
return !StringUtils.isBlank(name);
}

public DataTypeName(String name, @NonNull String names){
this.name = name;
String[] tokens = names.split("\\.");
structNames = Stream.of(tokens).collect(Collectors.toList());
}

@Override
public String toString(){
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -66,21 +62,6 @@ public String toString(){
return stringBuilder.toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o==null || o.getClass() != getClass()) return false;
DataTypeName that = (DataTypeName) o;
return Objects.equals(name, that.name) &&
Arrays.equals(structNames.toArray(new String[0]),
that.structNames.toArray(new String[0]));
}

@Override
public int hashCode() {
return Objects.hash(name, structNames);
}

public void addStructName(String structName) {
structNames.add(structName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

package org.lfenergy.compas.sct.commons.dto;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.lfenergy.compas.scl2007b4.model.TPredefinedCDCEnum;

import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class DoTypeName extends DataTypeName {
public static final String VALIDATION_REGEX = "[A-Z][0-9A-Za-z]{0,11}(\\.[a-z][0-9A-Za-z]*(\\([0-9]+\\))?)?";
private TPredefinedCDCEnum cdc;
Expand All @@ -35,20 +33,6 @@ public static DoTypeName from(DoTypeName dataName){
return doTypeName;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || o.getClass() !=getClass()) return false;
if (!super.equals(o)) return false;
DoTypeName that = (DoTypeName) o;
return cdc == that.cdc;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), cdc);
}

public void merge(DoTypeName doName) {
if(!isDefined()) return;
if(cdc == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.sct.commons.Utils;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
Expand Down Expand Up @@ -92,11 +90,11 @@ public static <T extends TAnyLN> LNodeDTO from(AbstractLNAdapter<T> nodeAdapter,
)
)
);
ResumedDataTemplate filter = new ResumedDataTemplate();
filter.setLnInst(nodeAdapter.getLNInst());
filter.setLnClass(nodeAdapter.getLNClass());
filter.setPrefix(nodeAdapter.getPrefix());
filter.setLnType(nodeAdapter.getLnType());
ResumedDataTemplate filter = ResumedDataTemplate.builder()
.lnInst(nodeAdapter.getLNInst())
.lnClass(nodeAdapter.getLNClass())
.prefix(nodeAdapter.getPrefix())
.lnType(nodeAdapter.getLnType()).build();
List<ResumedDataTemplate> resumedDataTemplateList = lNodeTypeAdapter.getResumedDTTs(filter);
lNodeDTO.addAllResumedDataTemplate(resumedDataTemplateList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
package org.lfenergy.compas.sct.commons.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.lfenergy.compas.scl2007b4.model.TFCEnum;
import org.lfenergy.compas.scl2007b4.model.TLLN0Enum;
import org.lfenergy.compas.scl2007b4.model.TPredefinedBasicTypeEnum;
import org.lfenergy.compas.scl2007b4.model.TPredefinedCDCEnum;
import org.lfenergy.compas.scl2007b4.model.TVal;
import lombok.*;
import org.lfenergy.compas.scl2007b4.model.*;

import java.util.ArrayList;
import java.util.List;

import java.util.*;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@Builder(toBuilder = true)
public class ResumedDataTemplate {

private String prefix;
private String lnType;
private String lnClass;
private String lnInst;
@Builder.Default
@NonNull
private DoTypeName doName = new DoTypeName("");
@Builder.Default
@NonNull
private DaTypeName daName = new DaTypeName("");

public static ResumedDataTemplate copyFrom(ResumedDataTemplate dtt){
Expand All @@ -41,27 +44,29 @@ public static ResumedDataTemplate copyFrom(ResumedDataTemplate dtt){
}

public boolean isUpdatable(){
return daName.isDefined() && daName.isUpdatable();
return daName.isDefined() && daName.isUpdatable();
}

@JsonIgnore
public String getObjRef(String iedName, String ldInst){
StringBuilder stringBuilder = new StringBuilder();
//LDName
stringBuilder.append(iedName)
.append(ldInst)
.append("/");
return iedName + ldInst + "/" + getLNRef();
}

@JsonIgnore
public String getLNRef(){
StringBuilder stringBuilder = new StringBuilder();
if(TLLN0Enum.LLN_0.value().equals(lnClass)){
stringBuilder.append(TLLN0Enum.LLN_0.value());
} else {
stringBuilder.append(prefix)
.append(lnClass)
.append(lnInst);
.append(lnClass)
.append(lnInst);
}
stringBuilder.append('.')
.append(getDoRef())
.append('.')
.append(getDaRef());
.append(getDoRef())
.append('.')
.append(getDaRef());

return stringBuilder.toString();
}
Expand Down Expand Up @@ -120,13 +125,19 @@ public List<String> getBdaNames(){
return List.of(daName.getStructNames().toArray(new String[0]));
}

public <T extends DataTypeName> void addStructName(String structName, Class<T> cls){
if(cls.equals(DaTypeName.class) && isDaNameDefined()) {
daName.addStructName(structName);
} else if(cls.equals(DoTypeName.class) && isDoNameDefined()) {
public void addDoStructName(String structName){
if(isDoNameDefined()) {
doName.addStructName(structName);
} else {
throw new IllegalArgumentException("Cannot add Struct name for undefined data type");
throw new IllegalArgumentException("DO name must be defined before adding DO StructName");
}
}

public void addDaStructName(String structName){
if(isDaNameDefined()) {
daName.addStructName(structName);
} else {
throw new IllegalArgumentException("DA name must be defined before adding DA StructName");
}
}

Expand Down Expand Up @@ -190,7 +201,6 @@ public void setValImport(boolean valImport) {
}
}


public boolean isValImport(){
return daName.isValImport();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public static Set<ResumedDataTemplate> getDAI(SCL scd, String iedName, String ld
);

return lDeviceAdapter.getDAI(rDtt, updatable);

}

public static void updateDAI(SCL scd, String iedName, String ldInst, ResumedDataTemplate rDtt) throws ScdException {
Expand Down
Loading

0 comments on commit cee4f8a

Please sign in to comment.