class 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 public  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions);

}