Skip to content

Commit

Permalink
Merge pull request #250 from com-pas/241-updatedai-val-does-not-produ…
Browse files Browse the repository at this point in the history
…ce-subelements-sdi-as-expected

fix(#241): updateDai does not create DOI SDI DAI as expected
  • Loading branch information
massifben authored Mar 16, 2023
2 parents 2258b1a + 94ca16f commit 62aeade
Show file tree
Hide file tree
Showing 18 changed files with 890 additions and 576 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class ResumedDataTemplate {
private DaTypeName daName = new DaTypeName("");

/**
* Copies sumarized DataTypeTemplate informations to another one
* Copies summarized DataTypeTemplate information to another one
* @param dtt input
* @return Updated ResumedDataTemplate object
*/
Expand Down Expand Up @@ -89,7 +90,7 @@ public String getObjRef(String iedName, String ldInst){
}

/**
* Gets LNode reference informations
* Gets LNode reference information
* @return String LNode information concatenated
*/
@JsonIgnore
Expand Down Expand Up @@ -335,10 +336,13 @@ public boolean isValImport(){
return daName.isValImport();
}

/**
* Set Val of DA
* @param daiValue daiValue to set
* @return this
*/
public ResumedDataTemplate setVal(String daiValue) {
TVal newDaiVal = new TVal();
newDaiVal.setValue(daiValue);
this.setDaiValues(List.of(newDaiVal));
this.setDaiValues(List.of(SclConstructorHelper.newVal(daiValue)));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@
import org.lfenergy.compas.scl2007b4.model.TDAI;
import org.lfenergy.compas.scl2007b4.model.TDOI;
import org.lfenergy.compas.scl2007b4.model.TPrivate;
import org.lfenergy.compas.scl2007b4.model.TVal;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.util.CommonConstants;

import java.util.Map;

import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal;

/**
* A representation of the model object
* <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.AbstractDAIAdapter AbstractDAIAdapter}</b></em>.
* <p>
* The following features are supported:
* </p>
* <ol>
* <li>Adapter</li>
* <ul>
* <li>{@link AbstractDAIAdapter#getStructuredDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference</em>}</li>
* <li>{@link AbstractDAIAdapter#getDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference By Name</em>}</li>
* </ul>
* <li>Principal functions</li>
* <ul>
* <li>{@link AbstractDAIAdapter#addDAI(String) <em>Add <b>TDAI </b> under this object</em>}</li>
* <li>{@link AbstractDAIAdapter#addSDOI(String) <em>Add <b>TSDI </b> under this object</em>}</li>
* <li>{@link AbstractDAIAdapter#update(Long, String) <em>Update <b>TDAI</b> (sGroup, value)</em>}</li>
* <li>{@link AbstractDAIAdapter#update(Map) <em>Update Many <b>TDAI</b> (sGroup, value)</em>}</li>
* <li>{@link AbstractDAIAdapter#addPrivate(TPrivate) <em>Add <b>TPrivate </b> under this object</em>}</li>
Expand All @@ -52,30 +46,6 @@ protected AbstractDAIAdapter(P parentAdapter, TDAI currentElem) {
super(parentAdapter, currentElem);
}

/**
* Gets SDI from DAI by name
*
* @param sName SDI name
* @param <S> expected class type
* @return <em>IDataAdapter</em> related object
* @throws ScdException throws when specified SDI not present in DAI
*/
public <S extends IDataAdapter> S getStructuredDataAdapterByName(String sName) throws ScdException {
throw new UnsupportedOperationException("DAI doesn't have any SDI");
}

/**
* Gets DataAdapter by DAI
*
* @param sName DAI name
* @param <S> expected class type
* @return <em>IDataAdapter</em> related object
* @throws ScdException throws when specified DAI unknown
*/
public <S extends IDataAdapter> S getDataAdapterByName(String sName) throws ScdException {
throw new UnsupportedOperationException("DAI doesn't have any DAI");
}

/**
* Sets <em>ValImport</em> value
*
Expand Down Expand Up @@ -104,7 +74,7 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
}

/**
* Updates DAI SGroup value
* Updates DAI SGroup value. This method checks if DAI is updatable.
*
* @param sGroup SGroup to update
* @param val value
Expand All @@ -118,42 +88,31 @@ public void update(Long sGroup, String val) throws ScdException {
throw new ScdException(msg);
}
if (sGroup != null && sGroup != 0) {
updateSGroupVal(sGroup, val);
setSGroupVal(sGroup, val);
} else {
updateVal(val);
setVal(val);
}
}

private void updateSGroupVal(Long sGroup, String val) {
private void setSGroupVal(Long sGroup, String value) {
currentElem.getVal().stream()
.filter(tValElem -> tValElem.isSetSGroup() && sGroup.equals(tValElem.getSGroup()))
.findFirst()
.orElseGet(
() -> {
TVal newTVal = new TVal();
newTVal.setSGroup(sGroup);
currentElem.getVal().add(newTVal);
return newTVal;
})
.setValue(val);
.ifPresentOrElse(
tVal -> tVal.setValue(value),
() -> currentElem.getVal().add(newVal(value, sGroup)));
}

public void updateVal(String s) {
/**
* Set Val (without sGroup) for DAI without checking if DAI is updatable
* @param value new value
*/
public void setVal(String value) {
currentElem.getVal().stream().findFirst()
.orElseGet(
() -> {
TVal newTVal = new TVal();
currentElem.getVal().add(newTVal);
return newTVal;
})
.setValue(s);
}
.ifPresentOrElse(
tVal -> tVal.setValue(value),
() -> currentElem.getVal().add(newVal(value)));

public IDataAdapter addDAI(String name) {
throw new UnsupportedOperationException("DAI cannot contain an SDI");
}

public IDataAdapter addSDOI(String sdoName) {
throw new UnsupportedOperationException("DAI cannot contain an DAI");
}
}
Loading

0 comments on commit 62aeade

Please sign in to comment.