Search in sources :

Example 21 with ViewDefinitionState

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()));
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) java.util(java.util) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) MaterialFlowConstants(com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SubstituteComponentFields(com.qcadoo.mes.basic.constants.SubstituteComponentFields) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) Lists(com.google.common.collect.Lists) JSONObject(org.json.JSONObject) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) MaterialAvailabilityFields(com.qcadoo.mes.productFlowThruDivision.constants.MaterialAvailabilityFields) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal)

Example 22 with ViewDefinitionState

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;
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ComponentState(com.qcadoo.view.api.ComponentState) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductAttributeValueFields(com.qcadoo.mes.basic.constants.ProductAttributeValueFields) StringUtils(org.apache.commons.lang3.StringUtils) FileService(com.qcadoo.model.api.file.FileService) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) AttributeValueType(com.qcadoo.mes.basic.constants.AttributeValueType) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell) AttributeFields(com.qcadoo.mes.basic.constants.AttributeFields) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Iterator(java.util.Iterator) AttributeValueFields(com.qcadoo.mes.basic.constants.AttributeValueFields) IOException(java.io.IOException) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) AttributeDataType(com.qcadoo.mes.basic.constants.AttributeDataType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) Row(org.apache.poi.ss.usermodel.Row) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) InputStream(java.io.InputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException)

Example 23 with ViewDefinitionState

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;
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ComponentState(com.qcadoo.view.api.ComponentState) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductAttributeValueFields(com.qcadoo.mes.basic.constants.ProductAttributeValueFields) StringUtils(org.apache.commons.lang3.StringUtils) FileService(com.qcadoo.model.api.file.FileService) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) AttributeValueType(com.qcadoo.mes.basic.constants.AttributeValueType) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell) AttributeFields(com.qcadoo.mes.basic.constants.AttributeFields) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Iterator(java.util.Iterator) AttributeValueFields(com.qcadoo.mes.basic.constants.AttributeValueFields) IOException(java.io.IOException) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) AttributeDataType(com.qcadoo.mes.basic.constants.AttributeDataType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) Row(org.apache.poi.ss.usermodel.Row) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) InputStream(java.io.InputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException)

Example 24 with ViewDefinitionState

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();
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) TranslationService(com.qcadoo.localization.api.TranslationService) ArrayUtils.contains(org.apache.commons.lang3.ArrayUtils.contains) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ArrayUtils.indexOf(org.apache.commons.lang3.ArrayUtils.indexOf) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Service(org.springframework.stereotype.Service) Map(java.util.Map) PalletStorageStateDtoFields(com.qcadoo.mes.materialFlowResources.constants.PalletStorageStateDtoFields) Comparator.comparing(java.util.Comparator.comparing) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 25 with ViewDefinitionState

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);
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Arrays(java.util.Arrays) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Maps(com.google.common.collect.Maps) MovedPalletDto(com.qcadoo.mes.materialFlowResources.dto.MovedPalletDto) Collectors(java.util.stream.Collectors) MaterialFlowResourcesConstants(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) List(java.util.List) JSONObject(org.json.JSONObject) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) MODEL_PALLET_STORAGE_STATE_DTO(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants.MODEL_PALLET_STORAGE_STATE_DTO) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) PalletStorageStateDtoFields(com.qcadoo.mes.materialFlowResources.constants.PalletStorageStateDtoFields) Comparator.comparing(java.util.Comparator.comparing) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11