Search in sources :

Example 46 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class TechnologicalProcessRateHooks method findCurrentRate.

private BigDecimal findCurrentRate(Entity technologicalProcessRate) {
    SearchCriteriaBuilder scb = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRateItem").find().addOrder(SearchOrders.desc("dateFrom")).add(SearchRestrictions.belongsTo("technologicalProcessRate", technologicalProcessRate)).add(SearchRestrictions.or(SearchRestrictions.lt("dateFrom", new Date()), SearchRestrictions.eq("dateFrom", new Date())));
    Entity technologicalProcessRateItem = scb.setMaxResults(1).uniqueResult();
    if (Objects.isNull(technologicalProcessRateItem)) {
        return null;
    } else {
        return technologicalProcessRateItem.getDecimalField("actualRate");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Date(java.util.Date)

Example 47 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class NumberPatternElementHooks method validatesWith.

public boolean validatesWith(final DataDefinition dataDefinition, final Entity entity) {
    if (NumberPatternElement.XX.getStringValue().equals(entity.getStringField(NumberPatternElementFields.ELEMENT)) && StringUtils.isBlank(entity.getStringField(NumberPatternElementFields.VALUE))) {
        entity.addError(dataDefinition.getField(NumberPatternElementFields.VALUE), "basic.numberPatternElement.error.valueCannotBeEmpty");
        return false;
    }
    if (NumberPatternElement.N999.getStringValue().equals(entity.getStringField(NumberPatternElementFields.ELEMENT)) || NumberPatternElement.N9999.getStringValue().equals(entity.getStringField(NumberPatternElementFields.ELEMENT)) || NumberPatternElement.N99999.getStringValue().equals(entity.getStringField(NumberPatternElementFields.ELEMENT))) {
        Entity numberPattern = entity.getBelongsToField(NumberPatternElementFields.NUMBER_PATTERN);
        SearchCriteriaBuilder scb = numberPattern.getHasManyField(NumberPatternFields.NUMBER_PATTERN_ELEMENTS).find().add(SearchRestrictions.or(SearchRestrictions.or(SearchRestrictions.eq(NumberPatternElementFields.ELEMENT, NumberPatternElement.N999.getStringValue()), SearchRestrictions.eq(NumberPatternElementFields.ELEMENT, NumberPatternElement.N9999.getStringValue())), SearchRestrictions.eq(NumberPatternElementFields.ELEMENT, NumberPatternElement.N99999.getStringValue())));
        if (entity.getId() != null) {
            scb.add(SearchRestrictions.idNe(entity.getId()));
        }
        if (scb.list().getTotalNumberOfEntities() > 0) {
            entity.addError(dataDefinition.getField(NumberPatternElementFields.ELEMENT), "basic.numberPatternElement.error.thereCanBeOnlyOneSuchElement");
            return false;
        }
    } else if (!NumberPatternElement.XX.getStringValue().equals(entity.getStringField(NumberPatternElementFields.ELEMENT))) {
        Entity numberPattern = entity.getBelongsToField(NumberPatternElementFields.NUMBER_PATTERN);
        SearchCriteriaBuilder scb = numberPattern.getHasManyField(NumberPatternFields.NUMBER_PATTERN_ELEMENTS).find().add(SearchRestrictions.eq(NumberPatternElementFields.ELEMENT, entity.getStringField(NumberPatternElementFields.ELEMENT)));
        if (entity.getId() != null) {
            scb.add(SearchRestrictions.idNe(entity.getId()));
        }
        if (scb.list().getTotalNumberOfEntities() > 0) {
            entity.addError(dataDefinition.getField(NumberPatternElementFields.ELEMENT), "basic.numberPatternElement.error.thereCanBeOnlyOneSuchElement");
            return false;
        }
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 48 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class PalletNumberHelpersListHooks method addDiscriminatorRestrictionToGrid.

public final void addDiscriminatorRestrictionToGrid(final ViewDefinitionState view) {
    GridComponent palletNumberHelpersGrid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    palletNumberHelpersGrid.setCustomRestriction(new CustomRestriction() {

        @Override
        public void addRestriction(final SearchCriteriaBuilder searchBuilder) {
            searchBuilder.add(SearchRestrictions.eq(PalletNumberHelperFields.TEMPORARY, false));
        }
    });
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) GridComponent(com.qcadoo.view.api.components.GridComponent) CustomRestriction(com.qcadoo.model.api.search.CustomRestriction)

Example 49 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class MaintenanceEventContextService method prepareContextEntity.

public Entity prepareContextEntity(Entity maintenanceEventContextEntity) {
    SearchCriteriaBuilder searchCriteriaBuilder = maintenanceEventContextEntity.getDataDefinition().find();
    searchCriteriaBuilder.add(SearchRestrictions.belongsTo(MaintenanceEventContextFields.DIVISION, maintenanceEventContextEntity.getBelongsToField(MaintenanceEventContextFields.DIVISION)));
    searchCriteriaBuilder.add(SearchRestrictions.belongsTo(MaintenanceEventContextFields.FACTORY, maintenanceEventContextEntity.getBelongsToField(MaintenanceEventContextFields.FACTORY)));
    Date dateFrom = maintenanceEventContextEntity.getDateField(MaintenanceEventContextFields.DATE_FROM);
    Date dateTo = maintenanceEventContextEntity.getDateField(MaintenanceEventContextFields.DATE_TO);
    if (Objects.nonNull(dateFrom)) {
        searchCriteriaBuilder.add(SearchRestrictions.eq(MaintenanceEventContextFields.DATE_FROM, dateFrom));
    } else {
        searchCriteriaBuilder.add(SearchRestrictions.isNull(MaintenanceEventContextFields.DATE_FROM));
    }
    if (Objects.nonNull(dateTo)) {
        searchCriteriaBuilder.add(SearchRestrictions.eq(MaintenanceEventContextFields.DATE_TO, dateTo));
    } else {
        searchCriteriaBuilder.add(SearchRestrictions.isNull(MaintenanceEventContextFields.DATE_TO));
    }
    Entity maintenanceEventContextEntityFromDb = searchCriteriaBuilder.uniqueResult();
    if (maintenanceEventContextEntityFromDb == null) {
        maintenanceEventContextEntity.setField(MaintenanceEventContextFields.CONFIRMED, false);
        maintenanceEventContextEntity.setField(MaintenanceEventContextFields.DATE_FROM, dateFrom);
        maintenanceEventContextEntity.setField(MaintenanceEventContextFields.DATE_TO, dateTo);
        maintenanceEventContextEntity = maintenanceEventContextEntity.getDataDefinition().save(maintenanceEventContextEntity);
    } else {
        Long id = maintenanceEventContextEntity.getId();
        maintenanceEventContextEntity = maintenanceEventContextEntityFromDb;
        if (id == null) {
            maintenanceEventContextEntity.setField(MaintenanceEventContextFields.CONFIRMED, false);
        }
    }
    return maintenanceEventContextEntity;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 50 with SearchCriteriaBuilder

use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.

the class MaintenanceEventService method getExistingEventsForEvent.

public List<Entity> getExistingEventsForEvent(final Entity event, final String type) {
    SearchCriteriaBuilder scb = getMaintenanceEventDD().find();
    if (event.getId() != null) {
        scb = scb.add(SearchRestrictions.ne("id", event.getId()));
    }
    scb = scb.add(SearchRestrictions.eq(MaintenanceEventFields.TYPE, type));
    scb = scb.add(SearchRestrictions.or(SearchRestrictions.eq(MaintenanceEventFields.STATE, MaintenanceEventStateStringValues.NEW), SearchRestrictions.eq(MaintenanceEventFields.STATE, MaintenanceEventStateStringValues.IN_PROGRESS)));
    if (event.getBelongsToField(MaintenanceEventFields.SUBASSEMBLY) != null) {
        scb.add(SearchRestrictions.belongsTo(MaintenanceEventFields.SUBASSEMBLY, event.getBelongsToField(MaintenanceEventFields.SUBASSEMBLY)));
    } else {
        scb = scb.add(SearchRestrictions.isNull(MaintenanceEventFields.SUBASSEMBLY));
    }
    if (event.getBelongsToField(MaintenanceEventFields.WORKSTATION) != null) {
        scb.add(SearchRestrictions.belongsTo(MaintenanceEventFields.WORKSTATION, event.getBelongsToField(MaintenanceEventFields.WORKSTATION)));
    } else {
        scb = scb.add(SearchRestrictions.isNull(MaintenanceEventFields.WORKSTATION));
    }
    if (event.getBelongsToField(MaintenanceEventFields.PRODUCTION_LINE) != null) {
        scb.add(SearchRestrictions.belongsTo(MaintenanceEventFields.PRODUCTION_LINE, event.getBelongsToField(MaintenanceEventFields.PRODUCTION_LINE)));
    } else {
        scb = scb.add(SearchRestrictions.isNull(MaintenanceEventFields.PRODUCTION_LINE));
    }
    if (event.getBelongsToField(MaintenanceEventFields.DIVISION) != null) {
        scb.add(SearchRestrictions.belongsTo(MaintenanceEventFields.DIVISION, event.getBelongsToField(MaintenanceEventFields.DIVISION)));
    } else {
        scb = scb.add(SearchRestrictions.isNull(MaintenanceEventFields.DIVISION));
    }
    if (event.getBelongsToField(MaintenanceEventFields.FACTORY) != null) {
        scb.add(SearchRestrictions.belongsTo(MaintenanceEventFields.FACTORY, event.getBelongsToField(MaintenanceEventFields.FACTORY)));
    } else {
        scb = scb.add(SearchRestrictions.isNull(MaintenanceEventFields.FACTORY));
    }
    return scb.list().getEntities();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8