예제 #1
0
 @Override
 public <TInput, TOutput> CommandResult<TOutput> execute(
     ServiceLocator locator,
     Serialization<TInput> input,
     Serialization<TOutput> output,
     TInput data,
     Principal principal) {
   Argument arg;
   try {
     arg = input.deserialize(data, Argument.class);
   } catch (IOException e) {
     return CommandResult.badRequest(e.getMessage());
   }
   Optional<Class<?>> manifest = domainModel.find(arg.Name);
   if (!manifest.isPresent()) {
     return CommandResult.badRequest("Unable to find specified domain object: " + arg.Name);
   }
   if (!Identifiable.class.isAssignableFrom(manifest.get())) {
     return CommandResult.badRequest("Specified type is not an identifiable: " + arg.Name);
   }
   if (!permissions.canAccess(manifest.get(), principal)) {
     return CommandResult.forbidden(arg.Name);
   }
   Repository repository;
   try {
     repository = locator.resolve(Repository.class, manifest.get());
   } catch (ReflectiveOperationException e) {
     return CommandResult.badRequest(
         "Error resolving repository for: " + arg.Name + ". Reason: " + e.getMessage());
   }
   Optional<Object> found = repository.find(arg.Uri);
   if (!found.isPresent()) {
     return new CommandResult<>(null, "Object not found", 404);
   }
   try {
     return CommandResult.success("Object found", output.serialize(found.get()));
   } catch (IOException e) {
     return new CommandResult<>(null, "Error serializing result.", 500);
   }
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 @Override
 public <TInput, TOutput> CommandResult<TOutput> execute(
     ServiceLocator locator,
     Serialization<TInput> input,
     Serialization<TOutput> output,
     TInput data,
     Principal principal) {
   Argument<TInput> arg;
   try {
     arg = input.deserialize(data, Argument.class, data.getClass());
   } catch (IOException e) {
     return CommandResult.badRequest(e.getMessage());
   }
   Optional<Class<?>> manifest = domainModel.find(arg.ReportName);
   if (!manifest.isPresent()) {
     return CommandResult.badRequest("Couldn't find report type: " + arg.ReportName);
   }
   if (!permissions.canAccess(manifest.get(), principal)) {
     return CommandResult.forbidden(arg.ReportName);
   }
   if (!Report.class.isAssignableFrom(manifest.get())) {
     return CommandResult.badRequest("Specified type is not a report: " + arg.ReportName);
   }
   final Report report;
   try {
     report = (Report) input.deserialize(arg.Data, manifest.get());
   } catch (IOException e) {
     return CommandResult.badRequest(
         "Error deserializing report: " + arg.ReportName + ". Reason: " + e.getMessage());
   }
   final Object result = report.populate(locator);
   try {
     return CommandResult.success("Report populated", output.serialize(result));
   } catch (IOException e) {
     return new CommandResult<>(null, "Error serializing result.", 500);
   }
 }