use of org.rembx.jeeshop.rest.WebApplicationException 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.rest.WebApplicationException in project jeeshop by remibantos.
the class OrdersCT method modifyUnknownCatalog_ShouldThrowNotFoundException.
@Test
public void modifyUnknownCatalog_ShouldThrowNotFoundException() {
Order detachedOrder = new Order();
detachedOrder.setId(9999L);
try {
service.modify(detachedOrder);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class MailTemplates method modify.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
public MailTemplate modify(MailTemplate mailTemplate) {
MailTemplate existingMailTemplate = entityManager.find(MailTemplate.class, mailTemplate.getId());
checkNotNull(existingMailTemplate);
MailTemplate existingTplWithSameLocaleAndName = mailTemplateFinder.findByNameAndLocale(mailTemplate.getName(), mailTemplate.getLocale());
if (existingTplWithSameLocaleAndName != null && !existingTplWithSameLocaleAndName.getId().equals(mailTemplate.getId())) {
throw new WebApplicationException(Response.Status.CONFLICT);
}
return entityManager.merge(mailTemplate);
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class DiscountsCT method modifyUnknownDiscount_ShouldThrowNotFoundException.
@Test
public void modifyUnknownDiscount_ShouldThrowNotFoundException() {
Discount detachedDiscountToModify = new Discount(9999L);
try {
service.modify(detachedDiscountToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.
the class OrdersCT method find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException.
@Test
public void find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException() throws Exception {
entityManager.getTransaction().begin();
User user = new User("777@test.com", "test", "M.", "John", "Doe", "+33616161616", null, null, "fr_FR", null);
entityManager.persist(user);
entityManager.getTransaction().commit();
when(sessionContextMock.isCallerInRole(JeeshopRoles.USER)).thenReturn(true);
when(sessionContextMock.isCallerInRole(JeeshopRoles.ADMIN)).thenReturn(false);
when(sessionContextMock.getCallerPrincipal()).thenReturn(new PrincipalImpl("777@test.com"));
try {
service.find(1L, null);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
} finally {
entityManager.getTransaction().begin();
entityManager.remove(user);
entityManager.persist(user);
}
}
Aggregations