Search in sources :

Example 11 with TblMle

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

the class TblPcrManifestJpaController method create.

public void create(TblPcrManifest tblPcrManifest) {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedBy = tblPcrManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy = em.getReference(updatedBy.getClass(), updatedBy.getId());
                tblPcrManifest.setUpdatedBy(updatedBy);
            }
            TblDbPortalUser createdBy = tblPcrManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy = em.getReference(createdBy.getClass(), createdBy.getId());
                tblPcrManifest.setCreatedBy(createdBy);
            }*/
        TblMle mleId = tblPcrManifest.getMleId();
        if (mleId != null) {
            mleId = em.getReference(mleId.getClass(), mleId.getId());
            tblPcrManifest.setMleId(mleId);
        }
        em.persist(tblPcrManifest);
        /*
            if (updatedBy != null) {
                updatedBy.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(updatedBy);
            }
            if (createdBy != null) {
                createdBy.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(createdBy);
            }*/
        if (mleId != null) {
            mleId.getTblPcrManifestCollection().add(tblPcrManifest);
            em.merge(mleId);
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblMle(com.intel.mtwilson.as.data.TblMle)

Example 12 with TblMle

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

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

the class MwMleSourceJpaController method edit.

public void edit(MwMleSource mwMleSource) throws NonexistentEntityException, Exception {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwMleSource persistentMwMleSource = em.find(MwMleSource.class, mwMleSource.getId());
        TblMle mleIdOld = persistentMwMleSource.getMleId();
        TblMle mleIdNew = mwMleSource.getMleId();
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            mwMleSource.setMleId(mleIdNew);
        }
        mwMleSource = em.merge(mwMleSource);
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getMwMleSourceCollection().remove(mwMleSource);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getMwMleSourceCollection().add(mwMleSource);
            em.merge(mleIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = mwMleSource.getId();
            if (findMwMleSource(id) == null) {
                throw new NonexistentEntityException("The mwMleSource with id " + id + " no longer exists.");
            }
        }
        throw ex;
    } finally {
        em.close();
    }
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 14 with TblMle

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

the class HostBOTest method testAddHost.

@Test
public void testAddHost() {
    TxtHost host = mockHost();
    when(hostsJpaController.findByName(anyString())).thenReturn(null);
    when(hostsJpaController.findByIPAddress(anyString())).thenReturn(null);
    TblMle biosMle = new TblMle(1, "DELL", "A08", "PCR", "BIOS", "0");
    TblMle vmmMle = new TblMle(2, "XEN", "4.3", "PCR", "VMM", "18");
    when(mleJpaController.findBiosMle(anyString(), anyString(), anyString())).thenReturn(biosMle);
    when(mleJpaController.findVmmMle(anyString(), anyString(), anyString(), anyString())).thenReturn(vmmMle);
    String response = hostBO.addHost(host);
    assertTrue(response.equalsIgnoreCase("true"));
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) Matchers.anyString(org.mockito.Matchers.anyString) TxtHost(com.intel.mtwilson.datatypes.TxtHost) Test(org.junit.Test)

Example 15 with TblMle

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

the class HostBO method findVmmMleForHost.

private TblMle findVmmMleForHost(TxtHost host) throws IOException {
    TblMleJpaController tblMleJpaController = getMleJpaController();
    TblMle vmmMleId = tblMleJpaController.findVmmMle(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion());
    if (vmmMleId == null) {
        throw new ASException(ErrorCode.AS_VMM_INCORRECT, host.getVmm().getName(), host.getVmm().getVersion());
    }
    return vmmMleId;
}
Also used : TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException)

Aggregations

TblMle (com.intel.mtwilson.as.data.TblMle)65 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)25 ASException (com.intel.mountwilson.as.common.ASException)20 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)20 EntityManager (javax.persistence.EntityManager)20 NoResultException (javax.persistence.NoResultException)19 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)18 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)17 ArrayList (java.util.ArrayList)16 Matchers.anyString (org.mockito.Matchers.anyString)14 EntityNotFoundException (javax.persistence.EntityNotFoundException)11 TblHosts (com.intel.mtwilson.as.data.TblHosts)9 TblOem (com.intel.mtwilson.as.data.TblOem)9 TblOs (com.intel.mtwilson.as.data.TblOs)9 Query (javax.persistence.Query)8 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)8 Test (org.junit.Test)8 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)7 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)6