Search in sources :

Example 36 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class LeaveController method historicLeave.

public void historicLeave(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        Employee employee = user.getEmployee();
        ActionViewBuilder actionView = ActionView.define(I18n.get("Colleague Leave Requests")).model(LeaveRequest.class.getName()).add("grid", "leave-request-grid").add("form", "leave-request-form").param("search-filters", "leave-request-filters");
        actionView.domain("(self.statusSelect = 3 OR self.statusSelect = 4)");
        if (employee == null || !employee.getHrManager()) {
            actionView.domain(actionView.get().getDomain() + " AND self.user.employee.managerUser = :_user").context("_user", user);
        }
        response.setView(actionView.map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 37 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class LeaveController method showSubordinateLeaves.

public void showSubordinateLeaves(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        String domain = "self.user.employee.managerUser.employee.managerUser = :_user AND self.statusSelect = 2";
        long nbLeaveRequests = Query.of(LeaveRequest.class).filter(domain).bind("_user", user).count();
        if (nbLeaveRequests == 0) {
            response.setNotify(I18n.get("No Leave Request to be validated by your subordinates"));
        } else {
            ActionViewBuilder actionView = ActionView.define(I18n.get("Leaves to be Validated by your subordinates")).model(LeaveRequest.class.getName()).add("grid", "leave-request-grid").add("form", "leave-request-form").param("search-filters", "leave-request-filters");
            response.setView(actionView.domain(domain).context("_user", user).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 38 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getProcessPerUser.

@SuppressWarnings({ "serial", "unchecked" })
@Override
public List<Map<String, Object>> getProcessPerUser(WkfModel wkfModel) {
    User user = AuthUtils.getUser();
    List<Map<String, Object>> dataList = new ArrayList<>();
    List<WkfProcess> processList = getProcesses(wkfModel);
    for (WkfProcess process : processList) {
        Map<String, Object> processMap = new HashMap<>();
        List<Map<String, Object>> configList = new ArrayList<>();
        WkfProcessConfig firstProcessConfig = null;
        List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
        this.sortProcessConfig(processConfigs);
        int taskAssignedToMe = 0;
        List<String> _modelList = new ArrayList<>();
        for (WkfProcessConfig processConfig : processConfigs) {
            boolean isDirectCreation = processConfig.getIsDirectCreation();
            firstProcessConfig = firstProcessConfig == null ? processConfig.getIsStartModel() ? processConfig : null : firstProcessConfig;
            boolean isMetaModel = processConfig.getMetaModel() != null;
            String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
            if (_modelList.contains(modelName)) {
                continue;
            }
            _modelList.add(modelName);
            Map<String, Object> _map = this.computeStatus(isMetaModel, modelName, process, user);
            List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
            List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statuses");
            if (!statusList.isEmpty()) {
                taskAssignedToMe += statusList.stream().map(s -> (int) s.get("statusCount")).reduce(0, Integer::sum);
            }
            Map<String, Object> taskMap = (Map<String, Object>) _map.get("tasks");
            configList.add(new HashMap<String, Object>() {

                {
                    put("type", "model");
                    put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
                    put("modelRecordCount", recordIdsPerModel.size());
                    put("isMetaModel", isMetaModel);
                    put("recordIdsPerModel", recordIdsPerModel);
                    put("statuses", statusList);
                    put("tasks", taskMap);
                }
            });
            configList.add(new HashMap<String, Object>() {

                {
                    put("type", "button");
                    put("isDirectCreation", isDirectCreation);
                    put("modelName", modelName);
                    put("isMetaModel", isMetaModel);
                }
            });
        }
        processMap.put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
        processMap.put("taskAssignedToMe", taskAssignedToMe);
        processMap.put("itemList", configList);
        processMap.put("processConfig", firstProcessConfig);
        dataList.add(processMap);
    }
    return dataList;
}
Also used : User(com.axelor.auth.db.User) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 39 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class BpmDashboardServiceImpl method getData.

@SuppressWarnings({ "unchecked", "serial" })
@Override
public Map<String, Object> getData(int offset) {
    User user = AuthUtils.getUser();
    Map<String, Object> dataMap = new HashMap<>();
    List<Map<String, Object>> modelList = new ArrayList<>();
    List<WkfModel> wkfModelList = this.getWkfModelsByUser(user);
    long totalRecord = wkfModelList.size();
    List<WkfModel> showWkfModels = wkfModelList.stream().skip(offset).limit(FETCH_LIMIT).collect(Collectors.toList());
    for (WkfModel wkfModel : showWkfModels) {
        boolean isSuperAdmin = user.getCode().equals("admin");
        boolean isAdmin = wkfModelController.isAdmin(wkfModel, user);
        boolean isManager = wkfModelController.isManager(wkfModel, user);
        boolean isUser = wkfModelController.isUser(wkfModel, user);
        List<WkfProcess> processes = wkfModelService.getProcesses(wkfModel);
        List<Map<String, Object>> processList = new ArrayList<>();
        for (WkfProcess process : processes) {
            List<Map<String, Object>> configList = new ArrayList<>();
            List<WkfProcessConfig> processConfigs = process.getWkfProcessConfigList();
            wkfModelService.sortProcessConfig(processConfigs);
            List<String> _modelList = new ArrayList<>();
            for (WkfProcessConfig processConfig : processConfigs) {
                boolean isMetaModel = processConfig.getMetaModel() != null;
                String modelName = isMetaModel ? processConfig.getMetaModel().getName() : processConfig.getMetaJsonModel().getName();
                if (_modelList.contains(modelName)) {
                    continue;
                }
                _modelList.add(modelName);
                Map<String, Object> _map = this.computeConfigs(process, modelName, isMetaModel, user);
                List<Long> recordIdsUserPerModel = (List<Long>) _map.get("recordIdsUserPerModel");
                List<Map<String, Object>> statusUserList = (List<Map<String, Object>>) _map.get("statusUserList");
                List<Long> recordIdsPerModel = (List<Long>) _map.get("recordIdsPerModel");
                List<Map<String, Object>> statusList = (List<Map<String, Object>>) _map.get("statusList");
                List<Long> recordIdsModel = new ArrayList<>();
                if (isSuperAdmin || isAdmin || isManager) {
                    recordIdsModel.addAll(recordIdsPerModel);
                    recordIdsModel.addAll(recordIdsUserPerModel);
                } else if (isUser) {
                    recordIdsModel.addAll(recordIdsUserPerModel);
                }
                configList.add(new HashMap<String, Object>() {

                    {
                        put("type", "model");
                        put("title", !StringUtils.isBlank(processConfig.getTitle()) ? processConfig.getTitle() : modelName);
                        put("modelName", modelName);
                        put("modelRecordCount", recordIdsModel.size());
                        put("isMetaModel", isMetaModel);
                        put("recordIdsPerModel", recordIdsModel);
                        put("userStatuses", statusUserList);
                        put("statuses", statusList);
                    }
                });
            }
            processList.add(new HashMap<String, Object>() {

                {
                    put("title", !StringUtils.isBlank(process.getDescription()) ? process.getDescription() : process.getName());
                    put("itemList", configList);
                }
            });
        }
        modelList.add(new HashMap<String, Object>() {

            {
                put("title", wkfModel.getName());
                put("processList", processList);
                put("isSuperAdmin", isSuperAdmin);
                put("isAdmin", isAdmin);
                put("isManager", isManager);
                put("isUser", isUser);
            }
        });
    }
    dataMap.put("$modelList", modelList);
    dataMap.put("$offset", offset);
    dataMap.put("$limit", FETCH_LIMIT);
    dataMap.put("$totalRecord", totalRecord);
    return dataMap;
}
Also used : User(com.axelor.auth.db.User) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfModel(com.axelor.apps.bpm.db.WkfModel) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class UserController method comparePfpValidatorCompanySet.

@SuppressWarnings("unchecked")
public void comparePfpValidatorCompanySet(ActionRequest request, ActionResponse response) {
    Integer pfpValidatorUserId = (Integer) request.getContext().get("_userId");
    LinkedHashMap<String, Object> newPfpValidatorUserMap = (LinkedHashMap<String, Object>) request.getContext().get("newPfpValidatorUser");
    if (newPfpValidatorUserMap == null) {
        return;
    }
    UserRepository userRepository = Beans.get(UserRepository.class);
    User newPfpValidatorUser = userRepository.find(((Integer) newPfpValidatorUserMap.get("id")).longValue());
    User pfpValidatorUser = userRepository.find(pfpValidatorUserId.longValue());
    Set<Company> pfpValidatorUserCompanySet = pfpValidatorUser.getCompanySet();
    Set<Company> newPfpValidatorUserCompanySet = newPfpValidatorUser.getCompanySet();
    if (!pfpValidatorUserCompanySet.equals(newPfpValidatorUserCompanySet)) {
        response.setAttr("$pfpValidatorCompanySetLabel", "title", String.format(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_COMPANY_SET_NOT_EQUAL), newPfpValidatorUser.getName(), pfpValidatorUser.getName()));
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", false);
    } else {
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", true);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

User (com.axelor.auth.db.User)157 AxelorException (com.axelor.exception.AxelorException)35 Employee (com.axelor.apps.hr.db.Employee)28 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)25 Transactional (com.google.inject.persist.Transactional)24 LocalDate (java.time.LocalDate)23 Filter (com.axelor.rpc.filter.Filter)22 BigDecimal (java.math.BigDecimal)22 ClientViewService (com.axelor.apps.portal.service.ClientViewService)20 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)17 List (java.util.List)17 Map (java.util.Map)16 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)12 LocalDateTime (java.time.LocalDateTime)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 Beans (com.axelor.inject.Beans)11 Inject (com.google.inject.Inject)11 Product (com.axelor.apps.base.db.Product)9