Tuesday, March 17, 2015

Read this, Share yours, Learning for all!: Deployment Strategy - Create Package.xml from Excel with component list using ANT

Read this, Share yours, Learning for all!: Deployment Strategy - Create Package.xml from Excel with component list using ANT

Deployment Strategy - Create Package.xml from Excel with component list using ANT

When it comes to deployment the easiest way is change sets, however not the best method. As per my experience ANT tool is the best possible tool for developer to deploy.
Source for ANT : Package.xml file.
How to create a Package.xml file? Manually?
The Answer is No. Why?
The reason being is Human are always prone to error. Below post will try to explain how ANT + Java program can be used to convert the excel file to package.xml file.

Use Case: We have a list of components in excel. We need a deployment?
Traditional way : Go ahead and create change set and deploy
Drawback : Too much time consuming.
Automated and easy way - Create package.xml from excel and ANT to deploy
Approach - Find excel to Xml source at web. Modified as per my need.

Steps to create a automated package.xml file

1. Always add components in the excel sheet with following format-






















save file as .xls file only as java program given below will convert 2003 files.(can be modified)

2. Column 1 - Metadata Name of component
    Column 2- API name of Object or folder associated with components
    Column 3 - API name of component.

3. Download POI apache .jar library, create a java project and add below class and download jar file to build path.

4. Provide Filename.XLs as argument and execute in Eclipse.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class POIExcelReader {
 HashMap<String, ArrayList<String>> hashMapMetaData = new HashMap<String, ArrayList<String>>();
 // ArrayList<String> memberSet = new ArrayList<String>();
 String preMetaType = null;
 ArrayList<String> apexComponents = new ArrayList<String>(
   Arrays.asList(new String[]{"ApexClass", "ApexComponent",
     "ApexPage", "ApexTrigger", "ApprovalProcess",
     "CustomApplication", "CustomField", "CustomLabel",
     "CustomLabels", "CustomObject", "Dashboard", "Document",
     "EmailTemplate", "FieldSet", "HomePageLayout", "Layout",
     "Letterhead", "ListView", "Profile", "Queue", "RecordType",
     "Report", "StaticResource", "ValidationRule", "WebLink",
     "WorkflowAlert", "WorkflowFieldUpdate", "WorkflowRule"}));

 ArrayList<String> prefixObjectMetaType = new ArrayList<String>(
   Arrays.asList(new String[]{"ApprovalProcess", "ApprovalProcess",
     "CustomField", "FieldSet", "ListView",
     "RecordType", "ValidationRule", "WebLink", "WorkflowAlert",
     "WorkflowFieldUpdate", "WorkflowRule"}));

 ArrayList<String> folderComponents = new ArrayList<String>(
   Arrays.asList(new String[]{"EmailTemplate", "Report", "Dashboard",
     "Document"}));
 public POIExcelReader() {
 }

 public void displayFromExcel(String xlsPath) {
  InputStream inputStream = null;
  try {
   inputStream = new FileInputStream(xlsPath);
  } catch (FileNotFoundException e) {
   System.out.println("File not found in the specified path.");
   e.printStackTrace();
  }

  POIFSFileSystem fileSystem = null;

  try {
   // Initializing the XML document
   DocumentBuilderFactory factory = DocumentBuilderFactory
     .newInstance();
   DocumentBuilder builder = factory.newDocumentBuilder();
   Document document = builder.newDocument();
   Element rootElement = document.createElement("package");
   document.appendChild(rootElement);
   System.out
     .println("Generating Package.Xml from source XML file....");

   fileSystem = new POIFSFileSystem(inputStream);
   HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
   HSSFSheet sheet = workBook.getSheetAt(0);
   Iterator<?> rows = sheet.rowIterator();

   while (rows.hasNext()) {
    String metaDataType = null;
    String member = null;
    String objectName = null;
    HSSFRow row = (HSSFRow) rows.next();

    // get a row, iterate through cells.
    Iterator<?> cells = row.cellIterator();

    while (cells.hasNext()) {
     HSSFCell cell = (HSSFCell) cells.next();
     // STRING CELL TYPE
     HSSFRichTextString richTextString = cell
       .getRichStringCellValue();
     String cellValue = richTextString.getString();
     // System.out.println("String: " + cellValue);
     if (apexComponents.contains(cellValue)
       && metaDataType == null) {
      metaDataType = cellValue;
     } else if (cellValue == "Layout" || objectName == null) {
      objectName = cellValue;
     } else {
      member = cellValue;
     }
    } // end while
     // System.out.println("ObjectName: " + objectName+
     // " Metadatatype==>" + metaDataType + " member==>" +
     // member);
    // Add metaDataType and Members in Map
    createMetadataMap(metaDataType, objectName, member);
   } // end while
   // Create XML file String
   for (String metaDataType : hashMapMetaData.keySet()) {
    String headerStringName = new String("name");
    String headerStringMembers = new String("members");
    Element packageElement = document.createElement("types");
    rootElement.appendChild(packageElement);
    // Add each members in its Own Metadatatype
    for (String members : hashMapMetaData.get(metaDataType)) {
     Element headerElement = document
       .createElement(headerStringMembers);
     packageElement.appendChild(headerElement);
     headerElement.appendChild(document.createTextNode(members));
    }
    Element headerElement = document
      .createElement(headerStringName);
    packageElement.appendChild(headerElement);
    headerElement
      .appendChild(document.createTextNode(metaDataType));
   }
   // Add Version at end of XML doc
   Element packageElement = document.createElement("version");
   rootElement.appendChild(packageElement);
   packageElement.appendChild(document.createTextNode("32.0"));

   // Format XML File
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer();
   // Add indentation to output
   transformer.setOutputProperty(OutputKeys.INDENT, "yes");
   transformer.setOutputProperty(
     "{http://xml.apache.org/xslt}indent-amount", "2");

   DOMSource source = new DOMSource(document);
   StreamResult result = new StreamResult(new File("package.xml"));
   transformer.transform(source, result);
   System.out.println("Package.xml generated Successfully");

  } catch (IOException e) {
   System.out.println("IOException " + e.getMessage());
  } catch (ParserConfigurationException e) {
   System.out
     .println("ParserConfigurationException " + e.getMessage());
  } catch (TransformerConfigurationException e) {
   System.out.println("TransformerConfigurationException "
     + e.getMessage());
  } catch (TransformerException e) {
   System.out.println("TransformerException " + e.getMessage()
     + e.getMessageAndLocation());
  }
 }
 public void createMetadataMap(String metaType, String object, String member) {
  ArrayList<String> memberSet = new ArrayList<>();
  if (metaType != null && member != null && object != null) {
   // System.out.println("Before IF Inside" + object + metaType);
   if (prefixObjectMetaType.contains(metaType)) {
    member = object + "." + member;
   } else if (metaType.equalsIgnoreCase("Layout")) {
    // System.out.println("object Inside" + object + metaType);
    member = object + "-" + member;
   } else if (folderComponents.contains(metaType)) {
    member = object + "/" + member;
   }
   if (hashMapMetaData.keySet().contains(metaType)) {
    memberSet = hashMapMetaData.get(metaType);
    memberSet.add(member);
    hashMapMetaData.put(metaType, memberSet);
   } else {
    memberSet.add(member);
    hashMapMetaData.put(metaType, memberSet);
   }
  }
 }

 public static void main(String[] args) {
  POIExcelReader poiExample = new POIExcelReader();
  if (!(args.length == 0)) {
   String xlsPath = System.getProperty("user.dir").toString() + "\\"
     + args[0];
   System.out.println("The Excel File Path is ==" + xlsPath);
   poiExample.displayFromExcel(xlsPath);
  } else {
   System.out
     .println("Please put the Excel file in current folder and provide the fileName as an argument");
   System.exit(0);
  }


 }
}
5. execute Java program
6. check for workspace folder, file package.xml should have been created.
7. Configure ant to use this xml file and deploy the components.

This is my first blog post and its 4.00AM IST so please neglect any mistakes or not a blog language. Will learn! :) I am waiting for your feedback and suggestions on this post. Happy Coding !!! :)


Friday, February 5, 2010

Choosing A Good Domain Name

Another good tip for successful web experience..injoy it!



Choosing A Good Domain Name


Choosing a domain name for your site is one of the most important steps towards creating the perfect internet presence. If you run an on-line business, picking a name that will be marketable and achieve success in search engine placement is paramount. Many factors must be considered when choosing a good domain name. This article summarizes all the different things to consider before making that final registration step!


Short and Sweet

Domain names can be really long or really short (1 - 67 characters). In general, it is far better to choose a domain name that is short in length. The shorter your domain name, the easier it will be for people remember. Remembering a domain name is very important from a marketability perspective. As visitors reach your site and enjoy using it, they will likely tell people about it. And those people may tell others, etc. As with any business, word of mouth is the most powerful marketing tool to drive traffic to your site (and it's free too!). If your site is long and difficult to pronounce, people will not remember the name of the site and unless they bookmark the link, they may never return.



Your Ad Here





Consider Alternatives



Unless a visitor reaches your site through a bookmark or a link from another site, they have typed in your domain name. Most people on the internet are terrible typists and misspell words constantly. If your domain name is easy to misspell, you should think about alternate domain names to purchase. For example, if your site will be called "MikesTools.com", you should also consider buying "MikeTools.com" and "MikeTool.com". You should also secure the different top level domain names besides the one you will use for marketing purposes ("MikesTools.net", "MikesTools.org", etc.) You should also check to see if there are existing sites based on the misspelled version of the domain name you are considering. "MikesTools.com" may be available, but "MikesTool.com" may be home to a graphic pornography site. You would hate for a visitor to walk away thinking you were hosting something they did not expect.

Also consider domain names that may not include the name of your company, but rather what your company provides. For example, if the name of your company is Mike's Tools, you may want to consider domain names that target what you sell. For example: "buyhammers.com" or "hammer-and-nail.com". Even though these example alternative domain names do not include the name of your company, it provides an avenue for visitors from your target markets. Remember that you can own multiple domain names, all of which can point to a single domain. For example, you could register "buyhammers.com", "hammer-and-nail.com", and "mikestools.com" and have "buyhammers.com" and "hammer-and-nail.com" point to "mikestools.com".


Hyphens: Your Friend and Enemy

Domain name availability has become more and more scant over the years. Many single word domain names have been scooped up which it makes it more and more difficult to find a domain name that you like and is available. When selecting a domain name, you have the option of including hyphens as part of the name. Hyphens help because it allows you to clearly separate multiple words in a domain name, making it less likely that a person will accidentally misspell the name. For example, people are more likely to misspell "domainnamecenter.com" than they are "domain-name-center.com". Having words crunched together makes it hard on the eyes, increasing the likelihood of a misspelling. On the other hand, hyphens make your domain name longer. The longer the domain name, the easier it is for people to forget it altogether. Also, if someone recommends a site to someone else, they may forget to mention that each word in the domain name is separated by a hyphen. If do you choose to leverage hyphens, limit the number of words between the hyphens to three. Another advantage to using hyphens is that search engines are able to pick up each unique word in the domain name as key words, thus helping to make your site more visible in search engine results.



Your Ad Here





Dot What?

There are many top level domain names available today including .com, .net, .org, and .biz. In most cases, the more unusual the top level domain, the more available domain names are available. However, the .com top level domain is far and away the most commonly used domain on the internet, driven by the fact that it was the first domain extension put to use commercially and has received incredible media attention. If you cannot lay your hands on a .com domain name, look for a .net domain name, which is the second most commercially popular domain name extension.


Long Arm of the Law

Be very careful not to register domain names that include trademarked names. Although internet domain name law disputes are tricky and have few cases in existence, the risk of a legal battle is not a risk worth taking. Even if you believe your domain name is untouchable by a business that has trademarked a name, do not take the chance: the cost of litigation is extremely high and unless you have deep pockets you will not likely have the resources to defend yourself in a court of law. Even stay away from domain names in which part of the name is trademarked: the risks are the same.




Your Ad Here




Search Engines and Directories

All search engines and directories are different. Each has a unique process for being part of the results or directory listing and each has a different way of sorting and listing domain names. Search engines and directories are the most important on-line marketing channel, so consider how your domain name choice affects site placement before you register the domain. Most directories simply list links to home pages in alphabetical order. If possible, choose a domain name with a letter of the alphabet near the beginning ("a" or "b"). For example, "aardvark-pest-control.com" will come way above "joes-pest-control.com". However, check the directories before you choose a domain name. You may find that the directories you would like be in are already cluttered with domain names beginning with the letter "a". Search engines scan websites and sort results based on key words. Key words are words that a person visiting a search engine actually search on. Having key words as part of your domain name can help you get better results.




Your Ad Here