Saturday, 27 April 2013

Guidelines - Assets Upload into CQ DAM

Here are the few guidelines suggested by CQ Experts (from google groups):


1. Folder/Asset Naming convention

    a. Is it good a have a folder/Asset name contains underscore ( _ ).

        Eg:  /content/dam/Test/Advanced_buttons
    
    Is CQ providing any best naming conventions.

2. Assets (Images/pdf/docs whatever)
   
     a. What is the max size limit of an Asset?

3. What is the max number of Assets that we can upload in a dam folder.

Comments:

1. Yes folders can have underscores. I didn't see any issue till now.
2. Max size limit I am not sure but I injected around 10 to 30 MB size with out any issues.
3. There should not be much issue even if you inject 100 to 150 gigs of assets. we migrated around 130 gigs with out much issues. In terms of number of assets inside a particular folder (Number of nodes at one level) Adobe recommends dont use more than 200 to 250 at one level. If it is more than that front end DAM UI will slows down (still repository doesn't show any issue)


Quick Notes


How to get a Resource when we have node path:

In Java:

@Reference 
private ResourceResolverFactory resourceResolverFactory;

ResourceResolver resolver=null;

resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

Resource res=null;
res= resolver.getResource("PATH");

In JSP:

Resource res= resourceResolver.getResource("PATH");


How to get a Node, Get node property, Add/Update node property:


Node node = res.adaptTo(Node.class);

Get propoerty:

String prop= node.getProperty("Prop_name").getValue().getString();

String prop = node.setProperty("Prop_name","Value");

Note: Don't forget to save the session when the node is updated.

Update Node using PersistableValueMap:


Resource resource = resolver.getResource("Node Path");
if(resource !=null)
{
PersistableValueMap valueMap= resource.adaptTo(PersistableValueMap.class);
valueMap.put("propname","value");
valueMap.save();

}



How to get a JackRabbit session in the Workflow:

final JackrabbitSession jackrabbitSession = (JackrabbitSession) wfsession.getSession();
UserManager userManager = jackrabbitSession.getUserManager();

Friday, 11 January 2013

Store Form Data

Task: Create a page which has form by default where we can add different form fields like text, radio buttons, file upload and so on..

Sol
  Step 1:  Create a template and add properties as shown in the following example. Here the template name is 'formtemplate' 
   Also add resourceType property to the template..

           

Step 2: 
      Add property called Sling:resourceType as 'foundation/components/parsys'

Step 3:
      
     Will up soon...
    
      



Note: 

   1. While configuring Action to store the data, we specify the path as follows:
      Eg: /tmp/formdata   or /tmp/formdata/
   
   To Override the form data, We have to specify like
      /tmp/formdata
   To store data in another node, We have to specify like
      /tmp/formdata/


   
     

Retrieve OSGI Configurations

Scenario: How to retrieve configuration details in jsp/class ?

Solutions

@Reference
    ConfigurationAdmin configAdmin;


Configuration config = configAdmin.getConfiguration("com.day.cq.mailer.DefaultMailService");
           
Dictionary<?, ?> d = config.getProperties();

log.debug("Configurations Dictionary:{}"+d);

String hostName= (String) d.get("smtp.host");



Sunday, 6 January 2013

Configuring Email Notification


In order to send email from CQ, the Day CQ Mail Service needs to be configured properly. 
Procedure: 1. Go to felix web console (http://<host-name>:<port>/system/console/configMgr)
2. Search for Day CQ Mail Service
3. Edit and configure as follows:

a.  The SMTP server port must be 25 or higher.
b.  The SMTP server host name must not be blank.
c.  The "From" address must not be blank.  

Screen shot:


Simple code to send an email

There are difference ways to send an email.

Method 1: Using SimpleEmail

        SimpleEmail email = new SimpleEmail();
        email.setHostName('smtp.gmail.com");
        email.addTo("mail@gmail.com", "John Doe");
        email.setFrom("yourmail@gmail.com", "Me");
        email.setSubject("Test message");
        email.setMsg("This is a simple test of commons-email");
        email.send();

Method 2: Using HtmlEmail without using MessageGateway


        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.gmail.com");
        email.addTo("mail@domain.com", "John Doe");
        email.setFrom("yourmail@domain.com", "Me");
        email.setSubject("Test email with inline image");

        // set the html message //
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"
        +cid+"\"></html>");
         
        // set the alternative message
        email.setTextMsg("Your email client does not support HTML messages");
        email.send();

Note: We can also read smtp details from the felix console configurations instead of passing smtp details directly. 
Ref: http://www.blogger.com/blogger.g?blogID=8547815981944994348#editor/target=post;postID=3901523167605550399