org.sonatype.nexus.repository.view.Payload Java Examples

The following examples show how to use org.sonatype.nexus.repository.view.Payload. 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: OrientPyPiHostedHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handle request for search.
 */
public Handler search() {
  return context -> {
    Payload payload = checkNotNull(context.getRequest().getPayload());
    try (InputStream is = payload.openInputStream()) {
      QueryBuilder query = parseSearchRequest(context.getRepository().getName(), is);
      List<PyPiSearchResult> results = new ArrayList<>();
      for (SearchHit hit : searchQueryService.browse(unrestricted(query))) {
        Map<String, Object> source = hit.getSource();
        Map<String, Object> formatAttributes = (Map<String, Object>) source.getOrDefault(
            MetadataNodeEntityAdapter.P_ATTRIBUTES, Collections.emptyMap());
        Map<String, Object> pypiAttributes = (Map<String, Object>) formatAttributes.getOrDefault(PyPiFormat.NAME,
            Collections.emptyMap());
        String name = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_NAME));
        String version = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_VERSION));
        String summary = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_SUMMARY));
        results.add(new PyPiSearchResult(name, version, summary));
      }
      String response = buildSearchResponse(results);
      return HttpResponses.ok(new StringPayload(response, ContentTypes.APPLICATION_XML));
    }
  };
}
 
Example #2
Source File: ComposerJsonProcessor.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Rewrites the provider JSON so that source entries are removed and dist entries are pointed back to Nexus.
 */
public Payload rewriteProviderJson(final Repository repository, final Payload payload) throws IOException {
  Map<String, Object> json = parseJson(payload);
  if (json.get(PACKAGES_KEY) instanceof Map) {
    Map<String, Object> packagesMap = (Map<String, Object>) json.get(PACKAGES_KEY);
    for (String packageName : packagesMap.keySet()) {
      Map<String, Object> packageVersions = (Map<String, Object>) packagesMap.get(packageName);
      for (String packageVersion : packageVersions.keySet()) {
        // TODO: Make this more robust, right now it makes a lot of assumptions and doesn't deal with bad things well
        Map<String, Object> versionInfo = (Map<String, Object>) packageVersions.get(packageVersion);
        versionInfo.remove(SOURCE_KEY); // TODO: For now don't allow sources, probably should make this configurable?

        Map<String, Object> distInfo = (Map<String, Object>) versionInfo.get(DIST_KEY);
        if (distInfo != null && ZIP_TYPE.equals(distInfo.get(TYPE_KEY))) {
          versionInfo.put(DIST_KEY,
              buildDistInfo(repository, packageName, packageVersion, (String) distInfo.get(REFERENCE_KEY),
                  (String) distInfo.get(SHASUM_KEY), ZIP_TYPE));
        }
      }
    }
  }
  return new StringPayload(mapper.writeValueAsString(json), payload.getContentType());
}
 
Example #3
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Content put(final MavenPath path, final Payload payload)
    throws IOException
{
  log.debug("PUT {} : {}", getRepository().getName(), path.getPath());

  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, HashType.ALGORITHMS)) {
    if (path.getFileName().equals(METADATA_FILENAME) && mavenMetadataValidationEnabled) {
      log.debug("Validating maven-metadata.xml before storing");
      try {
        metadataValidator.validate(path.getPath(), tempBlob.get());
      }
      catch (InvalidContentException e) {
        log.warn(e.toString());
        return Optional.ofNullable(get(path)).orElseThrow(() -> e);
      }
    }
    return doPut(path, payload, tempBlob);
  }
}
 
Example #4
Source File: MavenArchetypeCatalogFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void rebuildArchetypeCatalog() throws IOException {
  log.debug("Rebuilding hosted archetype catalog for {}", getRepository().getName());

  Path path = Files.createTempFile(HOSTED_ARCHETYPE_CATALOG, XML);
  ArchetypeCatalog hostedCatalog = createArchetypeCatalog();

  try {
    HashedPayload hashedPayload = createArchetypeCatalogFile(hostedCatalog, path);
    try (Payload payload = hashedPayload.getPayload()) {
      mavenContentFacet.put(archetypeCatalogMavenPath, payload);
      putHashedContent(archetypeCatalogMavenPath, hashedPayload);
      log.trace("Rebuilt hosted archetype catalog for {} with {} archetype",
          getRepository().getName(), hostedCatalog.getArchetypes().size());
    }
  }
  finally {
    Files.delete(path);
  }
}
 
Example #5
Source File: ComposerHostedUploadHandler.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  String vendor = getVendorToken(context);
  String project = getProjectToken(context);
  String version = getVersionToken(context);

  Request request = checkNotNull(context.getRequest());
  Payload payload = checkNotNull(request.getPayload());

  Repository repository = context.getRepository();
  ComposerHostedFacet hostedFacet = repository.facet(ComposerHostedFacet.class);

  hostedFacet.upload(vendor, project, version, payload);
  return HttpResponses.ok();
}
 
Example #6
Source File: ComposerGroupMergingHandler.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected final Response doGet(@Nonnull final Context context,
                               @Nonnull final GroupHandler.DispatchedRepositories dispatched)
    throws Exception
{
  Repository repository = context.getRepository();
  GroupFacet groupFacet = repository.facet(GroupFacet.class);

  makeUnconditional(context.getRequest());
  Map<Repository, Response> responses;
  try {
    responses = getAll(context, groupFacet.members(), dispatched);
  }
  finally {
    makeConditional(context.getRequest());
  }

  List<Payload> payloads = responses.values().stream()
      .filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null)
      .map(Response::getPayload)
      .collect(Collectors.toList());
  if (payloads.isEmpty()) {
    return notFoundResponse(context);
  }
  return HttpResponses.ok(merge(repository, payloads));
}
 
Example #7
Source File: MavenUploadHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Content handle(
    final Repository repository,
    final File content,
    final String path)
    throws IOException
{
  MavenPath mavenPath = parser.parsePath(path);

  ensurePermitted(repository.getName(), Maven2Format.NAME, mavenPath.getPath(), toMap(mavenPath.getCoordinates()));

  if (mavenPath.getHashType() != null) {
    log.debug("skipping hash file {}", mavenPath);
    return null;
  }

  Path contentPath = content.toPath();
  Payload payload = new StreamPayload(() -> new FileInputStream(content), content.length(), Files.probeContentType(contentPath));
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  Content asset = mavenFacet.put(mavenPath, payload);
  putChecksumFiles(mavenFacet, mavenPath, asset);
  return asset;
}
 
Example #8
Source File: DescriptionHelper.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
public void describeRequest(final Description desc, final Request request) {
  desc.topic("Request");

  desc.addTable("Details", ImmutableMap.<String, Object>builder()
          .put("Action", request.getAction())
          .put("path", request.getPath()).build()
  );

  desc.addTable("Parameters", toMap(request.getParameters()));
  desc.addTable("Headers", toMap(request.getHeaders()));
  desc.addTable("Attributes", toMap(request.getAttributes()));

  if (request.isMultipart()) {
    Iterable<PartPayload> parts = request.getMultiparts();
    checkState(parts != null);
    for (Payload payload : parts) {
      desc.addTable("Payload", toMap(payload));
    }
  }
  else {
    if (request.getPayload() != null) {
      desc.addTable("Payload", toMap(request.getPayload()));
    }
  }
}
 
Example #9
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutIndex(final String name,
                             final TempBlob tempBlob,
                             final Payload payload,
                             final Map<String, Object> attributes) throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = findAsset(tx, bucket, name);
  if (asset == null) {
    asset = tx.createAsset(bucket, getRepository().getFormat());
    asset.name(name);
  }
  if (attributes != null) {
    for (Entry<String, Object> entry : attributes.entrySet()) {
      asset.formatAttributes().set(entry.getKey(), entry.getValue());
    }
  }
  return saveAsset(tx, asset, tempBlob, payload);
}
 
Example #10
Source File: HelmHostedFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Asset upload(String path, TempBlob tempBlob, Payload payload, AssetKind assetKind) throws IOException {
  checkNotNull(path);
  checkNotNull(tempBlob);
  if (assetKind != HELM_PACKAGE && assetKind != HELM_PROVENANCE) {
    throw new IllegalArgumentException("Unsupported assetKind: " + assetKind);
  }

  StorageTx tx = UnitOfWork.currentTx();
  InputStream inputStream = tempBlob.get();
  HelmAttributes attributes = helmAttributeParser.getAttributes(assetKind, inputStream);
  final Asset asset =
      helmFacet.findOrCreateAsset(tx, path, assetKind, attributes);
  helmFacet.saveAsset(tx, asset, tempBlob, payload);
  return asset;
}
 
Example #11
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void replaceWithUnchangedExisting() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(
          new StringPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><metadata></metadata>",
              "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(1)).get(eq(mavenPath));
  verify(mavenFacet, times(0)).put(eq(mavenPath), any(Payload.class));
}
 
Example #12
Source File: RHostedFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Asset doPutArchive(final String path,
                             final TempBlob archiveContent,
                             final Payload payload) throws IOException
{

  StorageTx tx = UnitOfWork.currentTx();
  RFacet rFacet = facet(RFacet.class);

  Map<String, String> attributes;
  try (InputStream is = archiveContent.get()) {
    attributes = extractDescriptionFromArchive(path, is);
  }

  Component component = rFacet.findOrCreateComponent(tx, path, attributes);
  Asset asset = rFacet.findOrCreateAsset(tx, component, path, attributes);
  saveAsset(tx, asset, archiveContent, payload);

  return asset;
}
 
Example #13
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateWithExisting() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(
          new StringPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><metadata><groupId>group</groupId></metadata>",
              "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.update(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(1)).get(eq(mavenPath));
  verify(mavenFacet, times(0)).put(eq(mavenPath), any(Payload.class));
}
 
Example #14
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutPackage(final TempBlob tempBlob,
                               final Payload content,
                               final ConanCoords coords,
                               final AssetKind assetKind) throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = getOrCreateComponent(tx, bucket, coords);

  String assetPath = getProxyAssetPath(coords, assetKind);
  Asset asset = findAsset(tx, bucket, assetPath);
  if (asset == null) {
    asset = tx.createAsset(bucket, component);
    asset.name(assetPath);
    asset.formatAttributes().set(P_ASSET_KIND, CONAN_PACKAGE.name());
  }
  else if (!asset.componentId().equals(EntityHelper.id(component))) {
    asset.componentId(EntityHelper.id(component));
  }
  return saveAsset(tx, asset, tempBlob, content, null);
}
 
Example #15
Source File: NpmTokenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Response login(final Context context) {
  final Payload payload = context.getRequest().getPayload();
  if (payload == null) {
    return NpmResponses.badRequest("Missing body");
  }
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) {
    NestedAttributesMap request = NpmJsonUtils.parse(tempBlob);
    String token = npmTokenManager.login(request.get("name", String.class), request.get("password", String.class));
    if (null != token) {
      NestedAttributesMap response = new NestedAttributesMap("response", Maps.newHashMap());
      response.set("ok", Boolean.TRUE.toString());
      response.set("rev", "_we_dont_use_revs_any_more");
      response.set("id", "org.couchdb.user:undefined");
      response.set("token", token);
      return HttpResponses.created(new BytesPayload(NpmJsonUtils.bytes(response), ContentTypes.APPLICATION_JSON));
    }
    else {
      return NpmResponses.badCredentials("Bad username or password");
    }
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #16
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected HttpRequestBase buildFetchHttpRequest(final URI uri, final Context context) {
  Request request = context.getRequest();
  // If we're doing a search operation, we have to proxy the content of the XML-RPC POST request to the PyPI server...
  if (isSearchRequest(request)) {
    Payload payload = checkNotNull(request.getPayload());
    try {
      ContentType contentType = ContentType.parse(payload.getContentType());
      HttpPost post = new HttpPost(uri);
      post.setEntity(new InputStreamEntity(payload.openInputStream(), payload.getSize(), contentType));
      return post;
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  return super.buildFetchHttpRequest(uri, context); // URI needs to be replaced here
}
 
Example #17
Source File: AptHostedFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public Asset ingestAsset(final Payload body) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(body, FacetHelper.hashAlgorithms)) {
    ControlFile control = AptPackageParser.parsePackage(tempBlob);
    if (control == null) {
      throw new IllegalOperationException("Invalid Debian package supplied");
    }
    return ingestAsset(control, tempBlob, body.getSize(), body.getContentType());
  }
}
 
Example #18
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void putDistTags(final NpmPackageId packageId, final String tag, final Payload payload)
    throws IOException
{
  checkNotNull(packageId);
  checkNotNull(tag);
  log.debug("Updating distTags: {}", packageId);

  if ("latest".equals(tag)) {
    throw new IOException("Unable to update latest tag");
  }

  String version = parseVersionToTag(packageId, tag, payload);
  doPutDistTags(packageId, tag, version);
}
 
Example #19
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void putPackage(final NpmPackageId packageId, @Nullable final String revision, final Payload payload)
    throws IOException
{
  checkNotNull(packageId);
  checkNotNull(payload);
  try (NpmPublishRequest request = npmRequestParser.parsePublish(getRepository(), payload)) {
    putPublishRequest(packageId, revision, request);
  }
}
 
Example #20
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 #21
Source File: OrientNpmHostedFacetTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  underTest = new OrientNpmHostedFacet(npmRequestParser);
  underTest.attach(repository);

  when(npmFacet.putTarball(any(), any(), any(), any())).thenReturn(mockAsset);

  when(storageFacet.createTempBlob(any(Payload.class), any())).thenAnswer(invocation -> {
    when(tempBlob.get()).thenReturn(((Payload) invocation.getArguments()[0]).openInputStream());
    return tempBlob;
  });
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);

  when(storageTx.createAsset(any(), any(Format.class))).thenReturn(packageRootAsset);
  when(packageRootAsset.formatAttributes()).thenReturn(new NestedAttributesMap("metadata", new HashMap<>()));
  when(packageRootAsset.name(any())).thenReturn(packageRootAsset);

  when(repository.facet(NpmFacet.class)).thenReturn(npmFacet);

  when(tempBlob.getHashes())
      .thenReturn(Collections.singletonMap(HashAlgorithm.SHA1, HashCode.fromBytes("abcd".getBytes())));
  when(storageTx.createBlob(anyString(), Matchers.<Supplier<InputStream>> any(), anyCollection(), anyMap(),
      anyString(), anyBoolean()))
      .thenReturn(assetBlob);

  UnitOfWork.beginBatch(storageTx);
}
 
Example #22
Source File: AptHostedFacet.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreBlob
public Asset ingestAsset(Payload body) throws IOException, PGPException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(body, FacetHelper.hashAlgorithms)) {
    ControlFile control = AptPackageParser.parsePackage(tempBlob);
    if (control == null) {
      throw new IllegalOperationException("Invalid Debian package supplied");
    }
    return ingestAsset(control, tempBlob, body.getSize(), body.getContentType());
  }
}
 
Example #23
Source File: DefaultHttpResponseSenderTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void customStatusMessageIsMaintainedWithPayload() throws Exception {
  when(request.getAction()).thenReturn(HttpMethods.GET);

  Payload detailedReason = new StringPayload("Please authenticate and try again", "text/plain");

  Response response = new Response.Builder()
      .status(Status.failure(FORBIDDEN, "You can't see this"))
      .payload(detailedReason).build();

  underTest.send(request, response, httpServletResponse);

  verify(httpServletResponse).setStatus(403, "You can't see this");
}
 
Example #24
Source File: ConanHostedFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
private void doPutArchive(final String assetPath,
                          final ConanCoords coord,
                          final Payload payload,
                          final AssetKind assetKind) throws IOException
{
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, ConanFacetUtils.HASH_ALGORITHMS)) {
    doPutArchive(coord, assetPath, tempBlob, assetKind);
  }
}
 
Example #25
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset and create a blob
 *
 * @return blob content
 */
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final Payload payload,
                          final HashCode hash) throws IOException
{
  AttributesMap contentAttributes = null;
  String contentType = null;
  if (payload instanceof Content) {
    contentAttributes = ((Content) payload).getAttributes();
    contentType = payload.getContentType();
  }
  return saveAsset(tx, asset, contentSupplier, contentType, contentAttributes, hash);
}
 
Example #26
Source File: PackagesGroupHandlerTest.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
private void setupRepository(final Repository repository) throws Exception {
  ViewFacet viewFacet = mock(ViewFacet.class);
  Response response = mock(Response.class);
  Payload payload = mock(Payload.class);
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(groupFacet.members()).thenReturn(members);
  when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(repository.facet(ViewFacet.class)).thenReturn(viewFacet);
  when(viewFacet.dispatch(any(), any())).thenReturn(response);
  when(response.getPayload()).thenReturn(payload);
  when(payload.openInputStream()).thenReturn(new FileInputStream(packages));
  when(response.getStatus()).thenReturn(new Status(true, 200));
}
 
Example #27
Source File: GolangDataAccess.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final Payload payload) throws IOException
{
  AttributesMap contentAttributes = null;
  String contentType = null;
  if (payload instanceof Content) {
    contentAttributes = ((Content) payload).getAttributes();
    contentType = payload.getContentType();
  }
  return saveAsset(tx, asset, contentSupplier, contentType, contentAttributes);
}
 
Example #28
Source File: RHostedFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Asset upload(final String path, final Payload payload) throws IOException {
  checkNotNull(path);
  checkNotNull(payload);
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, RFacetUtils.HASH_ALGORITHMS)) {
    return doPutArchive(path, tempBlob, payload);
  }
}
 
Example #29
Source File: GolangDataAccess.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreBlob
public Content maybeCreateAndSaveComponent(final Repository repository,
                                           final GolangAttributes golangAttributes,
                                           final String assetPath,
                                           final TempBlob tempBlob,
                                           final Payload payload,
                                           final AssetKind assetKind) throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(repository);

  Component component = findComponent(tx,
      repository,
      golangAttributes.getModule(),
      golangAttributes.getVersion());

  if (component == null) {
    component = tx.createComponent(bucket, repository.getFormat())
        .name(golangAttributes.getModule())
        .version(golangAttributes.getVersion());
    tx.saveComponent(component);
  }

  Asset asset = findAsset(tx, bucket, assetPath);
  if (asset == null) {
    asset = tx.createAsset(bucket, component);
    asset.name(assetPath);
    asset.formatAttributes().set(P_ASSET_KIND, assetKind.name());
  }
  return saveAsset(tx, asset, tempBlob, payload);
}
 
Example #30
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();
  }
}