Package org.jayasoft.woj.server.data

Examples of org.jayasoft.woj.server.data.LicenseDao


        }
        return l;
    }

    public License add(String encryptedLicense) {
        LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
       
        License l = lDao.getByKey(encryptedLicense);
        if (l != null) {
            LOGGER.info("cannot insert same license twice");
            return l;
        }
       
        l = new License();
        try {
            l.setKey(encryptedLicense);
        } catch (Exception e) {
            throw new IllegalArgumentException("license cannot be decoded: " + encryptedLicense);
        }
        lDao.insert(l);
        //reload for id
        l = lDao.getByKey(encryptedLicense);
        _licenses.put(new Long(l.getId()), l);
       
        return l;
    }
View Full Code Here


        return new Date(Long.parseLong(decodeEncodedLicense(encodedLicense)[2]));
    }

    public void controlLicenses() throws LicenseException {
        License[] licenses = getAll();
        LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();

        int licensesByKey = lDao.getLicenseCountByKey();
        if (licensesByKey > licenses.length) {
            throw new LicenseException("similar licenses found in DB");
        }
        for (int i = 0; i < licenses.length; i++) {
            License l = licenses[i];
            int usedLicenses = lDao.getUsedLicense(new Long(l.getId()));
            if (usedLicenses>l.getLicenseCount()) {
                LOGGER.warn("too many licenses in use for license: " + l.getKey());
                throw new LicenseException("too many licenses in use for license: " + l.getKey());
            }
        }
View Full Code Here

            }
        }
    }

    public void affectLicense(Long userId, Long licId) throws LicenseException {
        LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
        try {
          if(getAvailableLicenses(licId) > 0) {
            lDao.affectLicense(userId, licId);  
          } else {
            throw new LicenseException("No more free license for:"+get(licId));
          }
        } catch (DataAccessException dae) {
            LOGGER.warn("db error while affecting license:" + licId + " to user: " + userId);
View Full Code Here

            throw new LicenseException("cannot affect license:" + licId + " to user: " + userId);
        }
    }

    public void affectLicense(Long userId, String licKey) throws LicenseException {
        LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
        License l = lDao.getByKey(licKey);
        if (l!=null) {
            affectLicense(userId, new Long(l.getId()));
        } else {
            LOGGER.info("no license foudn for key: " + licKey);
        }
View Full Code Here

            LOGGER.info("no license foudn for key: " + licKey);
        }
    }

    public void freeLicense(Long userId) throws LicenseException {
        LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
        try {
            lDao.freeLicense(userId);
        } catch (DataAccessException dae) {
            LOGGER.warn("db error while freeing license for user:" + userId);
            throw new LicenseException("cannot free license of user:" + userId);
        }
    }
View Full Code Here

    }
   
    public int getAvailableLicenses(Long licId) {
      try {
      License l = get(licId);
      LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
      int used = lDao.getUsedLicense(licId);
      return l.getLicenseCount()-used;
    } catch (Exception e) {
      LOGGER.error("unable to get AvailableLicenses for license id" +licId, e);
    }
    return -1;
View Full Code Here

    private Map _licenses = new HashMap()// Long(licId) -> License
   
    public License[] getAll() {
        License[] licenses = null;
        if (_licenses.size()==0) {
            LicenseDao lDao = WOJServer.getInstance().getDataService().getLicenseDao();
             licenses = lDao.getAll();
             for (int i = 0; i < licenses.length; i++) {
                _licenses.put(new Long(licenses[i].getId()), licenses[i]);
            }
        } else {
            Collection licAsList = (Collection)_licenses.values();
View Full Code Here

TOP

Related Classes of org.jayasoft.woj.server.data.LicenseDao

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.