Package org.jayasoft.woj.portal.model

Examples of org.jayasoft.woj.portal.model.License


    if (user instanceof UserImpl) {
      UserImpl userImpl = (UserImpl) user;
      Set ls = userImpl.getBuyedLicenses();
      if(ls != null) {
        for (Iterator iter = ls.iterator(); iter.hasNext();) {
          License l = (License) iter.next();
          license += l.toString()+",";
        }
      }
    }
    params.put("license", license);
    m.setContent((String) _rbTE.build(MAIL_NEW_USER_ADMIN, params));
View Full Code Here


        InvoiceBuilder builder = ItextPDFInvoiceBuilder.instance();
        Order o = new Order();
        o.setTotalCost(50.0d);
        Invoice i = new Invoice();
        PaymentInfo pi = new PaymentInfo();
        License l = new License();
        Price p = new Price();
        p.setPriceByYear(50);
        l.setPrice(p);
        pi.setLicenses(Collections.singleton(l));
        o.setPayments(Collections.singleton(pi));
        o.setInvoice(i);
        Purchaser pur = getPurchaser();
        if (builder.buildInvoicePDF(o, pur, "inv-" + System.currentTimeMillis()) != null) {
View Full Code Here

            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) {
View Full Code Here

        throw new RegistrationException("cannot add  license to user", e);
      }
    }

    private void upgradeLicenses(UserImpl buyer, List licensesBought) throws DaoException, ServiceException {
        License licenseUsed = buyer.getLicenseUsed();
        LOGGER.debug("upgrading licenses of "+buyer+" ("+licenseUsed+") with "+licensesBought);
        if (licensesBought.isEmpty()) {
            return;
        }
        List availableLicenses = new ArrayList(licensesBought);
        List usersToUpdate = new ArrayList();
       
        if (isTrial(licenseUsed)
                || (licenseUsed == null && buyer.getBuyedLicenses().size() == licensesBought.size())) {
            // upgrade buyer license
            License l = (License)availableLicenses.remove(0);
            LOGGER.debug("upgrading buyer license to "+l);
            buyer.setLicenseUsed(l);
            DaoFactory.getUserDao().save(buyer);
            usersToUpdate.add(buyer);
        }

        Map trialLicensesByOwner = getTrialLicensesByOwner(buyer);

        LOGGER.debug(trialLicensesByOwner.size()+" licenses still need to be upgraded, "+availableLicenses.size()+" available");
        if (! trialLicensesByOwner.isEmpty() && trialLicensesByOwner.size() <= availableLicenses.size()) {
            // there is enough licenses for the number of currently used trial licenses: we upgrade them all
            LOGGER.debug("upgrading licenses of "+trialLicensesByOwner.keySet());
            for (Iterator iter = trialLicensesByOwner.keySet().iterator(); iter.hasNext();) {
                UserImpl owner = (UserImpl)iter.next();
                License newLicense = (License)availableLicenses.remove(0);
                owner.setLicenseUsed(newLicense);
                DaoFactory.getUserDao().save(owner);
                usersToUpdate.add(owner);
            }
        } else {
            LOGGER.debug("not enough licenses, no upgrade");
        }
       
        if (!canManageGroups(buyer.getLicenseUsed())) {
            // user does not have group management any more
            // all buyed trials used by others should now belong to them and be ungrouped
            for (Iterator iter = buyer.getBuyedLicenses().iterator(); iter.hasNext();) {
                License lic = (License)iter.next();
                if (isTrial(lic) && lic.getOwner() != null && lic.getOwner().getId() != buyer.getId()) {
                    lic.setBuyer(lic.getOwner());
                    if (lic.getGroup() != null) {
                        ServiceFactory.getGroupService().removeLicense(new Long(lic.getGroup().getId()), new Long(lic.getId()));
                    } else {
                        saveLicense(lic);
                    }
                }
            }
View Full Code Here

    private Map getTrialLicensesByOwner(UserImpl buyer) {
        Map licensesByOwner = new HashMap();
        Set alreadyBoughtLicenses = buyer.getBuyedLicenses();
        for (Iterator iter = alreadyBoughtLicenses.iterator(); iter.hasNext();) {
            License lic = (License)iter.next();
            if (lic.getOwner() != null && ServiceFactory.getLicenseService().isTrial(lic)) {
                licensesByOwner.put(lic.getOwner(), lic);
            }
        }
        return licensesByOwner;
    }
View Full Code Here

        if(licenseDao.hasTrialLicenseForHost(hostId)) {
            LOGGER.warn("user " + u.getLogin() + " is trying to register another trial for host " + hostId);
            throw ServiceException.create("You have already requested a trial license. If you want an extra trial time please contact us.", "Host id alread use in trial license", null);
        }
        try {
            License l = licenseDao.createTrial();
            l.setHostId(hostId);
           
            addFreeLicense(u, l);
        } catch (DaoException e) {
            LOGGER.warn("failed to add trial license to user " + u.getLogin() + " from host " + hostId, e);
            throw new ServiceException("cannot add trial license to user");
View Full Code Here

    public void addPersonalLicense(User u) throws ServiceException {
        LicenseDao licenseDao = DaoFactory.getLicenseDao();
        LOGGER.info("adding personal license to user " + u.getLogin());

        try {
            License l = licenseDao.createPersonal();
           
            addFreeLicense(u, l);
        } catch (DaoException e) {
            throw new ServiceException("failed to add personal license to user " + u.getLogin(), e);
        }
View Full Code Here

  }

    public void uninviteUserFromLicense(long licenseId) throws ServiceException {
        try {
            LicenseDao ldao = DaoFactory.getLicenseDao();
            License l = (License)ldao.find(new Long(licenseId));
            if (l.getInvitedMail()!=null) {
                l.setInvitedMail(null);
                ldao.save(l);
            }
        } catch (DaoException e) {
            throw ServiceException.create("cannot cancel invitation on license " + licenseId, "cannot cancel invitation on license " + licenseId + ", license not found in DB", e);
        }
View Full Code Here

            throw ServiceException.create("cannot cancel invitation on license " + licenseId, "cannot cancel invitation on license " + licenseId + ", license not found in DB", e);
        }
    }
   
  public void inviteUserToUseLicense(User userLogged, String mail, long licenseId) throws ServiceException {
    License licenseToAffect = null;
        try {
            licenseToAffect = (License) DaoFactory.getLicenseDao().find(new Long(licenseId));
        } catch (DaoException e1) {
            throw ServiceException.create("failed to invite user " + mail, "failed to invite user " + mail + " license "+ licenseId + " not found in DB", e1);
        }
       
        // We check if the license is already owned or invited
        if (licenseToAffect.getOwner() != null || licenseToAffect.getInvitedMail() != null) {
            return;
        }
       
        if (mail==null || !EmailHelper.doEmailSeemsValid(mail)) {
            throw new ServiceException(RessourceBundleApplicationMessage.error("woj.page.admin.user.license.error.invite.no.mail", new Object[] {licenseToAffect.getProductCode(), TimeUtil.getDate(licenseToAffect.getValidUntil())}));
        }
       
    User userToAffect = ServiceFactory.getUserService().getUserByEmail(mail);
    String invitedFisrtName = "";
    String invitedLastName = "";   
    if (userToAffect != null) {
      invitedFisrtName = ((UserImpl)userToAffect).getFirstName();
      invitedLastName = ((UserImpl)userToAffect).getLastName();
    }
   
    licenseToAffect.setInvitedMail(mail);
        ServiceFactory.getLicenseService().update(licenseToAffect);
    try {
            Portal.getInstance().getMailService().sendMail(Portal.getInstance().getMailFactory().createInviteUserMail(userLogged, invitedLastName, invitedFisrtName, mail, licenseToAffect));
        } catch (MessagingException e) {
            throw ServiceException.create("failed to send invitation mail to " + mail, "failed to send invitation mail to " + mail, e);
View Full Code Here

 
  public void acceptInvitation(InvitationInfo invitInfo) throws ServiceException {
    String mail = invitInfo.getMail();
    try {
      ClufImpl cluf = ServiceFactory.getLicenseService().getActiveCluf();
      License licenseToAffect = (License) DaoFactory.getLicenseDao().find(new Long(Long.parseLong(invitInfo.getLicenseId())));
      User userToAffect = invitInfo.getUser();
      if (mail == null || !mail.equals(licenseToAffect.getInvitedMail())) {
        throw new IllegalArgumentException("Failed to accept invitation for user with mail : " + mail + ". This user hasn't been invited");
       
      }
      // Check user is in session
      User u = DaoFactory.getUserDao().findUser(userToAffect.getLogin());
      if (u != null) {
//      BeanHelper.copy(userToAffect, u, UserImpl.class);
      userToAffect = u;
      }

//      License oldLic = ((UserImpl)userToAffect).getLicenseUsed();
//      if (oldLic != null && oldLic.getId() != licenseToAffect.getId()) {
//        oldLic.setOwner(null);
//        ServiceFactory.getLicenseService().update(oldLic);
//      }
      ((UserImpl)userToAffect).setLastAcceptedCluf(cluf);
      ((UserImpl)userToAffect).setLicenseUsed(licenseToAffect);
//      licenseToAffect.setOwner(userToAffect);
      licenseToAffect.setInvitedMail(null);
      ServiceFactory.getUserService().update(userToAffect);
//      ServiceFactory.getLicenseService().update(licenseToAffect);
    } catch (DaoException e) {
      throw new ServiceException("Failed to get License for id : " + invitInfo.getLicenseId(), e);
    }
View Full Code Here

TOP

Related Classes of org.jayasoft.woj.portal.model.License

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.