Search in sources :

Example 66 with User

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

the class SupplierViewController method getDeliveriesToPrepare.

public void getDeliveriesToPrepare(ActionRequest request, ActionResponse response) {
    try {
        SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
        User user = supplierViewService.getSupplierUser();
        String domain = Beans.get(SupplierViewService.class).getDeliveriesToPrepareOfSupplier(user);
        response.setView(ActionView.define(I18n.get("Deliveries to prepare")).model(StockMove.class.getName()).add("grid", "stock-move-supplier-grid").add("form", "stock-move-supplier-form").domain(domain).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) SupplierViewService(com.axelor.apps.supplierportal.service.SupplierViewService)

Example 67 with User

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

the class SupplierViewController method getLastDelivery.

/* StockMove OnClick*/
public void getLastDelivery(ActionRequest request, ActionResponse response) {
    try {
        SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
        User user = supplierViewService.getSupplierUser();
        String domain = Beans.get(SupplierViewService.class).getLastDeliveryOfSupplier(user);
        StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(domain).fetchOne();
        if (stockMove != null) {
            response.setView(ActionView.define(I18n.get("Last delivery")).model(StockMove.class.getName()).add("form", "stock-move-supplier-form").domain(domain).context("_showRecord", stockMove.getId()).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) StockMove(com.axelor.apps.stock.db.StockMove) SupplierViewService(com.axelor.apps.supplierportal.service.SupplierViewService) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository)

Example 68 with User

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

the class BusinessProjectMobileController method getProjects.

/*
   * This method is used in mobile application.
   * It was in ProjectTaskBusinessServiceImpl
   * @param request
   * @param response
   *
   * POST /open-suite-webapp/ws/action/com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects
   * fields: no field
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.businessproject.mobile.BusinessProjectMobileController:getProjects"
   * } }
   */
public void getProjects(ActionRequest request, ActionResponse response) {
    List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
    try {
        User user = AuthUtils.getUser();
        if (user != null) {
            List<Project> projectList = Beans.get(ProjectRepository.class).all().filter("self.imputable = true").fetch();
            for (Project project : projectList) {
                if ((project.getMembersUserSet() != null && project.getMembersUserSet().contains(user)) || user.equals(project.getAssignedTo())) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("name", project.getName());
                    map.put("id", project.getId().toString());
                    dataList.add(map);
                }
            }
        }
        response.setData(dataList);
        response.setTotal(dataList.size());
    } catch (Exception e) {
        response.setStatus(-1);
        response.setError(e.getMessage());
    }
}
Also used : Project(com.axelor.apps.project.db.Project) User(com.axelor.auth.db.User) ProjectRepository(com.axelor.apps.project.db.repo.ProjectRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 69 with User

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

the class ProdProcessService method getLanguageToPrinting.

public String getLanguageToPrinting(ProdProcess prodProcess) {
    User user = AuthUtils.getUser();
    String language = "en";
    if (user != null && !Strings.isNullOrEmpty(user.getLanguage())) {
        return user.getLanguage();
    }
    if (prodProcess == null) {
        return language;
    }
    Company company = prodProcess.getCompany();
    if (company != null && company.getPartner() != null) {
        language = ReportSettings.getPrintingLocale(company.getPartner());
    }
    return language;
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User)

Example 70 with User

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

the class SendMailQueueService method submitMailJob.

/**
 * Submit a mail job to an executor which will send mails in a separate thread.
 *
 * @param mailBuilder
 * @param message
 */
public void submitMailJob(MailBuilder mailBuilder, Message message) {
    long messageId = message.getId();
    log.debug("Submitting job to executor for message {}...", messageId);
    User currentUser = AuthUtils.getUser();
    executor.submit(() -> {
        try {
            final long startTime = System.currentTimeMillis();
            boolean done = false;
            PersistenceException persistenceException = null;
            log.debug("Sending message {}...", messageId);
            mailBuilder.send();
            log.debug("Message {} sent.", messageId);
            do {
                try {
                    inTransaction(() -> {
                        final Message updateMessage = findMessage(messageId);
                        getEntityManager().lock(updateMessage, LockModeType.PESSIMISTIC_WRITE);
                        updateMessage.setSentByEmail(true);
                        updateMessage.setStatusSelect(MessageRepository.STATUS_SENT);
                        updateMessage.setSentDateT(LocalDateTime.now());
                        if (currentUser != null) {
                            updateMessage.setSenderUser(userRepository.find(currentUser.getId()));
                        }
                        messageRepository.save(updateMessage);
                    });
                    done = true;
                } catch (PersistenceException e) {
                    persistenceException = e;
                    sleep();
                }
            } while (!done && System.currentTimeMillis() - startTime < ENTITY_FIND_TIMEOUT);
            if (!done) {
                throw persistenceException;
            }
        } catch (Exception e) {
            log.debug("Exception when sending email", e);
            TraceBackService.trace(e);
        }
        return true;
    });
}
Also used : User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) PersistenceException(javax.persistence.PersistenceException) PersistenceException(javax.persistence.PersistenceException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

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