use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class MaterialAvailabilityListHooks method fillInAvailableQuantity.
public void fillInAvailableQuantity(final ViewDefinitionState state) {
FormComponent formComponent = (FormComponent) state.getComponentByReference("product");
GridComponent grid = (GridComponent) state.getComponentByReference(QcadooViewConstants.L_GRID);
Entity product = formComponent.getEntity().getDataDefinition().get(formComponent.getEntityId());
List<Entity> warehouses = materialFlowResourcesService.getWarehouseLocationsFromDB();
List<Entity> materialAvailabilityList = Lists.newArrayList();
DataDefinition orderMaterialAvailabilityDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_MATERIAL_AVAILABILITY);
for (Entity warehouse : warehouses) {
Map<Long, BigDecimal> availableQuantities = materialFlowResourcesService.getQuantitiesForProductsAndLocation(Collections.singletonList(product), warehouse);
if (Objects.nonNull(availableQuantities.get(product.getId())) && BigDecimal.ZERO.compareTo(availableQuantities.get(product.getId())) < 0) {
Entity materialAvailability = orderMaterialAvailabilityDD.create();
materialAvailability.setField(MaterialAvailabilityFields.UNIT, product.getField(ProductFields.UNIT));
materialAvailability.setField(MaterialAvailabilityFields.AVAILABLE_QUANTITY, availableQuantities.get(product.getId()));
materialAvailability.setField(MaterialAvailabilityFields.LOCATION, warehouse);
materialAvailabilityList.add(materialAvailability);
}
}
grid.setEntities(materialAvailabilityList.stream().sorted(Comparator.comparing(e -> e.getBelongsToField(MaterialAvailabilityFields.LOCATION).getStringField(LocationFields.NAME))).collect(Collectors.toList()));
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class AttributeImportService method importResourceAttributeValues.
public boolean importResourceAttributeValues(final String path, final ViewDefinitionState view) throws IOException {
AttributeImportContainer container = new AttributeImportContainer();
InputStream stream = fileService.getInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
XSSFSheet sheet = workbook.getSheetAt(0);
List<AttributePosition> attributes = prepareAttributesList(sheet);
if (attributes.isEmpty()) {
view.addMessage("basic.attributeValuesImport.importFileEmpty", ComponentState.MessageType.INFO);
return container.getErrors().isEmpty();
}
try {
fillContainer(container, sheet, attributes, L_RESOURCE);
if (container.getAtribiutesValuesByType().isEmpty()) {
view.addMessage("basic.attributeValuesImport.importFileEmpty", ComponentState.MessageType.INFO);
return container.getErrors().isEmpty();
}
storeResourceAttributes(container, attributes);
view.addMessage("basic.attributeValuesImport.success", ComponentState.MessageType.SUCCESS);
return container.getErrors().isEmpty();
} catch (Exception exc) {
container.getErrors().forEach(err -> {
view.addTranslatedMessage(err, ComponentState.MessageType.FAILURE);
});
return false;
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class AttributeImportService method importProductAttributeValues.
public boolean importProductAttributeValues(final String path, final ViewDefinitionState view) throws IOException {
AttributeImportContainer container = new AttributeImportContainer();
InputStream stream = fileService.getInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
XSSFSheet sheet = workbook.getSheetAt(0);
List<AttributePosition> attributes = prepareAttributesList(sheet);
if (attributes.isEmpty()) {
view.addMessage("basic.attributeValuesImport.importFileEmpty", ComponentState.MessageType.INFO);
return container.getErrors().isEmpty();
}
try {
fillContainer(container, sheet, attributes, L_PRODUCT);
if (container.getAtribiutesValuesByType().isEmpty()) {
view.addMessage("basic.attributeValuesImport.importFileEmpty", ComponentState.MessageType.INFO);
return container.getErrors().isEmpty();
}
storeProductAttributes(container, attributes);
view.addMessage("basic.attributeValuesImport.success", ComponentState.MessageType.SUCCESS);
return container.getErrors().isEmpty();
} catch (Exception exc) {
container.getErrors().forEach(err -> {
view.addTranslatedMessage(err, ComponentState.MessageType.FAILURE);
});
return false;
}
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class PalletStorageStateDetailsHooks method setupHeaderLabel.
public void setupHeaderLabel(final ViewDefinitionState view) {
String[] descriminatorFiltersFields = new String[] { PalletStorageStateDtoFields.PALLET_NUMBER, PalletStorageStateDtoFields.TYPE_OF_PALLET, PalletStorageStateDtoFields.LOCATION_NUMBER, PalletStorageStateDtoFields.STORAGE_LOCATION_NUMBER };
Map<String, String> filters = ((GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID)).getFilters();
String headerText = filters.entrySet().stream().filter(fe -> contains(descriminatorFiltersFields, fe.getKey()) && !fe.getValue().equals("ISNULL")).sorted(comparing((fe) -> indexOf(descriminatorFiltersFields, fe.getKey()))).map(fe -> fe.getValue().replaceAll("[\\[\\]]", "")).collect(Collectors.joining(", "));
FieldComponent headerLabel = (FieldComponent) view.getComponentByReference("palletStorageDetailsHeaderLabel");
String headerLabelText = translationService.translate("materialFlowResources.palletStorageStateDetails.window.mainTab.headerLabel", LocaleContextHolder.getLocale());
headerLabel.setFieldValue(headerLabelText + " " + headerText);
headerLabel.requestComponentUpdateState();
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class PalletStorageStateHooks method onBeforeRender.
public final void onBeforeRender(final ViewDefinitionState view) throws JSONException {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
JSONObject context = view.getJsonContext();
Set<Long> palletIds = Arrays.stream(context.getString("window.mainTab.helper.gridLayout.selectedEntities").replaceAll("[\\[\\]]", "").split(",")).map(Long::valueOf).collect(Collectors.toSet());
String palletNumberFilter = context.getString("window.mainTab.helper.gridLayout.palletNumberFilter");
Entity helper = form.getEntity();
if (helper.getHasManyField(L_PALLET_STORAGE_STATE_DTOS).isEmpty()) {
List<Entity> generatedEntities = createHelperEntities(palletIds);
if (isNotBlank(palletNumberFilter) && !palletNumberFilter.equals("NULL")) {
List<String> numbersOrder = Arrays.asList(palletNumberFilter.replaceAll("[\\[\\]]", "").split(","));
generatedEntities.sort(comparing(ge -> numbersOrder.indexOf(ge.getStringField(L_PALLET_NUMBER))));
}
helper.setField(L_PALLET_STORAGE_STATE_DTOS, generatedEntities);
form.setEntity(helper);
setStorageLocationFilters(view);
}
}
Aggregations