dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21339
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10065: FRED-API: minor fixes
------------------------------------------------------------
revno: 10065
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-08 09:21:00 +0300
message:
FRED-API: minor fixes
modified:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.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-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-08 04:56:18 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-08 06:21:00 +0000
@@ -350,16 +350,7 @@
@RequestParam( value = "fields", required = false ) String fields,
HttpServletRequest request )
{
- OrganisationUnit organisationUnit;
-
- if ( id.length() == 11 )
- {
- organisationUnit = organisationUnitService.getOrganisationUnit( id );
- }
- else
- {
- organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
- }
+ OrganisationUnit organisationUnit = getOrganisationUnit( id );
if ( organisationUnit == null )
{
@@ -506,46 +497,6 @@
// PUT JSON
//--------------------------------------------------------------------------
- protected String generateETagHeaderValue( byte[] bytes )
- {
- StringBuilder builder = new StringBuilder( "\"0" );
- DigestUtils.appendMd5DigestAsHex( bytes, builder );
- builder.append( '"' );
- return builder.toString();
- }
-
- protected void checkIdentifier( Facility facility, String id ) throws IOException
- {
- Identifier identifier = new Identifier();
-
- identifier.setAgency( Identifier.DHIS2_AGENCY );
- identifier.setContext( Identifier.DHIS2_UID_CONTEXT );
- identifier.setId( id );
-
- if ( facility.getIdentifiers().isEmpty() )
- {
- facility.getIdentifiers().add( identifier );
- }
- else
- {
- boolean found = false;
-
- for ( Identifier i : facility.getIdentifiers() )
- {
- if ( i.getAgency().equals( Identifier.DHIS2_AGENCY ) && i.getContext().equals( Identifier.DHIS2_UID_CONTEXT ) )
- {
- i.setId( id );
- found = true;
- }
- }
-
- if ( !found )
- {
- facility.getIdentifiers().add( identifier );
- }
- }
- }
-
@RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
@PreAuthorize( "hasRole('F_FRED_UPDATE') or hasRole('ALL')" )
public ResponseEntity<String> updateFacility( @PathVariable String id, @RequestBody Facility facility, HttpServletRequest request ) throws Exception
@@ -553,16 +504,7 @@
HttpHeaders headers = new HttpHeaders();
headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
- OrganisationUnit organisationUnit;
-
- if ( id.length() == 11 )
- {
- organisationUnit = organisationUnitService.getOrganisationUnit( id );
- }
- else
- {
- organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
- }
+ OrganisationUnit organisationUnit = getOrganisationUnit( id );
if ( organisationUnit == null )
{
@@ -665,16 +607,7 @@
@PreAuthorize( "hasRole('F_FRED_DELETE') or hasRole('ALL')" )
public ResponseEntity<String> deleteFacility( @PathVariable String id ) throws HierarchyViolationException, IOException
{
- OrganisationUnit organisationUnit;
-
- if ( id.length() == 11 )
- {
- organisationUnit = organisationUnitService.getOrganisationUnit( id );
- }
- else
- {
- organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
- }
+ OrganisationUnit organisationUnit = getOrganisationUnit( id );
if ( organisationUnit == null )
{
@@ -702,4 +635,64 @@
{
return new ResponseEntity<String>( ex.getMessage(), HttpStatus.FORBIDDEN );
}
+
+ //--------------------------------------------------------------------------
+ // UTILS
+ //--------------------------------------------------------------------------
+
+ private OrganisationUnit getOrganisationUnit( String id )
+ {
+ OrganisationUnit organisationUnit;
+
+ if ( id.length() == 11 )
+ {
+ organisationUnit = organisationUnitService.getOrganisationUnit( id );
+ }
+ else
+ {
+ organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
+ }
+
+ return organisationUnit;
+ }
+
+ private String generateETagHeaderValue( byte[] bytes )
+ {
+ StringBuilder builder = new StringBuilder( "\"0" );
+ DigestUtils.appendMd5DigestAsHex( bytes, builder );
+ builder.append( '"' );
+ return builder.toString();
+ }
+
+ private void checkIdentifier( Facility facility, String id ) throws IOException
+ {
+ Identifier identifier = new Identifier();
+
+ identifier.setAgency( Identifier.DHIS2_AGENCY );
+ identifier.setContext( Identifier.DHIS2_UID_CONTEXT );
+ identifier.setId( id );
+
+ if ( facility.getIdentifiers().isEmpty() )
+ {
+ facility.getIdentifiers().add( identifier );
+ }
+ else
+ {
+ boolean found = false;
+
+ for ( Identifier i : facility.getIdentifiers() )
+ {
+ if ( i.getAgency().equals( Identifier.DHIS2_AGENCY ) && i.getContext().equals( Identifier.DHIS2_UID_CONTEXT ) )
+ {
+ i.setId( id );
+ found = true;
+ }
+ }
+
+ if ( !found )
+ {
+ facility.getIdentifiers().add( identifier );
+ }
+ }
+ }
}