Search in sources :

Example 1 with TblLocationPcr

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

the class TblLocationPcrJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblLocationPcr tblLocationPcr;
        try {
            tblLocationPcr = em.getReference(TblLocationPcr.class, id);
            tblLocationPcr.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblLocationPcr with id " + id + " no longer exists.", enfe);
        }
        em.remove(tblLocationPcr);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblLocationPcr(com.intel.mtwilson.as.data.TblLocationPcr) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 2 with TblLocationPcr

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

the class TblLocationPcrJpaController method getTblLocationPcrCount.

public int getTblLocationPcrCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblLocationPcr> rt = cq.from(TblLocationPcr.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblLocationPcr(com.intel.mtwilson.as.data.TblLocationPcr)

Example 3 with TblLocationPcr

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

the class TblLocationPcrJpaController method findTblLocationPcrByPcrValue.

public String findTblLocationPcrByPcrValue(String pcrValue) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblLocationPcr.findByPcrValue");
        query.setParameter("pcrValue", pcrValue);
        query.setHint(QueryHints.REFRESH, HintValues.TRUE);
        query.setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
        try {
            TblLocationPcr locationPcr = (TblLocationPcr) query.getSingleResult();
            String location = locationPcr.getLocation();
            log.info("PCR Value  " + pcrValue + " location " + location);
            return location;
        } catch (NoResultException e) {
            log.info("NoResultException: Location does not exist for pcr value {} ", pcrValue);
            return null;
        }
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblLocationPcr(com.intel.mtwilson.as.data.TblLocationPcr) NoResultException(javax.persistence.NoResultException)

Example 4 with TblLocationPcr

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

the class HostTrustBO method addHostLocation.

/**
     * Author: Sudhir
     * 
     * Add a new location mapping entry into the table.
     * 
     * @param hlObj
     * @return 
     */
public Boolean addHostLocation(HostLocation hlObj) {
    TblLocationPcrJpaController locJpaController = new TblLocationPcrJpaController(getEntityManagerFactory());
    try {
        if (hlObj != null && !hlObj.white_list_value.isEmpty()) {
            TblLocationPcr locPCR = locJpaController.findTblLocationPcrByPcrValueEx(hlObj.white_list_value);
            if (locPCR != null) {
                log.info(String.format("An entry already existing in the location table for the white list specified [%s | %s]", locPCR.getLocation(), hlObj.white_list_value));
                if (locPCR.getLocation().equals(hlObj.location)) {
                    // No need to do anything. Just exit.
                    return true;
                } else {
                    // Need to update the entry
                    log.info(String.format("Updating the location value for the white list specified to %s.", hlObj.location));
                    locPCR.setLocation(hlObj.location);
                    locJpaController.edit(locPCR);
                }
            } else {
                // Add a new entry for the location mapping table.
                locPCR = new TblLocationPcr();
                locPCR.setLocation(hlObj.location);
                locPCR.setPcrValue(hlObj.white_list_value);
                locJpaController.create(locPCR);
                log.info(String.format("Successfully added a new location value %s with white list %s.", hlObj.location, hlObj.white_list_value));
            }
        }
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return true;
}
Also used : TblLocationPcrJpaController(com.intel.mtwilson.as.controller.TblLocationPcrJpaController) TblLocationPcr(com.intel.mtwilson.as.data.TblLocationPcr) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 5 with TblLocationPcr

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

the class TblLocationPcrJpaController method findTblLocationPcrEntities.

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

Aggregations

TblLocationPcr (com.intel.mtwilson.as.data.TblLocationPcr)6 EntityManager (javax.persistence.EntityManager)5 Query (javax.persistence.Query)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 NoResultException (javax.persistence.NoResultException)2 ASException (com.intel.mountwilson.as.common.ASException)1 TblLocationPcrJpaController (com.intel.mtwilson.as.controller.TblLocationPcrJpaController)1 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1