Search in sources :

Example 1 with RuntimeExceptionWithArguments

use of com.qcadoo.model.api.exception.RuntimeExceptionWithArguments in project mes by qcadoo.

the class WarehouseIssueService method createWarehouseDocumentsForPositions.

public List<Entity> createWarehouseDocumentsForPositions(final ViewDefinitionState view, final List<Entity> issues, final Entity locationFrom, final Optional<String> additionalInfo) {
    List<Entity> validDocuments = Lists.newArrayList();
    if (!checkIfAllIssueQuantityGraterThanZero(issues)) {
        throw new RuntimeException("productFlowThruDivision.issue.state.accept.error.issueForZero");
    }
    UpdateIssuesLocationsQuantityStatusHolder updateIssuesStatus = tryUpdateIssuesLocationsQuantity(locationFrom, issues);
    if (!updateIssuesStatus.isUpdated()) {
        throw new RuntimeExceptionWithArguments("productFlowThruDivision.issue.state.accept.error.noProductsOnLocation", updateIssuesStatus.getMessage(), locationFrom.getStringField(LocationFields.NUMBER));
    } else {
        MultiMap warehouseIssuesMap = new MultiHashMap();
        for (Entity issue : issues) {
            warehouseIssuesMap.put(issue.getBelongsToField(L_LOCATION).getId(), issue);
        }
        for (Object key : warehouseIssuesMap.keySet()) {
            Long id = (Long) key;
            Entity locationTo = getLocationDD().get(id);
            Collection coll = (Collection) warehouseIssuesMap.get(key);
            CreationDocumentResponse response;
            if (additionalInfo.isPresent()) {
                response = createWarehouseDocumentForPositions(coll, locationFrom, locationTo, additionalInfo.get());
            } else {
                response = createWarehouseDocumentForPositions(coll, locationFrom, locationTo);
            }
            if (response.isValid()) {
                validDocuments.add(response.getDocument());
            } else {
                if (!response.getErrors().isEmpty()) {
                    response.getErrors().forEach(er -> view.addMessage(er));
                }
                throw new RuntimeExceptionWithArguments("productFlowThruDivision.issue.state.accept.error.documentsNotCreated");
            }
            updateIssuePosition(coll, response.getDocument());
        }
        Set<Entity> warehouseIssues = extractWarehouseIssues(issues);
        updateProductsToIssues(warehouseIssues, issues);
        updateWarehouseIssuesState(warehouseIssues);
        view.addMessage("productFlowThruDivision.issue.documentGeneration.success", ComponentState.MessageType.SUCCESS);
        return validDocuments;
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) MultiMap(org.apache.commons.collections.MultiMap) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) RuntimeExceptionWithArguments(com.qcadoo.model.api.exception.RuntimeExceptionWithArguments) Collection(java.util.Collection) MultiHashMap(org.apache.commons.collections.MultiHashMap) CreationDocumentResponse(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)

Aggregations

CreationDocumentResponse (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.CreationDocumentResponse)1 UpdateIssuesLocationsQuantityStatusHolder (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder)1 Entity (com.qcadoo.model.api.Entity)1 RuntimeExceptionWithArguments (com.qcadoo.model.api.exception.RuntimeExceptionWithArguments)1 Collection (java.util.Collection)1 MultiHashMap (org.apache.commons.collections.MultiHashMap)1 MultiMap (org.apache.commons.collections.MultiMap)1