Search in sources :

Example 1 with AssetUpload

use of org.sonatype.nexus.repository.upload.AssetUpload in project nexus-repository-r by sonatype-nexus-community.

the class RUploadHandlerTest method createComponentUpload.

private ComponentUpload createComponentUpload(final String packagePath, final String packageName) {
    when(payload.getName()).thenReturn(packageName);
    ComponentUpload component = new ComponentUpload();
    AssetUpload asset = new AssetUpload();
    asset.setFields(Collections.singletonMap(RUploadHandler.PATH_ID, packagePath));
    asset.setPayload(payload);
    component.getAssetUploads().add(asset);
    return component;
}
Also used : ComponentUpload(org.sonatype.nexus.repository.upload.ComponentUpload) AssetUpload(org.sonatype.nexus.repository.upload.AssetUpload)

Example 2 with AssetUpload

use of org.sonatype.nexus.repository.upload.AssetUpload in project nexus-repository-r by sonatype-nexus-community.

the class RUploadHandler method handle.

@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();
    }
}
Also used : UploadResponse(org.sonatype.nexus.repository.upload.UploadResponse) RHostedFacet(org.sonatype.nexus.repository.r.RHostedFacet) Asset(org.sonatype.nexus.repository.storage.Asset) PartPayload(org.sonatype.nexus.repository.view.PartPayload) AssetUpload(org.sonatype.nexus.repository.upload.AssetUpload)

Aggregations

AssetUpload (org.sonatype.nexus.repository.upload.AssetUpload)2 RHostedFacet (org.sonatype.nexus.repository.r.RHostedFacet)1 Asset (org.sonatype.nexus.repository.storage.Asset)1 ComponentUpload (org.sonatype.nexus.repository.upload.ComponentUpload)1 UploadResponse (org.sonatype.nexus.repository.upload.UploadResponse)1 PartPayload (org.sonatype.nexus.repository.view.PartPayload)1