use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (sessionContext.isCallerInRole(USER) && !sessionContext.isCallerInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@Context SecurityContext securityContext, @PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (securityContext.isUserInRole(USER) && !securityContext.isUserInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(securityContext.getUserPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UserFinder method findAll.
public List<User> findAll(Integer offset, Integer limit, String orderBy, Boolean isDesc) {
JPAQuery<User> query = new JPAQueryFactory(entityManager).selectFrom(user);
if (offset != null)
query.offset(offset);
if (limit != null)
query.limit(limit);
sortBy(orderBy, isDesc, query);
return query.fetch();
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class OrderFinder method enhanceOrder.
/**
* Enhance given order with Catalog items data and order static configuration.
*
* @param order the order to enhance
*/
public void enhanceOrder(Order order) {
User user = order.getUser();
order.getItems().forEach(orderItem -> {
Product product = catalogEntityManager.find(Product.class, orderItem.getProductId());
SKU sku = catalogEntityManager.find(SKU.class, orderItem.getSkuId());
product.setLocalizedPresentation(user.getPreferredLocale());
orderItem.setDisplayName(product.getLocalizedPresentation() != null ? product.getLocalizedPresentation().getDisplayName() : product.getName());
orderItem.setSkuReference(sku.getReference());
if (product.getLocalizedPresentation() != null && product.getLocalizedPresentation().getSmallImage() != null)
orderItem.setPresentationImageURI("products/" + orderItem.getProductId() + "/" + product.getLocalizedPresentation().getLocale() + "/" + product.getLocalizedPresentation().getSmallImage().getUri());
});
order.getOrderDiscounts().forEach(orderDiscount -> {
Discount discount = catalogEntityManager.find(Discount.class, orderDiscount.getDiscountId());
discount.setLocalizedPresentation(user.getPreferredLocale());
orderDiscount.setDisplayName(discount.getLocalizedPresentation().getDisplayName() != null ? discount.getLocalizedPresentation().getDisplayName() : discount.getName());
orderDiscount.setRateType(discount.getRateType());
if (discount.getLocalizedPresentation() != null && discount.getLocalizedPresentation().getSmallImage() != null)
orderDiscount.setPresentationImageURI("discounts/" + orderDiscount.getDiscountId() + "/" + discount.getLocalizedPresentation().getLocale() + "/" + discount.getLocalizedPresentation().getSmallImage().getUri());
});
order.setDeliveryFee(orderConfiguration.getFixedDeliveryFee());
order.setVat(orderConfiguration.getVAT());
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method resetPassword_shouldUpdateUserPasswordWhenActionTokenMatchesUserActionToken.
@Test
public void resetPassword_shouldUpdateUserPasswordWhenActionTokenMatchesUserActionToken() throws Exception {
User user = notActivatedTestUser();
service.resetPassword(sessionContextMock, user.getLogin(), user.getActionToken().toString(), "newPassword");
final User updatedUser = entityManager.find(User.class, user.getId());
assertThat(updatedUser).isNotNull();
assertThat(updatedUser.getPassword()).isEqualTo(hashSha256Base64("newPassword"));
assertThat(updatedUser.getActionToken()).isNull();
verify(mailerMock).sendMail(testMailTemplate.changePasswordMailTpl().getSubject(), user.getLogin(), testMailTemplate.changePasswordMailTpl().getContent());
removeTestUser(user);
}
Aggregations