Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Mapping Metadata (IIOMetadata) to Dam format(Converting to com.day.cq.dam.api.metadata.ExtractedMetadata object)

Avatar

Level 2

HI, 

we want to extract Metadata for CRW/CR2 files. 

we are using this code of JRAWIO-    http://jrawio.rawdarkroom.org

File file = new File("DSC1234.NEF"); ImageReader reader = ImageIO.getImageReaders(file).next(); reader.setInput(ImageIO.createImageInputStream(file)); IIOMetadata metadata = reader.getImageMetadata(0);
 
By this code, we are successful in extracting metadata fro CR2 files. 
 

but now we have to map this IIOMetadata to CQ Dam format (like for jpeg or dng format how we see the metadata in CRDX lite)

I am getting IIOMetadata object, but now I have to map this metadta.

CQ devloper using ExtractedMetadata object to mapping(i think, not sure)

so either i have to convert IIOMetadata to ExtractedMetadata object, 

or I have to map IIOMetadata object(so that it can appear like how jpeg or dng appear whenwe go to crdx lite)

so please help me in mapping.

or help me in extracting Metadata from CRW/CR2 files in a manner so that i can get ExtractedMeatadata object ro i can map easily. 

Thanks in advance

 
1 Accepted Solution

Avatar

Correct answer by
Level 10

what about getting each property from the IIOMetaData instance. Purhaps you can call getMetadataFormat which returns IIOMetadataFormat. Once you get all of the properties that you want, you can map by using a com.day.cq.dam.api.metadata.ExtractedMetadata instance by calling this object's setMetaDataProperty(String key, Object value) method. 

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

what about getting each property from the IIOMetaData instance. Purhaps you can call getMetadataFormat which returns IIOMetadataFormat. Once you get all of the properties that you want, you can map by using a com.day.cq.dam.api.metadata.ExtractedMetadata instance by calling this object's setMetaDataProperty(String key, Object value) method. 

Avatar

Level 2

hi sir, 

thanks a lot for answering my question. 

but since I am new to CQ and IIOMetadata thing,

I can get all the properties from IIOMetadata(if you can provide exact method it will help me a lot) but since IIOMetadata is a abstract tree, so it should have nodes child nodes, so how to maintain the same node structure in CRXDE. 

but more important point is if somebody changes property in CRXDE or create new Properties, then again if I upload the same image(after saving and then downloading and then deleting and then again uploading) then will the new properties will reflect in crxde. so please guide me, if you lil elaborate the solution. 

note: right now I am converting IIOMetadata to Node to String(stream result and string writer) and then to Input stream and then using Session.importXml, but by this I m getting metadata in crxde is lil buggy like its not similar to DNG or jpeg files, so if you can guide me in this approach, just I am not getting mapping properly y Session.importXml. so please help me out sir,

Attaching the screen shot of node structure in CRXDE which I am getting right now.  I hope by this YOu can understand what is I m doing wrong. actually the Xml which I am getting is also having Parent and child structure like this only, but IIOMetadata is not having this type of tree structure, so during conversion of IIOMetadata to XML inputSting, its not converting in a proper way. 

thanks a lot sir. 

Avatar

Level 2

hi sir, I am using this code for Converting IIOMetadata to jar,

and result i have posted in my other commentt please do help.      

attaching the xml data, which i m printing via string, in the doc file. please do look.                 

 

String[] mdatanames = metadata.getMetadataFormatNames();

String mdataname = mdatanames[0];

Node metadatadom = metadata.getAsTree(mdataname);

DOMSource source = new DOMSource(metadatadom);

 

ByteArrayOutputStream os = new ByteArrayOutputStream();

StreamResult result = new StreamResult(os);

Transformer transformer = TransformerFactory.newInstance().newTransformer();

transformer.transform(source, result);

ByteArrayInputStream bais =     new ByteArrayInputStream(os.toByteArray());

String nodePath1 = asset.getPath() + "/jcr:content/metadata" ;

session.importXML(nodePath1, bais, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);

Avatar

Level 10

It sounds like you are on the right approach. You are reading meta from images and you want to store in the JCR. However there is no automatic way to map data from the objects you are using to the JCR. For this use case, you will have to use the JCR API and write Java app logic to perform CRUD (Create, Replace, Update, and Delete) operations in the JRC.

Therefore - this use case is similar to other use cases where you want to store data in the JCR. Once you get the data into the JCR, I'd suggest using the JCR API to manage the data. If someone deletes the image and you want to remove the image metadata from the JCR, you would write a algorithm to lookup a node that represents image and remove the data. 

Likewise, when you read the data and want to store the data in the JCR, use the JCR API to create a node in the JCR (in the correct content tree in the JCR) to meet your needs and then write the metadata to properties of nodes. You will want to write an OSGi bundle that uses the JCR. To see how to use the JCR API from within a JCR bundle, see this community article:

http://scottsdigitalcommunity.blogspot.ca/2013/02/querying-adobe-experience-manager-data.html

Avatar

Level 2

Hi sir, 

there is a method by which I can map xml input string to jar node- session.importXml.

now session.importXml is working fine for me. 

but for creating xml input stream I m using code- 

 

 

String[] mdatanames = metadata.getMetadataFormatNames();

String mdataname = mdatanames[0];

Node metadatadom = metadata.getAsTree(mdataname);

DOMSource source = new DOMSource(metadatadom);

 

ByteArrayOutputStream os = new ByteArrayOutputStream();

StreamResult result = new StreamResult(os);

Transformer transformer = TransformerFactory.newInstance().newTransformer();

transformer.transform(source, result);

ByteArrayInputStream bais =     new ByteArrayInputStream(os.toByteArray());

 

 

}

By this code, I am getting xml Is,  but this Xml is not coming properly, I am attaching the word file in which i have copied the xml which I am getting. Since i m using this approach because in this approach there is no complexity .

so please guid me to create a proper XML so that JCR can import it. (jcr has certain rules to import XML correctly, since my xml is not  proper so importing result is not proper) 

 

node: CRUD approach will become very complex. 

Avatar

Level 10

Agreed - using Node CRUD would require coding some Java algorithms that would have to be tested and may get a little complex. If you want to explore the Import XML route -- look at this content in JCR docs:

Hop 3: Importing content

TODO: Update to match the style of previous hops.

To add content a bit more efficiently, you may want to try JCR's import facilities, such as Session.importXML. The following XML document by Elliotte Rusty Harold provides an interesting example that demonstrates a repository's namespace capabilities:

http://jackrabbit.apache.org/first-hops.html

Avatar

Level 2

HI sir,

I have already seen it. But Importing is working properly, but Its the Creation of XML Input Stream is not happening properly. I have uploded the doc file, in which You can see the XML String which I m getting(the same I am converting to IS). so that XML is kinda rough i should say. 

please help me in creating XML input stream properly from IIOMetadata object. 

thank you sir, for constant answering my queries, and helping me with your knowledge. 

Thanks a lot