argos/dmp-backend/core/src/main/java/eu/eudat/service/visibility/Field.java

69 lines
2.0 KiB
Java

package eu.eudat.service.visibility;
import eu.eudat.commons.types.description.FieldEntity;
import eu.eudat.model.persist.descriptionproperties.FieldPersist;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
public class Field {
private final String textValue;
private final List<String> textListValue;
private final Instant dateValue;
private final ExternalIdentifier externalIdentifier;
public String getTextValue() {
return textValue;
}
public List<String> getTextListValue() {
return textListValue;
}
public Instant getDateValue() {
return dateValue;
}
public ExternalIdentifier getExternalIdentifier() {
return externalIdentifier;
}
public Field(FieldPersist persist){
List<String> tempTextListValue;
this.textValue = persist.getTextValue();
this.dateValue = persist.getDateValue();
tempTextListValue = persist.getTextListValue();
if (persist.getExternalIdentifier() != null) this.externalIdentifier = new ExternalIdentifier(persist.getExternalIdentifier());
else this.externalIdentifier = null;
if (persist.getReference() != null) {
if (persist.getReferences() == null) persist.setReferences(new ArrayList<>());
persist.getReferences().add(persist.getReference());
}
if (persist.getReferences() != null && !persist.getReferences().isEmpty()){
tempTextListValue = persist.getReferences().stream().filter(x-> x.getId() != null).map(x-> x.getId().toString()).toList();
}
this.textListValue = tempTextListValue;
}
public Field(FieldEntity entity){
this.textValue = entity.getTextValue();
this.dateValue = entity.getDateValue();
this.textListValue = entity.getTextListValue();
if (entity.getExternalIdentifier() != null) this.externalIdentifier = new ExternalIdentifier(entity.getExternalIdentifier());
else this.externalIdentifier = null;
}
}