Search in sources :

Example 26 with TblHosts

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

the class TblHostsJpaController method findHostsByNameSearchCriteria.

public List<TblHosts> findHostsByNameSearchCriteria(String searchCriteria) {
    List<TblHosts> hostList = null;
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblHosts.findByNameSearchCriteria");
        query.setParameter("search", "%" + searchCriteria + "%");
        if (query.getResultList() != null && !query.getResultList().isEmpty()) {
            hostList = query.getResultList();
        }
    } finally {
        em.close();
    }
    return hostList;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblHosts(com.intel.mtwilson.as.data.TblHosts)

Example 27 with TblHosts

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

the class TblHostsJpaController method findByHwUUID.

public TblHosts findByHwUUID(String hardware_uuid) {
    TblHosts host = null;
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblHosts.findByHwUUID");
        query.setParameter("hardware_uuid", hardware_uuid);
        List<TblHosts> list = query.getResultList();
        if (list != null && list.size() > 0) {
            host = list.get(0);
        }
    } finally {
        em.close();
    }
    return host;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblHosts(com.intel.mtwilson.as.data.TblHosts)

Example 28 with TblHosts

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

the class TblMleJpaController method edit.

public void edit(TblMle tblMle) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblMle persistentTblMle = em.find(TblMle.class, tblMle.getId());
        Collection<TblHosts> tblHostsCollectionOld = persistentTblMle.getTblHostsCollection();
        Collection<TblHosts> tblHostsCollectionNew = tblMle.getTblHostsCollection();
        Collection<TblHosts> tblHostsCollection1Old = persistentTblMle.getTblHostsCollection1();
        Collection<TblHosts> tblHostsCollection1New = tblMle.getTblHostsCollection1();
        Collection<TblPcrManifest> tblPcrManifestCollectionOld = persistentTblMle.getTblPcrManifestCollection();
        Collection<TblPcrManifest> tblPcrManifestCollectionNew = tblMle.getTblPcrManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblHosts tblHostsCollectionOldTblHosts : tblHostsCollectionOld) {
            if (!tblHostsCollectionNew.contains(tblHostsCollectionOldTblHosts)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblHosts " + tblHostsCollectionOldTblHosts + " since its vmmMleId field is not nullable.");
            }
        }
        for (TblHosts tblHostsCollection1OldTblHosts : tblHostsCollection1Old) {
            if (!tblHostsCollection1New.contains(tblHostsCollection1OldTblHosts)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblHosts " + tblHostsCollection1OldTblHosts + " since its biosMleId field is not nullable.");
            }
        }
        for (TblPcrManifest tblPcrManifestCollectionOldTblPcrManifest : tblPcrManifestCollectionOld) {
            if (!tblPcrManifestCollectionNew.contains(tblPcrManifestCollectionOldTblPcrManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblPcrManifest " + tblPcrManifestCollectionOldTblPcrManifest + " since its mleId field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        Collection<TblHosts> attachedTblHostsCollectionNew = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollectionNewTblHostsToAttach : tblHostsCollectionNew) {
            tblHostsCollectionNewTblHostsToAttach = em.getReference(tblHostsCollectionNewTblHostsToAttach.getClass(), tblHostsCollectionNewTblHostsToAttach.getId());
            attachedTblHostsCollectionNew.add(tblHostsCollectionNewTblHostsToAttach);
        }
        tblHostsCollectionNew = attachedTblHostsCollectionNew;
        tblMle.setTblHostsCollection(tblHostsCollectionNew);
        Collection<TblHosts> attachedTblHostsCollection1New = new ArrayList<TblHosts>();
        for (TblHosts tblHostsCollection1NewTblHostsToAttach : tblHostsCollection1New) {
            tblHostsCollection1NewTblHostsToAttach = em.getReference(tblHostsCollection1NewTblHostsToAttach.getClass(), tblHostsCollection1NewTblHostsToAttach.getId());
            attachedTblHostsCollection1New.add(tblHostsCollection1NewTblHostsToAttach);
        }
        tblHostsCollection1New = attachedTblHostsCollection1New;
        tblMle.setTblHostsCollection1(tblHostsCollection1New);
        Collection<TblPcrManifest> attachedTblPcrManifestCollectionNew = new ArrayList<TblPcrManifest>();
        for (TblPcrManifest tblPcrManifestCollectionNewTblPcrManifestToAttach : tblPcrManifestCollectionNew) {
            tblPcrManifestCollectionNewTblPcrManifestToAttach = em.getReference(tblPcrManifestCollectionNewTblPcrManifestToAttach.getClass(), tblPcrManifestCollectionNewTblPcrManifestToAttach.getId());
            attachedTblPcrManifestCollectionNew.add(tblPcrManifestCollectionNewTblPcrManifestToAttach);
        }
        tblPcrManifestCollectionNew = attachedTblPcrManifestCollectionNew;
        tblMle.setTblPcrManifestCollection(tblPcrManifestCollectionNew);
        tblMle = em.merge(tblMle);
        for (TblHosts tblHostsCollectionNewTblHosts : tblHostsCollectionNew) {
            if (!tblHostsCollectionOld.contains(tblHostsCollectionNewTblHosts)) {
                TblMle oldVmmMleIdOfTblHostsCollectionNewTblHosts = tblHostsCollectionNewTblHosts.getVmmMleId();
                tblHostsCollectionNewTblHosts.setVmmMleId(tblMle);
                tblHostsCollectionNewTblHosts = em.merge(tblHostsCollectionNewTblHosts);
                if (oldVmmMleIdOfTblHostsCollectionNewTblHosts != null && !oldVmmMleIdOfTblHostsCollectionNewTblHosts.equals(tblMle)) {
                    oldVmmMleIdOfTblHostsCollectionNewTblHosts.getTblHostsCollection().remove(tblHostsCollectionNewTblHosts);
                    em.merge(oldVmmMleIdOfTblHostsCollectionNewTblHosts);
                }
            }
        }
        for (TblHosts tblHostsCollection1NewTblHosts : tblHostsCollection1New) {
            if (!tblHostsCollection1Old.contains(tblHostsCollection1NewTblHosts)) {
                TblMle oldBiosMleIdOfTblHostsCollection1NewTblHosts = tblHostsCollection1NewTblHosts.getBiosMleId();
                tblHostsCollection1NewTblHosts.setBiosMleId(tblMle);
                tblHostsCollection1NewTblHosts = em.merge(tblHostsCollection1NewTblHosts);
                if (oldBiosMleIdOfTblHostsCollection1NewTblHosts != null && !oldBiosMleIdOfTblHostsCollection1NewTblHosts.equals(tblMle)) {
                    oldBiosMleIdOfTblHostsCollection1NewTblHosts.getTblHostsCollection1().remove(tblHostsCollection1NewTblHosts);
                    em.merge(oldBiosMleIdOfTblHostsCollection1NewTblHosts);
                }
            }
        }
        for (TblPcrManifest tblPcrManifestCollectionNewTblPcrManifest : tblPcrManifestCollectionNew) {
            if (!tblPcrManifestCollectionOld.contains(tblPcrManifestCollectionNewTblPcrManifest)) {
                TblMle oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest = tblPcrManifestCollectionNewTblPcrManifest.getMleId();
                tblPcrManifestCollectionNewTblPcrManifest.setMleId(tblMle);
                tblPcrManifestCollectionNewTblPcrManifest = em.merge(tblPcrManifestCollectionNewTblPcrManifest);
                if (oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest != null && !oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest.equals(tblMle)) {
                    oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest.getTblPcrManifestCollection().remove(tblPcrManifestCollectionNewTblPcrManifest);
                    em.merge(oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest);
                }
            }
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblMle.getId();
            if (findTblMle(id) == null) {
                throw new NonexistentEntityException("The tblMle with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) NoResultException(javax.persistence.NoResultException) 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) EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts)

Example 29 with TblHosts

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

the class TblHostsJpaControllerTest method testCreate.

@Test
public void testCreate() throws CryptographyException {
    TblHosts tblHost = new TblHosts(HOST_ID);
    tblHostsJpaController.create(tblHost);
    verify(em).persist(tblHost);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) Test(org.junit.Test)

Example 30 with TblHosts

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

the class TblSamlAssertionJpaController method create.

public void create(TblSamlAssertion tblSamlAssertion) {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts hostId = tblSamlAssertion.getHostId();
        if (hostId != null) {
            hostId = em.getReference(hostId.getClass(), hostId.getId());
            tblSamlAssertion.setHostId(hostId);
        }
        em.persist(tblSamlAssertion);
        if (hostId != null) {
            hostId.getTblSamlAssertionCollection().add(tblSamlAssertion);
            em.merge(hostId);
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts)

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