@Test public void testHandle() throws IOException { ComponentUpload component = new ComponentUpload(); AssetUpload asset = new AssetUpload(); asset.setPayload(payload); component.getAssetUploads().add(asset); UploadResponse uploadResponse = underTest.handle(repository, component); assertThat(uploadResponse.getAssetPaths(), contains("@foo/bar/-/bar/bar-123.gz")); assertThat(uploadResponse.getComponentId().getValue(), is("nuId")); verify(contentPermissionChecker).isPermitted(eq(REPO_NAME), eq(NpmFormat.NAME), eq(BreadActions.EDIT), captor.capture()); VariableSource source = captor.getValue(); assertThat(source.getVariableSet(), hasSize(5)); assertThat(source.get("format"), is(Optional.of(NpmFormat.NAME))); assertThat(source.get("path"), is(Optional.of("@foo/bar/-/bar-1.5.3.tgz"))); assertThat(source.get("coordinate.packageScope"), is(Optional.of("foo"))); assertThat(source.get("coordinate.packageName"), is(Optional.of("bar"))); assertThat(source.get("coordinate.version"), is(Optional.of("1.5.3"))); }
@Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); @Override UploadResponse handle(final Repository repository, final ComponentUpload upload); @Override Content handle(
      final Repository repository,
      final File content,
      final String path); @Override UploadDefinition getDefinition(); @Override VariableResolverAdapter getVariableResolverAdapter(); @Override ContentPermissionChecker contentPermissionChecker(); @Override boolean supportsExportImport(); }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); @Override UploadResponse handle(final Repository repository, final ComponentUpload upload); @Override Content handle(
      final Repository repository,
      final File content,
      final String path); @Override UploadDefinition getDefinition(); @Override VariableResolverAdapter getVariableResolverAdapter(); @Override ContentPermissionChecker contentPermissionChecker(); @Override boolean supportsExportImport();  }