use of org.sagebionetworks.bridge.exceptions.LimitExceededException in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method internalLabShipmentRequest.
ResponseEntity<StatusMessage> internalLabShipmentRequest(App app, AccountId accountId) {
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
if (account.getDataGroups().contains(SHIP_TESTS_REQUESTED.name().toLowerCase())) {
throw new LimitExceededException("Limited to one active shipment request.");
}
boolean isTestUser = account.getDataGroups().contains(TEST_USER_GROUP);
LOG.info("Lab shipment requested for {} participant", isTestUser ? "test" : "non-test");
LocalDate date = LocalDate.now();
Order.ShippingInfo.Address address = validateAndGetAddress(account);
String orderNumber = account.getId() + "_" + date;
Order o = new Order(isTestUser, orderNumber, account.getId(), date, new Order.ShippingInfo(address, GBF_TEST_KIT_SHIP_METHOD), new Order.LineItem(GBF_TEST_KIT_PART_NUMBER, 1));
gbfOrderService.placeOrder(o, isTestUser);
JsonNode node = JsonNodeFactory.instance.objectNode().put(SHIPMENT_REPORT_KEY_ORDER_ID, orderNumber);
// participants will not have Org Sponsored Studies in RequestContext, so for lab shipment reports, don't set study IDs
writeReportAndUpdateState(app, account.getId(), node, SHIPMENT_REPORT, SHIP_TESTS_REQUESTED, false);
return ResponseEntity.accepted().body(new StatusMessage(isTestUser ? "Test" : "Non-test" + " shipment requested."));
}
Aggregations