Skip to content

Commit

Permalink
feat: use appropriate methods to convert the numbers in XML
Browse files Browse the repository at this point in the history
Conversion of the numbers using appropriate methods of each different type.

ING-3965
  • Loading branch information
emanuelaepure10 committed May 7, 2024
1 parent e2c5dd5 commit 4b3eb6c
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 0 deletions.
30 changes: 30 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.gml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,36 @@
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlTimeToTimestamp">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlIntegerToInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.IntegerToXmlInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.FloatToXmlFloat">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlFloatToFloat">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.LongToXmlLong">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlLongToLong">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.DoubleToXmlDouble">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlDoubleToDouble">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.BigDecimalToXmlDecimal">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlDecimalToBigDecimal">
</converter>
</extension>
<extension
point="eu.esdihumboldt.util.groovy.sandbox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
import org.apache.xmlbeans.XmlAnySimpleType;
import org.apache.xmlbeans.XmlDate;
import org.apache.xmlbeans.XmlDateTime;
import org.apache.xmlbeans.XmlDecimal;
import org.apache.xmlbeans.XmlDouble;
import org.apache.xmlbeans.XmlFloat;
import org.apache.xmlbeans.XmlInteger;
import org.apache.xmlbeans.XmlLong;
import org.apache.xmlbeans.XmlTime;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionService;
Expand Down Expand Up @@ -62,6 +67,12 @@ public class SimpleTypeUtil {
TYPE_MAP.put("dateTime", XmlDateTime.class); //$NON-NLS-1$
TYPE_MAP.put("date", XmlDate.class); //$NON-NLS-1$
TYPE_MAP.put("time", XmlTime.class); //$NON-NLS-1$

TYPE_MAP.put("integer", XmlInteger.class); //$NON-NLS-1$
TYPE_MAP.put("float", XmlFloat.class); //$NON-NLS-1$
TYPE_MAP.put("double", XmlDouble.class); //$NON-NLS-1$
TYPE_MAP.put("long", XmlLong.class); //$NON-NLS-1$
TYPE_MAP.put("decimal", XmlDecimal.class); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -111,6 +122,7 @@ else if (simpleTypeValue instanceof XmlDateTime) {
xmlDateTime.setGDateValue(gdate);
}

// Numbers should be handled here
if (simpleTypeValue != null) {
return simpleTypeValue.getStringValue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import java.math.BigDecimal;

import org.apache.xmlbeans.XmlDecimal;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:BigDecimal to {@link XmlDecimal}
*/
public class BigDecimalToXmlDecimal implements Converter<BigDecimal, XmlDecimal> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlDecimal convert(BigDecimal value) {
if (value == null) {
return null;
}

// Convert BigDecimal to string
String stringValue = value.toPlainString();

XmlDecimal xmlDecimalValue = XmlDecimal.Factory.newInstance();
xmlDecimalValue.setStringValue(stringValue);
return xmlDecimalValue;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlDouble;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Double to {@link XmlDouble}
*/
public class DoubleToXmlDouble implements Converter<Double, XmlDouble> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlDouble convert(Double value) {
if (value == null) {
return null;
}
return XmlDouble.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* aFloat with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlFloat;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Float to {@link XmlFloat}
*/
public class FloatToXmlFloat implements Converter<Float, XmlFloat> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlFloat convert(Float value) {
if (value == null) {
return null;
}
return XmlFloat.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlInteger;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Integer to {@link XmlInteger}
*/
public class IntegerToXmlInteger implements Converter<Integer, XmlInteger> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlInteger convert(Integer value) {
if (value == null) {
return null;
}
return XmlInteger.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlLong;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Long to {@link XmlLong}
*/
public class LongToXmlLong implements Converter<Long, XmlLong> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlLong convert(Long value) {
if (value == null) {
return null;
}
return XmlLong.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* aDecimal with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import java.math.BigDecimal;

import org.apache.xmlbeans.XmlDecimal;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:XmlDecimal to {@link BigDecimal}
*/
public class XmlDecimalToBigDecimal implements Converter<XmlDecimal, BigDecimal> {

/**
* @see Converter#convert(Object)
*/
@Override
public BigDecimal convert(XmlDecimal value) {
if (value == null) {
return null;
}
return value.getBigDecimalValue();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlDouble;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:XmlDouble to {@link Double}
*/
public class XmlDoubleToDouble implements Converter<XmlDouble, Double> {

/**
* @see Converter#convert(Object)
*/
@Override
public Double convert(XmlDouble value) {
if (value == null) {
return null;
}
return value.getDoubleValue();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlFloat;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:XmlFloat to {@link Float}
*/
public class XmlFloatToFloat implements Converter<XmlFloat, Float> {

/**
* @see Converter#convert(Object)
*/
@Override
public Float convert(XmlFloat value) {
if (value == null) {
return null;
}
return value.getFloatValue();
}

}
Loading

0 comments on commit 4b3eb6c

Please sign in to comment.