Search in sources :

Example 51 with ProcessException

use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.

the class CoversProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(GEOM1);
        Geometry geom2 = inputParameters.getValue(GEOM2);
        // ensure geometries are in the same CRS
        final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
        if (JTS.isConversionNeeded(geom1, geom2)) {
            geom2 = JTS.convertToCRS(geom2, resultCRS);
        }
        final Boolean result = (Boolean) geom1.covers(geom2);
        outputParameters.getOrCreate(RESULT).setValue(result);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (TransformException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 52 with ProcessException

use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.

the class UnionProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        Geometry geom1 = inputParameters.getValue(UnionDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(UnionDescriptor.GEOM2);
        // ensure geometries are in the same CRS
        final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
        if (JTS.isConversionNeeded(geom1, geom2)) {
            geom2 = JTS.convertToCRS(geom2, resultCRS);
        }
        final Geometry result = (Geometry) geom1.union(geom2);
        if (resultCRS != null) {
            JTS.setCRS(result, resultCRS);
        }
        outputParameters.getOrCreate(UnionDescriptor.RESULT_GEOM).setValue(result);
    } catch (Exception ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ProcessException(org.geotoolkit.process.ProcessException)

Example 53 with ProcessException

use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.

the class WithinProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(OverlapsDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(OverlapsDescriptor.GEOM2);
        // ensure geometries are in the same CRS
        final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
        if (JTS.isConversionNeeded(geom1, geom2)) {
            geom2 = JTS.convertToCRS(geom2, resultCRS);
        }
        final boolean result = geom1.within(geom2);
        outputParameters.getOrCreate(OverlapsDescriptor.RESULT).setValue(result);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (TransformException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 54 with ProcessException

use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.

the class WPS2Process method checkResult.

/**
 * A Function to ensure response object is success or failure. Otherwise, we request continually status until
 * we reach a result.
 *
 * @param response The execute response given by service.
 */
private Result checkResult(Object response) throws IOException, JAXBException, InterruptedException, ProcessException {
    if (response instanceof ExceptionResponse) {
        final ExceptionResponse report = (ExceptionResponse) response;
        throw new ProcessException("Exception when executing the process.", this, report.toException());
    } else if (response instanceof StatusInfo) {
        final StatusInfo statusInfo = (StatusInfo) response;
        Status status = statusInfo.getStatus();
        jobId = statusInfo.getJobID();
        if (Status.SUCCEEDED.equals(status)) {
            fireProgressing("WPS remote process has been successfully executed", 100f, false);
            return null;
        } else if (Status.FAILED.equals(status)) {
            throw new ProcessException("Process failed", this);
        } else if (Status.DISMISS.equals(status)) {
            throw new DismissProcessException("WPS remote process has been canceled", this);
        } else if (Status.ACCEPTED.equals(status)) {
            // Initial status
            fireProgressing("Process accepted: " + jobId, 0, false);
        } else {
            // Running
            final Integer progress = statusInfo.getPercentCompleted();
            // Not in the standard
            String message = statusInfo.getMessage();
            if (message == null || (message = message.trim()).isEmpty()) {
                message = status.name();
            }
            fireProgressing(message, progress == null ? Float.NaN : progress, false);
        }
        // loop until we have an answer
        Object tmpResponse;
        // TODO : make timelapse configurable
        int timeLapse = 3000;
        // we tolerate a few unmarshalling or IO errors, the servers behave differentely
        // and may not offer the result file right from the start
        int failCount = 0;
        while (true) {
            stopIfDismissed();
            synchronized (this) {
                wait(timeLapse);
            }
            try {
                tmpResponse = getStatus();
                failCount = 0;
            } catch (UnmarshalException | IOException ex) {
                if (failCount < 5 && !isDimissed()) {
                    failCount++;
                    continue;
                } else if (isDimissed()) {
                    throw new DismissProcessException("WPS remote process has been canceled", this);
                } else {
                    // happenning so we consider the process failed
                    throw ex;
                }
            }
            if (tmpResponse instanceof StatusInfo) {
                final StatusInfo statInfo = (StatusInfo) tmpResponse;
                status = statInfo.getStatus();
                if (Status.SUCCEEDED.equals(status)) {
                    fireProgressing("WPS remote process has been successfully executed", 100f, false);
                    return null;
                } else if (Status.FAILED.equals(status)) {
                    throw new ProcessException("Process failed", this);
                } else if (Status.DISMISS.equals(status)) {
                    throw new DismissProcessException("WPS remote process has been canceled", this);
                }
                // Not in the standard
                String message = statusInfo.getMessage();
                if (message == null || (message = message.trim()).isEmpty()) {
                    message = status.name();
                }
                final Integer percentCompleted = statInfo.getPercentCompleted();
                if (!Objects.equals(message, lastMessage) || !Objects.equals(percentCompleted, lastProgress)) {
                    lastMessage = message;
                    lastProgress = percentCompleted;
                    fireProgressing(lastMessage, lastProgress, false);
                }
            } else if (tmpResponse instanceof ExceptionResponse) {
                final ExceptionResponse report = (ExceptionResponse) tmpResponse;
                throw new ProcessException("Exception when executing the process.", this, report.toException());
            }
        }
    } else if (response instanceof Result) {
        final Result result = checkLegacyResult((Result) response);
        if (result.getJobID() != null) {
            jobId = result.getJobID();
        }
        return result;
    } else {
        throw new ProcessException("Unexpected response " + response, this);
    }
}
Also used : Status(org.geotoolkit.wps.xml.v200.Status) LegacyStatus(org.geotoolkit.wps.xml.v100.LegacyStatus) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) ExceptionResponse(org.geotoolkit.ows.xml.ExceptionResponse) StatusInfo(org.geotoolkit.wps.xml.v200.StatusInfo) DismissProcessException(org.geotoolkit.process.DismissProcessException) Result(org.geotoolkit.wps.xml.v200.Result)

Example 55 with ProcessException

use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.

the class WPS2Process method getStatus.

/**
 * Get current task status.<br>
 *
 * This method should not be called if process is not running.
 *
 * @return StatusInfo
 * @throws org.geotoolkit.process.ProcessException
 * @throws javax.xml.bind.UnmarshalException
 * @throws java.io.IOException
 */
private StatusInfo getStatus() throws ProcessException, JAXBException, IOException {
    if (jobId == null)
        throw new ProcessException("Process is not started.", this);
    if (isDimissed()) {
        throw new DismissProcessException("Process already dismissed", this);
    }
    final GetStatusRequest req = registry.getClient().createGetStatus(jobId);
    req.setDebug(debug);
    req.setClientSecurity(security);
    final Object response = req.getResponse();
    if (response instanceof ExceptionResponse) {
        final ExceptionResponse report = (ExceptionResponse) response;
        throw new ProcessException("Exception when executing the process.", this, report.toException());
    } else if (response instanceof StatusInfo) {
        return (StatusInfo) response;
    } else {
        throw new ProcessException("Unexpected response " + response.getClass().getName(), this);
    }
}
Also used : ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) ExceptionResponse(org.geotoolkit.ows.xml.ExceptionResponse) GetStatusRequest(org.geotoolkit.wps.client.GetStatusRequest) StatusInfo(org.geotoolkit.wps.xml.v200.StatusInfo) DismissProcessException(org.geotoolkit.process.DismissProcessException)

Aggregations

ProcessException (org.geotoolkit.process.ProcessException)70 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)27 Geometry (org.locationtech.jts.geom.Geometry)26 FactoryException (org.opengis.util.FactoryException)24 TransformException (org.opengis.referencing.operation.TransformException)21 RenderedImage (java.awt.image.RenderedImage)15 DataStoreException (org.apache.sis.storage.DataStoreException)13 IOException (java.io.IOException)12 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)12 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)11 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)11 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 BufferedImage (java.awt.image.BufferedImage)10 ArrayList (java.util.ArrayList)10 PixelIterator (org.apache.sis.image.PixelIterator)9 List (java.util.List)8 Parameters (org.apache.sis.parameter.Parameters)8 DismissProcessException (org.geotoolkit.process.DismissProcessException)8 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)7 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)7