How can I get a definition of fields available for use by the Query Builder? I have cobbled together a few pieces of some code samples I’ve found on the interwebs and have the following lines:
import org.apache.commons.io.FileUtils
import org.sonatype.nexus.repository.storage.Asset
import org.sonatype.nexus.repository.storage.Component;
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.Query.Builder;
import org.sonatype.nexus.repository.storage.StorageFacet
def repo = repository.repositoryManager.get('maven-thirdparty')
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
try {
tx.begin()
Builder qb = Query.builder()
qb.where('group').eq('rhel7')
qb.and('name').eq('openssl')
qb.and('version').eq('1.1.1f')
qb.and('version matches ').param('1.1.*')
//qb.and('name like ').param("v2/${item}/%") //example of using like
//qb.and('extension').eq('tgz') //doesn't work
//qb.and('maven2_extension').eq('tgz') //doesn't work
//qb.and('maven.extension').eq('tgz') //works in api, but not here
//qb.and('type').eq('tgz') //doesn't work
//qb.and('content_type').eq('application/x-tgz') //doesn't work
//version column needs a proper numeric sort, not char sort
//qb.suffix('order by version, last_updated desc limit 1') //code I'd like to have work
qb.suffix('order by ve55rsionn, last_updated desc limit 1') //apparently invalid column names are just ignored and the query will still work
Iterable<Component> comps = tx.findComponents(qb.build(), [repo])
comps.each { Component comp ->
log.info("Component:" + comp.toStringExternal());
log.info("Component... " + comp.attributes().toString());
log.info("Component... " + comp.getEntityMetadata().toString());
log.info("Component... " + comp.getEntityMetadata().getId().getValue());
tx.browseAssets(comp).each { Asset asset ->
log.info("Asset: " + asset)
log.info("Asset... " + asset.attributes().toString())
log.info("Asset... " + asset.contentType())
}
}
}
finally {
tx.close()
}
I’m wanting to “order by version, last_updated” and “limit 1”. I am currently doing this by pulling all results to a shell script and sorting & filtering there. Nexus v2 results given through the Lucene plugin sorted in this order by default. I want to be able to use a multi-column “order by” and also add maven properties extension and classifier to the where clause, but I don’t know what they’re actually called in the database?
I see someone here using “last_updated”:
Does a schema definition exist somewhere?
I already know about the Search API, so no posts suggesting I use that; it’s not robust enough for my use case.