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 textListValue; private final Instant dateValue; private final ExternalIdentifier externalIdentifier; public String getTextValue() { return textValue; } public List getTextListValue() { return textListValue; } public Instant getDateValue() { return dateValue; } public ExternalIdentifier getExternalIdentifier() { return externalIdentifier; } public Field(FieldPersist persist){ List 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; } }