Search in sources :

Example 16 with DataInput

use of org.geotoolkit.wps.xml.v200.DataInput in project kie-wb-common by kiegroup.

the class BPMNFormModelGeneratorImpl method readTaskVariables.

protected void readTaskVariables(UserTask userTask, ProcessTaskFormsGenerationResult result) {
    TaskFormVariables formVariables = new TaskFormVariables(userTask);
    List<DataInputAssociation> dataInputAssociations = userTask.getDataInputAssociations();
    if (dataInputAssociations != null) {
        for (DataInputAssociation inputAssociation : dataInputAssociations) {
            if (inputAssociation.getTargetRef() != null && !isMIInputCollection(userTask, inputAssociation)) {
                String name = ((DataInput) inputAssociation.getTargetRef()).getName();
                if (BPMNVariableUtils.isValidInputName(name)) {
                    String type = extractInputType(inputAssociation);
                    type = BPMNVariableUtils.getRealTypeForInput(type);
                    Variable variable = new Variable(name, type);
                    variable.setInput(true);
                    formVariables.addVariable(variable);
                } else if (BPMNVariableUtils.TASK_FORM_VARIABLE.equals(name)) {
                    List<Assignment> assignments = inputAssociation.getAssignment();
                    for (Iterator<Assignment> it = assignments.iterator(); it.hasNext() && StringUtils.isEmpty(formVariables.getTaskName()); ) {
                        Assignment assignment = it.next();
                        if (assignment.getFrom() != null) {
                            String taskName = ((FormalExpression) assignment.getFrom()).getBody();
                            if (!StringUtils.isEmpty(taskName)) {
                                // Parsing taskName... it comes in a <![CDATA[]]>
                                taskName = Parser.xmlParser().parseInput(taskName, "").text();
                                formVariables.setTaskName(taskName);
                            }
                        }
                    }
                }
            }
        }
    }
    List<DataOutputAssociation> dataOutputAssociations = userTask.getDataOutputAssociations();
    if (dataOutputAssociations != null) {
        dataOutputAssociations.forEach(outputAssociation -> {
            if (outputAssociation.getSourceRef() != null && outputAssociation.getSourceRef().size() == 1 && !isMIOutputCollection(userTask, outputAssociation)) {
                DataOutput output = (DataOutput) outputAssociation.getSourceRef().get(0);
                String name = output.getName();
                String type = extractOutputType(output);
                type = BPMNVariableUtils.getRealTypeForInput(type);
                Variable variable = new Variable(name, type);
                variable.setOutput(true);
                formVariables.addVariable(variable);
            }
        });
    }
    if (!StringUtils.isEmpty(formVariables.getTaskName())) {
        result.registerTaskFormVariables(userTask.getId(), formVariables);
    } else {
        logger.warn("Cannot generate a form for task '{}' since it has no form name.", userTask.getName());
    }
}
Also used : DataInput(org.eclipse.bpmn2.DataInput) Assignment(org.eclipse.bpmn2.Assignment) DataOutput(org.eclipse.bpmn2.DataOutput) Iterator(java.util.Iterator) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 17 with DataInput

use of org.geotoolkit.wps.xml.v200.DataInput in project geotoolkit by Geomatys.

the class WKTAdaptorTest method adapt.

private static String adapt(final Geometry geom) {
    final DataInput value = ADAPTOR.toWPS2Input(geom);
    assertNotNull(value);
    final List<Object> content = value.getData().getContent();
    assertNotNull(content);
    assertEquals("Number of values", 1, content.size());
    final Object innerContent = content.get(0);
    assertTrue(innerContent instanceof ComplexData);
    final ComplexData cData = (ComplexData) innerContent;
    return (String) cData.getContent().stream().filter(v -> v instanceof String).findAny().orElseThrow(() -> new AssertionError("No String content found"));
}
Also used : DataInput(org.geotoolkit.wps.xml.v200.DataInput) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) Coordinate(org.locationtech.jts.geom.Coordinate) Assert.assertTrue(org.junit.Assert.assertTrue) JTS(org.geotoolkit.geometry.jts.JTS) Test(org.junit.Test) Point(org.locationtech.jts.geom.Point) List(java.util.List) Geometry(org.locationtech.jts.geom.Geometry) CommonCRS(org.apache.sis.referencing.CommonCRS) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) Assert(org.junit.Assert) DataInput(org.geotoolkit.wps.xml.v200.DataInput) Assert.assertEquals(org.junit.Assert.assertEquals) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData)

Example 18 with DataInput

use of org.geotoolkit.wps.xml.v200.DataInput in project geotoolkit by Geomatys.

the class GMLAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, schema, null));
    final JAXPStreamFeatureWriter writer = new JAXPStreamFeatureWriter(gmlVersion, null, null);
    try {
        if (ENC_BASE64.equalsIgnoreCase(encoding)) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            writer.write(candidate, out);
            out.flush();
            String base64 = Base64.getEncoder().encodeToString(out.toByteArray());
            cdt.getContent().add(base64);
        } else if (ENC_UTF8.equalsIgnoreCase(encoding)) {
            final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
            final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
            final Document document = constructeur.newDocument();
            final DOMResult domResult = new DOMResult(document);
            writer.write(candidate, domResult);
            cdt.getContent().add(document.getDocumentElement());
        }
    } catch (IOException | XMLStreamException | DataStoreException | ParserConfigurationException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DOMResult(javax.xml.transform.dom.DOMResult) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) Document(org.w3c.dom.Document) ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) XMLStreamException(javax.xml.stream.XMLStreamException) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 19 with DataInput

use of org.geotoolkit.wps.xml.v200.DataInput in project geotoolkit by Geomatys.

the class OctetStreamAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Path candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final byte[] bytes;
    try {
        bytes = Files.readAllBytes(candidate);
    } catch (IOException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    final String base64 = Base64.getEncoder().encodeToString(bytes);
    final DataInput dit = new DataInput();
    final Data data = new Data();
    data.setEncoding("base64");
    data.getContent().add(base64);
    dit.setData(data);
    return dit;
}
Also used : ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Data(org.geotoolkit.wps.xml.v200.Data) IOException(java.io.IOException)

Example 20 with DataInput

use of org.geotoolkit.wps.xml.v200.DataInput in project geotoolkit by Geomatys.

the class WKTAdaptor method toWPS2Input.

@Override
public DataInput toWPS2Input(Object candidate) throws UnconvertibleObjectException {
    if (candidate instanceof ReferenceProxy)
        return super.toWPS2Input(candidate);
    final ComplexData cdt = new ComplexData();
    cdt.getContent().add(new org.geotoolkit.wps.xml.v200.Format(encoding, mimeType, null, null));
    Geometry geom = (Geometry) candidate;
    int srid = 0;
    int dimension = 2;
    try {
        CoordinateReferenceSystem crs = Geometries.wrap(geom).get().getCoordinateReferenceSystem();
        if (crs != null) {
            dimension = crs.getCoordinateSystem().getDimension();
            final IdentifiedObjectFinder finder = IdentifiedObjects.newFinder("EPSG");
            // TODO: Ensure no project strongly rely on that, then remove. It's pure non-sense/madness.
            // Note: If you read this after march 2020: do not ask : delete.
            finder.setIgnoringAxes(true);
            final CoordinateReferenceSystem epsgcrs = (CoordinateReferenceSystem) finder.findSingleton(crs);
            if (epsgcrs != null) {
                srid = IdentifiedObjects.lookupEPSG(epsgcrs);
                // force geometry in longitude first
                final CoordinateReferenceSystem crs2 = ((AbstractCRS) crs).forConvention(AxesConvention.RIGHT_HANDED);
                if (crs2 != crs) {
                    geom = org.apache.sis.internal.feature.jts.JTS.transform(geom, crs2);
                }
                if (crs2 != null)
                    dimension = crs2.getCoordinateSystem().getDimension();
            }
        }
    } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new UnconvertibleObjectException(ex.getMessage(), ex);
    }
    // String wkt = geom.toText();
    WKTWriter writer = new WKTWriter(dimension);
    String wkt = writer.write(geom);
    if (srid > 0) {
        wkt = "SRID=" + srid + ";" + wkt;
    }
    cdt.getContent().add(wkt);
    final Data data = new Data();
    data.getContent().add(cdt);
    final DataInput dit = new DataInput();
    dit.setData(data);
    return dit;
}
Also used : IdentifiedObjectFinder(org.apache.sis.referencing.factory.IdentifiedObjectFinder) WKTWriter(org.locationtech.jts.io.WKTWriter) FactoryException(org.opengis.util.FactoryException) AbstractCRS(org.apache.sis.referencing.crs.AbstractCRS) TransformException(org.opengis.referencing.operation.TransformException) Data(org.geotoolkit.wps.xml.v200.Data) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) ReferenceProxy(org.geotoolkit.wps.xml.ReferenceProxy) Format(org.geotoolkit.wps.xml.v200.Format) Geometry(org.locationtech.jts.geom.Geometry) DataInput(org.geotoolkit.wps.xml.v200.DataInput) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) ComplexData(org.geotoolkit.wps.xml.v200.ComplexData) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

DataInput (org.eclipse.bpmn2.DataInput)38 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)21 DataInput (org.geotoolkit.wps.xml.v200.DataInput)19 DataOutput (org.eclipse.bpmn2.DataOutput)17 Data (org.geotoolkit.wps.xml.v200.Data)15 FormalExpression (org.eclipse.bpmn2.FormalExpression)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)12 Assignment (org.eclipse.bpmn2.Assignment)11 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)11 List (java.util.List)10 ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)10 Format (org.geotoolkit.wps.xml.v200.Format)10 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)9 InputSet (org.eclipse.bpmn2.InputSet)9 InputOutputSpecification (org.eclipse.bpmn2.InputOutputSpecification)8 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)8 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)8 IOException (java.io.IOException)6