use of com.salesmanager.shop.store.api.exception.GenericRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderApi method updateOrderStatus.
@RequestMapping(value = { "/private/orders/{id}/status" }, method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public void updateOrderStatus(@PathVariable final Long id, @Valid @RequestBody String status, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
String user = authorizationUtils.authenticatedUser();
authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore);
Order order = orderService.getOrder(id, merchantStore);
if (order == null) {
throw new GenericRuntimeException("412", "Order not found [" + id + "]");
}
OrderStatus statusEnum = OrderStatus.valueOf(status);
orderFacade.updateOrderStatus(order, statusEnum, merchantStore);
return;
}
use of com.salesmanager.shop.store.api.exception.GenericRuntimeException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method verifyCustomerLink.
private Customer verifyCustomerLink(String token, String store) {
Customer customer = null;
try {
customer = customerService.getByPasswordResetToken(store, token);
if (customer == null) {
throw new ResourceNotFoundException("Customer not fount for store [" + store + "] and token [" + token + "]");
}
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot verify customer token", e);
}
Date tokenExpiry = customer.getCredentialsResetRequest().getCredentialsRequestExpiry();
if (tokenExpiry == null) {
throw new GenericRuntimeException("No expiry date configured for token [" + token + "]");
}
if (!DateUtil.dateBeforeEqualsDate(new Date(), tokenExpiry)) {
throw new GenericRuntimeException("Ttoken [" + token + "] has expired");
}
return customer;
}
use of com.salesmanager.shop.store.api.exception.GenericRuntimeException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method verifyUserLink.
private User verifyUserLink(String token, String store) {
User user = null;
try {
user = userService.getByPasswordResetToken(store, token);
if (user == null) {
throw new ResourceNotFoundException("Customer not fount for store [" + store + "] and token [" + token + "]");
}
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot verify customer token", e);
}
Date tokenExpiry = user.getCredentialsResetRequest().getCredentialsRequestExpiry();
if (tokenExpiry == null) {
throw new GenericRuntimeException("No expiry date configured for token [" + token + "]");
}
if (!DateUtil.dateBeforeEqualsDate(new Date(), tokenExpiry)) {
throw new GenericRuntimeException("Ttoken [" + token + "] has expired");
}
return user;
}
use of com.salesmanager.shop.store.api.exception.GenericRuntimeException in project shopizer by shopizer-ecommerce.
the class OrderApi method checkout.
/**
* Main checkout resource that will complete the order flow
* @param code
* @param order
* @param merchantStore
* @param language
* @return
*/
@RequestMapping(value = { "/cart/{code}/checkout" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderConfirmation checkout(// shopping cart
@PathVariable final String code, // order
@Valid @RequestBody PersistableAnonymousOrder order, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
Validate.notNull(order.getCustomer(), "Customer must not be null");
ShoppingCart cart;
try {
cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
// security password validation
PersistableCustomer presistableCustomer = order.getCustomer();
if (!StringUtils.isBlank(presistableCustomer.getPassword())) {
// validate customer password
credentialsService.validateCredentials(presistableCustomer.getPassword(), presistableCustomer.getRepeatPassword(), merchantStore, language);
}
Customer customer = new Customer();
customer = customerFacade.populateCustomerModel(customer, order.getCustomer(), merchantStore, language);
if (!StringUtils.isBlank(presistableCustomer.getPassword())) {
// check if customer already exist
customer.setAnonymous(false);
// username
customer.setNick(customer.getEmailAddress());
if (customerFacadev1.checkIfUserExists(customer.getNick(), merchantStore)) {
// 409 Conflict
throw new GenericRuntimeException("409", "Customer with email [" + customer.getEmailAddress() + "] is already registered");
}
}
order.setShoppingCartId(cart.getId());
Order modelOrder = orderFacade.processOrder(order, customer, merchantStore, language, LocaleUtils.getLocale(language));
Long orderId = modelOrder.getId();
// populate order confirmation
order.setId(orderId);
// set customer id
order.getCustomer().setId(modelOrder.getCustomerId());
return orderFacadeV1.orderConfirmation(modelOrder, customer, merchantStore, language);
} catch (Exception e) {
if (e instanceof CredentialsException) {
throw new GenericRuntimeException("412", "Credentials creation Failed [" + e.getMessage() + "]");
}
String message = e.getMessage();
if (StringUtils.isBlank(message)) {
// exception type
message = "APP-BACKEND";
if (e.getCause() instanceof com.salesmanager.core.modules.integration.IntegrationException) {
message = "Integration problen occured to complete order";
}
}
throw new ServiceRuntimeException("Error during checkout [" + message + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.GenericRuntimeException in project shopizer by shopizer-ecommerce.
the class AuthenticateCustomerApi method register.
/**
* Create new customer for a given MerchantStore, then authenticate that customer
*/
@RequestMapping(value = { "/customer/register" }, method = RequestMethod.POST, produces = { "application/json" })
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(httpMethod = "POST", value = "Registers a customer to the application", notes = "Used as self-served operation", response = AuthenticationResponse.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
@ResponseBody
public ResponseEntity<?> register(@Valid @RequestBody PersistableCustomer customer, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception {
customer.setUserName(customer.getEmailAddress());
if (customerFacade.checkIfUserExists(customer.getUserName(), merchantStore)) {
// 409 Conflict
throw new GenericRuntimeException("409", "Customer with email [" + customer.getEmailAddress() + "] is already registered");
}
Validate.notNull(customer.getUserName(), "Username cannot be null");
Validate.notNull(customer.getBilling(), "Requires customer Country code");
Validate.notNull(customer.getBilling().getCountry(), "Requires customer Country code");
customerFacade.registerCustomer(customer, merchantStore, language);
// Perform the security
Authentication authentication = null;
try {
authentication = jwtCustomerAuthenticationManager.authenticate(new UsernamePasswordAuthenticationToken(customer.getUserName(), customer.getPassword()));
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
if (authentication == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
SecurityContextHolder.getContext().setAuthentication(authentication);
// Reload password post-security so we can generate token
final JWTUser userDetails = (JWTUser) jwtCustomerDetailsService.loadUserByUsername(customer.getUserName());
final String token = jwtTokenUtil.generateToken(userDetails);
// Return the token
return ResponseEntity.ok(new AuthenticationResponse(customer.getId(), token));
}
Aggregations