Search in sources :

Example 26 with Filter

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

the class DuplicateObjectsService method fetchDuplicatedRecordIds.

private List<?> fetchDuplicatedRecordIds(Class<? extends Model> modelClass, String concatedFields, String subQuery, String filter) {
    log.debug("Fetch duplicated records for: {}", modelClass);
    StringBuilder queryBuilder = new StringBuilder("SELECT self.id FROM ");
    queryBuilder.append(modelClass.getSimpleName() + " self");
    queryBuilder.append(" WHERE ");
    queryBuilder.append(concatedFields);
    queryBuilder.append(" IN ");
    queryBuilder.append("(" + subQuery + ")");
    if (filter != null) {
        queryBuilder.append(" AND " + filter);
    }
    Filter securityFilter = getJpaSecurityFilter(modelClass);
    Object[] params = new Object[] {};
    if (securityFilter != null) {
        queryBuilder.append(" AND (" + securityFilter.getQuery() + ")");
        log.debug("JPA filter query: {}", securityFilter.getQuery());
        params = securityFilter.getParams().toArray();
        log.debug("JPA filter params: {}", securityFilter.getParams());
    }
    String query = queryBuilder.toString();
    log.debug("Final query prepared: {}", query);
    Query finalQuery = JPA.em().createQuery(query);
    for (int i = 0; i < params.length; i++) {
        finalQuery.setParameter(i, params[i]);
    }
    return finalQuery.getResultList();
}
Also used : Query(javax.persistence.Query) Filter(com.axelor.rpc.filter.Filter)

Example 27 with Filter

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

the class ClientViewServiceImpl method getLastDeliveryIndicator.

/* StockMove Indicators */
protected String getLastDeliveryIndicator(User user) {
    List<Filter> filters = getLastDeliveryOfUser(user);
    StockMove stockMove = Filter.and(filters).build(StockMove.class).order("-realDate").fetchOne();
    if (stockMove == null) {
        return I18n.get(CLIENT_PORTAL_NO_DATE);
    }
    return stockMove.getRealDate() != null ? stockMove.getRealDate().format(DATE_FORMATTER) : I18n.get(CLIENT_PORTAL_NO_DATE);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter)

Example 28 with Filter

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

the class ClientViewServiceImpl method getNewTasksOfUser.

@Override
public List<Filter> getNewTasksOfUser(User user) {
    List<Filter> filters = new ArrayList<>();
    Filter filterFromPermission = security.getFilter(JpaSecurity.CAN_READ, ProjectTask.class);
    Filter filter = new JPQLFilter("self.status = '" + ProjectTaskRepository.STATUS_NEW + "' AND self.typeSelect = '" + ProjectTaskRepository.TYPE_TASK + "' AND self.project.clientPartner.id = " + user.getPartner().getId());
    if (user.getActiveCompany() != null) {
        filter = Filter.and(filter, new JPQLFilter(" self.project.company.id = " + user.getActiveCompany().getId()));
    }
    filters.add(filter);
    addPermissionFilter(filters, filterFromPermission);
    return filters;
}
Also used : Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) ArrayList(java.util.ArrayList) JPQLFilter(com.axelor.rpc.filter.JPQLFilter)

Example 29 with Filter

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

the class ClientViewServiceImpl method getResolvedTicketsOfUser.

@Override
public List<Filter> getResolvedTicketsOfUser(User user) {
    List<Filter> filters = new ArrayList<>();
    Filter filterFromPermission = security.getFilter(JpaSecurity.CAN_READ, Ticket.class);
    Filter filter = new JPQLFilter("self.customer.id = " + user.getPartner().getId() + " AND self.assignedToUser.id = " + user.getId() + " AND self.statusSelect IN (" + TicketRepository.STATUS_RESOLVED + ", " + TicketRepository.STATUS_CLOSED + ")");
    filters.add(filter);
    addPermissionFilter(filters, filterFromPermission);
    return filters;
}
Also used : Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) ArrayList(java.util.ArrayList) JPQLFilter(com.axelor.rpc.filter.JPQLFilter)

Example 30 with Filter

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

the class ClientViewServiceImpl method getPlannedDeliveriesOfUser.

@Override
public List<Filter> getPlannedDeliveriesOfUser(User user) {
    List<Filter> filters = new ArrayList<>();
    Filter filterFromPermission = security.getFilter(JpaSecurity.CAN_READ, StockMove.class);
    Filter filter = new JPQLFilter("self.partner.id = " + user.getPartner().getId() + " AND self.typeSelect = " + StockMoveRepository.TYPE_OUTGOING + " AND self.statusSelect = " + StockMoveRepository.STATUS_PLANNED + " AND self.isReversion != true");
    if (user.getActiveCompany() != null) {
        filter = Filter.and(filter, new JPQLFilter(" self.company.id = " + user.getActiveCompany().getId()));
    }
    filters.add(filter);
    addPermissionFilter(filters, filterFromPermission);
    return filters;
}
Also used : Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) ArrayList(java.util.ArrayList) JPQLFilter(com.axelor.rpc.filter.JPQLFilter)

Aggregations

Filter (com.axelor.rpc.filter.Filter)47 JPQLFilter (com.axelor.rpc.filter.JPQLFilter)23 ArrayList (java.util.ArrayList)22 User (com.axelor.auth.db.User)21 ClientViewService (com.axelor.apps.portal.service.ClientViewService)19 StockMove (com.axelor.apps.stock.db.StockMove)7 Invoice (com.axelor.apps.account.db.Invoice)5 Ticket (com.axelor.apps.helpdesk.db.Ticket)5 SaleOrder (com.axelor.apps.sale.db.SaleOrder)5 ProjectTask (com.axelor.apps.project.db.ProjectTask)4 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)3 HashMap (java.util.HashMap)3 AdvancedExport (com.axelor.apps.base.db.AdvancedExport)2 AdvancedExportService (com.axelor.apps.base.service.advancedExport.AdvancedExportService)2 Project (com.axelor.apps.project.db.Project)2 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)2 JpaSecurity (com.axelor.db.JpaSecurity)2 Model (com.axelor.db.Model)2 I18n (com.axelor.i18n.I18n)2 Beans (com.axelor.inject.Beans)2