Search in sources :

Example 6 with TblPcrManifest

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

the class TblPcrManifestJpaController method edit.

public void edit(TblPcrManifest tblPcrManifest) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPcrManifest persistentTblPcrManifest = em.find(TblPcrManifest.class, tblPcrManifest.getId());
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedByOld = persistentTblPcrManifest.getUpdatedBy();
            TblDbPortalUser updatedByNew = tblPcrManifest.getUpdatedBy();
            TblDbPortalUser createdByOld = persistentTblPcrManifest.getCreatedBy();
            TblDbPortalUser createdByNew = tblPcrManifest.getCreatedBy();
            */
        TblMle mleIdOld = persistentTblPcrManifest.getMleId();
        TblMle mleIdNew = tblPcrManifest.getMleId();
        /*
            if (updatedByNew != null) {
                updatedByNew = em.getReference(updatedByNew.getClass(), updatedByNew.getId());
                tblPcrManifest.setUpdatedBy(updatedByNew);
            }
            if (createdByNew != null) {
                createdByNew = em.getReference(createdByNew.getClass(), createdByNew.getId());
                tblPcrManifest.setCreatedBy(createdByNew);
            }*/
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            tblPcrManifest.setMleId(mleIdNew);
        }
        tblPcrManifest = em.merge(tblPcrManifest);
        /*
            if (updatedByOld != null && !updatedByOld.equals(updatedByNew)) {
                updatedByOld.getTblPcrManifestCollection().remove(tblPcrManifest);
                updatedByOld = em.merge(updatedByOld);
            }
            if (updatedByNew != null && !updatedByNew.equals(updatedByOld)) {
                updatedByNew.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(updatedByNew);
            }
            if (createdByOld != null && !createdByOld.equals(createdByNew)) {
                createdByOld.getTblPcrManifestCollection().remove(tblPcrManifest);
                createdByOld = em.merge(createdByOld);
            }
            if (createdByNew != null && !createdByNew.equals(createdByOld)) {
                createdByNew.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(createdByNew);
            }
            */
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getTblPcrManifestCollection().remove(tblPcrManifest);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getTblPcrManifestCollection().add(tblPcrManifest);
            em.merge(mleIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblPcrManifest.getId();
            if (findTblPcrManifest(id) == null) {
                throw new NonexistentEntityException("The tblPcrManifest 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) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 7 with TblPcrManifest

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

the class ReportsBO method getPcrManifestLog.

public PcrLogReport getPcrManifestLog(TblHosts tblHosts, TblTaLog log, Boolean failureOnly) throws NumberFormatException, IOException {
    TblPcrManifest tblPcrManifest = getPcrModuleManifest(tblHosts, log.getMleId(), log.getManifestName());
    PcrLogReport manifest = new PcrLogReport();
    manifest.setName(Integer.parseInt(log.getManifestName()));
    manifest.setValue(log.getManifestValue());
    manifest.setVerifiedOn(log.getUpdatedOn());
    manifest.setTrustStatus(getTrustStatus(log.getTrustStatus()));
    manifest.setWhiteListValue(tblPcrManifest.getValue());
    addManifestLogs(tblHosts.getId(), manifest, log, failureOnly, tblPcrManifest);
    return manifest;
}
Also used : TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 8 with TblPcrManifest

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

the class TblPcrManifestJpaControllerTest method testCreate.

@Test
public void testCreate() {
    TblPcrManifest tblPcrManifest = new TblPcrManifest(PcrManifest_ID, "0", "31B97D97B4679917EC3C1D943635693FFBAB4143");
    tblPcrManifestJpaController.create(tblPcrManifest);
    verify(em).persist(tblPcrManifest);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) Test(org.junit.Test)

Example 9 with TblPcrManifest

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

the class TblPcrManifestJpaControllerTest method testEdit.

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

Example 10 with TblPcrManifest

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

the class PcrGKVStrategyTest method getPcrManifestMap.

private HashMap<String, ? extends IManifest> getPcrManifestMap(TblMle mle) {
    HashMap<String, IManifest> pcrManifests = new HashMap<String, IManifest>();
    for (TblPcrManifest pcrMf : mle.getTblPcrManifestCollection()) {
        pcrMf = pcrManifestJpaController.findPcrManifestById(pcrMf.getId());
        pcrManifests.put(pcrMf.getName().trim(), new PcrManifest(Integer.valueOf(pcrMf.getName()), pcrMf.getValue().trim()));
    }
    return pcrManifests;
}
Also used : HashMap(java.util.HashMap) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) IManifest(com.intel.mountwilson.manifest.data.IManifest)

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