use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.
the class TblHostSpecificManifestJpaController method findByModuleAndHostID.
public TblHostSpecificManifest findByModuleAndHostID(int hostId, int moduleID) {
EntityManager em = getEntityManager();
try {
Query query = em.createNamedQuery("TblHostSpecificManifest.findByModuleAndHostID");
query.setParameter("hostID", hostId);
query.setParameter("Module_Manifest_ID", moduleID);
TblHostSpecificManifest tblHostSpecificManifest = (TblHostSpecificManifest) query.getSingleResult();
return tblHostSpecificManifest;
} catch (NoResultException e) {
log.error("NoResultException: No Host specific manifest for Host [{}]", String.valueOf(hostId));
return null;
} finally {
em.close();
}
}
use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.
the class HostBO method addModuleWhiteList.
private void addModuleWhiteList(PcrManifest pcr19, TblHosts tblHosts, TxtHost host, String uuid) {
try {
TblModuleManifestJpaController tblModuleManifestJpa = getModuleJpaController();
TblMleJpaController tblMleJpa = getMleJpaController();
TblEventTypeJpaController tblEventJpa = getEventJpaController();
TblPackageNamespaceJpaController tblPackageJpa = getPackageJpaController();
TblEventType tblEvent;
TblMle tblMle = tblMleJpa.findTblMleByUUID(uuid);
TblPackageNamespace nsPackNS;
if (tblMle == null) {
try {
// First check if the entry exists in the MLE table.
tblMle = getMleDetails(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion(), "");
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, host.getVmm().getName(), host.getVmm().getVersion());
}
}
if (tblMle == null) {
log.error("MLE specified is not found in the DB");
throw new ASException(ErrorCode.WS_MLE_RETRIEVAL_ERROR, this.getClass().getSimpleName());
}
String eventName;
String componentName;
// String fullComponentName = "";
String fullComponentName;
String digest;
String packageName;
String packageVendor;
String packageVersion;
String extendedtoPCR;
boolean useHostSpecificDigest;
try {
// Before we insert the record, we need the identity for the event name
if (pcr19.containsPcrEventLog(19)) {
PcrEventLog pcrEventLog = pcr19.getPcrEventLog(19);
if (pcrEventLog != null) {
for (Measurement m : pcrEventLog.getEventLog()) {
extendedtoPCR = m.getInfo().get("ExtendedToPCR");
if (extendedtoPCR != null) {
if (extendedtoPCR.equals("19")) {
//tblEvent = tblEventJpa.findEventTypeByName(m.getInfo().get("EventName"));
eventName = m.getInfo().get("EventName");
componentName = m.getInfo().get("ComponentName");
packageName = String.valueOf(m.getInfo().get("PackageName"));
packageVendor = String.valueOf(m.getInfo().get("PackageVendor"));
packageVersion = String.valueOf(m.getInfo().get("PackageVersion"));
extendedtoPCR = String.valueOf(m.getInfo().get("ExtendedToPCR"));
digest = String.valueOf(m.getValue());
useHostSpecificDigest = Boolean.valueOf(m.getInfo().get("UseHostSpecificDigest"));
try {
// Before we insert the record, we need the identity for the event name
tblEvent = tblEventJpa.findEventTypeByName(eventName);
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST, eventName);
}
validateNull("EventName", eventName);
validateNull("ComponentName", componentName);
// corresponds to VMware, then we will append the event type fieldName to the component name. Otherwise we won't
if (eventName.contains("Vim25")) {
fullComponentName = tblEvent.getFieldName() + "." + componentName;
} else {
fullComponentName = componentName;
}
Integer componentID = tblModuleManifestJpa.findByMleIdEventId(tblMle.getId(), fullComponentName, tblEvent.getId());
if (componentID != null && componentID != 0) {
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_ALREADY_EXISTS, componentName);
}
try {
// Since there will be only one entry for now, we will just hardcode it for now.
// TO-DO: See if we can change this.
// Nov-12,2013: Changed to use the function that accepts the ID instead of the name for better
// performance.
nsPackNS = tblPackageJpa.findByName("Standard_Global_NS");
} catch (NoResultException nre) {
throw new ASException(ErrorCode.WS_NAME_SPACE_DOES_NOT_EXIST);
}
TblModuleManifest newModuleRecord = new TblModuleManifest();
if (uuid != null && !uuid.isEmpty()) {
newModuleRecord.setUuid_hex(uuid);
} else {
newModuleRecord.setUuid_hex(new UUID().toString());
}
newModuleRecord.setMleId(tblMle);
newModuleRecord.setMle_uuid_hex(tblMle.getUuid_hex());
newModuleRecord.setEventID(tblEvent);
newModuleRecord.setNameSpaceID(nsPackNS);
newModuleRecord.setComponentName(fullComponentName);
newModuleRecord.setDigestValue(digest);
newModuleRecord.setPackageName(packageName);
newModuleRecord.setPackageVendor(packageVendor);
newModuleRecord.setPackageVersion(packageVersion);
newModuleRecord.setUseHostSpecificDigestValue(useHostSpecificDigest);
newModuleRecord.setExtendedToPCR(extendedtoPCR);
newModuleRecord.setDescription("");
tblModuleManifestJpa.create(newModuleRecord);
// break;
}
}
}
}
}
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST);
}
} catch (ASException ase) {
throw ase;
} catch (Exception e) {
// throw new ASException(ErrorCode.SYSTEM_ERROR, "Exception while adding Module white list data. " + e.getMessage(), e);
// throw new ASException(e);
log.error("Error during Module whitelist creation.", e);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_CREATE_ERROR, e.getClass().getSimpleName());
}
}
use of javax.persistence.NoResultException 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 javax.persistence.NoResultException 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 javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class StatisticsDAOImpl method findRawMarkByWebResourceAndAudit.
/**
* Native sql query :
* SELECT Raw_Mark
* FROM WEB_RESOURCE_STATISTICS
* WHERE Id_Web_Resource=:idWebResource
*
* @param idWebResource
* @return
* the mark for given audit and webresource
*/
@Override
public Float findRawMarkByWebResourceAndAudit(Long idWebResource, boolean isManual) {
StringBuilder queryString = new StringBuilder();
queryString.append(SELECT_STR);
queryString.append(RAW_MARK_FIELD_STR);
queryString.append(RETRIEVE_MARK_QUERY);
queryString.append(IS_AUDIT_MANUAL);
Query query = entityManager.createNativeQuery(queryString.toString());
query.setParameter("idWebResource", idWebResource);
query.setParameter("isManual", isManual);
try {
Object result = query.getSingleResult();
if (result instanceof Float) {
return (Float) result;
} else if (result instanceof Double) {
return ((Double) result).floatValue();
} else {
return (float) 0;
}
} catch (NoResultException e) {
return (float) 0;
}
}
Aggregations