Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOTECH-3049: Added data transfer objects to the Dhis2 module. #495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.motechproject.dhis2.dto.DataElementDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
Expand Down Expand Up @@ -45,6 +46,10 @@ public void setUuid(String uuid) {
this.uuid = uuid;
}

public DataElementDto toDto () {
return new DataElementDto(name, uuid);
}

@Override
public boolean equals(Object o) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.motechproject.dhis2.domain;

import org.motechproject.dhis2.dto.OrgUnitDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
Expand Down Expand Up @@ -42,4 +43,9 @@ public String getUuid() {
public void setUuid(String uuid) {
this.uuid = uuid;
}

public OrgUnitDto toDto () {
return new OrgUnitDto(name, uuid);
}

}
19 changes: 19 additions & 0 deletions dhis2/src/main/java/org/motechproject/dhis2/domain/Program.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.motechproject.dhis2.domain;

import org.motechproject.dhis2.dto.ProgramDto;
import org.motechproject.dhis2.dto.StageDto;
import org.motechproject.dhis2.dto.TrackedEntityAttributeDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Cascade;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
import org.motechproject.mds.util.SecurityMode;

import javax.jdo.annotations.Unique;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -105,4 +109,19 @@ public String getProgramType() {
public void setProgramType(String programType) {
this.programType = programType;
}

public ProgramDto toDto() {
List<StageDto> stageDtos = new ArrayList<>();
List<TrackedEntityAttributeDto> trackedEntityAttributeDtos = new ArrayList<>();

for (Stage stage : stages) {
stageDtos.add(stage.toDto());
}

for (TrackedEntityAttribute trackedEntityAttribute : attributes) {
trackedEntityAttributeDtos.add(trackedEntityAttribute.toDto());
}

return new ProgramDto(uuid, name, trackedEntity.toDto(), stageDtos, trackedEntityAttributeDtos, singleEvent, registration, programType);
}
}
13 changes: 13 additions & 0 deletions dhis2/src/main/java/org/motechproject/dhis2/domain/Stage.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.motechproject.dhis2.domain;

import org.motechproject.dhis2.dto.DataElementDto;
import org.motechproject.dhis2.dto.StageDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
import org.motechproject.mds.util.SecurityMode;

import javax.jdo.annotations.Unique;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -69,4 +72,14 @@ public String getProgram() {
public void setProgram(String program) {
this.program = program;
}

public StageDto toDto() {
List<DataElementDto> dataElementDtos = new ArrayList<>();

for (DataElement dataElement : dataElements) {
dataElementDtos.add(dataElement.toDto());
}

return new StageDto(uuid, name, dataElementDtos, program, registration);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.motechproject.dhis2.domain;

import org.motechproject.dhis2.dto.TrackedEntityDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
Expand Down Expand Up @@ -42,4 +43,8 @@ public String getUuid() {
public void setUuid(String uuid) {
this.uuid = uuid;
}

public TrackedEntityDto toDto() {
return new TrackedEntityDto(name, uuid);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.motechproject.dhis2.domain;

import org.motechproject.dhis2.dto.TrackedEntityAttributeDto;
import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
Expand Down Expand Up @@ -42,4 +43,8 @@ public String getUuid() {
public void setUuid(String uuid) {
this.uuid = uuid;
}

public TrackedEntityAttributeDto toDto() {
return new TrackedEntityAttributeDto(name, uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.motechproject.dhis2.dto;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class DataElementDto {
private String uuid;
private String name;

public DataElementDto() { }

public DataElementDto(String name, String uuid) {
this.uuid = uuid;
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public boolean equals(Object o) {

if (this == o) {
return true;
}

if (!(o instanceof DataElementDto)) {
return false;
}

DataElementDto other = (DataElementDto) o;

return ObjectUtils.equals(uuid, other.uuid) && ObjectUtils.equals(name, other.name);
}

@Override
public int hashCode() {
return new HashCodeBuilder().append(uuid).append(name).toHashCode();
}
}
54 changes: 54 additions & 0 deletions dhis2/src/main/java/org/motechproject/dhis2/dto/OrgUnitDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.motechproject.dhis2.dto;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class OrgUnitDto {
private String uuid;

private String name;

public OrgUnitDto() { }

public OrgUnitDto(String name, String uuid) {
this.uuid = uuid;
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public boolean equals(Object o) {

if (this == o) {
return true;
}

if (!(o instanceof OrgUnitDto)) {
return false;
}

OrgUnitDto other = (OrgUnitDto) o;

return ObjectUtils.equals(uuid, other.uuid) && ObjectUtils.equals(name, other.name);
}

@Override
public int hashCode() {
return new HashCodeBuilder().append(uuid).append(name).toHashCode();
}
}
137 changes: 137 additions & 0 deletions dhis2/src/main/java/org/motechproject/dhis2/dto/ProgramDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.motechproject.dhis2.dto;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

import java.util.List;

public class ProgramDto {

private String uuid;

private String name;

private TrackedEntityDto trackedEntity;

private List<StageDto> stages;

private List<TrackedEntityAttributeDto> attributes;

private boolean singleEvent;

private boolean registration;

private String programType;

public ProgramDto() {}

public ProgramDto(String uuid, String name, TrackedEntityDto trackedEntity, List<StageDto> stages, List<TrackedEntityAttributeDto> attributes, boolean singleEvent, boolean registration, String programType) {
this.uuid = uuid;
this.name = name;
this.trackedEntity = trackedEntity;
this.stages = stages;
this.attributes = attributes;
this.singleEvent = singleEvent;
this.registration = registration;
this.programType = programType;
}

public boolean isSingleEvent() {
return singleEvent;
}

public void setSingleEvent(boolean singleEvent) {
this.singleEvent = singleEvent;
}

public boolean hasRegistration() {
return registration;
}

public void setRegistration(boolean registration) {
this.registration = registration;
}

public TrackedEntityDto getTrackedEntity() {
return trackedEntity;
}

public void setTrackedEntity(TrackedEntityDto trackedEntity) {
this.trackedEntity = trackedEntity;
}

public List<StageDto> getStages() {
return stages;
}

public void setStages(List<StageDto> stages) {
this.stages = stages;
}

public List<TrackedEntityAttributeDto> getAttributes() {
return attributes;
}

public void setAttributes(List<TrackedEntityAttributeDto> attributes) {
this.attributes = attributes;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getProgramType() {
return programType;
}

public void setProgramType(String programType) {
this.programType = programType;
}

@Override
public boolean equals(Object o) {

if (this == o) {
return true;
}

if (!(o instanceof ProgramDto)) {
return false;
}

ProgramDto other = (ProgramDto) o;

return ObjectUtils.equals(uuid, other.uuid) &&
ObjectUtils.equals(name, other.name) &&
ObjectUtils.equals(trackedEntity, other.trackedEntity) &&
ObjectUtils.equals(stages, other.stages) &&
ObjectUtils.equals(attributes, other.attributes) &&
ObjectUtils.equals(singleEvent, other.singleEvent) &&
ObjectUtils.equals(registration, other.registration) &&
ObjectUtils.equals(programType, other.programType);
}

@Override
public int hashCode() {
return new HashCodeBuilder().append(uuid).
append(name).
append(trackedEntity).
append(stages).
append(attributes).
append(singleEvent).
append(registration).
append(programType).toHashCode();
}
}
Loading