Java Code Examples for org.sonatype.nexus.transaction.UnitOfWork#end()

The following examples show how to use org.sonatype.nexus.transaction.UnitOfWork#end() . 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: MavenProxyIndexFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void publishIndex() throws IOException {
  log.debug("Fetching maven index properties from remote");
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try(DuplicateDetectionStrategy<Record> strategy = duplicateDetectionStrategyProvider.get()) {
    if (!prefetchIndexFiles(getRepository())) {
      if (Boolean.TRUE.equals(config.cacheFallback)) {
        log.debug("No remote index found... generating partial index from caches");
        publishHostedIndex(getRepository(), strategy);
      }
      else {
        log.debug("No remote index found... nothing to publish");
      }
    }
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 2
Source File: RUploadHandler.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
  final AssetUpload assetUpload = upload.getAssetUploads().get(0);
  final PartPayload payload = assetUpload.getPayload();
  final Map<String, String> fields = assetUpload.getFields();
  final String uploadPath = removeInitialSlashFromPath(fields.get(PATH_ID));
  final String assetPath = buildPath(uploadPath, payload.getName());

  ensurePermitted(repository.getName(), RFormat.NAME, assetPath, Collections.emptyMap());
  validateArchiveUploadPath(assetPath);

  try {
    UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
    Asset asset = repository.facet(RHostedFacet.class).upload(assetPath, payload);
    return new UploadResponse(asset);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 3
Source File: OrientMavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void writeWithoutValidation(
    final Repository repository,
    final String path,
    final Payload payload) throws IOException
{
  final MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final StorageFacet storageFacet = repository.facet(StorageFacet.class);

  final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
  UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
  try {
    try (TempBlob tempBlob = storageFacet.createTempBlob(payload, HashType.ALGORITHMS)) {

      mavenFacet.put(mavenPath, tempBlob, MavenMimeRulesSource.METADATA_TYPE, new AttributesMap());
    }
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 4
Source File: CleanupPreviewHelperImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public PagedResponse<ComponentXO> getSearchResults(final CleanupPolicyPreviewXO previewXO,
                                                   final Repository repository,
                                                   final QueryOptions queryOptions)
{
  CleanupPolicy cleanupPolicy = toCleanupPolicy(previewXO);

  UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
  try {
    return searchForComponents(repository, cleanupPolicy, queryOptions);
  } finally {
    UnitOfWork.end();
  }
}
 
Example 5
Source File: AptUploadHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
  AptHostedFacet hostedFacet = repository.facet(AptHostedFacet.class);
  StorageFacet storageFacet = repository.facet(StorageFacet.class);

  try (TempBlob tempBlob = storageFacet
      .createTempBlob(upload.getAssetUploads().get(0).getPayload(), FacetHelper.hashAlgorithms)) {
    ControlFile controlFile = AptPackageParser.parsePackage(tempBlob);
    if (controlFile == null) {
      throw new IOException("Invalid debian package:  no control file");
    }
    String name = controlFile.getField("Package").map(f -> f.value).get();
    String version = controlFile.getField("Version").map(f -> f.value).get();
    String architecture = controlFile.getField("Architecture").map(f -> f.value).get();
    String assetPath = FacetHelper.buildAssetPath(name, version, architecture);

    doValidation(repository, assetPath);

    UnitOfWork.begin(storageFacet.txSupplier());
    try {
      Asset asset = hostedFacet.ingestAsset(upload.getAssetUploads().get(0).getPayload());
      return new UploadResponse(asset);
    }
    finally {
      UnitOfWork.end();
    }
  }
}
 
Example 6
Source File: PurgeUnusedSnapshotsFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Purges snapshots from the given repository, returning a set of the affected groups for metadata rebuilding.
 */
private void purgeSnapshotsFromRepository(final int numberOfDays) {
  LocalDate olderThan = LocalDate.now().minusDays(numberOfDays);
  UnitOfWork.beginBatch(facet(StorageFacet.class).txSupplier());
  try {
    deleteUnusedSnapshotComponents(olderThan);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 7
Source File: RawITSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected Content read(final Repository repository, final String path) throws IOException {
  RawContentFacet rawFacet = repository.facet(RawContentFacet.class);
  UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
  try {
    return rawFacet.get(path);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 8
Source File: OrientMavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Payload read(final Repository repository, final String path) throws IOException {
  final MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
  UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
  try {
    return mavenFacet.get(mavenPath);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 9
Source File: OrientMavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void write(final Repository repository, final String path, final Payload payload) throws IOException {
  final MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
  UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
  try {
    mavenFacet.put(mavenPath, payload);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 10
Source File: FormatStoreManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static void assertDaoBinding(final ContentStoreSupport<?> store,
                                     final Class<? extends ContentDataAccess> daoClass)
{
  // internal dao() method expects to be called from a transactional method, so mimic one here
  UnitOfWork.begin(store::openSession);
  try {
    Transactional.operation.run(() -> assertThat(store.dao(), is(instanceOf(daoClass))));
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 11
Source File: MavenIndexFacetSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
public DateTime lastPublished() throws IOException {
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    return MavenIndexPublisher.lastPublished(getRepository());
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example 12
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void replaceWithExistingCorrupted() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(new StringPayload("ThisIsNotAnXml", "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.replace(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(2)).get(eq(mavenPath));
  verify(mavenFacet, times(1)).put(eq(mavenPath), any(Payload.class));
}
 
Example 13
Source File: OrientPyPiHostedFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void teardown() {
  UnitOfWork.end();
}
 
Example 14
Source File: RepositoryFacetTestSupport.java    From nexus-repository-r with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void tearDown() {
  UnitOfWork.end();
}
 
Example 15
Source File: OrientNpmGroupPackageHandlerTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void tearDown() {
  UnitOfWork.end();
}
 
Example 16
Source File: MavenFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void cleanup() {
  UnitOfWork.end();
}
 
Example 17
Source File: HelmUploadHandler.java    From nexus-repository-helm with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public UploadResponse handle(Repository repository, ComponentUpload upload) throws IOException {
  HelmHostedFacet facet = repository.facet(HelmHostedFacet.class);
  StorageFacet storageFacet = repository.facet(StorageFacet.class);

  PartPayload payload = upload.getAssetUploads().get(0).getPayload();

  String fileName = payload.getName() != null ? payload.getName() : StringUtils.EMPTY;
  AssetKind assetKind = AssetKind.getAssetKindByFileName(fileName);

  if (assetKind != AssetKind.HELM_PROVENANCE && assetKind != AssetKind.HELM_PACKAGE) {
    throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz or .tgz.prov");
  }

  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, HASH_ALGORITHMS)) {
    HelmAttributes attributesFromInputStream = helmPackageParser.getAttributes(assetKind, tempBlob.get());
    String extension = assetKind.getExtension();
    String name = attributesFromInputStream.getName();
    String version = attributesFromInputStream.getVersion();

    if (StringUtils.isBlank(name)) {
      throw new ValidationErrorsException("Metadata is missing the name attribute");
    }

    if (StringUtils.isBlank(version)) {
      throw new ValidationErrorsException("Metadata is missing the version attribute");
    }

    String path = String.format("%s-%s%s", name, version, extension);

    ensurePermitted(repository.getName(), NAME, path, Collections.emptyMap());
    try {
      UnitOfWork.begin(storageFacet.txSupplier());
      Asset asset = facet.upload(path, tempBlob, payload, assetKind);
      return new UploadResponse(asset);
    }
    finally {
      UnitOfWork.end();
    }
  }
}
 
Example 18
Source File: NpmFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  UnitOfWork.end();
}
 
Example 19
Source File: LastDownloadedHandlerTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void tearDown() {
  UnitOfWork.end();
}
 
Example 20
Source File: RawContentFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void tearDown() {
  UnitOfWork.end();
}