Search in sources :

Example 21 with TblPcrManifest

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

the class TblPcrManifestJpaControllerTest method testDestroy.

@Test
public void testDestroy() throws NonexistentEntityException {
    TblPcrManifest tblPcrManifest = new TblPcrManifest(PcrManifest_ID, "0", "31B97D97B4679917EC3C1D943635693FFBAB4143");
    doReturn(tblPcrManifest).when(em).getReference(TblPcrManifest.class, PcrManifest_ID);
    tblPcrManifestJpaController.destroy(PcrManifest_ID);
    verify(em).remove(tblPcrManifest);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) Test(org.junit.Test)

Example 22 with TblPcrManifest

use of com.intel.mtwilson.as.data.TblPcrManifest 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 23 with TblPcrManifest

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

the class TblPcrManifestJpaController method findByMleIdName.

/**
     * Added By: Sudhir on June 20, 2012
     * 
     * This method checks if the specified pcr entry already exists for the MLE.
     * @param id: Identity of the MLE
     * @param pcrName: Name of the PCR
     * @return : Single row result if there is a match or else null.
     */
public TblPcrManifest findByMleIdName(Integer id, String pcrName) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblPcrManifest.findByMleIdName");
        query.setParameter("mleId", id);
        query.setParameter("name", pcrName);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        TblPcrManifest pcrManifest = (TblPcrManifest) query.getSingleResult();
        return pcrManifest;
    } catch (NoResultException e) {
        log.error(String.format("PCR Manifest for MLE %d PCR#  not found in Database ", id, pcrName));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 24 with TblPcrManifest

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

the class HostBOTest method mockGetHost.

public TblHosts mockGetHost() {
    TblHosts tblHosts = new TblHosts();
    tblHosts.setId(1);
    tblHosts.setName(SERVER_NAME);
    tblHosts.setIPAddress(SERVER_NAME);
    String biosName = "DELL";
    String biosVersion = "A08";
    String oemName = "DELL";
    TblMle biosMle = new TblMle();
    biosMle.setId(1);
    biosMle.setName(biosName);
    biosMle.setVersion(biosVersion);
    TblOem oem = new TblOem();
    oem.setId(1);
    oem.setName(oemName);
    biosMle.setOemId(oem);
    Collection<TblPcrManifest> tblPcrManifestCollection = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifest = new TblPcrManifest();
    tblPcrManifest.setId(1);
    tblPcrManifest.setName("0");
    tblPcrManifest.setValue("31B97D97B4679917EC3C1D943635693FFBAB4143");
    tblPcrManifestCollection.add(tblPcrManifest);
    biosMle.setTblPcrManifestCollection(tblPcrManifestCollection);
    tblHosts.setBiosMleId(biosMle);
    String vmmName = "XEN";
    String vmmVersion = "4.3";
    String osName = "Fedora";
    String osVersion = "20";
    TblMle vmmMle = new TblMle();
    vmmMle.setId(1);
    vmmMle.setName(vmmName);
    vmmMle.setVersion(vmmVersion);
    TblOs os = new TblOs();
    os.setId(1);
    os.setName(osName);
    os.setVersion(osVersion);
    vmmMle.setOsId(os);
    Collection<TblPcrManifest> tblPcrManifestCollectionVMM = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifestVMM = new TblPcrManifest();
    tblPcrManifestVMM.setId(2);
    tblPcrManifestVMM.setName("18");
    tblPcrManifestVMM.setValue("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    tblPcrManifestCollection.add(tblPcrManifestVMM);
    vmmMle.setTblPcrManifestCollection(tblPcrManifestCollectionVMM);
    tblHosts.setVmmMleId(vmmMle);
    tblHosts.setTlsPolicyName("");
    tblHosts.setPort(8181);
    return tblHosts;
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 25 with TblPcrManifest

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

the class ReportsBOTest method mockFindByName.

public TblHosts mockFindByName() {
    TblHosts tblHosts = new TblHosts();
    tblHosts.setId(1);
    tblHosts.setName(SERVER_NAME);
    tblHosts.setIPAddress(SERVER_NAME);
    String biosName = "DELL";
    String biosVersion = "A08";
    String oemName = "DELL";
    TblMle biosMle = new TblMle();
    biosMle.setId(1);
    biosMle.setName(biosName);
    biosMle.setVersion(biosVersion);
    TblOem oem = new TblOem();
    oem.setId(1);
    oem.setName(oemName);
    biosMle.setOemId(oem);
    Collection<TblPcrManifest> tblPcrManifestCollection = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifest = new TblPcrManifest();
    tblPcrManifest.setId(1);
    tblPcrManifest.setName("0");
    tblPcrManifest.setValue("31B97D97B4679917EC3C1D943635693FFBAB4143");
    tblPcrManifestCollection.add(tblPcrManifest);
    biosMle.setTblPcrManifestCollection(tblPcrManifestCollection);
    tblHosts.setBiosMleId(biosMle);
    String vmmName = "XEN";
    String vmmVersion = "4.3";
    String osName = "Fedora";
    String osVersion = "20";
    TblMle vmmMle = new TblMle();
    vmmMle.setId(1);
    vmmMle.setName(vmmName);
    vmmMle.setVersion(vmmVersion);
    TblOs os = new TblOs();
    os.setId(1);
    os.setName(osName);
    os.setVersion(osVersion);
    vmmMle.setOsId(os);
    Collection<TblPcrManifest> tblPcrManifestCollectionVMM = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifestVMM = new TblPcrManifest();
    tblPcrManifestVMM.setId(2);
    tblPcrManifestVMM.setName("18");
    tblPcrManifestVMM.setValue("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    tblPcrManifestCollectionVMM.add(tblPcrManifestVMM);
    vmmMle.setTblPcrManifestCollection(tblPcrManifestCollectionVMM);
    tblHosts.setVmmMleId(vmmMle);
    return tblHosts;
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) TblOs(com.intel.mtwilson.as.data.TblOs)

Aggregations

TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)34 TblMle (com.intel.mtwilson.as.data.TblMle)18 Matchers.anyString (org.mockito.Matchers.anyString)12 ArrayList (java.util.ArrayList)9 EntityManager (javax.persistence.EntityManager)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)8 TblHosts (com.intel.mtwilson.as.data.TblHosts)7 Test (org.junit.Test)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)6 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)6 TblOem (com.intel.mtwilson.as.data.TblOem)6 TblOs (com.intel.mtwilson.as.data.TblOs)6 NoResultException (javax.persistence.NoResultException)5 ASException (com.intel.mountwilson.as.common.ASException)4 IManifest (com.intel.mountwilson.manifest.data.IManifest)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)4 HashMap (java.util.HashMap)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4