コード例 #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);
  }
コード例 #2
0
 @Override
 public BrowseResult<Asset> browseComponentAssets(
     final Repository repository, final String componentId) {
   checkNotNull(repository);
   checkNotNull(componentId);
   try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) {
     storageTx.begin();
     Component component = storageTx.findComponent(new DetachedEntityId(componentId));
     if (component == null) {
       return new BrowseResult<>(0, Collections.emptyList());
     }
     VariableResolverAdapter variableResolverAdapter =
         variableResolverAdapterManager.get(component.format());
     List<Asset> assets =
         StreamSupport.stream(storageTx.browseAssets(component).spliterator(), false)
             .filter(
                 (Asset asset) ->
                     contentPermissionChecker.isPermitted(
                         repository.getName(),
                         asset.format(),
                         BreadActions.BROWSE,
                         variableResolverAdapter.fromAsset(asset)))
             .collect(Collectors.toList());
     return new BrowseResult<>(assets.size(), assets);
   }
 }