------------------------------------------------------------ revno: 22110 committer: Abyot Asalefew Gizaw <ab...@dhis2.org> branch nick: dhis2 timestamp: Wed 2016-03-02 16:49:46 +0100 message: new property teiSearchOrganisationUnits is now added to user object. This new property defines the scope that a user can be allowed to search tracked entity instances. modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml
-- 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-api/src/main/java/org/hisp/dhis/user/User.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2016-02-11 09:27:02 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2016-03-02 15:49:46 +0000 @@ -111,6 +111,12 @@ */ @Scanned private Set<OrganisationUnit> dataViewOrganisationUnits = new HashSet<>(); + + /** + * Organisation units for tracked entity instance search operations. + */ + @Scanned + private Set<OrganisationUnit> teiSearchOrganisationUnits = new HashSet<>(); /** * Ordered favorite apps. @@ -202,6 +208,10 @@ return !CollectionUtils.isEmpty( organisationUnits ); } + // ------------------------------------------------------------------------- + // Logic - data view organisation unit + // ------------------------------------------------------------------------- + public boolean hasDataViewOrganisationUnit() { return !CollectionUtils.isEmpty( dataViewOrganisationUnits ); @@ -234,6 +244,44 @@ { return hasDataViewOrganisationUnit() ? dataViewOrganisationUnits : organisationUnits; } + + // ------------------------------------------------------------------------- + // Logic - tei search organisation unit + // ------------------------------------------------------------------------- + + public boolean hasTeiSearchOrganisationUnit() + { + return !CollectionUtils.isEmpty( teiSearchOrganisationUnits ); + } + + public OrganisationUnit getTeiSearchOrganisationUnit() + { + return CollectionUtils.isEmpty( teiSearchOrganisationUnits ) ? null : teiSearchOrganisationUnits.iterator().next(); + } + + public boolean hasTeiSearchOrganisationUnitWithFallback() + { + return hasTeiSearchOrganisationUnit() || hasOrganisationUnit(); + } + + /** + * Returns the first of the tei search organisation units associated with the + * user. If none, returns the first of the data capture organisation units. + * If none, return nulls. + */ + public OrganisationUnit getTeiSearchOrganisationUnitWithFallback() + { + return hasTeiSearchOrganisationUnit() ? getTeiSearchOrganisationUnit() : getOrganisationUnit(); + } + + /** + * Returns the tei search organisation units or organisation units if not exist. + */ + public Set<OrganisationUnit> getTeiSearchOrganisationUnitsWithFallback() + { + return hasTeiSearchOrganisationUnit() ? teiSearchOrganisationUnits : organisationUnits; + } + public String getOrganisationUnitsName() { @@ -609,6 +657,21 @@ public void setDataViewOrganisationUnits( Set<OrganisationUnit> dataViewOrganisationUnits ) { this.dataViewOrganisationUnits = dataViewOrganisationUnits; + } + + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlElementWrapper( localName = "teiSearchOrganisationUnits", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "teiSearchOrganisationUnit", namespace = DxfNamespaces.DXF_2_0 ) + public Set<OrganisationUnit> getTeiSearchOrganisationUnits() + { + return teiSearchOrganisationUnits; + } + + public void setTeiSearchOrganisationUnits( Set<OrganisationUnit> teiSearchOrganisationUnits ) + { + this.teiSearchOrganisationUnits = teiSearchOrganisationUnits; } public List<String> getApps() @@ -672,6 +735,9 @@ dataViewOrganisationUnits.clear(); dataViewOrganisationUnits.addAll( user.getDataViewOrganisationUnits() ); + + teiSearchOrganisationUnits.clear(); + teiSearchOrganisationUnits.addAll( user.getTeiSearchOrganisationUnits() ); } } @@ -702,6 +768,7 @@ "\"groups\":\"" + groups + "\", " + "\"organisationUnits\":\"" + organisationUnits + "\", " + "\"dataViewOrganisationUnits\":\"" + dataViewOrganisationUnits + "\" " + + "\"teiSearchOrganisationUnits\":\"" + teiSearchOrganisationUnits + "\" " + "}"; } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2015-11-23 06:52:49 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2016-03-02 15:49:46 +0000 @@ -69,7 +69,14 @@ <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid" foreign-key="fk_userdatavieworgunits_organisationunitid" /> </set> - + + <set name="teiSearchOrganisationUnits" table="userteisearchorgunits"> + <cache usage="read-write" /> + <key column="userinfoid" foreign-key="fk_userteisearchorgunits_userinfoid" /> + <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid" + foreign-key="fk_userteisearchorgunits_organisationunitid" /> + </set> + <!-- Dynamic attribute values --> <set name="attributeValues" table="userattributevalues" cascade="delete-orphan">
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp