Search in sources :

Example 11 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblHostSpecificManifestJpaController method findTblHostSpecificManifestEntities.

private List<TblHostSpecificManifest> findTblHostSpecificManifestEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblHostSpecificManifest.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 12 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblHostSpecificManifestJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHostSpecificManifest tblHostSpecificManifest;
        try {
            tblHostSpecificManifest = em.getReference(TblHostSpecificManifest.class, id);
            tblHostSpecificManifest.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblHostSpecificManifest with id " + id + " no longer exists.", enfe);
        }
        TblModuleManifest moduleManifestID = tblHostSpecificManifest.getModuleManifestID();
        if (moduleManifestID != null) {
            moduleManifestID.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifest);
            em.merge(moduleManifestID);
        }
        em.remove(tblHostSpecificManifest);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 13 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblHostSpecificManifestJpaController method findByHostID.

public TblHostSpecificManifest findByHostID(int hostId) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblHostSpecificManifest.findByHostID");
        query.setParameter("hostID", hostId);
        TblHostSpecificManifest tblHostSpecificManifest = (TblHostSpecificManifest) query.getSingleResult();
        return tblHostSpecificManifest;
    } catch (NoResultException e) {
        log.error("NoResultException: No Host specific manifest for Host [{}]", String.valueOf(hostId));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) NoResultException(javax.persistence.NoResultException)

Example 14 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class TblHostSpecificManifestJpaController method getTblHostSpecificManifestCount.

public int getTblHostSpecificManifestCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblHostSpecificManifest> rt = cq.from(TblHostSpecificManifest.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 15 with TblHostSpecificManifest

use of com.intel.mtwilson.as.data.TblHostSpecificManifest in project OpenAttestation by OpenAttestation.

the class HostBO method deleteHostSpecificManifest.

// PREMIUM FEATURE ? 
private void deleteHostSpecificManifest(TblHosts tblHosts) throws NonexistentEntityException, IOException {
    //TblHostSpecificManifestJpaController tblHostSpecificManifestJpaController = My.jpa().mwHostSpecificManifest();
    TblHostSpecificManifestJpaController tblHostSpecificManifestJpaController = getHostSpecificManifestJpaController();
    for (TblModuleManifest moduleManifest : tblHosts.getVmmMleId().getTblModuleManifestCollection()) {
        if (moduleManifest.getUseHostSpecificDigestValue() != null && moduleManifest.getUseHostSpecificDigestValue().booleanValue()) {
            // For open source we used to have multiple module manifests for the same hosts. So, the below query by hostID was returning multiple results.
            TblHostSpecificManifest hostSpecificManifest = tblHostSpecificManifestJpaController.findByModuleAndHostID(tblHosts.getId(), moduleManifest.getId());
            if (hostSpecificManifest != null) {
                log.debug("Deleting Host specific manifest." + moduleManifest.getComponentName() + ":" + hostSpecificManifest.getDigestValue());
                tblHostSpecificManifestJpaController.destroy(hostSpecificManifest.getId());
            }
        }
    }
}
Also used : TblHostSpecificManifestJpaController(com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Aggregations

TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)16 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)9 EntityManager (javax.persistence.EntityManager)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)7 NoResultException (javax.persistence.NoResultException)7 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 TblEventType (com.intel.mtwilson.as.data.TblEventType)5 TblMle (com.intel.mtwilson.as.data.TblMle)5 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)5 ArrayList (java.util.ArrayList)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)3 ASException (com.intel.mountwilson.as.common.ASException)2 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)2 TblHostSpecificManifestJpaController (com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController)2 TblHosts (com.intel.mtwilson.as.data.TblHosts)2 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)2 IOException (java.io.IOException)2