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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations