dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31994
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16347: add new parameter to DataElementOperands controller, persisted=true/false, allows for getting onl...
------------------------------------------------------------
revno: 16347
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-08-08 15:54:26 +0700
message:
add new parameter to DataElementOperands controller, persisted=true/false, allows for getting only persisted operands
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.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/metadata/Options.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2014-08-07 11:46:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2014-08-08 08:54:26 +0000
@@ -96,17 +96,17 @@
return null;
}
-
+
protected static boolean stringAsBoolean( String str, boolean defaultValue )
{
return str != null ? Boolean.parseBoolean( str ) : defaultValue;
}
-
+
protected static boolean stringIsTrue( String str )
{
return stringAsBoolean( str, false );
}
-
+
protected static int stringAsInt( String str )
{
return stringAsInt( str, 0 );
@@ -155,18 +155,18 @@
//--------------------------------------------------------------------------
/**
- * Indicates whether the given object type is enabled. Takes the assumeTrue
+ * Indicates whether the given object type is enabled. Takes the assumeTrue
* parameter into account.
*/
public boolean isEnabled( String type )
{
String enabled = options.get( type );
- return stringIsTrue( enabled ) || ( enabled == null && assumeTrue );
+ return stringIsTrue( enabled ) || (enabled == null && assumeTrue);
}
/**
- * Indicates whether the given object type is disabled. Takes the assumeTrue
+ * Indicates whether the given object type is disabled. Takes the assumeTrue
* parameter into account.
*/
public boolean isDisabled( String type )
@@ -178,7 +178,7 @@
{
return stringAsDate( options.get( key ) );
}
-
+
/**
* Indicates whether the options contains the given parameter key.
*/
@@ -188,14 +188,14 @@
}
/**
- * Indicates whether the options contains a non-null option value for the given
+ * Indicates whether the options contains a non-null option value for the given
* parameter key.
*/
public boolean containsValue( String key )
{
return options.get( key ) != null;
}
-
+
/**
* Returns the option value for the given parameter key.
*/
@@ -209,15 +209,15 @@
*/
public Integer getInt( String key )
{
- return options.get( key ) != null ? Integer.parseInt( options.get( key ) ) : null;
+ return options.containsKey( key ) ? Integer.parseInt( options.get( key ) ) : null;
}
-
+
/**
* Indicates whether the option value for the parameter key is true.
*/
public boolean isTrue( String key )
{
- return options.get( key ) != null && Boolean.parseBoolean( options.get( key ) );
+ return options.containsKey( key ) && Boolean.parseBoolean( options.get( key ) );
}
//--------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2014-08-05 04:47:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2014-08-08 08:54:26 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.collect.Lists;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.PagerUtils;
import org.hisp.dhis.dataelement.DataElement;
@@ -56,16 +57,25 @@
protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options )
{
- List<DataElement> dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) );
- List<DataElementOperand> entityList = new ArrayList<>( categoryService.getFullOperands( dataElements ) );
+ List<DataElementOperand> dataElementOperands;
+
+ if ( options.isTrue( "persisted" ) )
+ {
+ dataElementOperands = Lists.newArrayList( manager.getAll( DataElementOperand.class ) );
+ }
+ else
+ {
+ List<DataElement> dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) );
+ dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElements ) );
+ }
if ( options.hasPaging() )
{
- Pager pager = new Pager( options.getPage(), entityList.size(), options.getPageSize() );
+ Pager pager = new Pager( options.getPage(), dataElementOperands.size(), options.getPageSize() );
metaData.setPager( pager );
- entityList = PagerUtils.pageCollection( entityList, pager );
+ dataElementOperands = PagerUtils.pageCollection( dataElementOperands, pager );
}
- return entityList;
+ return dataElementOperands;
}
}