Search in sources :

Example 11 with TblModuleManifest

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

the class TblEventTypeJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblEventType tblEventType;
        try {
            tblEventType = em.getReference(TblEventType.class, id);
            tblEventType.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblEventType with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<TblModuleManifest> tblModuleManifestCollectionOrphanCheck = tblEventType.getTblModuleManifestCollection();
        for (TblModuleManifest tblModuleManifestCollectionOrphanCheckTblModuleManifest : tblModuleManifestCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblEventType (" + tblEventType + ") cannot be destroyed since the TblModuleManifest " + tblModuleManifestCollectionOrphanCheckTblModuleManifest + " in its tblModuleManifestCollection field has a non-nullable eventID field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        em.remove(tblEventType);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 12 with TblModuleManifest

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

the class TblEventTypeJpaController method create.

public void create(TblEventType tblEventType) {
    if (tblEventType.getTblModuleManifestCollection() == null) {
        tblEventType.setTblModuleManifestCollection(new ArrayList<TblModuleManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        Collection<TblModuleManifest> attachedTblModuleManifestCollection = new ArrayList<TblModuleManifest>();
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifestToAttach : tblEventType.getTblModuleManifestCollection()) {
            tblModuleManifestCollectionTblModuleManifestToAttach = em.getReference(tblModuleManifestCollectionTblModuleManifestToAttach.getClass(), tblModuleManifestCollectionTblModuleManifestToAttach.getId());
            attachedTblModuleManifestCollection.add(tblModuleManifestCollectionTblModuleManifestToAttach);
        }
        tblEventType.setTblModuleManifestCollection(attachedTblModuleManifestCollection);
        em.persist(tblEventType);
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifest : tblEventType.getTblModuleManifestCollection()) {
            TblEventType oldEventIDOfTblModuleManifestCollectionTblModuleManifest = tblModuleManifestCollectionTblModuleManifest.getEventID();
            tblModuleManifestCollectionTblModuleManifest.setEventID(tblEventType);
            tblModuleManifestCollectionTblModuleManifest = em.merge(tblModuleManifestCollectionTblModuleManifest);
            if (oldEventIDOfTblModuleManifestCollectionTblModuleManifest != null) {
                oldEventIDOfTblModuleManifestCollectionTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionTblModuleManifest);
                em.merge(oldEventIDOfTblModuleManifestCollectionTblModuleManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Example 13 with TblModuleManifest

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

the class TblEventTypeJpaController method edit.

public void edit(TblEventType tblEventType) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblEventType persistentTblEventType = em.find(TblEventType.class, tblEventType.getId());
        Collection<TblModuleManifest> tblModuleManifestCollectionOld = persistentTblEventType.getTblModuleManifestCollection();
        Collection<TblModuleManifest> tblModuleManifestCollectionNew = tblEventType.getTblModuleManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblModuleManifest tblModuleManifestCollectionOldTblModuleManifest : tblModuleManifestCollectionOld) {
            if (!tblModuleManifestCollectionNew.contains(tblModuleManifestCollectionOldTblModuleManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblModuleManifest " + tblModuleManifestCollectionOldTblModuleManifest + " since its eventID field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        Collection<TblModuleManifest> attachedTblModuleManifestCollectionNew = new ArrayList<TblModuleManifest>();
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifestToAttach : tblModuleManifestCollectionNew) {
            tblModuleManifestCollectionNewTblModuleManifestToAttach = em.getReference(tblModuleManifestCollectionNewTblModuleManifestToAttach.getClass(), tblModuleManifestCollectionNewTblModuleManifestToAttach.getId());
            attachedTblModuleManifestCollectionNew.add(tblModuleManifestCollectionNewTblModuleManifestToAttach);
        }
        tblModuleManifestCollectionNew = attachedTblModuleManifestCollectionNew;
        tblEventType.setTblModuleManifestCollection(tblModuleManifestCollectionNew);
        tblEventType = em.merge(tblEventType);
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifest : tblModuleManifestCollectionNew) {
            if (!tblModuleManifestCollectionOld.contains(tblModuleManifestCollectionNewTblModuleManifest)) {
                TblEventType oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest = tblModuleManifestCollectionNewTblModuleManifest.getEventID();
                tblModuleManifestCollectionNewTblModuleManifest.setEventID(tblEventType);
                tblModuleManifestCollectionNewTblModuleManifest = em.merge(tblModuleManifestCollectionNewTblModuleManifest);
                if (oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest != null && !oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest.equals(tblEventType)) {
                    oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionNewTblModuleManifest);
                    em.merge(oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest);
                }
            }
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblEventType.getId();
            if (findTblEventType(id) == null) {
                throw new NonexistentEntityException("The tblEventType 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) ArrayList(java.util.ArrayList) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) 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) TblEventType(com.intel.mtwilson.as.data.TblEventType)

Example 14 with TblModuleManifest

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

the class TblHostSpecificManifestJpaController method edit.

public void edit(TblHostSpecificManifest tblHostSpecificManifest) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHostSpecificManifest persistentTblHostSpecificManifest = em.find(TblHostSpecificManifest.class, tblHostSpecificManifest.getId());
        TblModuleManifest moduleManifestIDOld = persistentTblHostSpecificManifest.getModuleManifestID();
        TblModuleManifest moduleManifestIDNew = tblHostSpecificManifest.getModuleManifestID();
        if (moduleManifestIDNew != null) {
            moduleManifestIDNew = em.getReference(moduleManifestIDNew.getClass(), moduleManifestIDNew.getId());
            tblHostSpecificManifest.setModuleManifestID(moduleManifestIDNew);
        }
        tblHostSpecificManifest = em.merge(tblHostSpecificManifest);
        if (moduleManifestIDOld != null && !moduleManifestIDOld.equals(moduleManifestIDNew)) {
            moduleManifestIDOld.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifest);
            moduleManifestIDOld = em.merge(moduleManifestIDOld);
        }
        if (moduleManifestIDNew != null && !moduleManifestIDNew.equals(moduleManifestIDOld)) {
            moduleManifestIDNew.getTblHostSpecificManifestCollection().add(tblHostSpecificManifest);
            em.merge(moduleManifestIDNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblHostSpecificManifest.getId();
            if (findTblHostSpecificManifest(id) == null) {
                throw new NonexistentEntityException("The tblHostSpecificManifest 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) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 15 with TblModuleManifest

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

the class HostBO method createHostSpecificManifestRecords.

private List<TblHostSpecificManifest> createHostSpecificManifestRecords(TblMle vmmMleId, HashMap<String, ? extends IManifest> pcrManifest, String hostType) throws IOException {
    List<TblHostSpecificManifest> tblHostSpecificManifests = new ArrayList<>();
    if (vmmMleId.getRequiredManifestList().contains(MODULE_PCR) && pcrManifest != null) {
        PcrManifest pcrMf19 = (PcrManifest) pcrManifest.get(MODULE_PCR);
        if (pcrMf19.containsPcrEventLog(19)) {
            PcrEventLog pcrEventLog = pcrMf19.getPcrEventLog(19);
            if (pcrEventLog != null) {
                for (Measurement m : pcrEventLog.getEventLog()) {
                    if (m != null && m.getInfo() != null && (!m.getInfo().isEmpty())) {
                        m.getInfo().get("EventName");
                        m.getInfo().get("ComponentName");
                        if (hostType.equals("intel") && m.getInfo().get("EventName") != null) {
                            log.debug("Adding host specific manifest for event " + m.getInfo().get("EventName") + ": field=" + m.getLabel() + " component=" + m.getInfo().get("ComponentName"));
                            log.debug("Querying manifest for event: " + m.getInfo().get("EventName") + ": MLE_ID=" + vmmMleId.getId() + " component=" + m.getInfo().get("ComponentName"));
                            // For open source XEN and KVM both the modules that get extended to PCR 19 should be added into the host specific table
                            //TblModuleManifest tblModuleManifest = My.jpa().mwModuleManifest().findByMleNameEventName(vmmMleId.getId(), m.getInfo().get("ComponentName"),  m.getInfo().get("EventName"));
                            TblModuleManifestJpaController tblModuleManifestJpaController = getModuleJpaController();
                            TblModuleManifest tblModuleManifest = tblModuleManifestJpaController.findByMleNameEventName(vmmMleId.getId(), m.getInfo().get("ComponentName"), m.getInfo().get("EventName"));
                            TblHostSpecificManifest tblHostSpecificManifest = new TblHostSpecificManifest();
                            tblHostSpecificManifest.setDigestValue(m.getValue().toString());
                            tblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
                            tblHostSpecificManifests.add(tblHostSpecificManifest);
                        }
                    }
                }
            }
        } else {
            log.warn("No PCR 19 found.SO not saving host specific manifest.");
        }
    } else {
        log.warn("It is not possible to get PCR 19 info. Unable to perform database insertion");
    }
    return tblHostSpecificManifests;
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) TblModuleManifestJpaController(com.intel.mtwilson.as.controller.TblModuleManifestJpaController) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) PcrEventLog(com.intel.mtwilson.util.model.PcrEventLog)

Aggregations

TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)28 EntityManager (javax.persistence.EntityManager)21 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)11 NoResultException (javax.persistence.NoResultException)10 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)9 TblEventType (com.intel.mtwilson.as.data.TblEventType)9 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)9 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)9 ArrayList (java.util.ArrayList)9 EntityNotFoundException (javax.persistence.EntityNotFoundException)9 Query (javax.persistence.Query)9 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)9 TblMle (com.intel.mtwilson.as.data.TblMle)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)5 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)3 ASException (com.intel.mountwilson.as.common.ASException)2 TblHostSpecificManifestJpaController (com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController)2 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)2 Measurement (com.intel.mtwilson.util.model.Measurement)2 PcrEventLog (com.intel.mtwilson.util.model.PcrEventLog)2