Java Code Examples for org.sonatype.nexus.repository.storage.StorageTx#findAssets()

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#findAssets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AptHostedFacet.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
private List<Asset> selectOldPackagesToRemove(String packageName, String arch) throws IOException, PGPException {
  if (config.assetHistoryLimit == null) {
    return Collections.emptyList();
  }
  int count = config.assetHistoryLimit;
  StorageTx tx = UnitOfWork.currentTx();
  Map<String, Object> sqlParams = new HashMap<>();
  sqlParams.put(P_PACKAGE_NAME, packageName);
  sqlParams.put(P_ARCHITECTURE, arch);
  sqlParams.put(P_ASSET_KIND, "DEB");
  Iterable<Asset> assets = tx.findAssets(ASSETS_BY_PACKAGE_AND_ARCH, sqlParams,
      Collections.singleton(getRepository()), "");
  List<Asset> removals = new ArrayList<>();
  Map<String, List<Asset>> assetsByArch = StreamSupport.stream(assets.spliterator(), false)
      .collect(Collectors.groupingBy(a -> a.formatAttributes().get(P_ARCHITECTURE, String.class)));
  for (Map.Entry<String, List<Asset>> entry : assetsByArch.entrySet()) {
    if (entry.getValue().size() <= count) {
      continue;
    }

    int trimCount = entry.getValue().size() - count;
    Set<String> keepVersions = entry.getValue().stream()
        .map(a -> new Version(a.formatAttributes().get(P_PACKAGE_VERSION, String.class))).sorted().skip(trimCount)
        .map(v -> v.toString()).collect(Collectors.toSet());

    entry.getValue().stream()
        .filter(a -> !keepVersions.contains(a.formatAttributes().get(P_PACKAGE_VERSION, String.class)))
        .forEach((item) -> removals.add(item));
  }

  return removals;
}
 
Example 2
Source File: OrientPyPiDataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds all the assets for a particular component name.
 *
 * @return list of assets
 */
static Iterable<Asset> findAssetsByComponentName(final StorageTx tx, final Repository repository, final String name)
{
  return tx.findAssets(
      Query.builder()
          .where("component.name").eq(name)
          .suffix("order by name desc")
          .build(),
      singletonList(repository)
  );
}
 
Example 3
Source File: GolangDataAccess.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds all the assets for a given module
 *
 * @return assets associated with a given module
 */
public Iterable<Asset> findAssetsForModule(final StorageTx tx,
                                           final Repository repository,
                                           final String moduleName)
{
  Query query = Query.builder()
      .where(P_NAME).like(moduleName + "/%")
      .build();

  return tx.findAssets(query, ImmutableList.of(repository));
}
 
Example 4
Source File: PurgeUnusedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find all assets without component that were last accessed before specified date.
 */
private Iterable<Asset> findUnusedAssets(final StorageTx tx, final Date olderThan) {
  String whereClause = String.format("%s IS NULL AND %s < :olderThan", P_COMPONENT, P_LAST_DOWNLOADED);
  Map<String, Object> sqlParams = ImmutableMap.of("olderThan", olderThan);

  checkCancellation();
  return tx.findAssets(whereClause, sqlParams, ImmutableList.of(getRepository()), null);
}
 
Example 5
Source File: OrientReindexNpmRepositoryTask.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Reads the next batch of tarball assets to process, starting after the RID of the last asset in the previous batch.
 */
private Iterable<Asset> readAssets(final Repository repository, final String lastId) {
  StorageTx storageTx = UnitOfWork.currentTx();
  Map<String, Object> parameters = ImmutableMap.of("rid", lastId, "limit", BATCH_SIZE);
  return storageTx.findAssets(ASSETS_WHERE, parameters, singletonList(repository), ASSETS_SUFFIX);
}
 
Example 6
Source File: RepairMetadataComponent.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
protected Iterable<Asset> readAssets(final Repository repository, final String lastId) {
  StorageTx storageTx = UnitOfWork.currentTx();
  Map<String, Object> parameters = ImmutableMap.of("rid", lastId, "limit", BATCH_SIZE);
  return storageTx.findAssets(ASSETS_WHERE, parameters, singletonList(repository), ASSETS_SUFFIX);
}