← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14432: include authority info in Schemas, wip

 

------------------------------------------------------------
revno: 14432
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-26 14:14:42 +0100
message:
  include authority info in Schemas, wip
removed:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authorities.java
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authority.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/AuthorityType.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/DataElementSchemaDescriptor.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
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authorities.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authorities.java	2014-03-26 12:33:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authorities.java	1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
-package org.hisp.dhis.schema;
-
-/*
- * 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.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@JacksonXmlRootElement( localName = "authorities", namespace = DxfNamespaces.DXF_2_0 )
-public class Authorities
-{
-    List<String> publicCreate;
-
-    List<String> privateCreate;
-}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authority.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authority.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Authority.java	2014-03-26 13:14:42 +0000
@@ -0,0 +1,133 @@
+package org.hisp.dhis.schema;
+
+/*
+ * 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.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "authority", namespace = DxfNamespaces.DXF_2_0 )
+public class Authority
+{
+    private AuthorityType type;
+
+    private Boolean publicAuthority;
+
+    private Boolean privateAuthority;
+
+    private Boolean externalAuthority;
+
+    private List<String> authorities;
+
+    public Authority()
+    {
+    }
+
+    public Authority( AuthorityType type, List<String> authorities )
+    {
+        this.type = type;
+        this.authorities = authorities;
+    }
+
+    public Authority( AuthorityType type, boolean isPublic, List<String> authorities )
+    {
+        this.type = type;
+        this.publicAuthority = isPublic;
+        this.privateAuthority = !isPublic;
+        this.authorities = authorities;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public AuthorityType getType()
+    {
+        return type;
+    }
+
+    public void setType( AuthorityType type )
+    {
+        this.type = type;
+    }
+
+    @JsonProperty( "public" )
+    @JacksonXmlProperty( isAttribute = true )
+    public Boolean getPublicAuthority()
+    {
+        return publicAuthority;
+    }
+
+    public void setPublicAuthority( Boolean publicAuthority )
+    {
+        this.publicAuthority = publicAuthority;
+    }
+
+    @JsonProperty( "private" )
+    @JacksonXmlProperty( isAttribute = true )
+    public Boolean getPrivateAuthority()
+    {
+        return privateAuthority;
+    }
+
+    public void setPrivateAuthority( Boolean privateAuthority )
+    {
+        this.privateAuthority = privateAuthority;
+    }
+
+    @JsonProperty( "external" )
+    @JacksonXmlProperty( isAttribute = true )
+    public Boolean getExternalAuthority()
+    {
+        return externalAuthority;
+    }
+
+    public void setExternalAuthority( Boolean externalAuthority )
+    {
+        this.externalAuthority = externalAuthority;
+    }
+
+    @JsonProperty
+    @JacksonXmlElementWrapper( localName = "authorities", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "authority", namespace = DxfNamespaces.DXF_2_0 )
+    public List<String> getAuthorities()
+    {
+        return authorities;
+    }
+
+    public void setAuthorities( List<String> authorities )
+    {
+        this.authorities = authorities;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/AuthorityType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/AuthorityType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/AuthorityType.java	2014-03-26 13:14:42 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.schema;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum AuthorityType
+{
+    CREATE, READ, UPDATE, DELETE
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-03-26 11:32:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-03-26 13:14:42 +0000
@@ -60,7 +60,7 @@
 
     private boolean shareable;
 
-    private Authorities authorities;
+    private List<Authority> authorities = Lists.newArrayList();
 
     private List<String> publicAuthorities = Lists.newArrayList();
 
@@ -142,13 +142,14 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public Authorities getAuthorities()
+    @JacksonXmlElementWrapper( localName = "authorities", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "authority", namespace = DxfNamespaces.DXF_2_0 )
+    public List<Authority> getAuthorities()
     {
         return authorities;
     }
 
-    public void setAuthorities( Authorities authorities )
+    public void setAuthorities( List<Authority> authorities )
     {
         this.authorities = authorities;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/DataElementSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/DataElementSchemaDescriptor.java	2014-03-26 09:23:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/DataElementSchemaDescriptor.java	2014-03-26 13:14:42 +0000
@@ -30,6 +30,8 @@
 
 import com.google.common.collect.Lists;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.schema.Authority;
+import org.hisp.dhis.schema.AuthorityType;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaDescriptor;
 import org.springframework.stereotype.Component;
@@ -46,8 +48,10 @@
         Schema schema = new Schema( DataElement.class, "dataElement", "dataElements" );
 
         schema.setShareable( true );
-        schema.setPublicAuthorities( Lists.newArrayList( "F_DATAELEMENT_PUBLIC_ADD" ) );
-        schema.setPrivateAuthorities( Lists.newArrayList( "F_DATAELEMENT_PRIVATE_ADD" ) );
+
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE, true, Lists.newArrayList( "F_DATAELEMENT_PUBLIC_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.CREATE, false, Lists.newArrayList( "F_DATAELEMENT_PRIVATE_ADD" ) ) );
+        schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_DATAELEMENT_DELETE" ) ) );
 
         return schema;
     }