Ejemplo n.º 1
0
  @Transactional(retryOn = {ONeedRetryException.class, ORecordDuplicatedException.class})
  protected void doPutContent(
      final String path, final Supplier<InputStream> streamSupplier, final Payload payload)
      throws IOException {
    StorageTx tx = UnitOfWork.currentTransaction();

    final Bucket bucket = tx.getBucket();
    Component component = getComponent(tx, path, bucket);
    Asset asset;
    if (component == null) {
      // CREATE
      component =
          tx.createComponent(bucket, getRepository().getFormat())
              .group(getGroup(path))
              .name(getName(path));

      // Set attributes map to contain "raw" format-specific metadata (in this case, path)
      component.formatAttributes().set(P_PATH, path);
      tx.saveComponent(component);

      asset = tx.createAsset(bucket, component);
      asset.name(component.name());
    } else {
      // UPDATE
      asset = tx.firstAsset(component);
    }

    AttributesMap contentAttributes = null;
    if (payload instanceof Content) {
      contentAttributes = ((Content) payload).getAttributes();
    }
    Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
    tx.setBlob(asset, path, streamSupplier.get(), hashAlgorithms, null, payload.getContentType());
    tx.saveAsset(asset);
  }
Ejemplo n.º 2
0
  @Override
  @Transactional
  public boolean delete(final String path) throws IOException {
    StorageTx tx = UnitOfWork.currentTransaction();

    final Component component = getComponent(tx, path, tx.getBucket());
    if (component == null) {
      return false;
    }

    tx.deleteComponent(component);
    return true;
  }
Ejemplo n.º 3
0
  @Nullable
  @Override
  @Transactional(retryOn = IllegalStateException.class)
  public Content get(final String path) {
    StorageTx tx = UnitOfWork.currentTransaction();

    final Component component = getComponent(tx, path, tx.getBucket());
    if (component == null) {
      return null;
    }

    final Asset asset = tx.firstAsset(component);
    final Blob blob = tx.requireBlob(asset.requireBlobRef());

    return marshall(asset, blob);
  }
Ejemplo n.º 4
0
  @Override
  @Transactional(retryOn = ONeedRetryException.class)
  public void setCacheInfo(final String path, final CacheInfo cacheInfo) throws IOException {
    StorageTx tx = UnitOfWork.currentTransaction();

    Component component = tx.findComponentWithProperty(P_PATH, path, tx.getBucket());

    if (component == null) {
      log.debug("Attempting to set last verified date for non-existent raw component {}", path);
    }

    final Asset asset = tx.firstAsset(component);

    log.debug("Updating cacheInfo of {} to {}", path, cacheInfo);
    CacheInfo.applyToAsset(asset, cacheInfo);
    tx.saveAsset(tx.firstAsset(component));
  }