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