public List addLicense(Order order) throws ServiceException, RegistrationException {
LOGGER.info("adding licenses to order:" + order.getId());
List newLicense = new ArrayList();
User u = order.getBuyer();
Price price = order.getPrice();
SpecialOffer so = order.getSpecialOffer();
int nb = order.getSubscribedUsers();
int duration = order.getSubscribedYears();
UserDao userDao = DaoFactory.getUserDao();
LicenseDao licenseDao = DaoFactory.getLicenseDao();
try {
ClufImpl cluf = getActiveCluf();
userDao.fetch(u);
UserImpl user = (UserImpl)userDao.findUser(u.getLogin());
userDao.fetch(user);
if ((user.getLastAcceptedCluf() == null) || !cluf.getVersion().equals(user.getLastAcceptedCluf().getVersion())) {
user.setLastAcceptedCluf(cluf);
}
for (int i = 0; i < nb; i++) {
License l = (License) licenseDao.newHandledObject();
l.setBuyer(user);
l.setPrice(price);
l.setSpecialOffer(so);
long validUntil = getValidUntil(duration);
l.setValidUntil(validUntil);
user.getBuyedLicenses().add(l);
newLicense.add(l);
//counter increment
price.getCounter().increment();
if(so != null) {
so.getCounter().increment();
}
}
ServiceFactory.getUserService().update(user);