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 24, 2024
1 parent d56e083 commit b33f486
Show file tree
Hide file tree
Showing 18 changed files with 661 additions and 0 deletions.
36 changes: 36 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,42 @@
<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>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.BigIntegerToXmlBigInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlIntegerToBigInteger">
</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,13 @@
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.XmlInt;
import org.apache.xmlbeans.XmlInteger;
import org.apache.xmlbeans.XmlLong;
import org.apache.xmlbeans.XmlShort;
import org.apache.xmlbeans.XmlTime;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionService;
Expand Down Expand Up @@ -62,6 +69,14 @@ 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("decimal", XmlDecimal.class); //$NON-NLS-1$
TYPE_MAP.put("double", XmlDouble.class); //$NON-NLS-1$
TYPE_MAP.put("float", XmlFloat.class); //$NON-NLS-1$
TYPE_MAP.put("int", XmlInt.class); //$NON-NLS-1$
TYPE_MAP.put("integer", XmlInteger.class); //$NON-NLS-1$
TYPE_MAP.put("long", XmlLong.class); //$NON-NLS-1$
TYPE_MAP.put("short", XmlShort.class); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -111,6 +126,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,45 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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,39 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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

import java.math.BigInteger;

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

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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,37 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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

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

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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,37 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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,38 @@
/*
* Copyright (c) 2024 wetransform GmbH
*
* 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:
* wetransform GmbH <http://www.wetransform.to>
*/

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

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

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

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

}
Loading

0 comments on commit b33f486

Please sign in to comment.