use of com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException in project OpenAttestation by OpenAttestation.
the class TblMleJpaController method edit.
public void edit(TblMle tblMle) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblMle persistentTblMle = em.find(TblMle.class, tblMle.getId());
Collection<TblHosts> tblHostsCollectionOld = persistentTblMle.getTblHostsCollection();
Collection<TblHosts> tblHostsCollectionNew = tblMle.getTblHostsCollection();
Collection<TblHosts> tblHostsCollection1Old = persistentTblMle.getTblHostsCollection1();
Collection<TblHosts> tblHostsCollection1New = tblMle.getTblHostsCollection1();
Collection<TblPcrManifest> tblPcrManifestCollectionOld = persistentTblMle.getTblPcrManifestCollection();
Collection<TblPcrManifest> tblPcrManifestCollectionNew = tblMle.getTblPcrManifestCollection();
List<String> illegalOrphanMessages = null;
for (TblHosts tblHostsCollectionOldTblHosts : tblHostsCollectionOld) {
if (!tblHostsCollectionNew.contains(tblHostsCollectionOldTblHosts)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain TblHosts " + tblHostsCollectionOldTblHosts + " since its vmmMleId field is not nullable.");
}
}
for (TblHosts tblHostsCollection1OldTblHosts : tblHostsCollection1Old) {
if (!tblHostsCollection1New.contains(tblHostsCollection1OldTblHosts)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain TblHosts " + tblHostsCollection1OldTblHosts + " since its biosMleId field is not nullable.");
}
}
for (TblPcrManifest tblPcrManifestCollectionOldTblPcrManifest : tblPcrManifestCollectionOld) {
if (!tblPcrManifestCollectionNew.contains(tblPcrManifestCollectionOldTblPcrManifest)) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("You must retain TblPcrManifest " + tblPcrManifestCollectionOldTblPcrManifest + " since its mleId field is not nullable.");
}
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
Collection<TblHosts> attachedTblHostsCollectionNew = new ArrayList<TblHosts>();
for (TblHosts tblHostsCollectionNewTblHostsToAttach : tblHostsCollectionNew) {
tblHostsCollectionNewTblHostsToAttach = em.getReference(tblHostsCollectionNewTblHostsToAttach.getClass(), tblHostsCollectionNewTblHostsToAttach.getId());
attachedTblHostsCollectionNew.add(tblHostsCollectionNewTblHostsToAttach);
}
tblHostsCollectionNew = attachedTblHostsCollectionNew;
tblMle.setTblHostsCollection(tblHostsCollectionNew);
Collection<TblHosts> attachedTblHostsCollection1New = new ArrayList<TblHosts>();
for (TblHosts tblHostsCollection1NewTblHostsToAttach : tblHostsCollection1New) {
tblHostsCollection1NewTblHostsToAttach = em.getReference(tblHostsCollection1NewTblHostsToAttach.getClass(), tblHostsCollection1NewTblHostsToAttach.getId());
attachedTblHostsCollection1New.add(tblHostsCollection1NewTblHostsToAttach);
}
tblHostsCollection1New = attachedTblHostsCollection1New;
tblMle.setTblHostsCollection1(tblHostsCollection1New);
Collection<TblPcrManifest> attachedTblPcrManifestCollectionNew = new ArrayList<TblPcrManifest>();
for (TblPcrManifest tblPcrManifestCollectionNewTblPcrManifestToAttach : tblPcrManifestCollectionNew) {
tblPcrManifestCollectionNewTblPcrManifestToAttach = em.getReference(tblPcrManifestCollectionNewTblPcrManifestToAttach.getClass(), tblPcrManifestCollectionNewTblPcrManifestToAttach.getId());
attachedTblPcrManifestCollectionNew.add(tblPcrManifestCollectionNewTblPcrManifestToAttach);
}
tblPcrManifestCollectionNew = attachedTblPcrManifestCollectionNew;
tblMle.setTblPcrManifestCollection(tblPcrManifestCollectionNew);
tblMle = em.merge(tblMle);
for (TblHosts tblHostsCollectionNewTblHosts : tblHostsCollectionNew) {
if (!tblHostsCollectionOld.contains(tblHostsCollectionNewTblHosts)) {
TblMle oldVmmMleIdOfTblHostsCollectionNewTblHosts = tblHostsCollectionNewTblHosts.getVmmMleId();
tblHostsCollectionNewTblHosts.setVmmMleId(tblMle);
tblHostsCollectionNewTblHosts = em.merge(tblHostsCollectionNewTblHosts);
if (oldVmmMleIdOfTblHostsCollectionNewTblHosts != null && !oldVmmMleIdOfTblHostsCollectionNewTblHosts.equals(tblMle)) {
oldVmmMleIdOfTblHostsCollectionNewTblHosts.getTblHostsCollection().remove(tblHostsCollectionNewTblHosts);
em.merge(oldVmmMleIdOfTblHostsCollectionNewTblHosts);
}
}
}
for (TblHosts tblHostsCollection1NewTblHosts : tblHostsCollection1New) {
if (!tblHostsCollection1Old.contains(tblHostsCollection1NewTblHosts)) {
TblMle oldBiosMleIdOfTblHostsCollection1NewTblHosts = tblHostsCollection1NewTblHosts.getBiosMleId();
tblHostsCollection1NewTblHosts.setBiosMleId(tblMle);
tblHostsCollection1NewTblHosts = em.merge(tblHostsCollection1NewTblHosts);
if (oldBiosMleIdOfTblHostsCollection1NewTblHosts != null && !oldBiosMleIdOfTblHostsCollection1NewTblHosts.equals(tblMle)) {
oldBiosMleIdOfTblHostsCollection1NewTblHosts.getTblHostsCollection1().remove(tblHostsCollection1NewTblHosts);
em.merge(oldBiosMleIdOfTblHostsCollection1NewTblHosts);
}
}
}
for (TblPcrManifest tblPcrManifestCollectionNewTblPcrManifest : tblPcrManifestCollectionNew) {
if (!tblPcrManifestCollectionOld.contains(tblPcrManifestCollectionNewTblPcrManifest)) {
TblMle oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest = tblPcrManifestCollectionNewTblPcrManifest.getMleId();
tblPcrManifestCollectionNewTblPcrManifest.setMleId(tblMle);
tblPcrManifestCollectionNewTblPcrManifest = em.merge(tblPcrManifestCollectionNewTblPcrManifest);
if (oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest != null && !oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest.equals(tblMle)) {
oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest.getTblPcrManifestCollection().remove(tblPcrManifestCollectionNewTblPcrManifest);
em.merge(oldMleIdOfTblPcrManifestCollectionNewTblPcrManifest);
}
}
}
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = tblMle.getId();
if (findTblMle(id) == null) {
throw new NonexistentEntityException("The tblMle with id " + id + " no longer exists.");
}
}
throw new ASDataException(ex);
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException in project OpenAttestation by OpenAttestation.
the class HostBO method deleteModulesForMLE.
private void deleteModulesForMLE(TxtHostRecord host) throws NonexistentEntityException, IOException {
TblMleJpaController tblMleJpaController = getMleJpaController();
TblModuleManifestJpaController tblModuleManifestJpaController = getModuleJpaController();
try {
TblMle tblMle = tblMleJpaController.findVmmMle(host.VMM_Name, host.VMM_Version, host.VMM_OSName, host.VMM_OSVersion);
if (tblMle != null) {
// Retrieve the list of all the modules for the specified VMM MLE.
List<TblModuleManifest> moduleList = tblModuleManifestJpaController.findTblModuleManifestByHardwareUuid(host.Hardware_Uuid);
if (moduleList != null && moduleList.size() > 0) {
for (TblModuleManifest moduleObj : moduleList) {
//if (moduleObj.getUseHostSpecificDigestValue()) // we cannot delete the host specific one since it would be referenced by the Hosts
// continue;
tblModuleManifestJpaController.destroy(moduleObj.getId());
}
}
}
} catch (IllegalOrphanException | NonexistentEntityException ex) {
log.error("Error during the deletion of VMM modules {}. ", host.VMM_Name, ex);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_DELETE_ERROR, ex.getClass().getSimpleName());
}
}
Aggregations