Package org.sonatype.nexus.component.model

Examples of org.sonatype.nexus.component.model.EntityId


  @Test
  public void updateAssetWithoutModifyingStream() throws IOException {
    registerTestAdapters();

    EntityId componentId = componentStore.createComponent(testComponent()).getId();
    EntityId assetId = componentStore.createAsset(componentId, testAsset(1)).getId();

    TestAsset sourceAsset = testAsset(2);
    sourceAsset.setStreamSupplier(null);
    TestAsset updatedAsset = componentStore.updateAsset(assetId, sourceAsset);
View Full Code Here


  @Test
  public void deleteNonExistingComponent() {
    registerTestAdapters();

    assertThat(componentStore.deleteComponent(TestComponent.class, new EntityId("bogusId")), is(false));
  }
View Full Code Here

  @Test
  public void deleteNonExistingAsset() {
    registerTestAdapters();

    assertThat(componentStore.deleteAsset(TestAsset.class, new EntityId("bogusId")), is(false));
  }
View Full Code Here

  public void deleteComponent() {
    registerTestAdapters();

    ComponentEnvelope<TestComponent, TestAsset> sourceEnvelope = testEnvelope(1);
    TestComponent storedComponent = componentStore.createComponentWithAssets(sourceEnvelope);
    EntityId assetId = storedComponent.getAssetIds().iterator().next();

    assertThat(componentStore.deleteComponent(TestComponent.class, storedComponent.getId()), is(true));
    assertThat(componentStore.deleteComponent(TestComponent.class, storedComponent.getId()), is(false));
    assertThat(componentStore.deleteAsset(TestAsset.class, assetId), is(false));
  }
View Full Code Here

  public void deleteAsset() {
    registerTestAdapters();

    ComponentEnvelope<TestComponent, TestAsset> sourceEnvelope = testEnvelope(1);
    TestComponent storedComponent = componentStore.createComponentWithAssets(sourceEnvelope);
    EntityId assetId = storedComponent.getAssetIds().iterator().next();

    assertThat(componentStore.deleteAsset(TestAsset.class, assetId), is(true));
    TestComponent updatedComponent = componentStore.readComponent(TestComponent.class, storedComponent.getId());
    assertThat(updatedComponent.getAssetIds().size(), is(0));
  }
View Full Code Here

    Class<A> assetClass = (Class<A>) sourceAsset.getClass();
    AssetAdapter<A> assetAdapter = registeredAssetAdapter(assetClass);
    ODocument componentDocument = retrieveExistingDocument(db, Component.class, componentId);

    // generate asset id
    EntityId assetId = entityIdFactory.newId();

    // create blob from source
    Blob blob = createBlob(blobTx, sourceAsset, assetId);
    checkArgument(blob != null, "Cannot store new asset without a content stream");
View Full Code Here

    C sourceComponent = sourceEnvelope.getComponent();
    Class<C> componentClass = (Class<C>) sourceComponent.getClass();
    ComponentAdapter<C> componentAdapter = registeredComponentAdapter(componentClass);

    // generate component id
    EntityId componentId = entityIdFactory.newId();

    // create component document using source data
    ODocument componentDocument = db.newInstance(new OClassNameBuilder().type(componentClass).build());
    componentAdapter.populateDocument(sourceComponent, componentDocument);

    // amend component document with system-managed data
    componentDocument.field(EntityAdapter.P_ID, componentId.asUniqueString());
    Set<ORID> assets = ImmutableSet.of();
    componentDocument.field(P_ASSETS, assets);

    // store component document
    componentDocument.save();

    // create all associated assets and hold on to them, their entity ids, and rids
    Set<EntityId> assetIds = Sets.newHashSet();
    Set<ORID> assetDocumentRids = Sets.newHashSet();
    for (A sourceAsset: sourceEnvelope.getAssets()) {
      Class<A> assetClass = (Class<A>) sourceAsset.getClass();
      AssetAdapter<A> assetAdapter = registeredAssetAdapter(assetClass);

      // generate asset id
      EntityId assetId = entityIdFactory.newId();

      // create blob from source
      Blob blob = createBlob(blobTx, sourceAsset, assetId);
      checkArgument(blob != null, "Cannot store new asset without a content stream");
View Full Code Here

    checkAllNotNull(db, assetId, sourceAsset, blobTx);
    Class<A> assetClass = (Class<A>) sourceAsset.getClass();
    AssetAdapter<A> assetAdapter = registeredAssetAdapter(assetClass);
    ODocument assetDocument = retrieveExistingDocument(db, assetClass, assetId);
    ODocument componentDocument = assetDocument.field(P_COMPONENT);
    EntityId componentId = new EntityId((String) componentDocument.field(EntityAdapter.P_ID));

    // update asset document using source data
    assetAdapter.populateDocument(sourceAsset, assetDocument);

    // grab the local blob
View Full Code Here

  private <A extends Asset> A assetFrom(AssetAdapter<A> assetAdapter,
      ODocument assetDocument) {
    ODocument componentDocument = assetDocument.field(P_COMPONENT);
    // TODO: For performance, consider storing componentId as a STRING directly in the asset document.
    EntityId componentId = new EntityId((String) componentDocument.field(EntityAdapter.P_ID));
    Blob blob = getLocalBlob(assetDocument);
    return assetFrom(assetAdapter, assetDocument, componentId, blob);
  }
View Full Code Here

      EntityId componentId, final Blob blob) {
    try {
      A asset = assetEntityAdapter.getEntityClass().newInstance();
      // set type-specific, then base/system-controlled properties
      assetEntityAdapter.populateEntity(assetDocument, asset);
      asset.setId(new EntityId((String) assetDocument.field(P_ID)));
      asset.setComponentId(componentId);
      asset.setContentType((String) assetDocument.field(P_CONTENT_TYPE));
      asset.setPath((String) assetDocument.field(P_PATH));
      asset.setFirstCreated(new DateTime((Date) assetDocument.field(P_FIRST_CREATED)));
      asset.setLastModified(blob.getMetrics().getCreationTime());
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.component.model.EntityId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.