org.sonatype.nexus.orient.DatabaseUpgradeSupport Java Examples

The following examples show how to use org.sonatype.nexus.orient.DatabaseUpgradeSupport. 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: P2Upgrade_1_1.java    From nexus-repository-p2 with Eclipse Public License 1.0 6 votes vote down vote up
private void updateP2AssetNames(final List<String> p2RepositoryNames) {
  OCommandSQL updateAssetCommand = new OCommandSQL(REMOVE_UNNECESSARY_SLASH_FROM_ASSET_NAME);
  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, ASSET_CLASS_NAME, (db, type) -> {
    OIndex<?> bucketIdx = db.getMetadata().getIndexManager().getIndex(I_REPOSITORY_NAME);
    p2RepositoryNames.forEach(repositoryName -> {
      OIdentifiable bucket = (OIdentifiable) bucketIdx.get(repositoryName);
      if (bucket == null) {
        log.warn("Unable to find bucket for {}", repositoryName);
      }
      else {
        int updates = db.command(updateAssetCommand).execute(bucket.getIdentity());
        if (updates > 0) {
          log.info("Updated {} p2 asset(s) names in repository {}: ", updates, repositoryName);
        }
      }
    });
  });
}
 
Example #2
Source File: ConanUpgrade_1_1.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
private void removeAttributesFromConanManifest(final List<String> repositoryNames) {
  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, ASSET_CLASS_NAME,
      (db, type) -> {
        String selectAssetQuery =
            String.format("select from asset where bucket = ? and attributes.conan.asset_kind = '%s'",
                AssetKind.CONAN_MANIFEST.name());
        findAssets(db, repositoryNames, selectAssetQuery)
            .forEach(oDocument -> {

              Map<String, Object> attributes = oDocument.field(P_ATTRIBUTES);
              // remove all attributes, except asset_kind from conan "bucket"
              attributes
                  .put(ConanFormat.NAME, Collections.singletonMap(P_ASSET_KIND, AssetKind.CONAN_MANIFEST.name()));
              oDocument.field(P_ATTRIBUTES, attributes);

              oDocument.save();
            });
      }
  );
}
 
Example #3
Source File: ConanUpgrade_1_1.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
private void deleteDownloadUrls(final List<String> repositoryNames) {
  log.debug("Deleting DOWNLOAD_URLS assets from conan repositories ({}).", repositoryNames);

  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, ASSET_CLASS_NAME, (db, type) -> {
    OSchemaProxy schema = db.getMetadata().getSchema();
    if (schema.existsClass(ASSET_CLASS_NAME)) {
      repositoryNames.forEach(repositoryName -> {
        OIndex<?> bucketIdx = db.getMetadata().getIndexManager().getIndex(new OIndexNameBuilder()
            .type("bucket")
            .property(P_REPOSITORY_NAME)
            .build());
        OIdentifiable bucket = (OIdentifiable) bucketIdx.get(repositoryName);

        db.command(new OCommandSQL(DELETE_FROM_ASSET_WHERE_BUCKET_AND_ASSET_KIND))
            .execute(bucket, AssetKind.DOWNLOAD_URL.name());
      });
    }
  });
}
 
Example #4
Source File: P2Upgrade_1_1.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
private void updateP2BrowseNodes(final List<String> p2RepositoryNames) {
  log.info("Deleting browse_node data from p2 repositories to be rebuilt ({}).", p2RepositoryNames);

  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, C_BROWSE_NODE, (db, type) -> {
    OSchemaProxy schema = db.getMetadata().getSchema();
    if (schema.existsClass(C_BROWSE_NODE)) {
      db.command(new OCommandSQL(DELETE_BROWSE_NODE_FROM_REPOSITORIES)).execute(p2RepositoryNames);
    }
  });
}
 
Example #5
Source File: ConanUpgrade_1_1.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
private void updateHostedAssetPath(final List<String> repositoryNames) {
  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, ASSET_CLASS_NAME,
      (db, type) -> findAssets(db, repositoryNames, "select from asset where bucket = ?")
          .forEach(oDocument -> {

            Map<String, Object> attributes = oDocument.field(P_ATTRIBUTES);
            Map<String, Object> conan = (Map<String, Object>) attributes.get(ConanFormat.NAME);
            String asset_kind = (String) conan.get(P_ASSET_KIND);
            AssetKind assetKind = AssetKind.valueOf(asset_kind);
            if (AssetKind.DOWNLOAD_URL == assetKind) {
              return;
            }

            String name = oDocument.field(P_ASSET_NAME);
            String nextName = null;

            String strategy0 = "/v1/conans/v1/conans/v1/conans/";
            String strategy1 = "/v1/conans/v1/conans/";
            String strategy3 = "/v1/conans/";
            String conans = "conans/";

            if (name.startsWith(strategy0)) { // broken based on refactor-v1-api HOSTED
              nextName = conans + name.substring(strategy0.length());
            }
            else if (name.startsWith(strategy1)) { // broken based on refactor-v1-api HOSTED
              nextName = conans + name.substring(strategy1.length());
            }
            else if (name.startsWith(strategy3)) { // latest(master) HOSTED
              nextName = conans + name.substring(strategy3.length());
            }

            if (nextName != null) {
              oDocument.field(P_ASSET_NAME, nextName);
              oDocument.save();
            }
          })
  );
}
 
Example #6
Source File: ConanUpgrade_1_1.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteConanBrowseNodes(final List<String> repositoryNames) {
  log.debug("Deleting browse_node data from conan repositories to be rebuilt ({}).", repositoryNames);

  DatabaseUpgradeSupport.withDatabaseAndClass(componentDatabaseInstance, C_BROWSE_NODE, (db, type) -> {
    OSchemaProxy schema = db.getMetadata().getSchema();
    if (schema.existsClass(C_BROWSE_NODE)) {
      db.command(new OCommandSQL(DELETE_BROWSE_NODE_FROM_REPOSITORIES)).execute(repositoryNames);
    }
  });
}