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;
}
}
Aggregations