Search in sources :

Example 1 with AdditionalParameter

use of org.geotoolkit.ows.xml.v200.AdditionalParameter in project geotoolkit by Geomatys.

the class OWSXmlBindingTest method additionalParametersTypeUnmarshalingTest.

@Test
public void additionalParametersTypeUnmarshalingTest() throws JAXBException {
    Unmarshaller unmarshaller = owsPool.acquireUnmarshaller();
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<ns4:AdditionalParameters xmlns:ows=\"http://www.opengis.net/ows\" xmlns:ns4=\"http://www.opengis.net/ows/2.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ins=\"http://www.inspire.org\">\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-1</ns4:Name>\n" + "    <ns4:Value xsi:type=\"xs:string\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">value 1</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-2</ns4:Name>\n" + "    <ns4:Value xsi:type=\"xs:string\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">value 2</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "</ns4:AdditionalParameters>" + '\n';
    StringReader sr = new StringReader(xml);
    AdditionalParametersType result = ((JAXBElement<AdditionalParametersType>) unmarshaller.unmarshal(sr)).getValue();
    AdditionalParametersType expResult = new AdditionalParametersType();
    List<AdditionalParameter> params = new ArrayList<>();
    params.add(new AdditionalParameter(new CodeType("param-1"), Arrays.asList("value 1")));
    params.add(new AdditionalParameter(new CodeType("param-2"), Arrays.asList("value 2")));
    expResult.setAdditionalParameter(params);
    assertEquals(expResult.getAdditionalParameter(), result.getAdditionalParameter());
}
Also used : AdditionalParametersType(org.geotoolkit.ows.xml.v200.AdditionalParametersType) StringReader(java.io.StringReader) AdditionalParameter(org.geotoolkit.ows.xml.v200.AdditionalParameter) ArrayList(java.util.ArrayList) CodeType(org.geotoolkit.ows.xml.v200.CodeType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 2 with AdditionalParameter

use of org.geotoolkit.ows.xml.v200.AdditionalParameter in project geotoolkit by Geomatys.

the class WPS2ProcessDescriptor method toDescriptor.

/**
 * Convert Description to GeneralParameterDescriptor.
 *
 * @throws UnsupportedOperationException if data type could not be mapped
 */
private static GeneralParameterDescriptor toDescriptor(String processId, Description input) throws UnsupportedParameterException {
    final List<? extends Description> subInputs;
    final DataDescription dataDescType;
    final int min;
    final int max;
    if (input instanceof InputDescription) {
        final InputDescription id = (InputDescription) input;
        subInputs = id.getInput();
        dataDescType = id.getDataDescription();
        max = id.getMaxOccurs();
        min = id.getMinOccurs();
    } else if (input instanceof OutputDescription) {
        final OutputDescription od = (OutputDescription) input;
        subInputs = od.getOutput();
        dataDescType = od.getDataDescription();
        min = 1;
        max = 1;
    } else {
        throw new IllegalArgumentException("Unexpected description type " + input.getClass());
    }
    final String inputName = input.getIdentifier().getValue();
    final String title = input.getFirstTitle();
    final String remarks = input.getFirstAbstract();
    Map userObject = new HashMap();
    for (MetadataType meta : input.getMetadata()) {
        if (meta instanceof AdditionalParametersType) {
            AdditionalParametersType params = (AdditionalParametersType) meta;
            for (AdditionalParameter param : params.getAdditionalParameter()) {
                userObject.put(param.getName().getValue(), param.getValue());
            }
        }
    }
    if (dataDescType instanceof LiteralData) {
        final LiteralData cd = (LiteralData) dataDescType;
        for (LiteralDataDomain domain : cd.getLiteralDataDomain()) {
            final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
            if (adaptor == null)
                continue;
            String defaultValueValue = null;
            final ValueType defaultValue = domain.getDefaultValue();
            if (defaultValue != null)
                defaultValueValue = defaultValue.getValue();
            final Unit unit = getUnit(domain.getUOM());
            Object[] allowedValues = null;
            if (domain.getAllowedValues() != null && domain.getAllowedValues().getStringValues() != null) {
                allowedValues = new Object[domain.getAllowedValues().getStringValues().size()];
                int i = 0;
                for (String value : domain.getAllowedValues().getStringValues()) {
                    allowedValues[i] = adaptor.convert(value);
                    i++;
                }
            }
            try {
                userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
                return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), adaptor.convert(defaultValueValue), allowedValues, userObject);
            } catch (UnconvertibleObjectException ex2) {
                throw new UnsupportedParameterException(processId, inputName, "Can't convert the default literal input value.", ex2);
            }
        }
        throw new UnsupportedParameterException(processId, inputName, "Unidentifiable literal input " + inputName);
    } else if (dataDescType instanceof ComplexData) {
        final ComplexData cdt = (ComplexData) dataDescType;
        // ensure default format is first in the list
        Collections.sort(cdt.getFormat(), (Format o1, Format o2) -> {
            boolean d1 = Boolean.TRUE.equals(o1.isDefault());
            boolean d2 = Boolean.TRUE.equals(o2.isDefault());
            if (d1 == d2)
                return 0;
            return d1 ? -1 : +1;
        });
        // find a complexe type adaptor
        DataAdaptor adaptor = null;
        for (Format format : cdt.getFormat()) {
            adaptor = ComplexAdaptor.getAdaptor(format);
            if (adaptor != null)
                break;
        }
        if (adaptor == null) {
            final StringBuilder sb = new StringBuilder();
            for (Format format : cdt.getFormat()) {
                if (sb.length() != 0)
                    sb.append(", ");
                sb.append(format.getMimeType()).append(' ');
                sb.append(format.getEncoding()).append(' ');
                sb.append(format.getSchema());
            }
            throw new UnsupportedParameterException(processId, inputName, "No compatible format found for parameter " + inputName + " formats : " + sb);
        }
        userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
        return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, adaptor.getValueClass(), null, null, userObject);
    } else if (dataDescType instanceof BoundingBoxData) {
        final BboxAdaptor adaptor = BboxAdaptor.create((BoundingBoxData) dataDescType);
        userObject.put(DataAdaptor.USE_ADAPTOR, adaptor);
        return new ExtendedParameterDescriptor(inputName, title, remarks, min, max, Envelope.class, null, null, userObject);
    } else if (!subInputs.isEmpty()) {
        // sub group type
        final List<GeneralParameterDescriptor> params = new ArrayList<>();
        for (Description dt : subInputs) {
            params.add(toDescriptor(processId, dt));
        }
        return new ParameterBuilder().addName(inputName).addName(title).setRemarks(remarks).createGroup(params.toArray(new GeneralParameterDescriptor[0]));
    } else {
        throw new UnsupportedParameterException(processId, inputName, "Unidentifiable input " + inputName + " " + dataDescType);
    }
}
Also used : AdditionalParametersType(org.geotoolkit.ows.xml.v200.AdditionalParametersType) DataDescription(org.geotoolkit.wps.xml.v200.DataDescription) Description(org.geotoolkit.wps.xml.v200.Description) InputDescription(org.geotoolkit.wps.xml.v200.InputDescription) OutputDescription(org.geotoolkit.wps.xml.v200.OutputDescription) ProcessDescription(org.geotoolkit.wps.xml.v200.ProcessDescription) HashMap(java.util.HashMap) InternationalString(org.opengis.util.InternationalString) DefaultInternationalString(org.apache.sis.util.DefaultInternationalString) Unit(javax.measure.Unit) DataDescription(org.geotoolkit.wps.xml.v200.DataDescription) BboxAdaptor(org.geotoolkit.wps.adaptor.BboxAdaptor) OutputDescription(org.geotoolkit.wps.xml.v200.OutputDescription) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Format(org.geotoolkit.wps.xml.v200.Format) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) DataAdaptor(org.geotoolkit.wps.adaptor.DataAdaptor) BoundingBoxData(org.geotoolkit.wps.xml.v200.BoundingBoxData) InputDescription(org.geotoolkit.wps.xml.v200.InputDescription) ArrayList(java.util.ArrayList) List(java.util.List) ParameterBuilder(org.apache.sis.parameter.ParameterBuilder) LiteralDataDomain(org.geotoolkit.wps.xml.v200.LiteralDataDomain) LiteralAdaptor(org.geotoolkit.wps.adaptor.LiteralAdaptor) LiteralData(org.geotoolkit.wps.xml.v200.LiteralData) ValueType(org.geotoolkit.ows.xml.v200.ValueType) MetadataType(org.geotoolkit.ows.xml.v200.MetadataType) DomainMetadataType(org.geotoolkit.ows.xml.v200.DomainMetadataType) AdditionalParameter(org.geotoolkit.ows.xml.v200.AdditionalParameter) ExtendedParameterDescriptor(org.geotoolkit.utility.parameter.ExtendedParameterDescriptor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with AdditionalParameter

use of org.geotoolkit.ows.xml.v200.AdditionalParameter in project geotoolkit by Geomatys.

the class OWSXmlBindingTest method additionalParametersTypeMarshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void additionalParametersTypeMarshallingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    Marshaller marshaller = owsPool.acquireMarshaller();
    final ObjectFactory factory = new ObjectFactory();
    AdditionalParametersType metadata = new AdditionalParametersType();
    List<AdditionalParameter> params = new ArrayList<>();
    params.add(new AdditionalParameter(new CodeType("param-1"), Arrays.asList("value 1")));
    params.add(new AdditionalParameter(new CodeType("param-2"), Arrays.asList("value 2")));
    metadata.setAdditionalParameter(params);
    StringWriter sw = new StringWriter();
    marshaller.marshal(factory.createAdditionalParameters(metadata), sw);
    String result = sw.toString();
    System.out.println(result);
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<ns4:AdditionalParameters xmlns:ows=\"http://www.opengis.net/ows\" xmlns:ns4=\"http://www.opengis.net/ows/2.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ins=\"http://www.inspire.org\">\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-1</ns4:Name>\n" + "    <ns4:Value xsi:type=\"xs:string\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">value 1</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-2</ns4:Name>\n" + "    <ns4:Value xsi:type=\"xs:string\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">value 2</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "</ns4:AdditionalParameters>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : Marshaller(javax.xml.bind.Marshaller) AdditionalParametersType(org.geotoolkit.ows.xml.v200.AdditionalParametersType) ObjectFactory(org.geotoolkit.ows.xml.v200.ObjectFactory) StringWriter(java.io.StringWriter) AdditionalParameter(org.geotoolkit.ows.xml.v200.AdditionalParameter) ArrayList(java.util.ArrayList) CodeType(org.geotoolkit.ows.xml.v200.CodeType)

Example 4 with AdditionalParameter

use of org.geotoolkit.ows.xml.v200.AdditionalParameter in project geotoolkit by Geomatys.

the class OWSXmlBindingTest method additionalParametersNoTypeUnmarshalingTest.

@Test
public void additionalParametersNoTypeUnmarshalingTest() throws JAXBException {
    Unmarshaller unmarshaller = owsPool.acquireUnmarshaller();
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<ns4:AdditionalParameters xmlns:ows=\"http://www.opengis.net/ows\" xmlns:ns4=\"http://www.opengis.net/ows/2.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ins=\"http://www.inspire.org\">\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-1</ns4:Name>\n" + "    <ns4:Value>value 1</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "  <ns4:AdditionalParameter>\n" + "    <ns4:Name>param-2</ns4:Name>\n" + "    <ns4:Value>value 2</ns4:Value>\n" + "  </ns4:AdditionalParameter>\n" + "</ns4:AdditionalParameters>" + '\n';
    StringReader sr = new StringReader(xml);
    AdditionalParametersType result = ((JAXBElement<AdditionalParametersType>) unmarshaller.unmarshal(sr)).getValue();
    AdditionalParametersType expResult = new AdditionalParametersType();
    List<AdditionalParameter> params = new ArrayList<>();
    params.add(new AdditionalParameter(new CodeType("param-1"), Arrays.asList("value 1")));
    params.add(new AdditionalParameter(new CodeType("param-2"), Arrays.asList("value 2")));
    expResult.setAdditionalParameter(params);
    assertEquals(expResult.getAdditionalParameter(), result.getAdditionalParameter());
}
Also used : AdditionalParametersType(org.geotoolkit.ows.xml.v200.AdditionalParametersType) StringReader(java.io.StringReader) AdditionalParameter(org.geotoolkit.ows.xml.v200.AdditionalParameter) ArrayList(java.util.ArrayList) CodeType(org.geotoolkit.ows.xml.v200.CodeType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

ArrayList (java.util.ArrayList)4 AdditionalParameter (org.geotoolkit.ows.xml.v200.AdditionalParameter)4 AdditionalParametersType (org.geotoolkit.ows.xml.v200.AdditionalParametersType)4 CodeType (org.geotoolkit.ows.xml.v200.CodeType)3 StringReader (java.io.StringReader)2 JAXBElement (javax.xml.bind.JAXBElement)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Unit (javax.measure.Unit)1 Marshaller (javax.xml.bind.Marshaller)1 ParameterBuilder (org.apache.sis.parameter.ParameterBuilder)1 DefaultInternationalString (org.apache.sis.util.DefaultInternationalString)1 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)1 DomainMetadataType (org.geotoolkit.ows.xml.v200.DomainMetadataType)1 MetadataType (org.geotoolkit.ows.xml.v200.MetadataType)1 ObjectFactory (org.geotoolkit.ows.xml.v200.ObjectFactory)1 ValueType (org.geotoolkit.ows.xml.v200.ValueType)1