dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32780
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16700: fixes to options/optionSets for dxf2 importer
------------------------------------------------------------
revno: 16700
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-09-12 15:50:22 +0700
message:
fixes to options/optionSets for dxf2 importer
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OptionSchemaDescriptor.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/Option.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/option/Option.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/Option.java 2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/Option.java 2014-09-12 08:50:22 +0000
@@ -35,8 +35,6 @@
/**
* @author Chau Thu Tran
- *
- * @version $ Option.java Jul 28, 2014 4:28:53 PM $
*/
@JacksonXmlRootElement( localName = "option", namespace = DxfNamespaces.DXF_2_0 )
public class Option
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionSet.java 2014-09-12 08:50:22 +0000
@@ -30,6 +30,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -37,6 +38,7 @@
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.annotation.Scanned;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
@@ -54,6 +56,7 @@
{
private static final Pattern OPTION_PATTERN = Pattern.compile( "\\[(.*)\\]" );
+ @Scanned
private List<Option> options = new ArrayList<>();
/**
@@ -76,6 +79,7 @@
}
@JsonProperty
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlElementWrapper( localName = "options", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "option", namespace = DxfNamespaces.DXF_2_0 )
@@ -129,10 +133,12 @@
public List<String> getOptionValues()
{
List<String> result = new ArrayList<>();
+
for( Option option : options )
{
result.add( option.getName() );
}
+
return result;
}
}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OptionSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OptionSchemaDescriptor.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OptionSchemaDescriptor.java 2014-09-12 08:50:22 +0000
@@ -0,0 +1,68 @@
+package org.hisp.dhis.schema.descriptors;
+
+/*
+ * 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.Lists;
+import org.hisp.dhis.option.Option;
+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;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Component
+public class OptionSchemaDescriptor implements SchemaDescriptor
+{
+ public static final String SINGULAR = "option";
+
+ public static final String PLURAL = "options";
+
+ public static final String API_ENDPOINT = "/" + PLURAL;
+
+ @Override
+ public Schema getSchema()
+ {
+ Schema schema = new Schema( Option.class, SINGULAR, PLURAL );
+
+ // TODO should probably expose endpoint for option also
+ // schema.setApiEndpoint( API_ENDPOINT );
+
+ schema.setShareable( false );
+ schema.setOrder( 1040 );
+
+ schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_OPTIONSET_PUBLIC_ADD" ) ) );
+ schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PRIVATE, Lists.newArrayList( "F_OPTIONSET_PRIVATE_ADD" ) ) );
+ schema.getAuthorities().add( new Authority( AuthorityType.DELETE, Lists.newArrayList( "F_OPTIONSET_DELETE" ) ) );
+
+ return schema;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java 2014-09-12 08:50:22 +0000
@@ -72,6 +72,7 @@
import org.hisp.dhis.mapping.MapLegendSet;
import org.hisp.dhis.mapping.MapView;
import org.hisp.dhis.message.MessageConversation;
+import org.hisp.dhis.option.Option;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
@@ -130,6 +131,8 @@
private List<Interpretation> interpretations = new ArrayList<>();
+ private List<Option> options = new ArrayList<>();
+
private List<OptionSet> optionSets = new ArrayList<>();
private List<DataElementCategory> categories = new ArrayList<>();
@@ -362,6 +365,19 @@
}
@JsonProperty
+ @JacksonXmlElementWrapper( localName = "options", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "option", namespace = DxfNamespaces.DXF_2_0 )
+ public List<Option> getOptions()
+ {
+ return options;
+ }
+
+ public void setOptions( List<Option> options )
+ {
+ this.options = options;
+ }
+
+ @JsonProperty
@JacksonXmlElementWrapper( localName = "optionSets", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "optionSet", namespace = DxfNamespaces.DXF_2_0 )
public List<OptionSet> getOptionSets()
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2014-09-11 06:03:17 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2014-09-12 08:50:22 +0000
@@ -1150,7 +1150,7 @@
'}';
}
- return object.toString();
+ return object != null ? object.toString() : "object is null";
}
private void reportReferenceError( Object object, Object reference )