use of javax.ws.rs.POST in project killbill by killbill.
the class AccountResource method payAllInvoices.
@TimedResource
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICE_PAYMENTS)
@ApiOperation(value = "Trigger a payment for all unpaid invoices")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response payAllInvoices(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @QueryParam(QUERY_PAYMENT_AMOUNT) final BigDecimal paymentAmount, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException, InvoiceApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext);
final Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext);
BigDecimal remainingRequestPayment = paymentAmount;
if (remainingRequestPayment == null) {
remainingRequestPayment = BigDecimal.ZERO;
for (final Invoice invoice : unpaidInvoices) {
remainingRequestPayment = remainingRequestPayment.add(invoice.getBalance());
}
}
for (final Invoice invoice : unpaidInvoices) {
final BigDecimal amountToPay = (remainingRequestPayment.compareTo(invoice.getBalance()) >= 0) ? invoice.getBalance() : remainingRequestPayment;
if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
final UUID paymentMethodId = externalPayment ? null : account.getPaymentMethodId();
createPurchaseForInvoice(account, invoice.getId(), amountToPay, paymentMethodId, externalPayment, null, null, pluginProperties, callContext);
}
remainingRequestPayment = remainingRequestPayment.subtract(amountToPay);
if (remainingRequestPayment.compareTo(BigDecimal.ZERO) == 0) {
break;
}
}
//
if (externalPayment && remainingRequestPayment.compareTo(BigDecimal.ZERO) > 0) {
invoiceApi.insertCredit(account.getId(), remainingRequestPayment, clock.getUTCToday(), account.getCurrency(), true, "pay all invoices", callContext);
}
return Response.status(Status.OK).build();
}
use of javax.ws.rs.POST in project neo4j by neo4j.
the class CypherService method cypher.
@POST
@SuppressWarnings({ "unchecked", "ParameterCanBeLocal" })
public Response cypher(String body, @Context HttpServletRequest request, @QueryParam(INCLUDE_STATS_PARAM) boolean includeStats, @QueryParam(INCLUDE_PLAN_PARAM) boolean includePlan, @QueryParam(PROFILE_PARAM) boolean profile) throws BadInputException {
usage.get(features).flag(http_cypher_endpoint);
Map<String, Object> command = input.readMap(body);
if (!command.containsKey(QUERY_KEY)) {
return output.badRequest(new InvalidArgumentsException("You have to provide the 'query' parameter."));
}
String query = (String) command.get(QUERY_KEY);
Map<String, Object> params;
try {
params = (Map<String, Object>) (command.containsKey(PARAMS_KEY) && command.get(PARAMS_KEY) != null ? command.get(PARAMS_KEY) : new HashMap<String, Object>());
} catch (ClassCastException e) {
return output.badRequest(new IllegalArgumentException("Parameters must be a JSON map"));
}
try {
QueryExecutionEngine executionEngine = cypherExecutor.getExecutionEngine();
boolean periodicCommitQuery = executionEngine.isPeriodicCommit(query);
CommitOnSuccessfulStatusCodeRepresentationWriteHandler handler = (CommitOnSuccessfulStatusCodeRepresentationWriteHandler) output.getRepresentationWriteHandler();
if (periodicCommitQuery) {
handler.closeTransaction();
}
TransactionalContext tc = cypherExecutor.createTransactionContext(query, params, request);
Result result;
if (profile) {
result = executionEngine.profileQuery(query, params, tc);
includePlan = true;
} else {
result = executionEngine.executeQuery(query, params, tc);
includePlan = result.getQueryExecutionType().requestedExecutionPlanDescription();
}
if (periodicCommitQuery) {
handler.setTransaction(database.beginTx());
}
return output.ok(new CypherResultRepresentation(result, includeStats, includePlan));
} catch (Throwable e) {
if (e.getCause() instanceof CypherException) {
return output.badRequest(e.getCause());
} else {
return output.badRequest(e);
}
}
}
use of javax.ws.rs.POST in project neo4j by neo4j.
the class RestfulGraphDatabase method createPagedTraverser.
@POST
@Path(PATH_TO_CREATE_PAGED_TRAVERSERS)
public Response createPagedTraverser(@PathParam("nodeId") long startNode, @PathParam("returnType") TraverserReturnType returnType, @QueryParam("pageSize") @DefaultValue(FIFTY_ENTRIES) int pageSize, @QueryParam("leaseTime") @DefaultValue(SIXTY_SECONDS) int leaseTimeInSeconds, String body) {
try {
validatePageSize(pageSize);
validateLeaseTime(leaseTimeInSeconds);
String traverserId = actions.createPagedTraverser(startNode, input.readMap(body), pageSize, leaseTimeInSeconds);
URI uri = new URI("node/" + startNode + "/paged/traverse/" + returnType + "/" + traverserId);
return output.created(new ListEntityRepresentation(actions.pagedTraverse(traverserId, returnType), uri.normalize()));
} catch (EvaluationException e) {
return output.badRequest(e);
} catch (BadInputException e) {
return output.badRequest(e);
} catch (NotFoundException e) {
return output.notFound(e);
} catch (URISyntaxException e) {
return output.serverError(e);
}
}
use of javax.ws.rs.POST in project neo4j by neo4j.
the class ConsoleService method exec.
@POST
public Response exec(@Context InputFormat input, String data) {
Map<String, Object> args;
try {
args = input.readMap(data);
} catch (BadInputException e) {
return output.badRequest(e);
}
if (!args.containsKey("command")) {
return Response.status(Status.BAD_REQUEST).entity("Expected command argument not present.").build();
}
ScriptSession scriptSession;
try {
scriptSession = getSession(args);
} catch (IllegalArgumentException e) {
return output.badRequest(e);
}
log.debug(scriptSession.toString());
try {
Pair<String, String> result = scriptSession.evaluate((String) args.get("command"));
List<Representation> list = new ArrayList<Representation>(asList(ValueRepresentation.string(result.first()), ValueRepresentation.string(result.other())));
return output.ok(new ListRepresentation(RepresentationType.STRING, list));
} catch (Exception e) {
List<Representation> list = new ArrayList<Representation>(asList(ValueRepresentation.string(e.getClass() + " : " + e.getMessage() + "\n"), ValueRepresentation.string(null)));
return output.ok(new ListRepresentation(RepresentationType.STRING, list));
}
}
use of javax.ws.rs.POST in project platformlayer by platformlayer.
the class KeychainResource method authorizeCertificateChain.
@POST
public ValidateTokenResponse authorizeCertificateChain(@QueryParam("project") String project, CertificateChainInfo chain) {
try {
requireSystemAccess();
} catch (AuthenticatorException e) {
log.warn("Error while checking system token", e);
throwInternalError();
}
UserEntity userEntity = null;
try {
boolean unlock = false;
userEntity = userAuthenticator.findUserFromKeychain(chain, unlock);
} catch (AuthenticatorException e) {
log.warn("Error while fetching user", e);
throwInternalError();
}
if (userEntity == null) {
throw404NotFound();
}
ValidateTokenResponse response = new ValidateTokenResponse();
response.access = new ValidateAccess();
response.access.user = Mapping.mapToUserValidation(userEntity);
// response.access.token = new Token();
// response.access.token.expires = checkTokenInfo.expiration;
// response.access.token.id = checkToken;
String checkProject = project;
if (checkProject != null) {
ProjectEntity projectEntity = null;
try {
projectEntity = userAuthenticator.findProject(checkProject);
} catch (AuthenticatorException e) {
log.warn("Error while fetching project", e);
throwInternalError();
}
if (projectEntity == null) {
throw404NotFound();
}
// Note that we do not unlock the user / project; we don't have any secret material
// TODO: We could return stuff encrypted with the user's public key
// projectEntity.unlockWithUser(userEntity);
//
// if (!projectEntity.isSecretValid()) {
// throw404NotFound();
// }
UserProjectEntity userProject = null;
try {
userProject = userAuthenticator.findUserProject(userEntity, projectEntity);
} catch (AuthenticatorException e) {
log.warn("Error while fetching project", e);
throwInternalError();
}
if (userProject == null) {
// Not a member of project
throw404NotFound();
}
response.access.project = Mapping.mapToProject(projectEntity);
response.access.project.roles = Mapping.mapToRoles(userProject.getRoles());
}
return response;
}
Aggregations