Skip to content

Commit

Permalink
chore: Remove unused code in tracker (#18759)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante authored Oct 4, 2024
1 parent 740d17c commit 1be08e0
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
package org.hisp.dhis.tracker.imports.converter;

import static org.hisp.dhis.util.DateUtils.fromInstant;
import static org.hisp.dhis.util.DateUtils.instantFromDate;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.imports.domain.Attribute;
import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier;
import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat;
import org.hisp.dhis.user.UserDetails;
import org.springframework.stereotype.Service;
Expand All @@ -47,26 +45,6 @@
@Service
public class AttributeValueConverterService
implements TrackerConverterService<Attribute, TrackedEntityAttributeValue> {
@Override
public Attribute to(TrackedEntityAttributeValue teav) {
Attribute attribute = new Attribute();

attribute.setAttribute(MetadataIdentifier.ofUid(teav.getAttribute().getUid()));
attribute.setCode(teav.getAttribute().getCode());
attribute.setDisplayName(teav.getAttribute().getDisplayName());
attribute.setCreatedAt(instantFromDate(teav.getCreated()));
attribute.setUpdatedAt(instantFromDate(teav.getLastUpdated()));
attribute.setStoredBy(teav.getStoredBy());
attribute.setValueType(teav.getAttribute().getValueType());
attribute.setValue(teav.getValue());

return attribute;
}

@Override
public List<Attribute> to(List<TrackedEntityAttributeValue> attributeValues) {
return attributeValues.stream().map(this::to).toList();
}

@Override
public TrackedEntityAttributeValue from(TrackerPreheat preheat, Attribute at, UserDetails user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -58,31 +56,6 @@ public class EnrollmentTrackerConverterService
org.hisp.dhis.tracker.imports.domain.Enrollment, Enrollment> {
private final NotesConverterService notesConverterService;

@Override
public org.hisp.dhis.tracker.imports.domain.Enrollment to(Enrollment enrollment) {
List<org.hisp.dhis.tracker.imports.domain.Enrollment> enrollments =
to(Collections.singletonList(enrollment));

if (enrollments.isEmpty()) {
return null;
}

return enrollments.get(0);
}

@Override
public List<org.hisp.dhis.tracker.imports.domain.Enrollment> to(
List<Enrollment> preheatEnrollments) {
List<org.hisp.dhis.tracker.imports.domain.Enrollment> enrollments = new ArrayList<>();

preheatEnrollments.forEach(
te -> {
// TODO: Add implementation
});

return enrollments;
}

@Override
public Enrollment from(
TrackerPreheat preheat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.dataelement.DataElement;
Expand All @@ -52,8 +50,6 @@
import org.hisp.dhis.program.ProgramType;
import org.hisp.dhis.program.UserInfoSnapshot;
import org.hisp.dhis.tracker.imports.domain.DataValue;
import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier;
import org.hisp.dhis.tracker.imports.domain.User;
import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat;
import org.hisp.dhis.user.UserDetails;
import org.hisp.dhis.util.DateUtils;
Expand All @@ -68,83 +64,6 @@ public class EventTrackerConverterService
implements RuleEngineConverterService<org.hisp.dhis.tracker.imports.domain.Event, Event> {
private final NotesConverterService notesConverterService;

@Override
public org.hisp.dhis.tracker.imports.domain.Event to(Event event) {
List<org.hisp.dhis.tracker.imports.domain.Event> events = to(Collections.singletonList(event));

if (events.isEmpty()) {
return null;
}

return events.get(0);
}

@Override
public List<org.hisp.dhis.tracker.imports.domain.Event> to(List<Event> events) {
List<org.hisp.dhis.tracker.imports.domain.Event> result = new ArrayList<>();

events.forEach(
event -> {
org.hisp.dhis.tracker.imports.domain.Event e =
new org.hisp.dhis.tracker.imports.domain.Event();
e.setEvent(event.getUid());

e.setStatus(event.getStatus());
e.setOccurredAt(DateUtils.instantFromDate(event.getOccurredDate()));
e.setScheduledAt(DateUtils.instantFromDate(event.getScheduledDate()));
e.setStoredBy(event.getStoredBy());
e.setCompletedBy(event.getCompletedBy());
e.setCompletedAt(DateUtils.instantFromDate(event.getCompletedDate()));
e.setCreatedAt(DateUtils.instantFromDate(event.getCreated()));
e.setCreatedAtClient(DateUtils.instantFromDate(event.getCreatedAtClient()));
e.setUpdatedAt(DateUtils.instantFromDate(event.getLastUpdated()));
e.setUpdatedAtClient(DateUtils.instantFromDate(event.getLastUpdatedAtClient()));
e.setGeometry(event.getGeometry());
e.setDeleted(event.isDeleted());

OrganisationUnit ou = event.getOrganisationUnit();

if (ou != null) {
e.setOrgUnit(MetadataIdentifier.ofUid(ou));
}

e.setEnrollment(event.getEnrollment().getUid());
e.setProgramStage(MetadataIdentifier.ofUid(event.getProgramStage()));
e.setAttributeOptionCombo(MetadataIdentifier.ofUid(event.getAttributeOptionCombo()));
e.setAttributeCategoryOptions(
event.getAttributeOptionCombo().getCategoryOptions().stream()
.map(CategoryOption::getUid)
.map(MetadataIdentifier::ofUid)
.collect(Collectors.toSet()));

Set<EventDataValue> dataValues = event.getEventDataValues();

for (EventDataValue dataValue : dataValues) {
DataValue value = new DataValue();
value.setCreatedAt(DateUtils.instantFromDate(dataValue.getCreated()));
value.setUpdatedAt(DateUtils.instantFromDate(dataValue.getLastUpdated()));
value.setDataElement(MetadataIdentifier.ofUid(dataValue.getDataElement()));
value.setValue(dataValue.getValue());
value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
value.setStoredBy(dataValue.getStoredBy());
value.setUpdatedBy(
Optional.ofNullable(dataValue.getLastUpdatedByUserInfo())
.map(this::convertUserInfo)
.orElse(null));
value.setCreatedBy(
Optional.ofNullable(dataValue.getCreatedByUserInfo())
.map(this::convertUserInfo)
.orElse(null));

e.getDataValues().add(value);
}

result.add(e);
});

return result;
}

@Override
public Event from(
TrackerPreheat preheat, org.hisp.dhis.tracker.imports.domain.Event event, UserDetails user) {
Expand Down Expand Up @@ -299,13 +218,4 @@ private Enrollment getEnrollment(TrackerPreheat preheat, String enrollment, Prog
// null
return null;
}

private User convertUserInfo(UserInfoSnapshot userInfoSnapshot) {
return User.builder()
.uid(userInfoSnapshot.getUid())
.username(userInfoSnapshot.getUsername())
.firstName(userInfoSnapshot.getFirstName())
.surname(userInfoSnapshot.getSurname())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.note.Note;
import org.hisp.dhis.tracker.imports.domain.User;
import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat;
import org.hisp.dhis.user.UserDetails;
import org.hisp.dhis.util.DateUtils;
import org.springframework.stereotype.Service;

/**
Expand All @@ -43,28 +41,6 @@
@RequiredArgsConstructor
public class NotesConverterService
implements TrackerConverterService<org.hisp.dhis.tracker.imports.domain.Note, Note> {
@Override
public org.hisp.dhis.tracker.imports.domain.Note to(Note note) {
org.hisp.dhis.tracker.imports.domain.Note trackerNote =
new org.hisp.dhis.tracker.imports.domain.Note();
trackerNote.setNote(note.getUid());
trackerNote.setValue(note.getNoteText());
trackerNote.setStoredAt(DateUtils.instantFromDate(note.getCreated()));
trackerNote.setCreatedBy(
User.builder()
.username(note.getLastUpdatedBy().getUsername())
.uid(note.getLastUpdatedBy().getUid())
.firstName(note.getLastUpdatedBy().getFirstName())
.surname(note.getLastUpdatedBy().getSurname())
.build());
trackerNote.setStoredBy(note.getCreator());
return trackerNote;
}

@Override
public List<org.hisp.dhis.tracker.imports.domain.Note> to(List<Note> notes) {
return notes.stream().map(this::to).toList();
}

@Override
public Note from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@
import static org.hisp.dhis.relationship.RelationshipEntity.PROGRAM_STAGE_INSTANCE;
import static org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.hisp.dhis.relationship.RelationshipKey;
import org.hisp.dhis.tracker.imports.domain.MetadataIdentifier;
import org.hisp.dhis.tracker.imports.domain.Relationship;
import org.hisp.dhis.tracker.imports.domain.RelationshipItem;
import org.hisp.dhis.tracker.imports.preheat.TrackerPreheat;
import org.hisp.dhis.tracker.imports.util.RelationshipKeySupport;
import org.hisp.dhis.user.UserDetails;
Expand All @@ -51,50 +48,6 @@
public class RelationshipTrackerConverterService
implements TrackerConverterService<Relationship, org.hisp.dhis.relationship.Relationship> {

@Override
public Relationship to(org.hisp.dhis.relationship.Relationship relationship) {
List<Relationship> relationships = to(Collections.singletonList(relationship));

if (relationships.isEmpty()) {
return null;
}

return relationships.get(0);
}

@Override
public List<Relationship> to(List<org.hisp.dhis.relationship.Relationship> relationships) {
return relationships.stream()
.map(
fromRelationship -> {
Relationship toRelationship = new Relationship();
toRelationship.setRelationship(fromRelationship.getUid());
toRelationship.setBidirectional(
fromRelationship.getRelationshipType().isBidirectional());
toRelationship.setCreatedAt(DateUtils.instantFromDate(fromRelationship.getCreated()));
toRelationship.setFrom(convertRelationshipType(fromRelationship.getFrom()));
toRelationship.setTo(convertRelationshipType(fromRelationship.getTo()));
toRelationship.setUpdatedAt(
DateUtils.instantFromDate(fromRelationship.getLastUpdated()));
toRelationship.setRelationshipType(
MetadataIdentifier.ofUid(fromRelationship.getRelationshipType().getUid()));

return toRelationship;
})
.toList();
}

private RelationshipItem convertRelationshipType(
org.hisp.dhis.relationship.RelationshipItem from) {
RelationshipItem relationshipItem = new RelationshipItem();
relationshipItem.setEnrollment(
from.getEnrollment() != null ? from.getEnrollment().getUid() : null);
relationshipItem.setEvent(from.getEvent() != null ? from.getEvent().getUid() : null);
relationshipItem.setTrackedEntity(
from.getTrackedEntity() != null ? from.getTrackedEntity().getUid() : null);
return relationshipItem;
}

@Override
public org.hisp.dhis.relationship.Relationship from(
TrackerPreheat preheat, Relationship fromRelationship, UserDetails user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.tracker.imports.converter;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.hisp.dhis.organisationunit.OrganisationUnit;
Expand All @@ -46,32 +45,6 @@
public class TrackedEntityTrackerConverterService
implements TrackerConverterService<
org.hisp.dhis.tracker.imports.domain.TrackedEntity, TrackedEntity> {
@Override
public org.hisp.dhis.tracker.imports.domain.TrackedEntity to(TrackedEntity trackedEntity) {
List<org.hisp.dhis.tracker.imports.domain.TrackedEntity> trackedEntities =
to(Collections.singletonList(trackedEntity));

if (trackedEntities.isEmpty()) {
return null;
}

return trackedEntities.get(0);
}

@Override
public List<org.hisp.dhis.tracker.imports.domain.TrackedEntity> to(
List<TrackedEntity> trackedEntities) {
return trackedEntities.stream()
.map(
te -> {
org.hisp.dhis.tracker.imports.domain.TrackedEntity trackedEntity =
new org.hisp.dhis.tracker.imports.domain.TrackedEntity();
trackedEntity.setTrackedEntity(te.getUid());

return trackedEntity;
})
.toList();
}

@Override
public TrackedEntity from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
* @author Morten Olav Hansen <[email protected]>
*/
public interface TrackerConverterService<From, To> {
From to(To object);

List<From> to(List<To> objects);

To from(TrackerPreheat preheat, From object, UserDetails user);

List<To> from(TrackerPreheat preheat, List<From> objects, UserDetails user);
Expand Down
Loading

0 comments on commit 1be08e0

Please sign in to comment.