diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java index 25a91b29c18d..1ea39b946112 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/TrackerIdentifierCollector.java @@ -102,8 +102,6 @@ private void collectTrackedEntities( addIdentifier(identifiers, TrackedEntityType.class, trackedEntity.getTrackedEntityType()); addIdentifier(identifiers, OrganisationUnit.class, trackedEntity.getOrgUnit()); - collectEnrollments(identifiers, trackedEntity.getEnrollments()); - trackedEntity .getAttributes() .forEach( @@ -123,7 +121,6 @@ private void collectEnrollments( addIdentifier(identifiers, OrganisationUnit.class, enrollment.getOrgUnit()); collectNotes(identifiers, enrollment.getNotes()); - collectEvents(identifiers, enrollment.getEvents()); enrollment .getAttributes() .forEach( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java index f5a61780045f..37c0cb4e510f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/TrackerObjectsMapper.java @@ -28,10 +28,6 @@ package org.hisp.dhis.tracker.imports.bundle; import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; -import static org.hisp.dhis.program.EnrollmentStatus.COMPLETED; -import static org.hisp.dhis.relationship.RelationshipEntity.PROGRAM_INSTANCE; -import static org.hisp.dhis.relationship.RelationshipEntity.PROGRAM_STAGE_INSTANCE; -import static org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE; import java.util.Date; import java.util.Optional; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java index 24aa7260154c..ef10e90f6756 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Attribute.java @@ -29,12 +29,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; -import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.hisp.dhis.common.ValueType; /** * @author Morten Olav Hansen @@ -43,21 +41,10 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class Attribute implements Serializable { @JsonProperty private MetadataIdentifier attribute; - @JsonProperty private String code; // remove - - @JsonProperty private String displayName; // remove - - @JsonProperty private Instant createdAt; // remove - - @JsonProperty private Instant updatedAt; // remove - @JsonProperty private String storedBy; - @JsonProperty private ValueType valueType; // remove - @JsonProperty private String value; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java index e62a4c6116aa..78a933a777e5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/DataValue.java @@ -42,7 +42,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields +// TODO(DHIS2-18223) Remove unused fields when fixing data values logic public class DataValue implements Serializable { @JsonProperty private Instant createdAt; // remove @@ -55,8 +55,4 @@ public class DataValue implements Serializable { @JsonProperty private MetadataIdentifier dataElement; @JsonProperty private String value; - - @JsonProperty private User createdBy; // remove - - @JsonProperty private User updatedBy; // remove } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java index 05f6ba440b0f..9fc015c798d8 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Enrollment.java @@ -47,16 +47,11 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class Enrollment implements TrackerDto, Serializable { @JsonProperty private String enrollment; - @JsonProperty private Instant createdAt; // remove - @JsonProperty private Instant createdAtClient; - @JsonProperty private Instant updatedAt; // remove - @JsonProperty private Instant updatedAtClient; @JsonProperty private String trackedEntity; @@ -73,25 +68,10 @@ public class Enrollment implements TrackerDto, Serializable { @JsonProperty private boolean followUp; - @JsonProperty private String completedBy; // remove - - @JsonProperty private Instant completedAt; // remove - - @JsonProperty private boolean deleted; // remove - @JsonProperty private String storedBy; - @JsonProperty private User createdBy; // remove - - @JsonProperty private User updatedBy; // remove - @JsonProperty private Geometry geometry; - @JsonProperty @Builder.Default private List events = new ArrayList<>(); // remove - - @JsonProperty @Builder.Default - private List relationships = new ArrayList<>(); // remove - @JsonProperty @Builder.Default private List attributes = new ArrayList<>(); @JsonProperty @Builder.Default private List notes = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java index 569a23b8c388..d5232846f0cc 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Event.java @@ -50,7 +50,6 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class Event implements TrackerDto, Serializable { @JsonProperty private String event; @@ -64,23 +63,14 @@ public class Event implements TrackerDto, Serializable { @JsonProperty private MetadataIdentifier orgUnit; - @JsonProperty @Builder.Default - private List relationships = new ArrayList<>(); // remove - @JsonProperty private Instant occurredAt; @JsonProperty private Instant scheduledAt; @JsonProperty private String storedBy; - @JsonProperty private boolean deleted; // remove - - @JsonProperty private Instant createdAt; // remove - @JsonProperty private Instant createdAtClient; - @JsonProperty private Instant updatedAt; // remove - @JsonProperty private Instant updatedAtClient; @JsonProperty private MetadataIdentifier attributeOptionCombo; @@ -96,10 +86,6 @@ public class Event implements TrackerDto, Serializable { @JsonProperty private User assignedUser; - @JsonProperty private User createdBy; // remove - - @JsonProperty private User updatedBy; // remove - @JsonProperty @Builder.Default private Set dataValues = new HashSet<>(); @JsonProperty @Builder.Default private List notes = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java index e5b52d852326..7eb5b3368904 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Note.java @@ -29,7 +29,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; -import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -45,15 +44,10 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class Note implements Serializable { @JsonProperty private String note; - @JsonProperty private Instant storedAt; // remove - @JsonProperty private String value; - @JsonProperty private User createdBy; // remove - @JsonProperty private String storedBy; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java index d46903a91fe0..0b498be6a639 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/Relationship.java @@ -43,22 +43,13 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class Relationship implements TrackerDto, Serializable { @JsonProperty private String relationship; - @JsonProperty private String relationshipName; // remove - @JsonProperty private MetadataIdentifier relationshipType; - @JsonProperty private Instant createdAt; // remove - @JsonProperty private Instant createdAtClient; - @JsonProperty private Instant updatedAt; // remove - - @JsonProperty private boolean bidirectional; - @JsonProperty private RelationshipItem from; @JsonProperty private RelationshipItem to; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java index 2f18fc01759c..1c16bdd93861 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/TrackedEntity.java @@ -46,43 +46,27 @@ @Builder @NoArgsConstructor @AllArgsConstructor -// TODO(DHIS2-18222) Remove unused fields public class TrackedEntity implements TrackerDto, Serializable { @JsonProperty private String trackedEntity; @JsonProperty private MetadataIdentifier trackedEntityType; - @JsonProperty private Instant createdAt; // remove - @JsonProperty private Instant createdAtClient; - @JsonProperty private Instant updatedAt; // remove - @JsonProperty private Instant updatedAtClient; @JsonProperty private MetadataIdentifier orgUnit; @JsonProperty private boolean inactive; - @JsonProperty private boolean deleted; // remove - @JsonProperty private boolean potentialDuplicate; @JsonProperty private Geometry geometry; @JsonProperty private String storedBy; - @JsonProperty private User createdBy; // remove - - @JsonProperty private User updatedBy; // remove - - @JsonProperty @Builder.Default - private List relationships = new ArrayList<>(); // remove - @JsonProperty @Builder.Default private List attributes = new ArrayList<>(); - @JsonProperty @Builder.Default private List enrollments = new ArrayList<>(); // remove - @Override public String getUid() { return this.trackedEntity; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java index 0509c17bad16..58fc980d024a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/domain/User.java @@ -48,10 +48,6 @@ public class User implements Serializable { @JsonProperty private String username; - @JsonProperty private String firstName; - - @JsonProperty private String surname; - public boolean isEmpty() { return isBlank(uid) && isBlank(username); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessor.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessor.java deleted file mode 100644 index cdbebe1f0cfb..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.preprocess; - -import org.hisp.dhis.relationship.RelationshipType; -import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; -import org.springframework.stereotype.Component; - -/** - * This preprocessor is responsible for populating the bidirectional field with the value from the - * RelationshipType - * - * @author Enrico Colasante - */ -@Component -public class BidirectionalRelationshipsPreProcessor implements BundlePreProcessor { - - @Override - public void process(TrackerBundle bundle) { - bundle - .getRelationships() - .forEach( - rel -> { - RelationshipType relType = - bundle.getPreheat().getRelationshipType(rel.getRelationshipType()); - if (relType != null) { - rel.setBidirectional(relType.isBidirectional()); - } - }); - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java index 211b4f58a957..fa16817ae8c0 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapper.java @@ -160,8 +160,6 @@ private static TrackedEntity mapTrackedEntity( .attributes( mapTrackedEntityTypeAttributes( submission.getValues(), existingAttributeValues, programAttributes)) - .enrollments( - List.of(Enrollment.builder().enrollment(submission.getEnrollment().getUid()).build())) .build(); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java index 9d9ad97beae5..e633fa74938f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/AttributeValidator.java @@ -28,7 +28,9 @@ package org.hisp.dhis.tracker.imports.validation.validator; import static org.hisp.dhis.system.util.ValidationUtils.valueIsValid; +import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1009; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1077; +import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1084; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1085; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1112; @@ -37,9 +39,11 @@ import org.hisp.dhis.common.ValueType; import org.hisp.dhis.encryption.EncryptionStatus; import org.hisp.dhis.external.conf.DhisConfigurationProvider; +import org.hisp.dhis.fileresource.FileResource; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; +import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.domain.Attribute; import org.hisp.dhis.tracker.imports.domain.TrackerDto; import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; @@ -67,7 +71,7 @@ protected AttributeValidator( protected void validateAttrValueType( Reporter reporter, - TrackerPreheat preheat, + TrackerBundle bundle, TrackerDto dto, Attribute attr, TrackedEntityAttribute teAttr) { @@ -77,12 +81,12 @@ protected void validateAttrValueType( if (valueType.equals(ValueType.ORGANISATION_UNIT)) { error = - preheat.getOrganisationUnit(attr.getValue()) == null + bundle.getPreheat().getOrganisationUnit(attr.getValue()) == null ? " Value " + attr.getValue() + " is not a valid org unit value" : null; } else if (valueType.equals(ValueType.USERNAME)) { error = - preheat.getUserByUsername(attr.getValue()).isPresent() + bundle.getPreheat().getUserByUsername(attr.getValue()).isPresent() ? null : " Value " + attr.getValue() + " is not a valid username value"; } else { @@ -99,6 +103,35 @@ protected void validateAttrValueType( if (error != null) { reporter.addError(dto, ValidationCode.E1007, valueType, error); + } else if (valueType.isFile()) { + validateFileNotAlreadyAssigned(reporter, bundle, dto, attr.getValue()); + } + } + + protected void validateFileNotAlreadyAssigned( + Reporter reporter, + TrackerBundle bundle, + org.hisp.dhis.tracker.imports.domain.TrackerDto trackerDto, + String value) { + + FileResource fileResource = bundle.getPreheat().get(FileResource.class, value); + + reporter.addErrorIfNull(fileResource, trackerDto, E1084, value); + + if (bundle.getStrategy(trackerDto).isCreate()) { + reporter.addErrorIf( + () -> fileResource != null && fileResource.isAssigned(), trackerDto, E1009, value); + } + + if (bundle.getStrategy(trackerDto).isUpdate()) { + reporter.addErrorIf( + () -> + fileResource != null + && fileResource.getFileResourceOwner() != null + && !fileResource.getFileResourceOwner().equals(trackerDto.getUid()), + trackerDto, + E1009, + value); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidator.java index a74750ceb250..f294ce005514 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidator.java @@ -95,7 +95,7 @@ public void validate(Reporter reporter, TrackerBundle bundle, Enrollment enrollm attributeValueMap.put(attribute.getAttribute(), attribute.getValue()); validateAttributeValue(reporter, enrollment, teAttribute, attribute.getValue()); - validateAttrValueType(reporter, bundle.getPreheat(), enrollment, attribute, teAttribute); + validateAttrValueType(reporter, bundle, enrollment, attribute, teAttribute); validateOptionSet(reporter, enrollment, teAttribute, attribute.getValue()); validateAttributeUniqueness( diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidator.java index 4ceefa78e566..f19eb5aaeb78 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidator.java @@ -28,26 +28,19 @@ package org.hisp.dhis.tracker.imports.validation.validator.trackedentity; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1006; -import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1009; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1076; -import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1084; import static org.hisp.dhis.tracker.imports.validation.ValidationCode.E1090; import static org.hisp.dhis.tracker.imports.validation.validator.ValidationUtils.getTrackedEntityAttributes; import static org.hisp.dhis.tracker.imports.validation.validator.ValidationUtils.validateOptionSet; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import org.hisp.dhis.external.conf.DhisConfigurationProvider; -import org.hisp.dhis.fileresource.FileResource; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.tracker.imports.TrackerIdSchemeParams; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.domain.Attribute; @@ -122,14 +115,6 @@ protected void validateAttributes( OrganisationUnit orgUnit, TrackedEntityType trackedEntityType) { TrackerPreheat preheat = bundle.getPreheat(); - Map valueMap = new HashMap<>(); - if (te != null) { - TrackerIdSchemeParams idSchemes = preheat.getIdSchemes(); - valueMap = - te.getTrackedEntityAttributeValues().stream() - .collect( - Collectors.toMap(v -> idSchemes.toMetadataIdentifier(v.getAttribute()), v -> v)); - } for (Attribute attribute : trackedEntity.getAttributes()) { TrackedEntityAttribute tea = preheat.getTrackedEntityAttribute(attribute.getAttribute()); @@ -166,54 +151,11 @@ protected void validateAttributes( } validateAttributeValue(reporter, trackedEntity, tea, attribute.getValue()); - validateAttrValueType(reporter, preheat, trackedEntity, attribute, tea); + validateAttrValueType(reporter, bundle, trackedEntity, attribute, tea); validateOptionSet(reporter, trackedEntity, tea, attribute.getValue()); validateAttributeUniqueness( reporter, preheat, trackedEntity, attribute.getValue(), tea, te, orgUnit); - - validateFileNotAlreadyAssigned(reporter, bundle, trackedEntity, attribute, valueMap); - } - } - - protected void validateFileNotAlreadyAssigned( - Reporter reporter, - TrackerBundle bundle, - org.hisp.dhis.tracker.imports.domain.TrackedEntity te, - Attribute attr, - Map valueMap) { - - boolean attrIsFile = attr.getValueType() != null && attr.getValueType().isFile(); - if (!attrIsFile) { - return; - } - - TrackedEntityAttributeValue trackedEntityAttributeValue = valueMap.get(attr.getAttribute()); - - // Todo: how can this be possible? is this acceptable? - if (trackedEntityAttributeValue != null - && !trackedEntityAttributeValue.getAttribute().getValueType().isFile()) { - return; - } - - FileResource fileResource = bundle.getPreheat().get(FileResource.class, attr.getValue()); - - reporter.addErrorIfNull(fileResource, te, E1084, attr.getValue()); - - if (bundle.getStrategy(te).isCreate()) { - reporter.addErrorIf( - () -> fileResource != null && fileResource.isAssigned(), te, E1009, attr.getValue()); - } - - if (bundle.getStrategy(te).isUpdate()) { - reporter.addErrorIf( - () -> - fileResource != null - && fileResource.getFileResourceOwner() != null - && !fileResource.getFileResourceOwner().equals(te.getUid()), - te, - E1009, - attr.getValue()); } } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java index cdbd4a65a393..6034a1c45c0a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/FileResourceSupplierTest.java @@ -187,18 +187,11 @@ private FileResource fileResource(String uid) { } private Attribute numericAttribute() { - return Attribute.builder() - .attribute(MetadataIdentifier.ofUid("numeric")) - .valueType(ValueType.NUMBER) - .build(); + return Attribute.builder().attribute(MetadataIdentifier.ofUid("numeric")).build(); } private Attribute fileAttribute(String uid, String value) { - return Attribute.builder() - .attribute(MetadataIdentifier.ofUid(uid)) - .valueType(ValueType.FILE_RESOURCE) - .value(value) - .build(); + return Attribute.builder().attribute(MetadataIdentifier.ofUid(uid)).value(value).build(); } private TrackedEntity trackedEntity(Attribute... attributes) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java index 7e17cd88d6ba..5f7746b8f2c7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/OrgUnitValueTypeSupplierTest.java @@ -183,18 +183,11 @@ private OrganisationUnit orgUnit(String uid) { } private Attribute numericAttribute() { - return Attribute.builder() - .attribute(MetadataIdentifier.ofUid("numeric")) - .valueType(ValueType.NUMBER) - .build(); + return Attribute.builder().attribute(MetadataIdentifier.ofUid("numeric")).build(); } private Attribute orgUnitAttribute(String uid, String value) { - return Attribute.builder() - .attribute(MetadataIdentifier.ofUid(uid)) - .valueType(ValueType.ORGANISATION_UNIT) - .value(value) - .build(); + return Attribute.builder().attribute(MetadataIdentifier.ofUid(uid)).value(value).build(); } private TrackedEntity trackedEntity(Attribute... attributes) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java index 8328cc0cd314..c82eaa23c82a 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preheat/supplier/UserSupplierTest.java @@ -129,11 +129,6 @@ private Event event(User user) { private User user() { String uid = CodeGenerator.generateUid(); - return User.builder() - .uid(uid) - .username("username" + uid) - .firstName("firstName") - .surname("surname") - .build(); + return User.builder().uid(uid).username("username" + uid).build(); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessorTest.java deleted file mode 100644 index b4e0df371803..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/BidirectionalRelationshipsPreProcessorTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.tracker.imports.preprocess; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.google.common.collect.Lists; -import org.hisp.dhis.relationship.RelationshipType; -import org.hisp.dhis.test.TestBase; -import org.hisp.dhis.tracker.imports.TrackerIdSchemeParam; -import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; -import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier; -import org.hisp.dhis.tracker.imports.domain.Relationship; -import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class BidirectionalRelationshipsPreProcessorTest extends TestBase { - - private static final String RELATIONSHIP_TYPE_UID = "RELATIONSHIP_TYPE"; - - private static final String BIDIRECTIONAL_RELATIONSHIP_TYPE_UID = - "BIDIRECTIONAL_RELATIONSHIP_TYPE"; - - private final BidirectionalRelationshipsPreProcessor preProcessorToTest = - new BidirectionalRelationshipsPreProcessor(); - - @Test - void testPreprocessorPopulateRelationshipBidirectionalFieldCorrectly() { - Relationship uniDirectionalRelationship = new Relationship(); - uniDirectionalRelationship.setRelationshipType(MetadataIdentifier.ofUid(RELATIONSHIP_TYPE_UID)); - uniDirectionalRelationship.setBidirectional(true); - Relationship biDirectionalRelationship = new Relationship(); - biDirectionalRelationship.setRelationshipType( - MetadataIdentifier.ofUid(BIDIRECTIONAL_RELATIONSHIP_TYPE_UID)); - biDirectionalRelationship.setBidirectional(false); - TrackerBundle bundle = - TrackerBundle.builder() - .relationships( - Lists.newArrayList(uniDirectionalRelationship, biDirectionalRelationship)) - .preheat(getPreheat()) - .build(); - assertTrue(uniDirectionalRelationship.isBidirectional()); - assertFalse(biDirectionalRelationship.isBidirectional()); - preProcessorToTest.process(bundle); - assertFalse(uniDirectionalRelationship.isBidirectional()); - assertTrue(biDirectionalRelationship.isBidirectional()); - } - - private TrackerPreheat getPreheat() { - RelationshipType uniDirectionalRelationshipType = createRelationshipType('A'); - uniDirectionalRelationshipType.setUid(RELATIONSHIP_TYPE_UID); - uniDirectionalRelationshipType.setBidirectional(false); - RelationshipType biDirectionalRelationshipType = createRelationshipType('B'); - biDirectionalRelationshipType.setUid(BIDIRECTIONAL_RELATIONSHIP_TYPE_UID); - biDirectionalRelationshipType.setBidirectional(true); - TrackerPreheat trackerPreheat = new TrackerPreheat(); - trackerPreheat.put( - TrackerIdSchemeParam.UID, - Lists.newArrayList(biDirectionalRelationshipType, uniDirectionalRelationshipType)); - return trackerPreheat; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/DuplicateRelationshipsPreProcessorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/DuplicateRelationshipsPreProcessorTest.java index 1cfc589b9644..d322421251a2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/DuplicateRelationshipsPreProcessorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/preprocess/DuplicateRelationshipsPreProcessorTest.java @@ -214,7 +214,6 @@ void test_on_identical_but_inverted_rels_none_is_removed() { Relationship.builder() .relationship(CodeGenerator.generateUid()) .relationshipType(MetadataIdentifier.ofUid(relType)) - .bidirectional(false) .from(trackedEntityRelationshipItem(fromTeUid)) .to(trackedEntityRelationshipItem(toTeUid)) .build(); @@ -222,7 +221,6 @@ void test_on_identical_but_inverted_rels_none_is_removed() { Relationship.builder() .relationship(CodeGenerator.generateUid()) .relationshipType(MetadataIdentifier.ofUid(relType)) - .bidirectional(false) .from(trackedEntityRelationshipItem(toTeUid)) .to(trackedEntityRelationshipItem(fromTeUid)) .build(); @@ -290,7 +288,6 @@ void test_on_identical_rels_relType_bi_1_is_removed() { Relationship.builder() .relationship(CodeGenerator.generateUid()) .relationshipType(MetadataIdentifier.ofUid(relType)) - .bidirectional(true) .from(trackedEntityRelationshipItem(fromTeUid)) .to(trackedEntityRelationshipItem(toTeUid)) .build(); @@ -298,7 +295,6 @@ void test_on_identical_rels_relType_bi_1_is_removed() { Relationship.builder() .relationship(CodeGenerator.generateUid()) .relationshipType(MetadataIdentifier.ofUid(relType)) - .bidirectional(true) .from(trackedEntityRelationshipItem(fromTeUid)) .to(trackedEntityRelationshipItem(toTeUid)) .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java index 9aa2f337c67f..5f51b81c504e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/sms/SmsImportMapperTest.java @@ -96,11 +96,6 @@ void mapEnrollmentWithNewTrackedEntityAndOnlyMandatoryFields() { .orgUnit(MetadataIdentifier.ofUid(input.getOrgUnit().getUid())) .trackedEntityType( MetadataIdentifier.ofUid(input.getTrackedEntityType().getUid())) - .enrollments( - List.of( - Enrollment.builder() - .enrollment(input.getEnrollment().getUid()) - .build())) .build())) .build(); assertEquals(expected, actual); @@ -144,11 +139,6 @@ void mapEnrollmentWithNewTrackedEntityAndAttributes() { .attribute(MetadataIdentifier.ofUid("fN8skWVI8JS")) .value("soap") .build())) - .enrollments( - List.of( - Enrollment.builder() - .enrollment(input.getEnrollment().getUid()) - .build())) .build())) .build(); assertEquals(expected, actual); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java index 127e2bc94daa..ae5cef216dc3 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/PersistablesFilterTest.java @@ -483,7 +483,6 @@ private static Entity enrollment(String uid, Entity p // set child/parent links Enrollment enrollment = Enrollment.builder().enrollment(uid).trackedEntity(parent.entity.getUid()).build(); - parent.entity.getEnrollments().add(enrollment); return new Entity<>(enrollment); } @@ -510,7 +509,6 @@ private static Entity event(String uid, Entity parent) { // enrollment. // They do have a "fake" enrollment (a default program) but it's not set on the event DTO. Event event = Event.builder().event(uid).enrollment(parent.entity.getUid()).build(); - parent.entity.getEvents().add(event); return new Entity<>(event); } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java index 8497ee5ad411..734aa4c167e1 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/enrollment/AttributeValidatorTest.java @@ -149,7 +149,6 @@ void shouldPassValidationWhenCreatingEnrollmentAndMandatoryAttributeIsPresentOnl Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); @@ -180,7 +179,6 @@ void shouldPassValidationWhenCreatingEnrollmentAndMandatoryAttributeIsPresentOnl Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); @@ -206,14 +204,12 @@ void shouldPassValidationWhenCreatingEnrollmentAndMandatoryAttributeIsPresentOnl Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) .value("value") .build(); @@ -245,7 +241,6 @@ void shouldPassValidationWhenCreatingEnrollmentAndMandatoryAttributeIsPresentOnl Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); @@ -275,7 +270,6 @@ void shouldFailValidationWhenCreatingEnrollmentAndValueIsNotPresentAndAttributeI Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); @@ -304,14 +298,10 @@ void shouldFailValidationWhenCreatingEnrollmentAndValueIsNullAndAttributeIsManda Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = - Attribute.builder() - .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) - .build(); + Attribute.builder().attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)).build(); when(program.getProgramAttributes()) .thenReturn( @@ -339,14 +329,10 @@ void shouldFailValidationWhenUpdatingEnrollmentAndValueIsNullAndAttributeIsManda Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = - Attribute.builder() - .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) - .build(); + Attribute.builder().attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)).build(); when(program.getProgramAttributes()) .thenReturn( @@ -374,14 +360,10 @@ void shouldPassValidationWhenValueIsNullAndAttributeIsNotMandatory() { Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = - Attribute.builder() - .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) - .build(); + Attribute.builder().attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)).build(); when(program.getProgramAttributes()) .thenReturn( @@ -408,13 +390,11 @@ void shouldFailValidationWhenValueIsInvalidPercentage() { Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_P)) - .valueType(ValueType.PERCENTAGE) .value("1000") .build(); @@ -444,14 +424,10 @@ void shouldFailValidationWhenValueIsInvalidPercentage() { Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = - Attribute.builder() - .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) - .build(); + Attribute.builder().attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)).build(); when(program.getProgramAttributes()) .thenReturn( @@ -481,14 +457,10 @@ void shouldFailValidationWhenValueIsInvalidPercentage() { Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE)) - .valueType(ValueType.TEXT) .value("value") .build(); Attribute attribute1 = - Attribute.builder() - .attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)) - .valueType(ValueType.TEXT) - .build(); + Attribute.builder().attribute(MetadataIdentifier.ofUid(TRACKED_ATTRIBUTE_1)).build(); when(program.getProgramAttributes()) .thenReturn( @@ -515,7 +487,6 @@ void shouldFailValidationWhenAttributeIsNotPresentInDB() { Attribute attribute = Attribute.builder() .attribute(MetadataIdentifier.ofUid("invalidAttribute")) - .valueType(ValueType.TEXT) .value("value") .build(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidatorTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidatorTest.java index c3706607d9ce..cc37a981cd61 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/imports/validation/validator/trackedentity/AttributeValidatorTest.java @@ -600,7 +600,6 @@ void validateFileResourceOwner() { Attribute attribute = new Attribute(); attribute.setAttribute(MetadataIdentifier.ofUid("tea")); - attribute.setValueType(ValueType.FILE_RESOURCE); attribute.setValue(fileResourceUid); TrackedEntity trackedEntity = diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java index 5a80340cecbd..a158032322ce 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/LastUpdateImportTest.java @@ -478,12 +478,13 @@ private org.hisp.dhis.tracker.imports.domain.Event importEventProgram() throws I } void enrollTrackerEntity() { - trackedEntity.setEnrollments(List.of(enrollment)); - assertNoErrors( trackerImportService.importTracker( new TrackerImportParams(), - TrackerObjects.builder().trackedEntities(List.of(trackedEntity)).build())); + TrackerObjects.builder() + .trackedEntities(List.of(trackedEntity)) + .enrollments(List.of(enrollment)) + .build())); } /** diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java index a0c064d3092b..13b10de7c07c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackerNotificationHandlerServiceTest.java @@ -347,7 +347,6 @@ void shouldSendEnrollmentCompletionNotificationOnlyOnce() { .enrollment(uid) .enrolledAt(Instant.now()) .occurredAt(Instant.now()) - .completedAt(Instant.now()) .build(); ImportReport importReport = diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/JobConfigurationRunErrorsControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/JobConfigurationRunErrorsControllerTest.java index d5514183393e..21217b5dc1b9 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/JobConfigurationRunErrorsControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/JobConfigurationRunErrorsControllerTest.java @@ -174,7 +174,7 @@ void testGetJobRunErrors_ListIncludeInput() throws InterruptedException { // language=JSON String expected = """ - {"trackedEntities":[{"trackedEntity":"sHH8mh1Fn0z","trackedEntityType":{"idScheme":"UID","identifier":"nEenWmSyUEp"},"orgUnit":{"idScheme":"UID","identifier":"DiszpKrYNg7"},"inactive":false,"deleted":false,"potentialDuplicate":false,"relationships":[],"attributes":[],"enrollments":[]}],"enrollments":[],"events":[],"relationships":[]}"""; + {"trackedEntities":[{"trackedEntity":"sHH8mh1Fn0z","trackedEntityType":{"idScheme":"UID","identifier":"nEenWmSyUEp"},"orgUnit":{"idScheme":"UID","identifier":"DiszpKrYNg7"},"inactive":false,"potentialDuplicate":false,"attributes":[]}],"enrollments":[],"events":[],"relationships":[]}"""; assertEquals(expected, trackerImportError.getObject("input").node().getDeclaration()); }