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");
}
}
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;
}
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));
}
});
}
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;
}
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();
}
Aggregations