What's the best way to use CSV source data in a list component? - aem

Disclaimer: I am not an AEM developer, I'm filling in on a project, so forgive me if I am missing the obvious.
I have a page template that will contain a component that will show a list of locations, this template will be used for many city pages.
I'm trying to figure out the best way to get the content into the JCR or read it using a script from a CSV file.
Are there any out-of-the box or open source components out there that can accomplish this?

There are several ways to accomplish your task. The easy part should be rendering the information. You would usually implement a Sling model or a class extending WCMUse, access the repository via the Sling API and render the resources via Adobe HTL. The resources being rendered have to be selected of course: write a Servlet which provides an interface to the resources and use an adequate form element in the component's dialog.
The hard part consists of two parts:
Perhaps just upload the file, process the data and by using the Sling API for resource creation, you can write the data into the repo. You could also utilise the DAM for such tasks and implement a workflow.
Depending on the amount of data, you might want to save the data as JSON string as property of a node.
I hoped that helped a bit.

"Are there any out-of-the box or open source components out there that can accomplish this?"
Simple answer: NO
While there are several libraries that can help you parse CSV files, storing it in JCR depends completely on your project. The structure can be arbitrary or (in a brute force way) you can just store the CSV file as data in your node but that may not be useful.
Depending on how you plan to use the data, it may be useful and optimal to save it in a relevant hierarchy for your project.

Related

How to upload files and attachments to the sobject record using REST API?

Salesforce has two different UIs and in accordance with it, it has the possibility to store attached files differently.
Two files were uploaded via the classic UI and they are marked as 'attachments'. Other files were uploaded through the new UI and they are marked as 'files'.
I want to upload all of these files using REST API. I cannot find the proper documentation. Can somebody help me with this?
That's not 100% true. In SF Classic UI you were able to upload Files too. It's "just" about knowing the right API name of the table and you'll find lots of examples online.
Attachment and Document objects have exactly same API names, you can view their definitions in SOAP API definition or in REST API explorer (there was something which you can still see in screenshot in here, seems to be down now, maybe they're moving it to another area in documentation...)
The Files (incl. "Chatter Files") are stored in ContentDocument and ContentVersion object. The name is unexpected because long time ago SF purchased another company's product and it was called "Salesforce Content". In beginning it was bit of mess, now it's better integrated into whole platform but still some things lurk like File folders can be called Libraries sometimes in documentation but actual API name is ContentWorkspace. The entity relationship diagram can help a bit: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_content.htm
ContentDocument is a header to which many places in SF link (imagine file wasting space on disk only once but being cross-linked from multiple records). It can have at least 1 version and if you need to update the document - you'd upload new version but all links in org wouldn't change, they'd still link to header.
So, how to use it?
REST API guide: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm
or maybe Chatter API guide (you tagged it with chatter so chances are you already use it): https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_files.htm
some of my answers here might help (shameless plug). They're about upload and reading data too and one is even about data loader... but you might experiment with exporting files first, get familiar with structure before you load?
https://stackoverflow.com/a/48668673/313628
https://stackoverflow.com/a/56268939/313628
https://stackoverflow.com/a/60284736/313628

Add custom metadata fields for DAM assets in a particular folder

I created custom metadata fields for DAM Assets in CQ 5.6.1 using the steps detailed here. However, as described in the document, these changed fields are available for ALL assets in the DAM.
I need these metadata fields to be made available to only a specific folder, say /content/dam/foo instead of every asset.
How can I achieve this?
In my knowledge, there is no straight forward way to achieve this but there is one trick to handle this.
AEM DAM has the notion of meta schema editors. These editors are tied to asset file type, meaning - jpeg, mov, etc. For an asset MIME type, you can define the meta data and its associated form.
AEM 6.0 provides choral UI interface to achieve this --
http://localhost:4502/libs/dam/gui/content/metadataschemaeditor/schemalist.html/dam/content/schemaeditors/forms
Am not aware of any such interface in AEM 5.6.1. The nodes tied to this are at /libs/dam/content/asseteditors/image/jpeg/formitems. You could overlay them at /apps to add the required metadata.
Coming to the question, the trick is to add the file type into your dam content hierarchy. Example - /content/dam/jpeg/foo, /content/dam/png/foo, etc. This way, you would get different metadata for different folders of the dam.
Adobe recommends this approach as AEM 6.0 introduced the concept of processing profiles which you could attach to folders. This way, your different file types could get different treatments.

adding metadata to layer in Illustrator

Is it possible to add metadata to a layer in Adobe Illustrator? I'm looking to pull layer data (description, etc.) into a database from layer info, after saving out as an SVG. I want to see if there is a cleaner method than adding an arbitrary text box to read separately from the actual object the metadata describes.
According to the Illustrator Scripting Reference, there's no metadata you can associate with a Layer object.
However, the Document object has a field for XMP Metadata. If you can shoehorn your metadata in there, that could be useful. (I'm not sure if that survives export to SVG, though.)
Otherwise, I think you're stuck doing something hacky, like putting the metadata into text objects. Is your objection to text boxes just that it seems inelegant? Or is it causing specific problems or drawbacks? If it's the latter, we might be able to help you come up with a better hack if you give more details about why text boxes are problematic for you.

Find all <forms> used on a site

Is there e.g. a crawler that can find (and list the form action etc.) all pages that have forms in my site?
I'd like to log all pages with unique actions to then audit further.
Norconex HTTP Collector is an open source web crawler that can certainly help you. Its "Importer" module has a "TextBetweenTagger" feature to extract text between any start and end text and store it in a metadata field of your choice. You can then filter out those that have no such text extracted (look at the EmptyMetadataFilter option for this).
You can do this without writing code. As far as storing the results, the product uses "Committers". A few committers are readily available (including a filesystem one), but you may want to write your own to "commit" your crawled data wherever you like (e.g. in a database).
Check its configuration page for ideas.

Uploading an image in Zend Framework

I am new in Zend Framework and learning it. I want to upload image into my database and display that image in view page. I search lots of tutorial but no step by step guidance. Want a help. Thanks in advance.
You need to take a look on Zend_Form_Element_File in Zend documentation:
The File form element provides a mechanism for supplying file upload
fields to your form. It utilizes Zend_File_Transfer internally to
provide this functionality, and the FormFile view helper as also the
File decorator to display the form element. By default, it uses the
Http transfer adapter, which introspects the $_FILES array and allows
you to attach validators and filters. Validators and filters attached
to the form element are in turn attached to the transfer adapter.
Database side, you need to use a BLOB type to hold your image (I assume you're using MySQL).
However, note that best practices are to store the image path in the database instead of the image itself.
At last, there are tons of tutorials out there that explains precisely how to do what you're looking for, you just need to look for "file upload using zend element file" and you will find them!