*/
private void saveSubmittedData(TenderData tenderData) {
ResourceTender tender = null;
boolean isSupply = tenderData.getTenderType() == TenderType.SUPPLY;
IModel<Resource> resourceModel = getResourceModel();
Resource resource = resourceModel.getObject();
if (isSupply) {
Supply supply = new Supply();
tender = supply;
BigDecimal workingHours = tenderData.getWorkingHours();
supply.setHours(workingHours);
PriceType priceType = tenderData.getPriceType();
supply.setPriceType(priceType);
ZECurrency currencyCode = moneyManager.getDefaultCurrency();
supply.setCurrency(currencyCode);
BigDecimal totalPrice = tenderData.getTotalPrice();
supply.setTotalPrice(totalPrice);
supply.setSupplyTime(tenderData.getSupplyTime());
} else {
tender = new Need();
}
User currentUser = authorizedUserService.getCurrentUser();
tender.setResource(resource);
tender.setUser(currentUser);
tender.setAdditionalInfo(tenderData.getInfo());
tender.setAmount(tenderData.getAmount());
tender.setLocation(tenderData.getLocation());
ResourceTender resourceTender = tenderWriter.save(tender);
if (currentUser != null && currentUser.equals(resource.getOwner())) {
if(resourceTender instanceof Need) {
needWorkflowManager.acceptTender((Need) resourceTender);
} else {
supplyWorkflowManager.acceptTender((Supply) resourceTender);
}
}
//TODO:old tender is not removed from the neeeds/supplies collection?!
if(resourceTender instanceof Supply) {
resource = resourceWriter.addSupply(resource, (Supply) resourceTender);
} else if(resourceTender instanceof Need) {
resource = resourceWriter.addNeed(resource, (Need) resourceTender);
}
resourceModel.setObject(resource);
eventsDispatcher.publishEvent(new TenderChanged(resource.getContract(),
resourceTender, TenderOperation.SUBMITTED));
// Reload the page
setResponsePage(EditContract.class, new PageParameters().add(
EditContract.PARAM_CONTRACT_ID, resource.getContract().getId()));
}