Search in sources :

Example 1 with TblHosts

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

the class TblHostsJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts tblHosts;
        try {
            tblHosts = em.getReference(TblHosts.class, id);
            tblHosts.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.", enfe);
        }
        TblMle vmmMleId = tblHosts.getVmmMleId();
        if (vmmMleId != null) {
            vmmMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(vmmMleId);
        }
        TblMle biosMleId = tblHosts.getBiosMleId();
        if (biosMleId != null) {
            biosMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(biosMleId);
        }
        em.remove(tblHosts);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 2 with TblHosts

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

the class TblHostsJpaController method edit.

public void edit(TblHosts tblHosts) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts persistentTblHosts = em.find(TblHosts.class, tblHosts.getId());
        TblMle vmmMleIdOld = persistentTblHosts.getVmmMleId();
        TblMle vmmMleIdNew = tblHosts.getVmmMleId();
        TblMle biosMleIdOld = persistentTblHosts.getBiosMleId();
        TblMle biosMleIdNew = tblHosts.getBiosMleId();
        if (vmmMleIdNew != null) {
            vmmMleIdNew = em.getReference(vmmMleIdNew.getClass(), vmmMleIdNew.getId());
            tblHosts.setVmmMleId(vmmMleIdNew);
        }
        if (biosMleIdNew != null) {
            biosMleIdNew = em.getReference(biosMleIdNew.getClass(), biosMleIdNew.getId());
            tblHosts.setBiosMleId(biosMleIdNew);
        }
        // encrypt addon connection string, persist, then restore the plaintext
        String addOnConnectionString = tblHosts.getAddOnConnectionInfo();
        if (addOnConnectionString != null) {
            tblHosts = em.merge(tblHosts);
        } else {
            tblHosts = em.merge(tblHosts);
        }
        if (vmmMleIdOld != null && !vmmMleIdOld.equals(vmmMleIdNew)) {
            vmmMleIdOld.getTblHostsCollection().remove(tblHosts);
            vmmMleIdOld = em.merge(vmmMleIdOld);
        }
        if (vmmMleIdNew != null && !vmmMleIdNew.equals(vmmMleIdOld)) {
            vmmMleIdNew.getTblHostsCollection().add(tblHosts);
            em.merge(vmmMleIdNew);
        }
        if (biosMleIdOld != null && !biosMleIdOld.equals(biosMleIdNew)) {
            biosMleIdOld.getTblHostsCollection().remove(tblHosts);
            biosMleIdOld = em.merge(biosMleIdOld);
        }
        if (biosMleIdNew != null && !biosMleIdNew.equals(biosMleIdOld)) {
            biosMleIdNew.getTblHostsCollection().add(tblHosts);
            em.merge(biosMleIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblHosts.getId();
            if (findTblHosts(id) == null) {
                throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 3 with TblHosts

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

the class TblHostsJpaController method findTblHostsEntities.

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

Example 4 with TblHosts

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

the class TblHostsJpaController method getTblHostsCount.

public int getTblHostsCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblHosts> rt = cq.from(TblHosts.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) TblHosts(com.intel.mtwilson.as.data.TblHosts) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 5 with TblHosts

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

the class TblMleJpaController method create.

public void create(TblMle tblMle) {
    if (tblMle.getTblHostsCollection() == null) {
        tblMle.setTblHostsCollection(new ArrayList<TblHosts>());
    }
    if (tblMle.getTblHostsCollection1() == null) {
        tblMle.setTblHostsCollection1(new ArrayList<TblHosts>());
    }
    if (tblMle.getTblPcrManifestCollection() == null) {
        tblMle.setTblPcrManifestCollection(new ArrayList<TblPcrManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        Collection<TblHosts> attachedTblHostsCollection = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollectionTblHostsToAttach : tblMle.getTblHostsCollection()) {
            tblHostsCollectionTblHostsToAttach = em.getReference(tblHostsCollectionTblHostsToAttach.getClass(), tblHostsCollectionTblHostsToAttach.getId());
            attachedTblHostsCollection.add(tblHostsCollectionTblHostsToAttach);
        }
        tblMle.setTblHostsCollection(attachedTblHostsCollection);
        Collection<TblHosts> attachedTblHostsCollection1 = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollection1TblHostsToAttach : tblMle.getTblHostsCollection1()) {
            tblHostsCollection1TblHostsToAttach = em.getReference(tblHostsCollection1TblHostsToAttach.getClass(), tblHostsCollection1TblHostsToAttach.getId());
            attachedTblHostsCollection1.add(tblHostsCollection1TblHostsToAttach);
        }
        tblMle.setTblHostsCollection1(attachedTblHostsCollection1);
        Collection<TblPcrManifest> attachedTblPcrManifestCollection = new ArrayList<TblPcrManifest>();
        for (TblPcrManifest tblPcrManifestCollectionTblPcrManifestToAttach : tblMle.getTblPcrManifestCollection()) {
            tblPcrManifestCollectionTblPcrManifestToAttach = em.getReference(tblPcrManifestCollectionTblPcrManifestToAttach.getClass(), tblPcrManifestCollectionTblPcrManifestToAttach.getId());
            attachedTblPcrManifestCollection.add(tblPcrManifestCollectionTblPcrManifestToAttach);
        }
        tblMle.setTblPcrManifestCollection(attachedTblPcrManifestCollection);
        em.persist(tblMle);
        for (TblHosts tblHostsCollectionTblHosts : tblMle.getTblHostsCollection()) {
            TblMle oldVmmMleIdOfTblHostsCollectionTblHosts = tblHostsCollectionTblHosts.getVmmMleId();
            tblHostsCollectionTblHosts.setVmmMleId(tblMle);
            tblHostsCollectionTblHosts = em.merge(tblHostsCollectionTblHosts);
            if (oldVmmMleIdOfTblHostsCollectionTblHosts != null) {
                oldVmmMleIdOfTblHostsCollectionTblHosts.getTblHostsCollection().remove(tblHostsCollectionTblHosts);
                em.merge(oldVmmMleIdOfTblHostsCollectionTblHosts);
            }
        }
        for (TblHosts tblHostsCollection1TblHosts : tblMle.getTblHostsCollection1()) {
            TblMle oldBiosMleIdOfTblHostsCollection1TblHosts = tblHostsCollection1TblHosts.getBiosMleId();
            tblHostsCollection1TblHosts.setBiosMleId(tblMle);
            tblHostsCollection1TblHosts = em.merge(tblHostsCollection1TblHosts);
            if (oldBiosMleIdOfTblHostsCollection1TblHosts != null) {
                oldBiosMleIdOfTblHostsCollection1TblHosts.getTblHostsCollection1().remove(tblHostsCollection1TblHosts);
                em.merge(oldBiosMleIdOfTblHostsCollection1TblHosts);
            }
        }
        for (TblPcrManifest tblPcrManifestCollectionTblPcrManifest : tblMle.getTblPcrManifestCollection()) {
            TblMle oldMleIdOfTblPcrManifestCollectionTblPcrManifest = tblPcrManifestCollectionTblPcrManifest.getMleId();
            tblPcrManifestCollectionTblPcrManifest.setMleId(tblMle);
            tblPcrManifestCollectionTblPcrManifest = em.merge(tblPcrManifestCollectionTblPcrManifest);
            if (oldMleIdOfTblPcrManifestCollectionTblPcrManifest != null) {
                oldMleIdOfTblPcrManifestCollectionTblPcrManifest.getTblPcrManifestCollection().remove(tblPcrManifestCollectionTblPcrManifest);
                em.merge(oldMleIdOfTblPcrManifestCollectionTblPcrManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Aggregations

TblHosts (com.intel.mtwilson.as.data.TblHosts)42 ASException (com.intel.mountwilson.as.common.ASException)17 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)15 EntityManager (javax.persistence.EntityManager)14 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)13 IOException (java.io.IOException)12 UnknownHostException (java.net.UnknownHostException)11 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)10 ArrayList (java.util.ArrayList)10 TblMle (com.intel.mtwilson.as.data.TblMle)9 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)9 NoResultException (javax.persistence.NoResultException)8 TblHostsJpaController (com.intel.mtwilson.as.controller.TblHostsJpaController)7 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)6 EntityNotFoundException (javax.persistence.EntityNotFoundException)6 Query (javax.persistence.Query)6 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)6 Hostname (com.intel.mtwilson.util.net.Hostname)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)4