Package org.candlepin.model.activationkeys

Source Code of org.candlepin.model.activationkeys.ActivationKeyCurator

/**
* Copyright (c) 2009 - 2012 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package org.candlepin.model.activationkeys;

import org.candlepin.common.exceptions.BadRequestException;
import org.candlepin.model.AbstractHibernateCurator;
import org.candlepin.model.Owner;

import com.google.inject.persist.Transactional;

import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
* SubscriptionTokenCurator
*/
public class ActivationKeyCurator extends AbstractHibernateCurator<ActivationKey> {

    protected ActivationKeyCurator() {
        super(ActivationKey.class);
    }

    public List<ActivationKey> listByOwner(Owner owner) {
        return (List<ActivationKey>) currentSession().createCriteria(ActivationKey.class)
        .add(Restrictions.eq("owner", owner)).list();
    }

    @Transactional
    public ActivationKey update(ActivationKey key) {
        save(key);
        return key;
    }

    @Transactional
    public ActivationKey lookupForOwner(String keyName, Owner owner) {
        return (ActivationKey) currentSession().createCriteria(ActivationKey.class)
            .add(Restrictions.eq("name", keyName)).add(Restrictions.eq("owner", owner))
            .uniqueResult();
    }

    public ActivationKey verifyAndLookupKey(String activationKeyId) {
        ActivationKey key = this.secureFind(activationKeyId);

        if (key == null) {
            throw new BadRequestException(
                i18n.tr("ActivationKey with id {0} could not be found.",
                    activationKeyId));
        }
        return key;
    }
}
TOP

Related Classes of org.candlepin.model.activationkeys.ActivationKeyCurator

TOP
Copyright © 2018 www.massapi.com. 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.