Sunday, April 20, 2014

Mail Notifications

To receive email notification in your mail box you need to set verb for the following methods:

1. Method Name : mail >> Verb : .\mail.exe
2. Method Name : dm_event_sender >> Verb : .\dmbasic.exe -f.\dm_html_sender.ebs -eMail
3. Method Name : smail >> Verb : .\smail.exe -server <your smtp server ip/name>

For setting the verb you need to login thru DA.

Monday, April 7, 2014

Deep Export from Documentum to desktop

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfDocument;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.operations.IDfExportNode;
import com.documentum.operations.IDfExportOperation;

/**
 *
 */

/**
 * @author mpoli_fujitsu
 *
 */
public class DeepExport {

/**
* @param args
* @throws DfException
*/

public static void main(String[] args) throws DfException {

IDfSessionManager sesMgr = getSessionMgr();
IDfSession session = sesMgr.getSession("XXXX");
IDfCollection rs = null;
IDfQuery query = new DfQuery();
query.setDQL(" SELECT   r_object_id,object_name,r_folder_path FROM   dm_folder WHERE  folder('/XXXX/Departments/Finance/Accounting/General Ledger/XXX Archived Files',descend)");
rs = query.execute(session, 0);
if (rs != null) {
while (rs.next()) {
//System.out.println(rs.getString("r_folder_path"));
String str=rs.getString("r_folder_path");
//String str1=str.substring(58);
//System.out.println(str1);
//folderCreation(str1,session);
//String str2="/XXXXX/Departments/Finance/Accounting/General Ledger".concat(str1);
try{

IDfCollection rs1 = null;
IDfQuery query1 = new DfQuery();
System.out.println(" SELECT * FROM  dm_document WHERE  folder('"+str+"')");
query1.setDQL(" SELECT * FROM  dm_document WHERE  folder('"+str+"')");
rs1 = query1.execute(session, 0);
if (rs1 != null) {
while (rs1.next()) {
System.out.println(rs1.getString("object_name"));
IDfDocument doc=(IDfDocument)session.getObject(new DfId(rs1.getString("r_object_id")));
IDfClientX clientx = new DfClientX();
IDfExportOperation eo = clientx.getExportOperation();
IDfExportNode node = (IDfExportNode) eo.add(doc);
String localpath="D:/Stock".concat(str.substring(58));
System.out.println("localpath----"+localpath);
node.setFilePath(localpath+"/"+rs1.getString("object_name")+"."+doc.getContentType());
if (eo.execute())
{
System.out.println("Export operation successful.");
}
else
{
System.out.println("Export operation failed.");
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
}

private static IDfSessionManager getSessionMgr(){
IDfSessionManager sessionMgr = null;
try{

IDfClientX clientx = new DfClientX();
IDfClient client = clientx.getLocalClient();
sessionMgr = client.newSessionManager();
IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
loginInfoObj.setUser("dmadmin");
loginInfoObj.setPassword("xxx);
sessionMgr.setIdentity("XXX", loginInfoObj);

}catch(DfException exp){
exp.printStackTrace();
}
return sessionMgr;

}
public static void folderCreation(String str,IDfSession session)
{
boolean dirFlag = false;
String str1="D:/Stock";
File stockDir = new File(str1.concat(str));
try {
dirFlag = stockDir.mkdirs();
} catch (SecurityException Se) {
System.out.println("Error while creating directory in Java:" + Se);
}
if (dirFlag)
System.out.println("Directory created successfully");
else
System.out.println("Directory was not created successfully");
//exportDocuments(str,session);
}


public  static void exportDocuments(String path,IDfSession session)
{
String str="/XXXXx/Departments/Finance/Accounting/General Ledger".concat(path);
try{

IDfCollection rs = null;
IDfQuery query = new DfQuery();
query.setDQL(" SELECT * FROM  dm_document WHERE  folder('"+str+"')");
rs = query.execute(session, 0);
if (rs != null) {
while (rs.next()) {
System.out.println(rs.getString("object_name"));
IDfDocument doc=(IDfDocument)session.getObject(new DfId(rs.getString("r_object_id")));
IDfClientX clientx = new DfClientX();
IDfExportOperation eo = clientx.getExportOperation();
IDfExportNode node = (IDfExportNode) eo.add(doc);
String localpath="D:/Stock".concat(path);
System.out.println("localpath----"+localpath);
node.setFilePath(localpath+"."+doc.getContentType());
if (eo.execute())
{
System.out.println("Export operation successful.");
}
else
{
System.out.println("Export operation failed.");
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public static String checkSpecialChar(String inputString)
{
Pattern pattern = Pattern.compile("[^a-z0-9]", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputString);
boolean b = matcher.find();
if(b)
{
System.out.println();
return inputString.replaceAll("[^a-zA-Z0-9]", "-");
}else
return inputString;
}
}

Deep Export to Documentum from local desktop

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfDocument;
import com.documentum.fc.client.IDfFolder;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.operations.IDfImportNode;
import com.documentum.operations.IDfImportOperation;

/**
 *
 */

/**
 * @author mpoli_fujitsu
 *
 */
public class DeepImport {
  //static String parentLocation="dfgdgdgdg";
/**
* @param args
* @throws DfException
*/
public static void main(String[] args) throws DfException {
System.out.println("dsfsdfsd");
File sourceLocation=new File("dfgdgdgd");
File targetLocation=new File("dfgdgdgdg");

try {
copyDirectory(sourceLocation , targetLocation );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


public static void copyDirectory(File sourceLocation , File targetLocation) throws IOException, DfException {
if (sourceLocation.isDirectory()) {

//System.out.println("Folder exists sourece Locaion*********************"+targetLocation.getParent());
// System.out.println("Folder name_________________________________________"+targetLocation.getName());
// System.out.println("ParentFolder name_++++++++++++++++++++++++++++++++++++++"+targetLocation.getParent());
createFolder(targetLocation.getParent(),targetLocation.getName());
//targetLocation.mkdir();



String[] children = sourceLocation.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
//System.out.println("Folder  sourece Locaion*********************"+sourceLocation);
}
} else {
System.out.println("sourece Locaion*********************"+sourceLocation.getName());
IDfSessionManager sesMgr = getSessionMgr();
IDfSession session = sesMgr.getSession("EDMS");
IDfClientX _clientx = new DfClientX();
IDfImportOperation _opi = _clientx.getImportOperation();
_opi.setSession(session);

IDfFolder _folder = session.getFolderByPath((targetLocation.getParent()).replace('\\', '/'));


_opi.setDestinationFolderId(_folder.getObjectId());

IDfImportNode _impNode = (IDfImportNode) _opi.add(sourceLocation.toString());
if (_impNode == null)
System.out.println ("Node is null.");

_impNode.setDocbaseObjectType("qd_project_doc");
_impNode.setNewObjectName(sourceLocation.getName());


//_opi.setSession(_dfcSes);
//
if (_opi.execute())
{
IDfDocument _newObj = (IDfDocument) _impNode.getNewObject();
_newObj.setObjectName(sourceLocation.getName());
_newObj.setString("process_area_name","Lusail Project Management");
_newObj.setString("document_type_name","Letter");
//_newObj.setOwnerName(_OWNER);
String resultString =
("Item" + _opi.getNewObjects().toString() +" imported successfully.");
System.out.println(resultString);
}
else
{
System.out.println ("Error during import operation.");
}

/*IDfDocument newFolder = (IDfDocument) session.newObject("dm_document");
newFolder.setObjectName(sourceLocation.getName());
//.replace('\\', '/');
newFolder.link((targetLocation.getParent()).replace('\\', '/'));
newFolder.save();*/
}
}
private static IDfSessionManager getSessionMgr(){
IDfSessionManager sessionMgr = null;
try{

IDfClientX clientx = new DfClientX();
IDfClient client = clientx.getLocalClient();
sessionMgr = client.newSessionManager();
IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
loginInfoObj.setUser("dmadmin");
loginInfoObj.setPassword("fgfdg");
sessionMgr.setIdentity("dfgdg", loginInfoObj);

}catch(DfException exp){
exp.printStackTrace();
}
return sessionMgr;

}
private static void createFolder(String edmsLocation,String folderName) throws DfException
{
System.out.println("edmsLocation*********************"+edmsLocation);
if(folderName.equalsIgnoreCase("Section - 3")){
System.out.println("Folder Name Washington Parcel A");
}else{
System.out.println("Folder name_________________________________________"+folderName);
IDfSessionManager sesMgr = getSessionMgr();
IDfSession session = sesMgr.getSession("EDMS");
IDfFolder newFolder = (IDfFolder) session.newObject("qd_folder");
newFolder.setObjectName(folderName);
//.replace('\\', '/');
newFolder.link(edmsLocation.replace('\\', '/'));
newFolder.save();
}
}
}