Integer t = obj.integer("task");
if (t == null) {
throw new BadRequestException("Request must contain task identifier");
}
final ImportTask task = imp.task(t);
if (task == null) {
throw new NotFoundException("No such task: " + t + " for import: " + id);
}
ResourceInfo resource = task.getLayer().getResource();
if (task.getState() == ImportTask.State.NO_CRS) {
JSONObj proj = obj.object("proj");
if (proj == null) {
throw new BadRequestException("Request must contain a 'proj' property");
}
try {
resource.setSRS(IO.srs(proj));
resource.setNativeCRS(IO.crs(proj));
importer.changed(task);
}
catch(Exception e) {
throw new BadRequestException("Unable to parse proj: " + proj.toString());
}
}
importer.run(imp, new ImportFilter() {
@Override
public boolean include(ImportTask t) {
return task.getId() == t.getId();
}
});
if (task.getState() == ImportTask.State.COMPLETE) {
return complete(task);
}
else {
switch(task.getState()) {
case NO_CRS:
case NO_BOUNDS:
return pending(task);
case ERROR:
return failed(task);