Search in sources :

Example 96 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class MleBO method addMleSource.

/**
    * Creates a new mapping entry in the DB between the MLE and the host that was used for whitelisiting.
    * 
    * @param mleSourceObj : Object containing the details of the host and the MLE.
    * @return True or False
    */
public String addMleSource(MleSource mleSourceObj) {
    TblMle tblMle;
    MleData mleData = null;
    try {
        try {
            mleData = mleSourceObj.getMleData();
            // Verify if the MLE exists in the system.
            tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion());
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        // Let us check if there is a mapping entry already for this MLE. If it does, then we need to return
        // back appropriate error.
        MwMleSource mleSourceCurrentObj = mleSourceJpaController.findByMleId(tblMle.getId());
        if (mleSourceCurrentObj != null) {
            log.error("White List host is already mapped to the MLE - " + tblMle.getName());
            throw new ASException(ErrorCode.WS_MLE_SOURCE_MAPPING_ALREADY_EXISTS, mleData.getName());
        }
        // Else create a new entry in the DB.
        MwMleSource mleSourceData = new MwMleSource();
        mleSourceData.setMleId(tblMle);
        mleSourceData.setHostName(mleSourceObj.getHostName());
        mleSourceJpaController.create(mleSourceData);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 97 with NoResultException

use of javax.persistence.NoResultException in project OpenMEAP by OpenMEAP.

the class ModelServiceImpl method findAppVersionByNameAndId.

@Override
public ApplicationVersion findAppVersionByNameAndId(String appName, String identifier) {
    Query q = entityManager.createQuery("select distinct av " + "from ApplicationVersion av " + "inner join fetch av.application a " + "where av.identifier=:identifier " + "and a.name=:name");
    q.setParameter("name", appName);
    q.setParameter("identifier", identifier);
    try {
        ApplicationVersion ver = (ApplicationVersion) q.getSingleResult();
        return ver;
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 98 with NoResultException

use of javax.persistence.NoResultException in project OpenMEAP by OpenMEAP.

the class ModelServiceImpl method getLastDeployment.

@Override
public Deployment getLastDeployment(Application app) {
    Query q = entityManager.createQuery("select distinct d " + "from Deployment d join d.application " + "where d.application.id=:id " + "order by d.createDate desc");
    q.setParameter("id", app.getId());
    q.setMaxResults(1);
    try {
        Object o = q.getSingleResult();
        return (Deployment) o;
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) Deployment(com.openmeap.model.dto.Deployment) NoResultException(javax.persistence.NoResultException)

Example 99 with NoResultException

use of javax.persistence.NoResultException in project OpenMEAP by OpenMEAP.

the class ModelServiceImpl method getApplicationArchiveByDeployment.

@Override
public ApplicationArchive getApplicationArchiveByDeployment(Deployment depl) {
    Query q = entityManager.createQuery("select distinct aa " + "from ApplicationArchive aa, Deployment d  " + "where d.applicationArchive=aa and d.id=:id ");
    q.setParameter("id", depl.getId());
    q.setMaxResults(1);
    try {
        Object o = q.getSingleResult();
        return ((ApplicationArchive) o);
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 100 with NoResultException

use of javax.persistence.NoResultException in project OpenMEAP by OpenMEAP.

the class ModelServiceImpl method countVersionsByHashAndHashAlg.

@Override
public int countVersionsByHashAndHashAlg(String hash, String hashAlg) {
    Query q = entityManager.createQuery("select count(av) " + "from ApplicationVersion av " + "left join av.archive ar " + "where ar.hash=:hash " + "and ar.hashAlgorithm=:hashAlgorithm");
    q.setParameter("hash", hash);
    q.setParameter("hashAlgorithm", hashAlg);
    try {
        Number ret = (Number) q.getSingleResult();
        return ret.intValue();
    } catch (NoResultException nre) {
        return 0;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)163 Query (javax.persistence.Query)127 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)13 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4