dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33863
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17348: support externalize for SqlView
------------------------------------------------------------
revno: 17348
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-11-03 19:28:28 +0700
message:
support externalize for SqlView
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/SqlViewSchemaDescriptor.java
dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/vote/ExternalAccessVoter.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
--
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/schema/descriptors/SqlViewSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/SqlViewSchemaDescriptor.java 2014-09-07 07:42:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/SqlViewSchemaDescriptor.java 2014-11-03 12:28:28 +0000
@@ -52,12 +52,14 @@
public Schema getSchema()
{
Schema schema = new Schema( SqlView.class, SINGULAR, PLURAL );
+ schema.setApiEndpoint( API_ENDPOINT );
schema.setShareable( true );
schema.setOrder( 1010 );
schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_SQLVIEW_PUBLIC_ADD" ) ) );
schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PRIVATE, Lists.newArrayList( "F_SQLVIEW_PRIVATE_ADD" ) ) );
schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_SQLVIEW_DELETE" ) ) );
+ schema.getAuthorities().add( new Authority( AuthorityType.EXTERNALIZE, Lists.newArrayList( "F_SQLVIEW_EXTERNAL" ) ) );
return schema;
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml 2014-03-24 18:52:45 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml 2014-11-03 12:28:28 +0000
@@ -20,6 +20,8 @@
<property name="sqlQuery" not-null="true" type="text" />
<!-- Access properties -->
+ <property name="externalAccess" />
+
<many-to-one name="user" class="org.hisp.dhis.user.User" column="userid" foreign-key="fk_sqlview_userid" />
<property name="publicAccess" length="8" />
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java 2014-10-02 17:01:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SqlViewController.java 2014-11-03 12:28:28 +0000
@@ -28,16 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Set;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.schema.descriptors.SqlViewSchemaDescriptor;
import org.hisp.dhis.sqlview.SqlView;
import org.hisp.dhis.sqlview.SqlViewService;
import org.hisp.dhis.system.grid.GridUtils;
+import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -46,16 +43,17 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Set;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping( value = SqlViewController.RESOURCE_PATH )
+@RequestMapping( value = SqlViewSchemaDescriptor.API_ENDPOINT )
public class SqlViewController
extends AbstractCrudController<SqlView>
{
- public static final String RESOURCE_PATH = "/sqlViews";
-
@Autowired
private SqlViewService sqlViewService;
@@ -63,120 +61,120 @@
private ContextUtils contextUtils;
@RequestMapping( value = "/{uid}/data", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
- public String getViewJson( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, Model model, HttpServletResponse response )
+ public String getViewJson( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, Model model, HttpServletResponse response )
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
model.addAttribute( "model", grid );
model.addAttribute( "viewClass", "detailed" );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
-
+
return grid != null ? "sqlView" : null;
}
@RequestMapping( value = "/{uid}/data.xml", method = RequestMethod.GET )
- public void getViewXml( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewXml( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING );
-
+
GridUtils.toXml( grid, response.getOutputStream() );
}
@RequestMapping( value = "/{uid}/data.csv", method = RequestMethod.GET )
- public void getViewCsv( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewCsv( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "sqlview.csv", true );
-
+
GridUtils.toCsv( grid, response.getOutputStream() );
}
-
+
@RequestMapping( value = "/{uid}/data.xls", method = RequestMethod.GET )
- public void getViewXls( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewXls( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "sqlview.xls", true );
-
+
GridUtils.toXls( grid, response.getOutputStream() );
}
@RequestMapping( value = "/{uid}/data.html", method = RequestMethod.GET )
- public void getViewHtml( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewHtml( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
-
+
GridUtils.toHtml( grid, response.getWriter() );
}
@RequestMapping( value = "/{uid}/data.html+css", method = RequestMethod.GET )
- public void getViewHtmlCss( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewHtmlCss( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
-
+
GridUtils.toHtmlCss( grid, response.getWriter() );
}
@RequestMapping( value = "/{uid}/data.pdf", method = RequestMethod.GET )
- public void getViewPdf( @PathVariable( "uid" ) String uid,
- @RequestParam(required=false) Set<String> criteria, HttpServletResponse response ) throws Exception
+ public void getViewPdf( @PathVariable( "uid" ) String uid,
+ @RequestParam( required = false ) Set<String> criteria, HttpServletResponse response ) throws Exception
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
Grid grid = sqlViewService.getSqlViewGrid( sqlView, SqlView.getCriteria( criteria ) );
-
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.RESPECT_SYSTEM_SETTING );
-
+
GridUtils.toPdf( grid, response.getOutputStream() );
}
-
+
@RequestMapping( value = "/{uid}/execute", method = RequestMethod.POST )
public void executeView( @PathVariable( "uid" ) String uid, HttpServletResponse response )
{
SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
-
+
if ( sqlView == null )
{
ContextUtils.notFoundResponse( response, "SQL view not found" );
return;
}
-
+
String result = sqlViewService.createViewTable( sqlView );
-
+
if ( result != null )
{
ContextUtils.conflictResponse( response, result );
}
else
{
- String location = RESOURCE_PATH + "/" + sqlView.getUid();
-
+ String location = SqlViewSchemaDescriptor.API_ENDPOINT + "/" + sqlView.getUid();
+
ContextUtils.createdResponse( response, "SQL view created", location );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/vote/ExternalAccessVoter.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/vote/ExternalAccessVoter.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/vote/ExternalAccessVoter.java 2014-11-03 12:28:28 +0000
@@ -37,6 +37,7 @@
import org.hisp.dhis.document.Document;
import org.hisp.dhis.report.Report;
import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.sqlview.SqlView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
@@ -67,6 +68,7 @@
externalClasses.put( "reportTables", ReportTable.class );
externalClasses.put( "reports", Report.class );
externalClasses.put( "documents", Document.class );
+ externalClasses.put( "sqlViews", SqlView.class );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2014-10-25 11:56:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2014-11-03 12:28:28 +0000
@@ -304,6 +304,7 @@
<value>F_REPORTTABLE_PUBLIC_ADD</value>
<value>F_MAP_EXTERNAL</value>
<value>F_CHART_EXTERNAL</value>
+ <value>F_SQLVIEW_EXTERNAL</value>
<value>F_REPORTTABLE_EXTERNAL</value>
<value>F_METADATA_EXPORT</value>
<value>F_METADATA_IMPORT</value>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-10-25 11:56:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-11-03 12:28:28 +0000
@@ -226,6 +226,7 @@
F_SQLVIEW_DELETE=Delete SQL View
F_SQLVIEW_EXECUTE=Execute SQL View
F_SQLVIEW_MANAGEMENT=Sql View Management
+F_SQLVIEW_EXTERNAL=Sql View External Access
F_VALIDATIONCRITERIA_ADD=Add/Update Validation Criteria
F_VALIDATIONCRITERIA_DELETE=Delete Validation Criteria
F_SEND_MESSAGE=Send message