Package models.entities

Examples of models.entities.Order


    }

    @Transactional
    public static Result getPossibleStates(Integer orderId) {
        try {
            Order order = DaoManager.getOrderDao().findById(orderId);
            if (order == null) {
                return notFound(Utilities.getJsonErrorNode("can't find order with id " + orderId));
            }
            String currentOrderState = order.getState().getName();
            String currentUserRole = SecurityController.getUser().getRole().getName();
            if (roleAccessibleStates.get(currentUserRole).contains(currentOrderState)) {
                List<String> possibleStates = possibleNextStates.get(currentOrderState);
                return ok(toJson(possibleStates));
            }
View Full Code Here


public class OrderController extends Controller {

    @Transactional
    public static Result getOrderStateChanges(int id) {
        try {
            Order order = DaoManager.getOrderDao().findById(id);
            if (order == null) {
                return notFound(Utilities.getJsonErrorNode("can't find order with id " + id));
            }
            OrderStateChangeListDto dto = OrderStateChangeListDto.createFrom(order.getChanges());
            return ok(toJson(dto));
        } catch (DataAccessException e) {
            Logger.error("can't find order with id " + id);
            return notFound("can't find order with id " + id);
        }
View Full Code Here

    public static Result add() {
        try {
            String requestBody = request().body().asJson().toString();
            Logger.debug("Add request body: " + requestBody);
            OrderDto dto = new ObjectMapper().readValue(requestBody, OrderDto.class);
            Order order = new Order();
            dto.mapBack(order);
            order.setState(DaoManager.getOrderStateDao().findByName("new"));
            order.setCreatedOn(Calendar.getInstance().getTime());
            DaoManager.getOrderDao().persist(order);
            OrderStateChange stateChange = new OrderStateChange();
            stateChange.setNewState(DaoManager.getOrderStateDao().findByName("new"));
            stateChange.setPerformedOn(Calendar.getInstance().getTime());
            stateChange.setChanger(SecurityController.getUser());
View Full Code Here

    @Transactional
    @Restrict({@Group("manager"), @Group("supervisor")})
    public static Result update(int id) {
        try {
            String requestBody = request().body().asJson().toString();
            Order order = DaoManager.getOrderDao().findById(id);
            if (order == null) {
                return notFound(Utilities.getJsonErrorNode("can't find order with id " + id));
            }
            Logger.debug("Edit request body: " + requestBody);
            OrderDto dto = new ObjectMapper().readValue(requestBody, OrderDto.class);
View Full Code Here

    }

    @Transactional
    public static Result getOrder(int id) {
        try {
            Order order = DaoManager.getOrderDao().findById(id);
            if (order == null) {
                return notFound(Utilities.getJsonErrorNode("can't find order with id " + id));
            }
            if (!SecurityController.hasAccessToOrder(order)) {
                return forbidden("not allowed to view the order " + id);
            }
            String currentUserRole = SecurityController.getUser().getRole().getName();
            String orderState = order.getState().getName();
            if (OrderStateController.roleAccessibleStates.get(currentUserRole).contains(orderState)) {
                OrderDto dto = OrderDto.createFrom(order);
                return ok(toJson(dto));
            }
            return forbidden("not allowed to view the order " + id);
View Full Code Here

    @Transactional
    public static Result updateOrderState(int id) {
        try {
            String requestBody = request().body().asJson().toString();
            Order order = DaoManager.getOrderDao().findById(id);
            if (order == null) {
                return notFound(Utilities.getJsonErrorNode("can't find order with id " + id));
            }
            Logger.debug("Update order state request body: " + requestBody);
            OrderStateChangeDto dto = new ObjectMapper().readValue(requestBody, OrderStateChangeDto.class);
            OrderStateChange stateChange = new OrderStateChange();
            dto.mapBack(stateChange);
            stateChange.setPerformedOn(Calendar.getInstance().getTime());
            stateChange.setChanger(SecurityController.getUser());
            stateChange.setAlteredOrder(order);
            order.setState(stateChange.getNewState());
            DaoManager.getOrderStateChangeDao().persist(stateChange);
        } catch (DataAccessException e) {
            Logger.error("failed to update order state", e);
            return badRequest(Utilities.getJsonErrorNode("failed to update order state"));
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of models.entities.Order

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.