Search in sources :

Example 1 with RepositorySearchException

use of com.intel.mtwilson.datatypes.RepositorySearchException in project OpenAttestation by OpenAttestation.

the class KvAttributeRepository method search.

@Override
public //    @RequiresPermissions("tag_kv_attributes:search")     
KvAttributeCollection search(KvAttributeFilterCriteria criteria) {
    log.debug("KvAttribute:Search - Got request to search for the KvAttributes.");
    KvAttributeCollection objCollection = new KvAttributeCollection();
    try (JooqContainer jc = TagJdbi.jooq()) {
        DSLContext jooq = jc.getDslContext();
        SelectQuery sql = jooq.select().from(MW_TAG_KVATTRIBUTE).getQuery();
        // all the data.
        if (criteria.filter) {
            if (criteria.id != null) {
                // when uuid is stored in database as the standard UUID string format (36 chars)
                sql.addConditions(MW_TAG_KVATTRIBUTE.ID.equalIgnoreCase(criteria.id.toString()));
            }
            if (criteria.nameEqualTo != null && criteria.nameEqualTo.length() > 0) {
                sql.addConditions(MW_TAG_KVATTRIBUTE.NAME.equalIgnoreCase(criteria.nameEqualTo));
            }
            if (criteria.nameContains != null && criteria.nameContains.length() > 0) {
                sql.addConditions(MW_TAG_KVATTRIBUTE.NAME.lower().contains(criteria.nameContains.toLowerCase()));
            }
            if (criteria.valueEqualTo != null && criteria.valueEqualTo.length() > 0) {
                sql.addConditions(MW_TAG_KVATTRIBUTE.VALUE.equalIgnoreCase(criteria.valueEqualTo));
            }
            if (criteria.valueContains != null && criteria.valueContains.length() > 0) {
                sql.addConditions(MW_TAG_KVATTRIBUTE.VALUE.lower().contains(criteria.valueContains.toLowerCase()));
            }
        }
        sql.addOrderBy(MW_TAG_KVATTRIBUTE.NAME, MW_TAG_KVATTRIBUTE.VALUE);
        log.debug("Opening tag-value dao");
        log.debug("Fetching records using JOOQ");
        Result<Record> result = sql.fetch();
        for (Record r : result) {
            KvAttribute obj = new KvAttribute();
            obj.setId(UUID.valueOf(r.getValue(MW_TAG_KVATTRIBUTE.ID)));
            //                obj.setId(r.getValue(MW_TAG_KVATTRIBUTE.ID.coerce(byte[].class), uuidConverter));
            //                obj.setId(r.getValue(MW_TAG_KVATTRIBUTE.ID, uuidConverter));
            //                obj.setId(r.getValue(MW_TAG_KVATTRIBUTE.ID));
            obj.setName(r.getValue(MW_TAG_KVATTRIBUTE.NAME));
            obj.setValue(r.getValue(MW_TAG_KVATTRIBUTE.VALUE));
            objCollection.getKvAttributes().add(obj);
        }
        sql.close();
    } catch (Exception ex) {
        log.error("KvAttribute:Search - Error during attribute search.", ex);
        throw new RepositorySearchException(ex, criteria);
    }
    log.debug("KvAttribute:Search - Returning back {} of results.", objCollection.getKvAttributes().size());
    return objCollection;
}
Also used : SelectQuery(org.jooq.SelectQuery) KvAttributeCollection(com.intel.mtwilson.datatypes.KvAttributeCollection) JooqContainer(com.intel.mtwilson.jooq.util.JooqContainer) KvAttribute(com.intel.mtwilson.datatypes.KvAttribute) DSLContext(org.jooq.DSLContext) Record(org.jooq.Record) RepositorySearchException(com.intel.mtwilson.datatypes.RepositorySearchException) RepositoryCreateException(com.intel.mtwilson.datatypes.RepositoryCreateException) RepositoryDeleteException(com.intel.mtwilson.datatypes.RepositoryDeleteException) RepositoryRetrieveException(com.intel.mtwilson.datatypes.RepositoryRetrieveException) RepositoryException(com.intel.mtwilson.datatypes.RepositoryException) RepositorySearchException(com.intel.mtwilson.datatypes.RepositorySearchException) RepositoryStoreConflictException(com.intel.mtwilson.datatypes.RepositoryStoreConflictException) RepositoryStoreException(com.intel.mtwilson.datatypes.RepositoryStoreException)

Aggregations

KvAttribute (com.intel.mtwilson.datatypes.KvAttribute)1 KvAttributeCollection (com.intel.mtwilson.datatypes.KvAttributeCollection)1 RepositoryCreateException (com.intel.mtwilson.datatypes.RepositoryCreateException)1 RepositoryDeleteException (com.intel.mtwilson.datatypes.RepositoryDeleteException)1 RepositoryException (com.intel.mtwilson.datatypes.RepositoryException)1 RepositoryRetrieveException (com.intel.mtwilson.datatypes.RepositoryRetrieveException)1 RepositorySearchException (com.intel.mtwilson.datatypes.RepositorySearchException)1 RepositoryStoreConflictException (com.intel.mtwilson.datatypes.RepositoryStoreConflictException)1 RepositoryStoreException (com.intel.mtwilson.datatypes.RepositoryStoreException)1 JooqContainer (com.intel.mtwilson.jooq.util.JooqContainer)1 DSLContext (org.jooq.DSLContext)1 Record (org.jooq.Record)1 SelectQuery (org.jooq.SelectQuery)1