Search in sources :

Example 81 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class UserController method validate.

public void validate(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        User user = request.getContext().asType(User.class);
        Map<String, String> errors = ModelTool.getUniqueErrors(user, UNIQUE_MESSAGES);
        if (!errors.isEmpty()) {
            response.setErrors(errors);
            return;
        }
        UserService userService = Beans.get(UserService.class);
        user = userService.changeUserPassword(user, context);
        response.setValue("transientPassword", user.getTransientPassword());
    } catch (ValidationException e) {
        response.setError(e.getMessage());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) User(com.axelor.auth.db.User) ValidationException(javax.validation.ValidationException) UserService(com.axelor.apps.base.service.user.UserService) ValidationException(javax.validation.ValidationException)

Example 82 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class UserController method setUserPartner.

public void setUserPartner(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Partner partner = Beans.get(PartnerRepository.class).find(context.asType(Partner.class).getId());
        if (context.get("created_from_user_id") != null && partner != null) {
            UserRepository userRepo = Beans.get(UserRepository.class);
            User user = userRepo.find(((Integer) context.get("created_from_user_id")).longValue());
            Beans.get(UserService.class).setUserPartner(partner, user);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) UserService(com.axelor.apps.base.service.user.UserService) Partner(com.axelor.apps.base.db.Partner) ValidationException(javax.validation.ValidationException)

Example 83 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class DuplicateObjectsController method addOriginal.

public void addOriginal(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    List<Map<String, Object>> duplicateObj = (List<Map<String, Object>>) context.get("duplicateObjects");
    Object originalObj = null;
    Object original = "";
    boolean flag = false;
    for (Map map : duplicateObj) {
        if ((boolean) map.get("selected")) {
            originalObj = context.get("originalObject");
            response.setAttr("$originalObject", "value", map);
            original = map;
            flag = true;
        }
    }
    if (!flag) {
        response.setAlert(I18n.get(IExceptionMessage.GENERAL_11));
    }
    duplicateObj.remove(original);
    if (originalObj != null) {
        duplicateObj.add((Map<String, Object>) originalObj);
    }
    response.setAttr("$duplicateObjects", "value", duplicateObj);
}
Also used : Context(com.axelor.rpc.Context) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class DuplicateObjectsController method extractModel.

private Class<? extends Model> extractModel(ActionRequest request, Set<String> fields) {
    Context context = request.getContext();
    String model = (String) context.get("_contextModel");
    if (model == null) {
        model = request.getModel();
        String duplicateFinderFields = (String) context.get("_duplicateFinderFields");
        if (duplicateFinderFields != null) {
            fields.addAll(Arrays.asList(duplicateFinderFields.split(";")));
        }
    } else {
        if (context.get("fieldsSet") != null) {
            List<HashMap<String, Object>> fieldsSet = (List<HashMap<String, Object>>) context.get("fieldsSet");
            for (HashMap<String, Object> field : fieldsSet) {
                fields.add((String) field.get("name"));
            }
        }
    }
    return (Class<? extends Model>) JPA.model(model);
}
Also used : Context(com.axelor.rpc.Context) HashMap(java.util.HashMap) Model(com.axelor.db.Model) ArrayList(java.util.ArrayList) List(java.util.List)

Example 85 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class FileTabController method updateFields.

public void updateFields(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Map<String, Object> map = context.getParent();
        if (map == null || (boolean) map.get("isConfigInFile") == true) {
            return;
        }
        FileTab fileTab = context.asType(FileTab.class);
        Beans.get(FileTabService.class).updateFields(fileTab);
        response.setValue("fileFieldList", fileTab.getFileFieldList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) FileTabService(com.axelor.apps.base.service.advanced.imports.FileTabService) FileTab(com.axelor.apps.base.db.FileTab)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10