Search in sources :

Example 6 with TblModuleManifest

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

the class TblPackageNamespaceJpaController method destroy.

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

Example 7 with TblModuleManifest

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

the class TblPackageNamespaceJpaController method edit.

public void edit(TblPackageNamespace tblPackageNamespace) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPackageNamespace persistentTblPackageNamespace = em.find(TblPackageNamespace.class, tblPackageNamespace.getId());
        Collection<TblModuleManifest> tblModuleManifestCollectionOld = persistentTblPackageNamespace.getTblModuleManifestCollection();
        Collection<TblModuleManifest> tblModuleManifestCollectionNew = tblPackageNamespace.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 nameSpaceID 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;
        tblPackageNamespace.setTblModuleManifestCollection(tblModuleManifestCollectionNew);
        tblPackageNamespace = em.merge(tblPackageNamespace);
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifest : tblModuleManifestCollectionNew) {
            if (!tblModuleManifestCollectionOld.contains(tblModuleManifestCollectionNewTblModuleManifest)) {
                TblPackageNamespace oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest = tblModuleManifestCollectionNewTblModuleManifest.getNameSpaceID();
                tblModuleManifestCollectionNewTblModuleManifest.setNameSpaceID(tblPackageNamespace);
                tblModuleManifestCollectionNewTblModuleManifest = em.merge(tblModuleManifestCollectionNewTblModuleManifest);
                if (oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest != null && !oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest.equals(tblPackageNamespace)) {
                    oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionNewTblModuleManifest);
                    em.merge(oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest);
                }
            }
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblPackageNamespace.getId();
            if (findTblPackageNamespace(id) == null) {
                throw new NonexistentEntityException("The tblPackageNamespace 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) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 8 with TblModuleManifest

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

the class TblModuleManifestJpaController method findByMleNameEventName.

/**
     * Modified By: Sudhir on June 21st to remove the throw of ASException. Instead the NoResultException is
     * being thrown, which is caught by the caller.
     * 
     * @param mleId
     * @param componentName
     * @param eventName
     * @return 
     */
public TblModuleManifest findByMleNameEventName(Integer mleId, String componentName, String eventName) {
    EntityManager em = getEntityManager();
    try {
        log.debug(String.format("Module Manifest for MLE: %d Component: %s Event: %s", mleId, componentName, eventName));
        Query query = em.createNamedQuery("TblModuleManifest.findByMleNameEventName");
        query.setParameter("name", componentName);
        query.setParameter("eventName", eventName);
        query.setParameter("mleId", mleId);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        TblModuleManifest tblModuleManifest = (TblModuleManifest) query.getSingleResult();
        return tblModuleManifest;
    } catch (NoResultException e) {
        log.error(String.format("Module Manifest for MLE %d Component %s Event %s  Not found in Database ", mleId, componentName, eventName), e);
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 9 with TblModuleManifest

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

the class TblModuleManifestJpaController method findTblModuleManifestByMleUuid.

public List<TblModuleManifest> findTblModuleManifestByMleUuid(String mleUuid) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByMleUuidHex");
        query.setParameter("mle_uuid_hex", mleUuid);
        List<TblModuleManifest> moduleList = query.getResultList();
        return moduleList;
    } catch (NoResultException e) {
        log.error(String.format("MLE information with UUID {} not found in the DB.", mleUuid));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 10 with TblModuleManifest

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

the class TblModuleManifestJpaController method create.

public void create(TblModuleManifest tblModuleManifest) {
    if (tblModuleManifest.getTblHostSpecificManifestCollection() == null) {
        tblModuleManifest.setTblHostSpecificManifestCollection(new ArrayList<TblHostSpecificManifest>());
    }
    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 = tblModuleManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy = em.getReference(updatedBy.getClass(), updatedBy.getId());
                tblModuleManifest.setUpdatedBy(updatedBy);
            }
            TblDbPortalUser createdBy = tblModuleManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy = em.getReference(createdBy.getClass(), createdBy.getId());
                tblModuleManifest.setCreatedBy(createdBy);
            }
            */
        TblMle mleId = tblModuleManifest.getMleId();
        if (mleId != null) {
            mleId = em.getReference(mleId.getClass(), mleId.getId());
            tblModuleManifest.setMleId(mleId);
        }
        TblEventType eventID = tblModuleManifest.getEventID();
        if (eventID != null) {
            eventID = em.getReference(eventID.getClass(), eventID.getId());
            tblModuleManifest.setEventID(eventID);
        }
        TblPackageNamespace nameSpaceID = tblModuleManifest.getNameSpaceID();
        if (nameSpaceID != null) {
            nameSpaceID = em.getReference(nameSpaceID.getClass(), nameSpaceID.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceID);
        }
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollection = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollection.add(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach);
        }
        tblModuleManifest.setTblHostSpecificManifestCollection(attachedTblHostSpecificManifestCollection);
        em.persist(tblModuleManifest);
        /*
            if (updatedBy != null) {
                updatedBy.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(updatedBy);
            }
            if (createdBy != null) {
                createdBy.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(createdBy);
            }*/
        if (mleId != null) {
            mleId.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleId);
        }
        if (eventID != null) {
            eventID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventID);
        }
        if (nameSpaceID != null) {
            nameSpaceID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceID);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifest : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest = tblHostSpecificManifestCollectionTblHostSpecificManifest.getModuleManifestID();
            tblHostSpecificManifestCollectionTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
            tblHostSpecificManifestCollectionTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionTblHostSpecificManifest);
            if (oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest != null) {
                oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionTblHostSpecificManifest);
                em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblMle(com.intel.mtwilson.as.data.TblMle) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

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