← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20424: KeyJsonValue, code style

 

------------------------------------------------------------
revno: 20424
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-01 11:03:27 +0200
message:
  KeyJsonValue, code style
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValue.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/DefaultKeyJsonValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/hibernate/HibernateKeyJsonValueStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.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-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValue.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValue.java	2015-10-01 09:03:27 +0000
@@ -32,7 +32,7 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 public class KeyJsonValue
     extends BaseIdentifiableObject

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueService.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueService.java	2015-10-01 09:03:27 +0000
@@ -31,7 +31,7 @@
 import java.util.List;
 
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 public interface KeyJsonValueService
 {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueStore.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/keyjsonvalue/KeyJsonValueStore.java	2015-10-01 09:03:27 +0000
@@ -33,12 +33,11 @@
 import java.util.List;
 
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 public interface KeyJsonValueStore
     extends GenericIdentifiableObjectStore<KeyJsonValue>
 {
-
     List<String> getNamespaces();
 
     List<String> getKeysInNamespace( String namespace );
@@ -46,5 +45,4 @@
     void deleteKeysInNamespace( String namespace );
 
     KeyJsonValue getKeyJsonValue( String namespace, String key );
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/DefaultKeyJsonValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/DefaultKeyJsonValueService.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/DefaultKeyJsonValueService.java	2015-10-01 09:03:27 +0000
@@ -33,13 +33,12 @@
 import java.util.List;
 
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 @Transactional
 public class DefaultKeyJsonValueService
     implements KeyJsonValueService
 {
-
     private KeyJsonValueStore keyJsonValueStore;
 
     public void setKeyJsonValueStore( KeyJsonValueStore keyJsonValueStore )
@@ -47,6 +46,10 @@
         this.keyJsonValueStore = keyJsonValueStore;
     }
 
+    // -------------------------------------------------------------------------
+    // KeyJsonValueService implementation
+    // -------------------------------------------------------------------------
+
     @Override
     public List<String> getNamespaces()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/hibernate/HibernateKeyJsonValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/hibernate/HibernateKeyJsonValueStore.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/keyjsonvalue/hibernate/HibernateKeyJsonValueStore.java	2015-10-01 09:03:27 +0000
@@ -36,27 +36,30 @@
 import java.util.List;
 
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 public class HibernateKeyJsonValueStore
     extends HibernateIdentifiableObjectStore<KeyJsonValue>
     implements KeyJsonValueStore
 {
     @Override
+    @SuppressWarnings("unchecked")
     public List<String> getNamespaces()
     {
         return getQuery( "SELECT distinct namespace FROM org.hisp.dhis.keyjsonvalue.KeyJsonValue" ).list();
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public List<String> getKeysInNamespace( String namespace )
     {
         return getQuery(
-            "SELECT distinct key FROM org.hisp.dhis.keyjsonvalue.KeyJsonValue WHERE namespace LIKE '" + namespace +
-                "'" ).list();
+            "SELECT distinct key FROM org.hisp.dhis.keyjsonvalue.KeyJsonValue WHERE namespace LIKE '" + 
+            namespace + "'" ).list();
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public void deleteKeysInNamespace( String namespace )
     {
         getCriteria( Restrictions.eq( "namespace", namespace ) ).list().forEach( o -> delete( (KeyJsonValue) o ) );
@@ -65,7 +68,8 @@
     @Override
     public KeyJsonValue getKeyJsonValue( String namespace, String key )
     {
-        return (KeyJsonValue) getCriteria( Restrictions.eq( "namespace", namespace ), Restrictions.eq( "key", key ) )
-            .uniqueResult();
+        return (KeyJsonValue) getCriteria( 
+            Restrictions.eq( "namespace", namespace ), 
+            Restrictions.eq( "key", key ) ).uniqueResult();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java	2015-09-30 19:20:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/render/DefaultRenderService.java	2015-10-01 09:03:27 +0000
@@ -30,10 +30,12 @@
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.databind.*;
 import com.fasterxml.jackson.databind.util.JSONPObject;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
+
 import org.springframework.util.StringUtils;
 
 import java.io.IOException;
@@ -141,6 +143,22 @@
         return xmlMapper.readValue( input, klass );
     }
 
+    @Override
+    public boolean isValidJson( String json )
+        throws IOException
+    {
+        try
+        {
+            jsonMapper.readValue( json, Object.class );
+        }
+        catch ( JsonParseException | JsonMappingException e )
+        {
+            return false;
+        }
+
+        return true;
+    }
+    
     //--------------------------------------------------------------------------
     // Helpers
     //--------------------------------------------------------------------------
@@ -182,24 +200,4 @@
         jsonMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
         xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true );
     }
-
-    public boolean isValidJson( String json )
-        throws IOException
-    {
-        try
-        {
-            jsonMapper.readValue( json, Object.class );
-        }
-        catch ( com.fasterxml.jackson.core.JsonParseException e )
-        {
-            return false;
-        }
-        catch ( JsonMappingException e )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-01 08:20:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/KeyJsonValueController.java	2015-10-01 09:03:27 +0000
@@ -28,6 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.keyjsonvalue.KeyJsonValue;
@@ -40,12 +45,8 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
 /**
- * Created by Stian Sandvold on 27.09.2015.
+ * @author Stian Sandvold
  */
 @Controller
 @RequestMapping( "/dataStore" )
@@ -58,9 +59,7 @@
     private RenderService renderService;
 
     @RequestMapping( value = "", method = RequestMethod.GET, produces = "application/json" )
-    public void getNamespaces(
-        HttpServletResponse response
-    )
+    public void getNamespaces( HttpServletResponse response )
         throws IOException
     {
         renderService.toJson( response.getOutputStream(), keyJsonValueService.getNamespaces() );
@@ -69,11 +68,9 @@
     @RequestMapping( value = "/{namespace}", method = RequestMethod.GET, produces = "application/json" )
     public void getKeysInNamespace(
         @PathVariable String namespace,
-        HttpServletResponse response
-    )
+        HttpServletResponse response )
         throws IOException, WebMessageException
     {
-
         if ( !keyJsonValueService.getNamespaces().contains( namespace ) )
         {
             throw new WebMessageException(
@@ -86,9 +83,7 @@
     @RequestMapping( value = "/{namespace}", method = RequestMethod.DELETE )
     public void deleteNamespace(
         @PathVariable String namespace,
-        HttpServletResponse response
-    )
-        throws WebMessageException
+        HttpServletResponse response ) throws WebMessageException
     {
 
         if ( !keyJsonValueService.getNamespaces().contains( namespace ) )
@@ -128,14 +123,12 @@
         HttpServletResponse response )
         throws IOException, WebMessageException
     {
-        // Check uniqueness of the key
         if ( keyJsonValueService.getKeyJsonValue( namespace, key ) != null )
         {
             throw new WebMessageException( WebMessageUtils
                 .conflict( "The key '" + key + "' already exists on the namespace '" + namespace + "'." ) );
         }
 
-        // Check json validity
         if ( !renderService.isValidJson( body ) )
         {
             throw new WebMessageException( WebMessageUtils.badRequest( "The data is not valid JSON." ) );
@@ -159,8 +152,7 @@
         @PathVariable String key,
         @RequestBody String body,
         HttpServletRequest request,
-        HttpServletResponse response
-    )
+        HttpServletResponse response )
         throws WebMessageException, IOException
     {
         KeyJsonValue keyJsonValue = keyJsonValueService.getKeyJsonValue( namespace, key );
@@ -171,7 +163,6 @@
                 .notFound( "The key '" + key + "' was not found in the namespace '" + namespace + "'." ) );
         }
 
-        // Check json validity
         if ( !renderService.isValidJson( body ) )
         {
             throw new WebMessageException( WebMessageUtils.badRequest( "The data is not valid JSON." ) );
@@ -188,8 +179,7 @@
     public void deleteKeyJsonValue(
         @PathVariable String namespace,
         @PathVariable String key,
-        HttpServletResponse response
-    )
+        HttpServletResponse response )
         throws WebMessageException
     {
         KeyJsonValue keyJsonValue = keyJsonValueService.getKeyJsonValue( namespace, key );