dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35893
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18380: removed realObject hack on TEIController, expands relative in relationship (for one level)
------------------------------------------------------------
revno: 18380
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-24 10:57:26 +0700
message:
removed realObject hack on TEIController, expands relative in relationship (for one level)
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java 2015-02-20 12:35:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java 2015-02-24 03:57:26 +0000
@@ -109,6 +109,12 @@
@Override
public TrackedEntityInstance getTrackedEntityInstance( org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance )
{
+ return getTrackedEntityInstance( entityInstance, true );
+ }
+
+ @Override
+ public TrackedEntityInstance getTrackedEntityInstance( org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance, boolean expandRelative )
+ {
if ( entityInstance == null )
{
return null;
@@ -132,6 +138,19 @@
relationship.setRelationship( entityRelationship.getRelationshipType().getUid() );
+ if ( expandRelative )
+ {
+ // we might have cases where A <=> A, so we only include the relative if the UIDs do not match
+ if ( !entityRelationship.getEntityInstanceA().getUid().equals( entityInstance.getUid() ) )
+ {
+ relationship.setRelative( getTrackedEntityInstance( entityRelationship.getEntityInstanceA(), false ) );
+ }
+ else if ( !entityRelationship.getEntityInstanceB().getUid().equals( entityInstance.getUid() ) )
+ {
+ relationship.setRelative( getTrackedEntityInstance( entityRelationship.getEntityInstanceB(), false ) );
+ }
+ }
+
trackedEntityInstance.getRelationships().add( relationship );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java 2015-02-24 03:57:26 +0000
@@ -31,8 +31,11 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.base.MoreObjects;
import org.hisp.dhis.common.DxfNamespaces;
+import java.util.Objects;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -42,11 +45,13 @@
private String displayName;
private String trackedEntityInstanceA;
-
+
private String trackedEntityInstanceB;
private String relationship;
+ private TrackedEntityInstance relative;
+
public Relationship()
{
}
@@ -74,7 +79,7 @@
{
this.trackedEntityInstanceA = trackedEntityInstanceA;
}
-
+
@JsonProperty
@JacksonXmlProperty( isAttribute = true )
public String getTrackedEntityInstanceB()
@@ -99,42 +104,51 @@
this.relationship = relationship;
}
- @Override
- public boolean equals( Object o )
- {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- Relationship that = (Relationship) o;
-
- if ( displayName != null ? !displayName.equals( that.displayName ) : that.displayName != null ) return false;
- if ( trackedEntityInstanceA != null ? !trackedEntityInstanceA.equals( that.trackedEntityInstanceA ) : that.trackedEntityInstanceA != null )
- return false;
- if ( trackedEntityInstanceB != null ? !trackedEntityInstanceB.equals( that.trackedEntityInstanceB ) : that.trackedEntityInstanceB != null )
- return false;
- if ( relationship != null ? !relationship.equals( that.relationship ) : that.relationship != null ) return false;
-
- return true;
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public TrackedEntityInstance getRelative()
+ {
+ return relative;
+ }
+
+ public void setRelative( TrackedEntityInstance relative )
+ {
+ this.relative = relative;
}
@Override
public int hashCode()
{
- int result = displayName != null ? displayName.hashCode() : 0;
- result = 31 * result + (trackedEntityInstanceA != null ? trackedEntityInstanceA.hashCode() : 0);
- result = 31 * result + (trackedEntityInstanceB != null ? trackedEntityInstanceB.hashCode() : 0);
- result = 31 * result + (relationship != null ? relationship.hashCode() : 0);
- return result;
+ return Objects.hash( displayName, trackedEntityInstanceA, trackedEntityInstanceB, relationship, relative );
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ {
+ return true;
+ }
+ if ( obj == null || getClass() != obj.getClass() )
+ {
+ return false;
+ }
+ final Relationship other = (Relationship) obj;
+ return Objects.equals( this.displayName, other.displayName )
+ && Objects.equals( this.trackedEntityInstanceA, other.trackedEntityInstanceA )
+ && Objects.equals( this.trackedEntityInstanceB, other.trackedEntityInstanceB )
+ && Objects.equals( this.relationship, other.relationship )
+ && Objects.equals( this.relative, other.relative );
}
@Override
public String toString()
{
- return "Relationship{" +
- "displayName='" + displayName + '\'' +
- ", trackedEntityInstanceA='" + trackedEntityInstanceA + '\'' +
- ", trackedEntityInstanceB='" + trackedEntityInstanceB + '\'' +
- ", relationship='" + relationship + '\'' +
- '}';
+ return MoreObjects.toStringHelper( this )
+ .add( "displayName", displayName )
+ .add( "trackedEntityInstanceA", trackedEntityInstanceA )
+ .add( "trackedEntityInstanceB", trackedEntityInstanceB )
+ .add( "relationship", relationship )
+ .toString();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstanceService.java 2015-02-24 03:57:26 +0000
@@ -48,6 +48,8 @@
TrackedEntityInstance getTrackedEntityInstance( org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance );
+ TrackedEntityInstance getTrackedEntityInstance( org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance, boolean expandRelative );
+
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java 2015-02-20 12:35:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java 2015-02-24 03:57:26 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService;
import org.hisp.dhis.dxf2.fieldfilter.FieldFilterService;
@@ -40,7 +41,6 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.objectfilter.ObjectFilterService;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.importexport.ImportStrategy;
import org.hisp.dhis.node.types.CollectionNode;
@@ -242,8 +242,7 @@
@RequestMapping( value = "/{id}", method = RequestMethod.GET )
@PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_SEARCH')" )
- public @ResponseBody RootNode getTrackedEntityInstanceById( @PathVariable( "id" ) String pvId,
- @RequestParam( value = "realObject", required = false, defaultValue = "false" ) boolean realObject )
+ public @ResponseBody RootNode getTrackedEntityInstanceById( @PathVariable( "id" ) String pvId )
throws NotFoundException
{
List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
@@ -253,18 +252,7 @@
fields.add( ":all" );
}
- CollectionNode collectionNode;
-
- if ( !realObject )
- {
- collectionNode = fieldFilterService.filter( TrackedEntityInstance.class,
- Lists.newArrayList( getTrackedEntityInstance( pvId ) ), fields );
- }
- else
- {
- collectionNode = fieldFilterService.filter( org.hisp.dhis.trackedentity.TrackedEntityInstance.class,
- Lists.newArrayList( instanceService.getTrackedEntityInstance( pvId ) ), fields );
- }
+ CollectionNode collectionNode = fieldFilterService.filter( TrackedEntityInstance.class, Lists.newArrayList( getTrackedEntityInstance( pvId ) ), fields );
RootNode rootNode = new RootNode( collectionNode.getChildren().get( 0 ) );
rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );