/**
*
*/
package dfs;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.codehaus.groovy.ant.FileScanner;
import com.documentum.xms.core.recipe.config.PropertySet;
import com.emc.documentum.fs.datamodel.core.DataObject;
import com.emc.documentum.fs.datamodel.core.DataPackage;
import com.emc.documentum.fs.datamodel.core.ObjectIdentity;
import com.emc.documentum.fs.datamodel.core.ObjectIdentitySet;
import com.emc.documentum.fs.datamodel.core.ObjectPath;
import com.emc.documentum.fs.datamodel.core.OperationOptions;
import com.emc.documentum.fs.datamodel.core.Qualification;
import com.emc.documentum.fs.datamodel.core.ReferenceRelationship;
import com.emc.documentum.fs.datamodel.core.Relationship;
import com.emc.documentum.fs.datamodel.core.VersionInfo;
import com.emc.documentum.fs.datamodel.core.VersionStrategy;
import com.emc.documentum.fs.datamodel.core.content.FileContent;
import com.emc.documentum.fs.datamodel.core.content.RenditionType;
import com.emc.documentum.fs.datamodel.core.context.RepositoryIdentity;
import com.emc.documentum.fs.datamodel.core.profiles.ContentProfile;
import com.emc.documentum.fs.datamodel.core.profiles.FormatFilter;
import com.emc.documentum.fs.datamodel.core.profiles.PageFilter;
import com.emc.documentum.fs.datamodel.core.profiles.PageModifierFilter;
import com.emc.documentum.fs.rt.ServiceException;
import com.emc.documentum.fs.rt.ServiceInvocationException;
import com.emc.documentum.fs.rt.context.ContextFactory;
import com.emc.documentum.fs.rt.context.IServiceContext;
import com.emc.documentum.fs.rt.context.ServiceFactory;
import com.emc.documentum.fs.services.core.CoreServiceException;
import com.emc.documentum.fs.services.core.client.IObjectService;
import com.emc.documentum.fs.services.core.client.IVersionControlService;
import com.emc.documentum.fs.services.core.impl.ObjectService;
/**
* @author mpoli_fujitsu
*
*/
public class SimpleClient {
public static final String repositoyName="XXXX";
public static final String userName="XXX";
public static final String passWord="XXXX";
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IObjectService ios=ServiceFactory.getInstance().getRemoteService(IObjectService.class, seriveContext,"core","http://abcdf:9080/services");
String file="D:/CTS_6.7_installation.pdf";
/* String folderPath="/Test";
//createWithContentDefaultContext(file,ios);
DataPackage obj= createAndLinkToFolder(folderPath,ios,file);
List<DataObject> dataObjects = obj.getDataObjects();
for (DataObject dObj : dataObjects)
{
com.emc.documentum.fs.datamodel.core.properties.PropertySet docProperties = dObj.getProperties();
String objectId = dObj.getIdentity().getValueAsString();
System.out.println(objectId);
}*/
//System.out.println(ps.get("r_object_id").getValueAsObject());
Qualification qualification=new Qualification("dm_document where r_object_id='09021e3c80036e0c'");
ObjectIdentity targetObjectIdentity=new ObjectIdentity(qualification,"XXXX");
checkin(targetObjectIdentity,file);
/*ObjectIdentitySet objidset=new ObjectIdentitySet(targetObjectIdentity);
OperationOptions opts=new OperationOptions();
DataPackage datapack=ios.get(objidset, opts);*/
/*Iterator itr=datapack.getDataObjects().iterator();
while(itr.hasNext())
{
System.out.println("success");
DataObject dobj=(DataObject)itr.next();
com.emc.documentum.fs.datamodel.core.properties.PropertySet ps=dobj.getProperties();
System.out.println(ps.get("object_name").getValueAsString());
System.out.println("title"+ps.get("title").getValueAsString());
ps.set("title","new title addedd");
}*/
}
public static DataPackage createWithContentDefaultContext(String filePath,IObjectService ios)
throws ServiceException
{
File testFile = new File(filePath);
if (!testFile.exists())
{
throw new RuntimeException("Test file: " +
testFile.toString() +
" does not exist");
}
ObjectIdentity objIdentity = new ObjectIdentity(repositoyName);
DataObject dataObject = new DataObject(objIdentity, "dm_document");
com.emc.documentum.fs.datamodel.core.properties.PropertySet properties = dataObject.getProperties();
properties.set("object_name", "MyImage");
properties.set("title", "MyImage");
properties.set("a_content_type", "gif");
dataObject.getContents().add(new FileContent(testFile.getAbsolutePath(), "pdf"));
OperationOptions operationOptions = null;
return ios.create(new DataPackage(dataObject), operationOptions);
}
public static DataPackage createAndLinkToFolder(String folderPath,IObjectService ios,String filePath)
{
try
{
File testFile = new File(filePath);
if (!testFile.exists())
{
throw new RuntimeException("Test file: " +testFile.toString() +" does not exist");
}
// create a contentless document to link into folder
String objectName = testFile.getName();
ObjectIdentity sampleObjId = new ObjectIdentity(repositoyName);
DataObject sampleDataObject = new DataObject(sampleObjId, "dm_document");
sampleDataObject.getProperties().set("object_name", objectName);
sampleDataObject.getContents().add(new FileContent(testFile.getAbsolutePath(), "pdf"));
// add the folder to link to as a ReferenceRelationship
ObjectPath objectPath = new ObjectPath(folderPath);
ObjectIdentity<ObjectPath> sampleFolderIdentity = new ObjectIdentity<ObjectPath>(objectPath, repositoyName);
ReferenceRelationship sampleFolderRelationship = new ReferenceRelationship();
sampleFolderRelationship.setName(Relationship.RELATIONSHIP_FOLDER);
sampleFolderRelationship.setTarget(sampleFolderIdentity);
sampleFolderRelationship.setTargetRole(Relationship.ROLE_PARENT);
sampleDataObject.getRelationships().add(sampleFolderRelationship);
// create a new document linked into parent folder
OperationOptions operationOptions = null;
DataPackage dataPackage = new DataPackage(sampleDataObject);
ios.create(dataPackage, operationOptions);
// System.out.println("before create"+);
return ios.create(dataPackage, operationOptions);
}
catch (ServiceException e)
{
throw new RuntimeException(e);
}
}
public static DataPackage checkout(ObjectIdentity objIdentity)
throws ServiceException
{
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IVersionControlService versionControlService=ServiceFactory.getInstance().getRemoteService(IVersionControlService.class, seriveContext,"core","http://abcdf::9080/services");
ObjectIdentitySet objIdSet = new ObjectIdentitySet();
objIdSet.getIdentities().add(objIdentity);
OperationOptions operationOptions = null;
DataPackage resultDp;
try
{
resultDp = versionControlService.checkout(objIdSet, operationOptions);
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
System.out.println("Checkout successful");
List<VersionInfo> vInfo = versionControlService.getVersionInfo(objIdSet);
VersionInfo versionInfo = vInfo.get(0);
System.out.println("Printing version info for " + versionInfo.getIdentity());
System.out.println("isCurrent is " + versionInfo.isCurrent());
System.out.println("Version is " + versionInfo.getVersion());
System.out.println("Symbolic labels are: ");
for (String label : versionInfo.getSymbolicLabels())
{
System.out.println(label);
}
//versionControlService.cancelCheckout(objIdSet);
//System.out.println("Checkout cancelled");
return resultDp;
}
public static DataPackage checkin(ObjectIdentity objIdentity, String newContentPath)
throws Exception
{
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IVersionControlService versionControlService=ServiceFactory.getInstance().getRemoteService(IVersionControlService.class, seriveContext,"core","http://abcdf::9080/services");
ObjectIdentitySet objIdSet = new ObjectIdentitySet();
objIdSet.getIdentities().add(objIdentity);
OperationOptions operationOptions = new OperationOptions();
ContentProfile contentProfile = new ContentProfile(FormatFilter.ANY, null,PageFilter.ANY,-1,PageModifierFilter.ANY,null);
operationOptions.setContentProfile(contentProfile);
DataPackage checkinPackage = versionControlService.checkout(objIdSet, operationOptions);
DataObject checkinObj = checkinPackage.getDataObjects().get(0);
checkinObj.setContents(null);
FileContent newContent = new FileContent();
newContent.setLocalPath(newContentPath);
// newContent.setRenditionType(RenditionType.PRIMARY);
newContent.setFormat(getExtension(newContentPath));
checkinObj.getContents().add(newContent);
boolean retainLock = false;
List<String> labels = new ArrayList<String>();
labels.add("CURRENT");
DataPackage resultDp;
try
{
resultDp = versionControlService.checkin(checkinPackage,VersionStrategy.NEXT_MINOR,retainLock,labels,operationOptions);
}
catch (ServiceException sE)
{
sE.printStackTrace();
throw new RuntimeException(sE);
}
return resultDp;
}
private static final String getExtension(final String FPATH) {
//final String FPATH = "/home/mem/index.html";
Filename myHomePage = new Filename(FPATH, '/', '.');
System.out.println("Extension = " + myHomePage.extension());
System.out.println("Filename = " + myHomePage.filename());
System.out.println("Path = " + myHomePage.path());
return myHomePage.extension();
}
}
class Filename {
private String fullPath;
private char pathSeparator, extensionSeparator;
public Filename(String str, char sep, char ext) {
fullPath = str;
pathSeparator = sep;
extensionSeparator = ext;
}
public String extension() {
int dot = fullPath.lastIndexOf(extensionSeparator);
return fullPath.substring(dot + 1);
}
public String filename() { // gets filename without extension
int dot = fullPath.lastIndexOf(extensionSeparator);
int sep = fullPath.lastIndexOf(pathSeparator);
return fullPath.substring(sep + 1, dot);
}
public String path() {
int sep = fullPath.lastIndexOf(pathSeparator);
return fullPath.substring(0, sep);
}
}
*
*/
package dfs;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.codehaus.groovy.ant.FileScanner;
import com.documentum.xms.core.recipe.config.PropertySet;
import com.emc.documentum.fs.datamodel.core.DataObject;
import com.emc.documentum.fs.datamodel.core.DataPackage;
import com.emc.documentum.fs.datamodel.core.ObjectIdentity;
import com.emc.documentum.fs.datamodel.core.ObjectIdentitySet;
import com.emc.documentum.fs.datamodel.core.ObjectPath;
import com.emc.documentum.fs.datamodel.core.OperationOptions;
import com.emc.documentum.fs.datamodel.core.Qualification;
import com.emc.documentum.fs.datamodel.core.ReferenceRelationship;
import com.emc.documentum.fs.datamodel.core.Relationship;
import com.emc.documentum.fs.datamodel.core.VersionInfo;
import com.emc.documentum.fs.datamodel.core.VersionStrategy;
import com.emc.documentum.fs.datamodel.core.content.FileContent;
import com.emc.documentum.fs.datamodel.core.content.RenditionType;
import com.emc.documentum.fs.datamodel.core.context.RepositoryIdentity;
import com.emc.documentum.fs.datamodel.core.profiles.ContentProfile;
import com.emc.documentum.fs.datamodel.core.profiles.FormatFilter;
import com.emc.documentum.fs.datamodel.core.profiles.PageFilter;
import com.emc.documentum.fs.datamodel.core.profiles.PageModifierFilter;
import com.emc.documentum.fs.rt.ServiceException;
import com.emc.documentum.fs.rt.ServiceInvocationException;
import com.emc.documentum.fs.rt.context.ContextFactory;
import com.emc.documentum.fs.rt.context.IServiceContext;
import com.emc.documentum.fs.rt.context.ServiceFactory;
import com.emc.documentum.fs.services.core.CoreServiceException;
import com.emc.documentum.fs.services.core.client.IObjectService;
import com.emc.documentum.fs.services.core.client.IVersionControlService;
import com.emc.documentum.fs.services.core.impl.ObjectService;
/**
* @author mpoli_fujitsu
*
*/
public class SimpleClient {
public static final String repositoyName="XXXX";
public static final String userName="XXX";
public static final String passWord="XXXX";
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IObjectService ios=ServiceFactory.getInstance().getRemoteService(IObjectService.class, seriveContext,"core","http://abcdf:9080/services");
String file="D:/CTS_6.7_installation.pdf";
/* String folderPath="/Test";
//createWithContentDefaultContext(file,ios);
DataPackage obj= createAndLinkToFolder(folderPath,ios,file);
List<DataObject> dataObjects = obj.getDataObjects();
for (DataObject dObj : dataObjects)
{
com.emc.documentum.fs.datamodel.core.properties.PropertySet docProperties = dObj.getProperties();
String objectId = dObj.getIdentity().getValueAsString();
System.out.println(objectId);
}*/
//System.out.println(ps.get("r_object_id").getValueAsObject());
Qualification qualification=new Qualification("dm_document where r_object_id='09021e3c80036e0c'");
ObjectIdentity targetObjectIdentity=new ObjectIdentity(qualification,"XXXX");
checkin(targetObjectIdentity,file);
/*ObjectIdentitySet objidset=new ObjectIdentitySet(targetObjectIdentity);
OperationOptions opts=new OperationOptions();
DataPackage datapack=ios.get(objidset, opts);*/
/*Iterator itr=datapack.getDataObjects().iterator();
while(itr.hasNext())
{
System.out.println("success");
DataObject dobj=(DataObject)itr.next();
com.emc.documentum.fs.datamodel.core.properties.PropertySet ps=dobj.getProperties();
System.out.println(ps.get("object_name").getValueAsString());
System.out.println("title"+ps.get("title").getValueAsString());
ps.set("title","new title addedd");
}*/
}
public static DataPackage createWithContentDefaultContext(String filePath,IObjectService ios)
throws ServiceException
{
File testFile = new File(filePath);
if (!testFile.exists())
{
throw new RuntimeException("Test file: " +
testFile.toString() +
" does not exist");
}
ObjectIdentity objIdentity = new ObjectIdentity(repositoyName);
DataObject dataObject = new DataObject(objIdentity, "dm_document");
com.emc.documentum.fs.datamodel.core.properties.PropertySet properties = dataObject.getProperties();
properties.set("object_name", "MyImage");
properties.set("title", "MyImage");
properties.set("a_content_type", "gif");
dataObject.getContents().add(new FileContent(testFile.getAbsolutePath(), "pdf"));
OperationOptions operationOptions = null;
return ios.create(new DataPackage(dataObject), operationOptions);
}
public static DataPackage createAndLinkToFolder(String folderPath,IObjectService ios,String filePath)
{
try
{
File testFile = new File(filePath);
if (!testFile.exists())
{
throw new RuntimeException("Test file: " +testFile.toString() +" does not exist");
}
// create a contentless document to link into folder
String objectName = testFile.getName();
ObjectIdentity sampleObjId = new ObjectIdentity(repositoyName);
DataObject sampleDataObject = new DataObject(sampleObjId, "dm_document");
sampleDataObject.getProperties().set("object_name", objectName);
sampleDataObject.getContents().add(new FileContent(testFile.getAbsolutePath(), "pdf"));
// add the folder to link to as a ReferenceRelationship
ObjectPath objectPath = new ObjectPath(folderPath);
ObjectIdentity<ObjectPath> sampleFolderIdentity = new ObjectIdentity<ObjectPath>(objectPath, repositoyName);
ReferenceRelationship sampleFolderRelationship = new ReferenceRelationship();
sampleFolderRelationship.setName(Relationship.RELATIONSHIP_FOLDER);
sampleFolderRelationship.setTarget(sampleFolderIdentity);
sampleFolderRelationship.setTargetRole(Relationship.ROLE_PARENT);
sampleDataObject.getRelationships().add(sampleFolderRelationship);
// create a new document linked into parent folder
OperationOptions operationOptions = null;
DataPackage dataPackage = new DataPackage(sampleDataObject);
ios.create(dataPackage, operationOptions);
// System.out.println("before create"+);
return ios.create(dataPackage, operationOptions);
}
catch (ServiceException e)
{
throw new RuntimeException(e);
}
}
public static DataPackage checkout(ObjectIdentity objIdentity)
throws ServiceException
{
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IVersionControlService versionControlService=ServiceFactory.getInstance().getRemoteService(IVersionControlService.class, seriveContext,"core","http://abcdf::9080/services");
ObjectIdentitySet objIdSet = new ObjectIdentitySet();
objIdSet.getIdentities().add(objIdentity);
OperationOptions operationOptions = null;
DataPackage resultDp;
try
{
resultDp = versionControlService.checkout(objIdSet, operationOptions);
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
System.out.println("Checkout successful");
List<VersionInfo> vInfo = versionControlService.getVersionInfo(objIdSet);
VersionInfo versionInfo = vInfo.get(0);
System.out.println("Printing version info for " + versionInfo.getIdentity());
System.out.println("isCurrent is " + versionInfo.isCurrent());
System.out.println("Version is " + versionInfo.getVersion());
System.out.println("Symbolic labels are: ");
for (String label : versionInfo.getSymbolicLabels())
{
System.out.println(label);
}
//versionControlService.cancelCheckout(objIdSet);
//System.out.println("Checkout cancelled");
return resultDp;
}
public static DataPackage checkin(ObjectIdentity objIdentity, String newContentPath)
throws Exception
{
ContextFactory contextfact= ContextFactory.getInstance();
IServiceContext seriveContext=contextfact.newContext();
RepositoryIdentity repid=new RepositoryIdentity();
repid.setRepositoryName(repositoyName);
repid.setPassword(passWord);
repid.setUserName(userName);
seriveContext.addIdentity(repid);
IVersionControlService versionControlService=ServiceFactory.getInstance().getRemoteService(IVersionControlService.class, seriveContext,"core","http://abcdf::9080/services");
ObjectIdentitySet objIdSet = new ObjectIdentitySet();
objIdSet.getIdentities().add(objIdentity);
OperationOptions operationOptions = new OperationOptions();
ContentProfile contentProfile = new ContentProfile(FormatFilter.ANY, null,PageFilter.ANY,-1,PageModifierFilter.ANY,null);
operationOptions.setContentProfile(contentProfile);
DataPackage checkinPackage = versionControlService.checkout(objIdSet, operationOptions);
DataObject checkinObj = checkinPackage.getDataObjects().get(0);
checkinObj.setContents(null);
FileContent newContent = new FileContent();
newContent.setLocalPath(newContentPath);
// newContent.setRenditionType(RenditionType.PRIMARY);
newContent.setFormat(getExtension(newContentPath));
checkinObj.getContents().add(newContent);
boolean retainLock = false;
List<String> labels = new ArrayList<String>();
labels.add("CURRENT");
DataPackage resultDp;
try
{
resultDp = versionControlService.checkin(checkinPackage,VersionStrategy.NEXT_MINOR,retainLock,labels,operationOptions);
}
catch (ServiceException sE)
{
sE.printStackTrace();
throw new RuntimeException(sE);
}
return resultDp;
}
private static final String getExtension(final String FPATH) {
//final String FPATH = "/home/mem/index.html";
Filename myHomePage = new Filename(FPATH, '/', '.');
System.out.println("Extension = " + myHomePage.extension());
System.out.println("Filename = " + myHomePage.filename());
System.out.println("Path = " + myHomePage.path());
return myHomePage.extension();
}
}
class Filename {
private String fullPath;
private char pathSeparator, extensionSeparator;
public Filename(String str, char sep, char ext) {
fullPath = str;
pathSeparator = sep;
extensionSeparator = ext;
}
public String extension() {
int dot = fullPath.lastIndexOf(extensionSeparator);
return fullPath.substring(dot + 1);
}
public String filename() { // gets filename without extension
int dot = fullPath.lastIndexOf(extensionSeparator);
int sep = fullPath.lastIndexOf(pathSeparator);
return fullPath.substring(sep + 1, dot);
}
public String path() {
int sep = fullPath.lastIndexOf(pathSeparator);
return fullPath.substring(0, sep);
}
}
I’ve been looking all over for this! Thank goodness I found it on Google. You have made my day! Thanks again! Keep update more excellent posts..
ReplyDeleteDocument Management Software India
Document Management Software Chennai
Document Management Software