dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30952
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15738: reorganized messageConverters, split RootNodeMessageConverter into XmlMessageConverter and JsonMe...
------------------------------------------------------------
revno: 15738
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-18 09:15:48 +0200
message:
reorganized messageConverters, split RootNodeMessageConverter into XmlMessageConverter and JsonMessageConverter
removed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultContextService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RenderServiceMessageConverter.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RootNodeMessageConverter.java
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/JsonMessageConverter.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/RenderServiceMessageConverter.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/XmlMessageConverter.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/ContextService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultContextService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-17 19:48:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-18 07:15:48 +0000
@@ -57,9 +57,9 @@
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.webapi.controller.exception.NotFoundException;
-import org.hisp.dhis.webapi.utils.ContextService;
+import org.hisp.dhis.webapi.service.ContextService;
import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.utils.LinkService;
+import org.hisp.dhis.webapi.service.LinkService;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-06-11 20:27:54 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-06-18 07:15:48 +0000
@@ -34,7 +34,7 @@
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.PagerUtils;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.webapi.utils.LinkService;
+import org.hisp.dhis.webapi.service.LinkService;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/JsonMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/JsonMessageConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/JsonMessageConverter.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.webapi.messageconverter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.collect.ImmutableList;
+import org.hisp.dhis.node.NodeService;
+import org.hisp.dhis.node.types.RootNode;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.AbstractHttpMessageConverter;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Component
+public class JsonMessageConverter extends AbstractHttpMessageConverter<RootNode>
+{
+ @Autowired
+ private NodeService nodeService;
+
+ public final ImmutableList<MediaType> SUPPORTED_MEDIA_TYPES = ImmutableList.<MediaType>builder()
+ .add( new MediaType( "application", "json", Charset.forName( "UTF-8" ) ) )
+ .build();
+
+ public JsonMessageConverter()
+ {
+ setSupportedMediaTypes( SUPPORTED_MEDIA_TYPES );
+ }
+
+ @Override
+ protected boolean supports( Class<?> clazz )
+ {
+ return RootNode.class.equals( clazz );
+ }
+
+ @Override
+ protected boolean canRead( MediaType mediaType )
+ {
+ return false;
+ }
+
+ @Override
+ protected RootNode readInternal( Class<? extends RootNode> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
+ {
+ return null;
+ }
+
+ @Override
+ protected void writeInternal( RootNode rootNode, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
+ {
+ nodeService.serialize( rootNode, "application/json", outputMessage.getBody() );
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/RenderServiceMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/RenderServiceMessageConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/RenderServiceMessageConverter.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,120 @@
+package org.hisp.dhis.webapi.messageconverter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import org.hisp.dhis.dxf2.render.RenderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.AbstractHttpMessageConverter;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+
+import java.io.IOException;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class RenderServiceMessageConverter extends AbstractHttpMessageConverter<Object>
+{
+ @Autowired
+ private RenderService renderService;
+
+ public RenderServiceMessageConverter( MediaType... supportedMediaTypes )
+ {
+ super( supportedMediaTypes );
+ }
+
+ @Override
+ protected boolean supports( Class<?> clazz )
+ {
+ return Object.class.isAssignableFrom( clazz );
+ }
+
+ @Override
+ protected Object readInternal( Class<?> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
+ {
+ MediaType mediaType = inputMessage.getHeaders().getContentType();
+
+ if ( mediaType.getSubtype().equals( "json" ) )
+ {
+ return renderService.fromJson( inputMessage.getBody(), clazz );
+ }
+ else if ( mediaType.getSubtype().equals( "xml" ) )
+ {
+ return renderService.fromXml( inputMessage.getBody(), clazz );
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void writeInternal( Object object, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
+ {
+ MediaType mediaType = outputMessage.getHeaders().getContentType();
+
+ if ( mediaType.getSubtype().equals( "json" ) )
+ {
+ renderService.toJson( outputMessage.getBody(), object );
+ }
+ else if ( mediaType.getSubtype().equals( "xml" ) )
+ {
+ renderService.toXml( outputMessage.getBody(), object );
+ }
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/XmlMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/XmlMessageConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/messageconverter/XmlMessageConverter.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.webapi.messageconverter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.collect.ImmutableList;
+import org.hisp.dhis.node.NodeService;
+import org.hisp.dhis.node.types.RootNode;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.AbstractHttpMessageConverter;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Component
+public class XmlMessageConverter extends AbstractHttpMessageConverter<RootNode>
+{
+ @Autowired
+ private NodeService nodeService;
+
+ public final ImmutableList<MediaType> SUPPORTED_MEDIA_TYPES = ImmutableList.<MediaType>builder()
+ .add( new MediaType( "application", "xml", Charset.forName( "UTF-8" ) ) )
+ .add( new MediaType( "text", "xml", Charset.forName( "UTF-8" ) ) )
+ .build();
+
+ public XmlMessageConverter()
+ {
+ setSupportedMediaTypes( SUPPORTED_MEDIA_TYPES );
+ }
+
+ @Override
+ protected boolean supports( Class<?> clazz )
+ {
+ return RootNode.class.equals( clazz );
+ }
+
+ @Override
+ protected boolean canRead( MediaType mediaType )
+ {
+ return false;
+ }
+
+ @Override
+ protected RootNode readInternal( Class<? extends RootNode> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
+ {
+ return null;
+ }
+
+ @Override
+ protected void writeInternal( RootNode rootNode, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
+ {
+ nodeService.serialize( rootNode, "application/xml", outputMessage.getBody() );
+ }
+}
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/ContextService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/ContextService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/ContextService.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.webapi.service;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface ContextService
+{
+ /**
+ * Get full path of servlet.
+ *
+ * @return Full HREF to servlet
+ * @see javax.servlet.http.HttpServletRequest
+ */
+ String getServletPath();
+
+ /**
+ * Get HREF to context.
+ *
+ * @return Full HREF to context (context root)
+ * @see javax.servlet.http.HttpServletRequest
+ */
+ String getContextPath();
+
+ /**
+ * Get active HttpServletRequest
+ *
+ * @return HttpServletRequest
+ */
+ HttpServletRequest getRequest();
+
+ /**
+ * Returns a list of values from a parameter, if the parameter doesn't exist, it will
+ * return a empty list.
+ *
+ * @param name Parameter to get
+ * @return List of parameter values, or empty if not found
+ */
+ Set<String> getParameterValues( String name );
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultContextService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultContextService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultContextService.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,113 @@
+package org.hisp.dhis.webapi.service;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.collect.Sets;
+import org.springframework.stereotype.Service;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Service
+public class DefaultContextService implements ContextService
+{
+ @Override
+ public String getServletPath()
+ {
+ HttpServletRequest request = getRequest();
+ return getContextPath() + request.getServletPath();
+ }
+
+ @Override
+ public String getContextPath()
+ {
+ HttpServletRequest request = getRequest();
+ StringBuilder builder = new StringBuilder();
+ String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
+ String xForwardedPort = request.getHeader( "X-Forwarded-Port" );
+
+ if ( xForwardedProto != null && (xForwardedProto.equalsIgnoreCase( "http" ) || xForwardedProto.equalsIgnoreCase( "https" )) )
+ {
+ builder.append( xForwardedProto );
+ }
+ else
+ {
+ builder.append( request.getScheme() );
+ }
+
+ builder.append( "://" ).append( request.getServerName() );
+
+ int port;
+
+ try
+ {
+ port = Integer.parseInt( xForwardedPort );
+ }
+ catch ( NumberFormatException e )
+ {
+ port = request.getServerPort();
+ }
+
+ if ( port != 80 && port != 443 )
+ {
+ builder.append( ":" ).append( port );
+ }
+
+ builder.append( request.getContextPath() );
+
+ return builder.toString();
+ }
+
+ @Override
+ public HttpServletRequest getRequest()
+ {
+ return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+ }
+
+ @Override
+ public Set<String> getParameterValues( String name )
+ {
+ if ( getRequest().getParameterValues( name ) == null )
+ {
+ return Sets.newHashSet();
+ }
+
+ Set<String> parameter = Sets.newHashSet();
+ String[] parameterValues = getRequest().getParameterValues( name );
+ Collections.addAll( parameter, parameterValues );
+
+ return parameter;
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,225 @@
+package org.hisp.dhis.webapi.service;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import javassist.util.proxy.ProxyFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.collection.spi.PersistentCollection;
+import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Service
+public class DefaultLinkService implements LinkService
+{
+ private static final Log log = LogFactory.getLog( DefaultLinkService.class );
+
+ @Autowired
+ private SchemaService schemaService;
+
+ @Autowired
+ private ContextService contextService;
+
+ @Override
+ public void generatePagerLinks( Pager pager, Class<?> klass )
+ {
+ if ( pager == null )
+ {
+ return;
+ }
+
+ Schema schema = schemaService.getDynamicSchema( klass );
+
+ if ( !schema.haveEndpoint() )
+ {
+ return;
+ }
+
+ String endpoint = contextService.getServletPath() + "/" + schema.getApiEndpoint();
+
+ if ( pager.getPage() < pager.getPageCount() )
+ {
+ String nextPath = endpoint + "?page=" + (pager.getPage() + 1);
+ nextPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
+
+ pager.setNextPage( nextPath );
+ }
+
+ if ( pager.getPage() > 1 )
+ {
+ if ( (pager.getPage() - 1) == 1 )
+ {
+ String prevPath = pager.pageSizeIsDefault() ? endpoint : endpoint + "?pageSize=" + pager.getPageSize();
+ pager.setPrevPage( prevPath );
+ }
+ else
+ {
+ String prevPath = endpoint + "?page=" + (pager.getPage() - 1);
+ prevPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
+
+ pager.setPrevPage( prevPath );
+ }
+ }
+ }
+
+ @Override
+ public <T> void generateLinks( T object )
+ {
+ generateLinks( object, contextService.getServletPath() );
+ }
+
+ @Override
+ public <T> void generateLinks( T object, String hrefBase )
+ {
+ if ( Collection.class.isInstance( object ) )
+ {
+ Collection<?> collection = (Collection<?>) object;
+
+ for ( Object collectionObject : collection )
+ {
+ generateLink( collectionObject, hrefBase, false );
+ }
+ }
+ else
+ {
+ generateLink( object, hrefBase, true );
+ }
+ }
+
+ private <T> void generateLink( T object, String hrefBase, boolean deepScan )
+ {
+ Schema schema = schemaService.getDynamicSchema( object.getClass() );
+
+ if ( schema == null )
+ {
+ log.warn( "Could not find schema for object of type " + object.getClass().getName() + "." );
+ return;
+ }
+
+ generateHref( object, hrefBase );
+
+ if ( !deepScan )
+ {
+ return;
+ }
+
+ for ( Property property : schema.getProperties() )
+ {
+ try
+ {
+ // TODO should we support non-idObjects?
+ if ( property.isIdentifiableObject() )
+ {
+ Object propertyObject = property.getGetterMethod().invoke( object );
+
+ if ( propertyObject == null )
+ {
+ continue;
+ }
+
+ // unwrap hibernate PersistentCollection
+ if ( PersistentCollection.class.isAssignableFrom( propertyObject.getClass() ) )
+ {
+ PersistentCollection collection = (PersistentCollection) propertyObject;
+ propertyObject = collection.getValue();
+ }
+
+ if ( !property.isCollection() )
+ {
+ generateHref( propertyObject, hrefBase );
+ }
+ else
+ {
+ Collection<?> collection = (Collection<?>) propertyObject;
+
+ for ( Object collectionObject : collection )
+ {
+ generateHref( collectionObject, hrefBase );
+ }
+ }
+
+ }
+ }
+ catch ( InvocationTargetException | IllegalAccessException ignored )
+ {
+ }
+ }
+ }
+
+ private <T> void generateHref( T object, String hrefBase )
+ {
+ if ( object == null )
+ {
+ return;
+ }
+
+ Class<?> klass = object.getClass();
+
+ if ( ProxyFactory.isProxyClass( klass ) )
+ {
+ klass = klass.getSuperclass();
+ }
+
+ Schema schema = schemaService.getDynamicSchema( klass );
+
+ if ( !schema.haveEndpoint() )
+ {
+ return;
+ }
+
+ try
+ {
+ Method getUid = object.getClass().getMethod( "getUid" );
+ Object value = getUid.invoke( object );
+
+ if ( !String.class.isInstance( value ) )
+ {
+ log.warn( "getUid on object of type " + object.getClass().getName() + " does not return a String." );
+ return;
+ }
+
+ Method setHref = object.getClass().getMethod( "setHref", String.class );
+ setHref.invoke( object, hrefBase + schema.getApiEndpoint() + "/" + value );
+ }
+ catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored )
+ {
+ }
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java 2014-06-18 07:15:48 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.webapi.service;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import org.hisp.dhis.common.Pager;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface LinkService
+{
+ /**
+ * Generate next/prev links for Pager class. Needs to know which class we are generating
+ * the pager for, so it can fetch the endpoint.
+ *
+ * @param pager Pager instance to update with prev/next links
+ * @param klass Class type which is paged
+ * @see org.hisp.dhis.common.Pager
+ */
+ void generatePagerLinks( Pager pager, Class<?> klass );
+
+ /**
+ * Generate HREF and set it using reflection, required a setHref(String) method in your class.
+ * <p/>
+ * Uses hrefBase from ContextService.getServletPath().
+ *
+ * @param object Object (can be collection) to set HREFs on
+ * @see javax.servlet.http.HttpServletRequest
+ * @see ContextService
+ */
+ <T> void generateLinks( T object );
+
+ /**
+ * Generate HREF and set it using reflection, required a setHref(String) method in your class.
+ *
+ * @param object Object (can be collection) to set HREFs on
+ * @param hrefBase Used as starting point of HREF
+ * @see javax.servlet.http.HttpServletRequest
+ */
+ <T> void generateLinks( T object, String hrefBase );
+}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextService.java 2014-06-07 14:03:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextService.java 1970-01-01 00:00:00 +0000
@@ -1,70 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.Set;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface ContextService
-{
- /**
- * Get full path of servlet.
- *
- * @return Full HREF to servlet
- * @see javax.servlet.http.HttpServletRequest
- */
- String getServletPath();
-
- /**
- * Get HREF to context.
- *
- * @return Full HREF to context (context root)
- * @see javax.servlet.http.HttpServletRequest
- */
- String getContextPath();
-
- /**
- * Get active HttpServletRequest
- *
- * @return HttpServletRequest
- */
- HttpServletRequest getRequest();
-
- /**
- * Returns a list of values from a parameter, if the parameter doesn't exist, it will
- * return a empty list.
- *
- * @param name Parameter to get
- * @return List of parameter values, or empty if not found
- */
- Set<String> getParameterValues( String name );
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultContextService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultContextService.java 2014-06-05 17:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultContextService.java 1970-01-01 00:00:00 +0000
@@ -1,113 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import com.google.common.collect.Sets;
-import org.springframework.stereotype.Service;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Service
-public class DefaultContextService implements ContextService
-{
- @Override
- public String getServletPath()
- {
- HttpServletRequest request = getRequest();
- return getContextPath() + request.getServletPath();
- }
-
- @Override
- public String getContextPath()
- {
- HttpServletRequest request = getRequest();
- StringBuilder builder = new StringBuilder();
- String xForwardedProto = request.getHeader( "X-Forwarded-Proto" );
- String xForwardedPort = request.getHeader( "X-Forwarded-Port" );
-
- if ( xForwardedProto != null && (xForwardedProto.equalsIgnoreCase( "http" ) || xForwardedProto.equalsIgnoreCase( "https" )) )
- {
- builder.append( xForwardedProto );
- }
- else
- {
- builder.append( request.getScheme() );
- }
-
- builder.append( "://" ).append( request.getServerName() );
-
- int port;
-
- try
- {
- port = Integer.parseInt( xForwardedPort );
- }
- catch ( NumberFormatException e )
- {
- port = request.getServerPort();
- }
-
- if ( port != 80 && port != 443 )
- {
- builder.append( ":" ).append( port );
- }
-
- builder.append( request.getContextPath() );
-
- return builder.toString();
- }
-
- @Override
- public HttpServletRequest getRequest()
- {
- return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- }
-
- @Override
- public Set<String> getParameterValues( String name )
- {
- if ( getRequest().getParameterValues( name ) == null )
- {
- return Sets.newHashSet();
- }
-
- Set<String> parameter = Sets.newHashSet();
- String[] parameterValues = getRequest().getParameterValues( name );
- Collections.addAll( parameter, parameterValues );
-
- return parameter;
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java 2014-06-17 19:48:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/DefaultLinkService.java 1970-01-01 00:00:00 +0000
@@ -1,225 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import javassist.util.proxy.ProxyFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.collection.spi.PersistentCollection;
-import org.hisp.dhis.common.Pager;
-import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.Schema;
-import org.hisp.dhis.schema.SchemaService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collection;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Service
-public class DefaultLinkService implements LinkService
-{
- private static final Log log = LogFactory.getLog( DefaultLinkService.class );
-
- @Autowired
- private SchemaService schemaService;
-
- @Autowired
- private ContextService contextService;
-
- @Override
- public void generatePagerLinks( Pager pager, Class<?> klass )
- {
- if ( pager == null )
- {
- return;
- }
-
- Schema schema = schemaService.getDynamicSchema( klass );
-
- if ( !schema.haveEndpoint() )
- {
- return;
- }
-
- String endpoint = contextService.getServletPath() + "/" + schema.getApiEndpoint();
-
- if ( pager.getPage() < pager.getPageCount() )
- {
- String nextPath = endpoint + "?page=" + (pager.getPage() + 1);
- nextPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
-
- pager.setNextPage( nextPath );
- }
-
- if ( pager.getPage() > 1 )
- {
- if ( (pager.getPage() - 1) == 1 )
- {
- String prevPath = pager.pageSizeIsDefault() ? endpoint : endpoint + "?pageSize=" + pager.getPageSize();
- pager.setPrevPage( prevPath );
- }
- else
- {
- String prevPath = endpoint + "?page=" + (pager.getPage() - 1);
- prevPath += pager.pageSizeIsDefault() ? "" : "&pageSize=" + pager.getPageSize();
-
- pager.setPrevPage( prevPath );
- }
- }
- }
-
- @Override
- public <T> void generateLinks( T object )
- {
- generateLinks( object, contextService.getServletPath() );
- }
-
- @Override
- public <T> void generateLinks( T object, String hrefBase )
- {
- if ( Collection.class.isInstance( object ) )
- {
- Collection<?> collection = (Collection<?>) object;
-
- for ( Object collectionObject : collection )
- {
- generateLink( collectionObject, hrefBase, false );
- }
- }
- else
- {
- generateLink( object, hrefBase, true );
- }
- }
-
- private <T> void generateLink( T object, String hrefBase, boolean deepScan )
- {
- Schema schema = schemaService.getDynamicSchema( object.getClass() );
-
- if ( schema == null )
- {
- log.warn( "Could not find schema for object of type " + object.getClass().getName() + "." );
- return;
- }
-
- generateHref( object, hrefBase );
-
- if ( !deepScan )
- {
- return;
- }
-
- for ( Property property : schema.getProperties() )
- {
- try
- {
- // TODO should we support non-idObjects?
- if ( property.isIdentifiableObject() )
- {
- Object propertyObject = property.getGetterMethod().invoke( object );
-
- if ( propertyObject == null )
- {
- continue;
- }
-
- // unwrap hibernate PersistentCollection
- if ( PersistentCollection.class.isAssignableFrom( propertyObject.getClass() ) )
- {
- PersistentCollection collection = (PersistentCollection) propertyObject;
- propertyObject = collection.getValue();
- }
-
- if ( !property.isCollection() )
- {
- generateHref( propertyObject, hrefBase );
- }
- else
- {
- Collection<?> collection = (Collection<?>) propertyObject;
-
- for ( Object collectionObject : collection )
- {
- generateHref( collectionObject, hrefBase );
- }
- }
-
- }
- }
- catch ( InvocationTargetException | IllegalAccessException ignored )
- {
- }
- }
- }
-
- private <T> void generateHref( T object, String hrefBase )
- {
- if ( object == null )
- {
- return;
- }
-
- Class<?> klass = object.getClass();
-
- if ( ProxyFactory.isProxyClass( klass ) )
- {
- klass = klass.getSuperclass();
- }
-
- Schema schema = schemaService.getDynamicSchema( klass );
-
- if ( !schema.haveEndpoint() )
- {
- return;
- }
-
- try
- {
- Method getUid = object.getClass().getMethod( "getUid" );
- Object value = getUid.invoke( object );
-
- if ( !String.class.isInstance( value ) )
- {
- log.warn( "getUid on object of type " + object.getClass().getName() + " does not return a String." );
- return;
- }
-
- Method setHref = object.getClass().getMethod( "setHref", String.class );
- setHref.invoke( object, hrefBase + schema.getApiEndpoint() + "/" + value );
- }
- catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored )
- {
- }
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java 2014-06-17 19:48:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/LinkService.java 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import org.hisp.dhis.common.Pager;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface LinkService
-{
- /**
- * Generate next/prev links for Pager class. Needs to know which class we are generating
- * the pager for, so it can fetch the endpoint.
- *
- * @param pager Pager instance to update with prev/next links
- * @param klass Class type which is paged
- * @see org.hisp.dhis.common.Pager
- */
- void generatePagerLinks( Pager pager, Class<?> klass );
-
- /**
- * Generate HREF and set it using reflection, required a setHref(String) method in your class.
- * <p/>
- * Uses hrefBase from ContextService.getServletPath().
- *
- * @param object Object (can be collection) to set HREFs on
- * @see javax.servlet.http.HttpServletRequest
- * @see org.hisp.dhis.webapi.utils.ContextService
- */
- <T> void generateLinks( T object );
-
- /**
- * Generate HREF and set it using reflection, required a setHref(String) method in your class.
- *
- * @param object Object (can be collection) to set HREFs on
- * @param hrefBase Used as starting point of HREF
- * @see javax.servlet.http.HttpServletRequest
- */
- <T> void generateLinks( T object, String hrefBase );
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RenderServiceMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RenderServiceMessageConverter.java 2014-06-17 07:49:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RenderServiceMessageConverter.java 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import org.hisp.dhis.dxf2.render.RenderService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpInputMessage;
-import org.springframework.http.HttpOutputMessage;
-import org.springframework.http.MediaType;
-import org.springframework.http.converter.AbstractHttpMessageConverter;
-import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.http.converter.HttpMessageNotWritableException;
-
-import java.io.IOException;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class RenderServiceMessageConverter extends AbstractHttpMessageConverter<Object>
-{
- @Autowired
- private RenderService renderService;
-
- public RenderServiceMessageConverter( MediaType... supportedMediaTypes )
- {
- super( supportedMediaTypes );
- }
-
- @Override
- protected boolean supports( Class<?> clazz )
- {
- return Object.class.isAssignableFrom( clazz );
- }
-
- @Override
- protected Object readInternal( Class<?> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
- {
- MediaType mediaType = inputMessage.getHeaders().getContentType();
-
- if ( mediaType.getSubtype().equals( "json" ) )
- {
- return renderService.fromJson( inputMessage.getBody(), clazz );
- }
- else if ( mediaType.getSubtype().equals( "xml" ) )
- {
- return renderService.fromXml( inputMessage.getBody(), clazz );
- }
-
- return null;
- }
-
- @Override
- protected void writeInternal( Object object, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
- {
- MediaType mediaType = outputMessage.getHeaders().getContentType();
-
- if ( mediaType.getSubtype().equals( "json" ) )
- {
- renderService.toJson( outputMessage.getBody(), object );
- }
- else if ( mediaType.getSubtype().equals( "xml" ) )
- {
- renderService.toXml( outputMessage.getBody(), object );
- }
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RootNodeMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RootNodeMessageConverter.java 2014-06-01 13:38:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/RootNodeMessageConverter.java 1970-01-01 00:00:00 +0000
@@ -1,82 +0,0 @@
-package org.hisp.dhis.webapi.utils;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import org.hisp.dhis.node.NodeService;
-import org.hisp.dhis.node.types.RootNode;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpInputMessage;
-import org.springframework.http.HttpOutputMessage;
-import org.springframework.http.MediaType;
-import org.springframework.http.converter.AbstractHttpMessageConverter;
-import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.http.converter.HttpMessageNotWritableException;
-
-import java.io.IOException;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class RootNodeMessageConverter extends AbstractHttpMessageConverter<RootNode>
-{
- @Autowired
- private NodeService nodeService;
-
- public RootNodeMessageConverter( MediaType... supportedMediaTypes )
- {
- super( supportedMediaTypes );
- }
-
- @Override
- protected boolean supports( Class<?> clazz )
- {
- return RootNode.class.equals( clazz );
- }
-
- @Override
- protected boolean canRead( MediaType mediaType )
- {
- return false;
- }
-
- @Override
- protected RootNode readInternal( Class<? extends RootNode> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
- {
- return null;
- }
-
- @Override
- protected void writeInternal( RootNode rootNode, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
- {
- MediaType mediaType = outputMessage.getHeaders().getContentType();
- String contentType = String.format( "%s/%s", mediaType.getType(), mediaType.getSubtype() );
-
- nodeService.serialize( rootNode, contentType, outputMessage.getBody() );
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2014-06-02 07:45:44 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2014-06-18 07:15:48 +0000
@@ -13,16 +13,8 @@
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
- <bean id="org.hisp.dhis.webapi.utils.RootNodeMessageConverter" class="org.hisp.dhis.webapi.utils.RootNodeMessageConverter">
- <constructor-arg name="supportedMediaTypes">
- <list>
- <value>application/json</value>
- <value>application/xml</value>
- </list>
- </constructor-arg>
- </bean>
-
- <bean id="org.hisp.dhis.webapi.utils.RenderServiceMessageConverter" class="org.hisp.dhis.webapi.utils.RenderServiceMessageConverter">
+ <bean id="org.hisp.dhis.webapi.utils.RenderServiceMessageConverter"
+ class="org.hisp.dhis.webapi.messageconverter.RenderServiceMessageConverter">
<constructor-arg name="supportedMediaTypes">
<list>
<value>application/json</value>
@@ -33,7 +25,8 @@
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
- <ref bean="org.hisp.dhis.webapi.utils.RootNodeMessageConverter" />
+ <ref bean="xmlMessageConverter" />
+ <ref bean="jsonMessageConverter" />
<ref bean="org.hisp.dhis.webapi.utils.RenderServiceMessageConverter" />
<bean class="org.hisp.dhis.api.mobile.support.DataStreamSerializableMessageConverter" />
</mvc:message-converters>