use of net.idea.restnet.i.task.ITaskResult in project ambit-mirror by ideaconsult.
the class AuthTokenFactory method testURI.
@Test
public void testURI() throws Exception {
ICallableTask c = new ICallableTask() {
protected UUID uuid;
public ITaskResult call() throws Exception {
return new TaskResult("quickTaskURI");
}
@Override
public UUID getUuid() {
return uuid;
}
@Override
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@Override
public String getTaskCategory() {
return null;
}
};
app.addTask("Test task", c, new Reference(String.format("http://localhost:%d", port)), getUserToken());
testGet(getTestURI(), MediaType.TEXT_URI_LIST);
}
use of net.idea.restnet.i.task.ITaskResult in project ambit-mirror by ideaconsult.
the class PingResource method pingI5.
protected ITask<ITaskResult, String> pingI5(Reference uri, Context context) throws ResourceException {
ITask<ITaskResult, String> task;
DBConnection dbc = new DBConnection(context);
I5LightClient cli = null;
long now = System.currentTimeMillis();
if (server == null)
server = dbc.getProperty("i5.server");
if (user == null)
user = dbc.getProperty("i5.user");
if (pass == null)
pass = dbc.getProperty("i5.pass");
task = new Task<ITaskResult, String>(user);
task.setName("Ping " + server);
task.setStatus(TaskStatus.Running);
task.setUri(new TaskResult(uri.toString(), false));
try {
cli = new I5LightClient(server);
if (cli.login(user, pass)) {
task.setStatus(TaskStatus.Completed);
} else {
task.setStatus(TaskStatus.Error);
task.setError(new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED));
}
} catch (Exception x) {
task.setError(new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage()));
task.setStatus(TaskStatus.Error);
} finally {
try {
cli.logout();
} catch (Exception x) {
}
}
task.setTimeCompleted(System.currentTimeMillis());
return task;
}
use of net.idea.restnet.i.task.ITaskResult in project ambit-mirror by ideaconsult.
the class TaskCreator method processItem.
@Override
public Object processItem(T item) throws AmbitException {
try {
ICallableTask callable = getCallable(form, item);
if (async) {
ITask<Reference, USERID> task = createTask(callable, item);
tasks.add(task.getUuid());
} else {
ITaskResult ref = callable.call();
}
} catch (AmbitException x) {
throw x;
} catch (Exception x) {
throw new AmbitException(x);
}
return item;
}
use of net.idea.restnet.i.task.ITaskResult in project ambit-mirror by ideaconsult.
the class TaskJSONReporter method processItem.
@Override
public void processItem(UUID item, Writer output) {
try {
if (comma != null)
output.write(comma);
ITask<ITaskResult, USERID> task = storage.findTask(item);
String uri = task.getUri() == null ? null : task.getUri().toString();
StringWriter errorTrace = null;
if (task.getError() != null) {
try {
ResourceException exception = task.getError();
errorTrace = new StringWriter();
if (exception instanceof ImportSubstanceException) {
errorTrace.write(((ImportSubstanceException) exception).getDetails());
} else if (exception.getCause() == null)
exception.printStackTrace(new PrintWriter(errorTrace));
else
exception.getCause().printStackTrace(new PrintWriter(errorTrace));
} catch (Exception x) {
}
}
output.write(String.format(format, uri, item.toString(), task.getName() == null ? "" : JSONUtils.jsonEscape(task.getName()), task.getError() == null ? "" : JSONUtils.jsonEscape(task.getError().toString()), task.getPolicyError() == null ? "" : JSONUtils.jsonEscape(task.getPolicyError().toString()), task.getStatus() == null ? "" : task.getStatus(), task.getStarted(), task.getTimeCompleted(), task.getUri() == null ? "" : task.getUri(), errorTrace == null ? null : JSONUtils.jsonQuote(JSONUtils.jsonEscape(errorTrace.toString()))));
comma = ",";
} catch (IOException x) {
Context.getCurrentLogger().severe(x.getMessage());
}
}
use of net.idea.restnet.i.task.ITaskResult in project ambit-mirror by ideaconsult.
the class OpenSSOPoliciesResource method post.
@Override
protected Representation post(Representation entity, Variant variant) throws ResourceException {
synchronized (this) {
ArrayList<UUID> tasks = new ArrayList<UUID>();
try {
Form form = entity.isAvailable() ? new Form(entity) : new Form();
ICallableTask callable = createCallable(form, null);
ITask<ITaskResult, String> task = ((ITaskApplication) getApplication()).addTask(String.format("Create policy"), callable, getRequest().getRootRef(), callable instanceof CallablePOST, getToken());
task.update();
setStatus(task.isDone() ? Status.SUCCESS_OK : Status.SUCCESS_ACCEPTED);
tasks.add(task.getUuid());
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
}
if (tasks.size() == 0)
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
else {
ITaskStorage storage = ((ITaskApplication) getApplication()).getTaskStorage();
FactoryTaskConvertor<Object> tc = new FactoryTaskConvertor<Object>(storage);
if (tasks.size() == 1)
return tc.createTaskRepresentation(tasks.get(0), variant, getRequest(), getResponse(), null);
else
return tc.createTaskRepresentation(tasks.iterator(), variant, getRequest(), getResponse(), null);
}
}
}
Aggregations