context.load().json("/my/folder/co/aem/core/workflow/dam/xyz.json", "/content/dam/test/abc.zip");
Resource resource = context.resourceResolver().getResource("/content/dam/test/abc.zip");
Asset asset = resource.adaptTo(Asset.class); //here asset is null
Solved! Go to Solution.
Views
Replies
Total Likes
Please check example
https://github.com/arunpatidar02/com.aemlab.junitapp/tree/master/core/src/test
jsons are inside resources folder
Views
Replies
Total Likes
Hi Arun,
Thanks for your reply. i didnot get any reference.
i'm trying to adapt "resource.adaptTo(Asset.class)" resource as Asset but i'm getting null not sure why this is happening.
Here i'm getting resource.
Views
Replies
Total Likes
Can you try to chekc if Resource is null or not?
If Resource is not null then make sure your json contains node type of dam:Asset
I have shared the reference to let you know, how you can created resources using json in your test cases
Views
Replies
Total Likes
Hi Arun,
Resource is not null and node type is dam:Asset. still i'm not getting the Asset asset = resource.adaptTo(Asset.class);
Views
Replies
Total Likes
Can you please share the json here?
Views
Replies
Total Likes
Hi Arun, here its
{
"jcr:primaryType":"sling:Folder",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 12:24:07 GMT+0530",
"abc.zip":{
"jcr:primaryType":"dam:Asset",
"jcr:mixinTypes":[
"mix:referenceable"
],
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"jcr:uuid":"5335343gfdsfgafdaafdf",
"jcr:content":{
"jcr:primaryType":"dam:AssetContent",
"dam:assetState":"processing",
"renditions":{
"jcr:primaryType":"nt:folder",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"original":{
"jcr:primaryType":"nt:file",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"jcr:content":{
"jcr:primaryType":"oak:Resource",
"jcr:lastModifiedBy":"admin",
"jcr:mimeType":"application/zip",
"jcr:lastModified":"Tue Nov 15 2022 13:17:18 GMT+0530",
":jcr:data":13721771
}
}
},
"related":{
"jcr:primaryType":"nt:unstructured"
},
"metadata":{
"jcr:primaryType":"nt:unstructured",
"jcr:mixinTypes":[
"cq:Taggable"
]
}
}
},
"jcr:content":{
"jcr:primaryType":"nt:unstructured",
"jcr:title":"testing",
"dam:noThumbnail":true,
"sourcing":"false",
"folderThumbnail":{
"jcr:primaryType":"nt:file",
"jcr:createdBy":"abc-service",
"jcr:created":"Tue Nov 15 2022 13:01:03 GMT+0530",
"jcr:content":{
"jcr:primaryType":"nt:unstructured",
"dam:folderThumbnailPaths":[
],
"height":140,
"bgcolor":-1,
"width":240,
"jcr:lastModified":"Tue Nov 15 2022 13:17:10 GMT+0530",
"jcr:data":631
}
}
}
}
Views
Replies
Total Likes
Your json is incorrect?
Try to check the primary type of Resource, it should be dam:Asset ?
you can remove the first nesting e.g. your json should look like below
{ "jcr:primaryType": "dam:Asset", "jcr:mixinTypes": [ "mix:referenceable" ], "jcr:content": { "jcr:primaryType": "dam:AssetContent", "dam:assetState": "processing", "renditions": { "jcr:primaryType": "nt:folder", "original": { "jcr:primaryType": "nt:file", "jcr:content": { "jcr:primaryType": "oak:Resource", "jcr:mimeType": "application/zip", ":jcr:data": 13721771 } } }, "related": { "jcr:primaryType": "nt:unstructured" }, "metadata": { "jcr:primaryType": "nt:unstructured", "jcr:mixinTypes": [ "cq:Taggable" ] } } }
Views
Replies
Total Likes
Hi Arun,
primary type of Resource is dam:Asset but still i'm not able to adopt it as asset.
Views
Replies
Total Likes
Hi Arun,
it works for me. Thank you so much for helping on this. I really appreciate your effort on this!!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies