Search in sources :

Example 1 with MwMleSource

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

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

the class MleBO method updateMleSource.

/**
    * Updates an existing MLE with the name of the white list host that was used to modify the white list values.
    * @param mleSourceObj
    * @return 
    */
public String updateMleSource(MleSource mleSourceObj) {
    TblMle tblMle;
    MleData mleData = null;
    try {
        try {
            mleData = mleSourceObj.getMleData();
            // Verify if the MLE exists in the system.
            tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion());
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        // If the mapping does not exist already in the db, then we need to return back error.
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        if (mwMleSource == null) {
            throw new ASException(ErrorCode.WS_MLE_SOURCE_MAPPING_DOES_NOT_EXIST, mleData.getName());
        }
        mwMleSource.setHostName(mleSourceObj.getHostName());
        mleSourceJpaController.edit(mwMleSource);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 3 with MwMleSource

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

the class MleBO method deleteMleSource.

/**
    * Deletes an existing mapping between the MLE and the WhiteList host that was used during the creation of MLE.
    * This method is called during the deletion of MLEs.
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String deleteMleSource(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblMle tblMle;
    try {
        try {
            // First check if the entry exists in the MLE table.
            tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        // configured manully, this entry does not exist.
        if (mwMleSource != null)
            mleSourceJpaController.destroy(mwMleSource.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 4 with MwMleSource

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

the class MwMleSourceJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwMleSource mwMleSource;
        try {
            mwMleSource = em.getReference(MwMleSource.class, id);
            mwMleSource.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwMleSource with id " + id + " no longer exists.", enfe);
        }
        TblMle mleId = mwMleSource.getMleId();
        if (mleId != null) {
            mleId.getMwMleSourceCollection().remove(mwMleSource);
            em.merge(mleId);
        }
        em.remove(mwMleSource);
        em.getTransaction().commit();
    } 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) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 5 with MwMleSource

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

the class MwMleSourceJpaController method findMwMleSourceEntities.

private List<MwMleSource> findMwMleSourceEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(MwMleSource.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MwMleSource(com.intel.mtwilson.as.data.MwMleSource)

Aggregations

MwMleSource (com.intel.mtwilson.as.data.MwMleSource)9 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)6 TblMle (com.intel.mtwilson.as.data.TblMle)6 ASException (com.intel.mountwilson.as.common.ASException)4 MwMleSourceJpaController (com.intel.mtwilson.as.controller.MwMleSourceJpaController)4 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)4 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)4 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 MleData (com.intel.mtwilson.datatypes.MleData)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2