@Override public boolean equals(final Object o) { if (this == o) { return true; } else if (o instanceof AttachedEntityVersion) { AttachedEntityVersion that = (AttachedEntityVersion)o; return version == that.version; } else if (o instanceof EntityVersion) { EntityVersion that = (EntityVersion)o; return getValue().equals(that.getValue()); } return false; }
private void updateRevision(final NestedAttributesMap packageRoot, final Asset packageRootAsset, final boolean createdPackageRoot) { String newRevision = "1"; if (!createdPackageRoot) { if (packageRoot.contains(NpmMetadataUtils.META_REV)) { String rev = packageRoot.get(NpmMetadataUtils.META_REV, String.class); newRevision = Integer.toString(Integer.parseInt(rev) + 1); } else { /* This is covering the edge case when a new package is uploaded to a repository where the packageRoot already exists. If that packageRoot was created using an earlier version of NXRM where we didn't store the rev then we need to add it in. We also add the rev in on download but it is possible that someone is uploading a package where the packageRoot has never been downloaded before. */ newRevision = EntityHelper.version(packageRootAsset).getValue(); } } packageRoot.set(NpmMetadataUtils.META_ID, packageRootAsset.name()); packageRoot.set(NpmMetadataUtils.META_REV, newRevision); }
/** * Returns detached entity metadata. */ public DetachedEntityMetadata detach() { return new DetachedEntityMetadata( new DetachedEntityId(id.getValue()), new DetachedEntityVersion(version.getValue()) ); }
/** * For NEXUS-18094 we moved the revision number to live in the package root file so that the revision number doesn't * change as the database record changes (previously it used the Orient Document Version number). This method allows * us to avoid the need for an upgrade step by upgrading package roots without a rev as they are fetched. */ @TransactionalStoreBlob protected void maybeAddRevision(final Asset packageRootAsset, final NestedAttributesMap packageRoot) { if (!packageRoot.contains(NpmMetadataUtils.META_REV)) { String newRevision = EntityHelper.version(packageRootAsset).getValue(); packageRoot.set(NpmMetadataUtils.META_ID, packageRootAsset.name()); packageRoot.set(NpmMetadataUtils.META_REV, newRevision); try { NpmFacetUtils.savePackageRoot(UnitOfWork.currentTx(), packageRootAsset, packageRoot); } catch (IOException e) { log.error("Failed to update revision in package root {}", packageRoot.get(NpmMetadataUtils.NAME), e); } } }