use of com.day.cq.dam.api.AssetManager in project acs-aem-commons by Adobe-Consulting-Services.
the class S3AssetIngestorTest method setup.
@Before
public void setup() throws PersistenceException {
context.registerAdapter(ResourceResolver.class, AssetManager.class, new Function<ResourceResolver, AssetManager>() {
@Nullable
@Override
public AssetManager apply(@Nullable ResourceResolver input) {
return assetManager;
}
});
context.create().resource("/content/dam", JcrConstants.JCR_PRIMARYTYPE, "sling:Folder");
context.resourceResolver().commit();
ingestor = new S3AssetIngestor(context.getService(MimeTypeService.class));
ingestor.jcrBasePath = "/content/dam";
ingestor.ignoreFileList = Collections.emptyList();
ingestor.ignoreExtensionList = Collections.emptyList();
ingestor.ignoreFolderList = Arrays.asList(".ds_store");
ingestor.existingAssetAction = AssetIngestor.AssetAction.skip;
int port = FreePortFinder.findFreeLocalPort();
s3Mock = new S3Mock.Builder().withPort(port).withInMemoryBackend().build();
s3Mock.start();
S3ClientOptions options = S3ClientOptions.builder().setPathStyleAccess(true).build();
s3Client = new AmazonS3Client(new AnonymousAWSCredentials());
s3Client.setS3ClientOptions(options);
s3Client.setEndpoint("http://localhost:" + port);
ingestor.s3Client = s3Client;
ingestor.bucket = TEST_BUCKET;
s3Client.createBucket(TEST_BUCKET);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
CheckedConsumer<ResourceResolver> method = (CheckedConsumer<ResourceResolver>) invocation.getArguments()[0];
method.accept(context.resourceResolver());
return null;
}
}).when(actionManager).deferredWithResolver(any(CheckedConsumer.class));
}
use of com.day.cq.dam.api.AssetManager in project acs-aem-commons by Adobe-Consulting-Services.
the class AssetIngestor method createAsset.
@SuppressWarnings("squid:S00112")
private void createAsset(Source source, String assetPath, ResourceResolver r, boolean versioning) throws Exception {
r.adaptTo(Session.class).getWorkspace().getObservationManager().setUserData(CHANGED_BY_WORKFLOW);
AssetManager assetManager = r.adaptTo(AssetManager.class);
String type = mimetypeService.getMimeType(source.getName());
if (versioning) {
// is asset is null, no version gets created
Asset asset = r.getResource(assetPath).adaptTo(Asset.class);
// once you are past this first version, default behavior is to start numbering 1.0, 1.1 and so on
assetManager.createRevision(asset, "initial version of asset", asset.getName());
r.commit();
r.refresh();
// once version is committed we are safe to create, which only replaces the original version
}
assetManager.createAsset(assetPath, source.getStream(), type, false);
r.commit();
r.refresh();
totalImportedData.accumulateAndGet(source.getLength(), (p, x) -> p + x);
assetCount.incrementAndGet();
}
use of com.day.cq.dam.api.AssetManager in project acs-aem-commons by Adobe-Consulting-Services.
the class FileAssetIngestorTest method setup.
@Before
public void setup() throws PersistenceException {
context.registerAdapter(ResourceResolver.class, AssetManager.class, new Function<ResourceResolver, AssetManager>() {
@Nullable
@Override
public AssetManager apply(@Nullable ResourceResolver input) {
return assetManager;
}
});
context.create().resource("/content/dam", JcrConstants.JCR_PRIMARYTYPE, "sling:Folder");
context.resourceResolver().commit();
ingestor = new FileAssetIngestor(context.getService(MimeTypeService.class));
ingestor.jcrBasePath = "/content/dam";
ingestor.ignoreFileList = Collections.emptyList();
ingestor.ignoreExtensionList = Collections.emptyList();
ingestor.ignoreFolderList = Arrays.asList(".ds_store");
ingestor.existingAssetAction = AssetIngestor.AssetAction.skip;
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
CheckedConsumer<ResourceResolver> method = (CheckedConsumer<ResourceResolver>) invocation.getArguments()[0];
method.accept(context.resourceResolver());
return null;
}
}).when(actionManager).deferredWithResolver(any(CheckedConsumer.class));
tempDirectory = Files.createTempDir();
ingestor.fileBasePath = tempDirectory.getAbsolutePath();
}
Aggregations