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();
}
}
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";
}
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";
}
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();
}
}
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();
}
}
Aggregations