pradeepdsp
Programmer
Hi Expert,
I have attached a sample program where i have to get records from livelink content server and i need to sort first based on folder and Documents based on Alphabets
I tried by sortByRegion=OTName&sortByRegion=OTSubType this didnt work is their any way to solve this.
Below is sample code:
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.net.URL;
import javax.xml.soap.*;
import javax.xml.namespace.QName;
import javax.xml.ws.soap.MTOMFeature;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import com.sun.xml.internal.ws.developer.WSBindingProvider;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Headers;
import com.opentext.livelink.service.core.*;
import com.opentext.livelink.service.docman.*;
import com.opentext.livelink.service.docman.Node;
import com.opentext.livelink.service.searchservices.*;
import com.opentext.livelink.service.memberservice.MemberService;
import com.opentext.livelink.service.memberservice.MemberService_Service;
import com.opentext.livelink.service.collaboration.Collaboration;
import com.opentext.livelink.service.collaboration.Collaboration_Service;
import com.opentext.livelink.service.lesconfig.ConfigService;
import com.opentext.livelink.service.lesconfig.ConfigService_Service;
import com.opentext.livelink.service.workflowservice.WorkflowService;
import com.opentext.livelink.service.workflowservice.WorkflowService_Service;
import com.opentext.ecm.api.OTAuthentication;
public class TestLiveLink{
final static String NET_WSDL_LOCATION = " final static String JAVA_WSDL_LOCATION = " //" //"
final static String NET_OR_JAVA = "JAVA"; //".NET" or "JAVA";
final static String CORE_NAMESPACE = "urn:Core.service.livelink.opentext.com";
final static String COLLABORATION_NAMESPACE = "urn:Collaboration.service.livelink.opentext.com";
final static String CONFIG_NAMESPACE = "urn:LesConfig.service.livelink.opentext.com";
final static String MEMBER_NAMESPACE = "urn:MemberService.service.livelink.opentext.com";
final static String WORKFLOW_NAMESPACE = "urn:WorkflowService.service.livelink.opentext.com";
final static String DOCMAN_NAMESPACE = "urnocMan.service.livelink.opentext.com";
final static String SEARCH_NAMESPACE = "urn:SearchServices.service.livelink.opentext.com";
final static String ECM_API_NAMESPACE = "urn:api.ecm.opentext.com";
public static void main(String[] args){
String admToken;
try{
System.out.println("********************** SERVICE USED "+ NET_OR_JAVA + " **********************");
admToken = getAuthenticationToken("Test1", "Password2");
DocumentManagement dm = getDMService(admToken);
SearchService searchService = getSearchService(admToken);
AdminService as = getAdminService(admToken);
Collaboration cs = getCollaborationService(admToken);
MemberService ms = getMemberService(admToken);
ConfigService cons = getConfigService(admToken);
IndexService is = getIndexService(admToken);
WorkflowService ws = getWorkflowService(admToken);
XmlService xs = getXmlService(admToken);
/**
* Node Attributes
* 1. Node ID - Node
* 2. Version - Node - NodeVersionInfo
* 3. Create Date - Node
* 4. File Data Size - Node - NodeVersionInfo
* 5. Created By - Node
* 6. Comments - Node
* 7. Catalog - Node - Value 2 indicates Hidden. Value 0 indicates LIST; 1 indicates FEATURED; 2 indicates HIDDEN.
*/
//DocumentManagement Service
listNodesUsingDocMan(dm);
listNodesUsingNodePageSpecification(dm);
listNodesUsingDocManListNodes(dm);
listUserFavoritesUsingDocMan(dm);
listMetadataLanguageUsingDocMan(dm);
listDocVersionsUsingDocMan(dm);
/**
* OTSubType Details
* 0 - Folder
* 1 - Alias [Shortcut]
* 131 - Category
* 136 - Compound Document
* 140 - URL
* 144 - Document
* 202 - Project
* 204 - Task List
* 207 - Channel
* 215 - Discussion
* 299 - LiveReport
*/
//Search Service
listQueryLanguagesUsingSearch(searchService);
listDataCollectionsUsingSearch(searchService);
listFieldInfoUsingSearch(searchService);
searchBasedOnSubType(searchService);
//DocumentManagement and Content Service
downloadFile(dm, admToken);
uploadFile(dm, admToken);
}catch(Exception e){
e.printStackTrace();
}
}
public static XMLGregorianCalendar getXMLGregorianCalendar(Date date) throws Exception{
XMLGregorianCalendar xmlCalender=null;
GregorianCalendar calender = new GregorianCalendar();
calender.setTime(date);
xmlCalender = DatatypeFactory.newInstance().newXMLGregorianCalendar(calender);
return xmlCalender;
}
private static void uploadFile(DocumentManagement dm, String admToken) {
String name = "TestRJM3.docx";
String comment = "Uploaded through the Web Service";
boolean advancedVersionControl = false;
int parentID = 2000;
String contextId;
String filePath = "E:/Livelink/TestUpload/"+name;
try{
File file = new File(filePath);
if(!file.exists()){
System.out.println("File does not exist at "+filePath);
return;
}
contextId = dm.createDocumentContext(parentID, file.getName(), comment, advancedVersionControl, null);
System.out.println("ContextId is "+contextId);
FileAtts fileAtts = new FileAtts();
fileAtts.setCreatedDate(getXMLGregorianCalendar(new Date(file.lastModified())));
fileAtts.setFileName(file.getName());
fileAtts.setFileSize(file.length());
fileAtts.setModifiedDate(getXMLGregorianCalendar(new Date(file.lastModified())));
ContentService contentService = getContentService(admToken, contextId, fileAtts);
String objectID = contentService.uploadContent(new DataHandler(new FileDataSource(file)));
System.out.println("uploaded object Id:"+objectID);
Node node = dm.getNode(Integer.parseInt(objectID));
System.out.println("Node id is:"+node.getID());
}catch(Exception e){
System.out.println("Upload Failed "+e.getMessage());
}
}
private static void downloadFile(DocumentManagement dm, String admToken) {
//Download the File
int downloadFileId = 5846;
int downloadFileVersion = 2;
String filePath = "E:/";
String fileName = "Issue.xlsx";
System.out.println("------------------------------------------------------------");
System.out.println("Downloading file with ID as "+downloadFileId+" Version "+downloadFileVersion+" to Path \""+filePath+"\" with FileName as \""+fileName+"\"");
try{
String contextID;
contextID = dm.getVersionContentsContext(downloadFileId, downloadFileVersion);
ContentService contentService = getContentService(admToken, contextID, null);
OutputStream os = new FileOutputStream(new File(filePath+fileName));
DataHandler file = contentService.downloadContent(contextID);
file.writeTo(os);
System.out.println("Download SUCCESSFUL");
}catch(Exception ee){
System.out.println("Download Failed "+ee.getMessage());
}
}
private static void listDocVersionsUsingDocMan(DocumentManagement dm) {
//List All Versions based on Node ID
int documentId = 3015;
Node node = dm.getNode(documentId);
if(!node.isIsContainer()){
List<Version> allVersions = node.getVersionInfo().getVersions();
if(allVersions.size() > 1){
for(Version version : allVersions){
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.print("Comment : "+version.getComment());
System.out.print(" : CreateDate : "+convertDate(version.getCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileCreateDate : "+convertDate(version.getFileCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileDataSize : "+version.getFileDataSize()+"bytes");
System.out.print(" : FileModifyDate : "+convertDate(version.getFileModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : FileName : "+version.getFilename());
System.out.print(" : FileType : "+version.getFileType());
System.out.print(" : ID : "+version.getID());
System.out.print(" : MimeType : "+version.getMimeType());
System.out.print(" : ModifyDate : "+convertDate(version.getModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : NodeID : "+version.getNodeID());
System.out.print(" : Number : "+version.getNumber());
System.out.print(" : Owner : "+version.getOwner());
System.out.print(" : VerMajor : "+version.getVerMajor());
System.out.println(" : VerMinor : "+version.getVerMinor());
}
} else {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.print("Comment : "+allVersions.get(0).getComment());
System.out.print(" : CreateDate : "+convertDate(allVersions.get(0).getCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileCreateDate : "+convertDate(allVersions.get(0).getFileCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileDataSize : "+allVersions.get(0).getFileDataSize()+"bytes");
System.out.print(" : FileModifyDate : "+convertDate(allVersions.get(0).getFileModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : FileName : "+allVersions.get(0).getFilename());
System.out.print(" : FileType : "+allVersions.get(0).getFileType());
System.out.print(" : ID : "+allVersions.get(0).getID());
System.out.print(" : MimeType : "+allVersions.get(0).getMimeType());
System.out.print(" : ModifyDate : "+convertDate(allVersions.get(0).getModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : NodeID : "+allVersions.get(0).getNodeID());
System.out.print(" : Number : "+allVersions.get(0).getNumber());
System.out.print(" : Owner : "+allVersions.get(0).getOwner());
System.out.print(" : VerMajor : "+allVersions.get(0).getVerMajor());
System.out.println(" : VerMinor : "+allVersions.get(0).getVerMinor());
}
}
}
private static void searchBasedOnSubType(SearchService searchService) {
SingleSearchRequest singleSearchRequest = new SingleSearchRequest();
singleSearchRequest.setDataCollectionSpec("'LES Enterprise'");
singleSearchRequest.setQueryLanguage("Livelink Search API V1");
singleSearchRequest.setFirstResultToRetrieve(1);
singleSearchRequest.setNumResultsToRetrieve(100);
//singleSearchRequest.setResultOrderSpec("sortByRegion=OTCreatedBy"); //sortDirecton=ascending
singleSearchRequest.setResultOrderSpec("sortByRegion=OTName&sortDirection=ascending"); //sortDirecton=ascending
//singleSearchRequest.setResultSetSpec("where1=(\"OTSubType\":0 OR \"OTSubType\":1 OR \"OTSubType\":144) AND OTLocation:* 3349 *");
singleSearchRequest.setResultSetSpec("where1=(\"OTSubType\":0 OR \"OTSubType\":1 OR \"OTSubType\":144) AND \"OTParentID\":2000 AND \"OTModifyDate\":<20140818");
/**
* OTSubType Details
* 0 - Folder
* 1 - Alias [Shortcut]
* 131 - Category
* 136 - Compound Document
* 140 - URL
* 144 - Document
* 202 - Project
* 204 - Task List
* 207 - Channel
* 215 - Discussion
* 299 - LiveReport
*/
//singleSearchRequest.setResultSetSpec("where1=*LITE*");
//singleSearchRequest.getResultTransformationSpec().add("OTAssignedToName"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTCreateDate"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTCreatedByName"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateAssigned"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateCompleted"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateDue"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateStarted"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTDCategory");
//singleSearchRequest.getResultTransformationSpec().add("OTDComment"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTFileType");
singleSearchRequest.getResultTransformationSpec().add("OTLocation");
singleSearchRequest.getResultTransformationSpec().add("OTMIMEType");
//singleSearchRequest.getResultTransformationSpec().add("OTModifyDate"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTName");
singleSearchRequest.getResultTransformationSpec().add("OTObject");
singleSearchRequest.getResultTransformationSpec().add("OTObjectDate");
singleSearchRequest.getResultTransformationSpec().add("OTObjectSize");
singleSearchRequest.getResultTransformationSpec().add("OTDataSize");
singleSearchRequest.getResultTransformationSpec().add("OTDataID");
singleSearchRequest.getResultTransformationSpec().add("OTParentID");
singleSearchRequest.getResultTransformationSpec().add("OTSubTypeName");
singleSearchRequest.getResultTransformationSpec().add("OTSubType");
singleSearchRequest.getResultTransformationSpec().add("OTNodeGUID");
//singleSearchRequest.getResultTransformationSpec().add("OTReservedByName"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTReservedDate"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTSubType"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("Score");/*Score not allowed when using sortByRegion*/
singleSearchRequest.getResultTransformationSpec().add("OTDocTitle");
singleSearchRequest.getResultTransformationSpec().add("OTFileType");
singleSearchRequest.getResultTransformationSpec().add("OTVersion");
singleSearchRequest.getResultTransformationSpec().add("OTVersionName");
singleSearchRequest.getResultTransformationSpec().add("OTModifyDate");
SingleSearchResponse results = searchService.search(singleSearchRequest, "");
System.out.println("------------------------SEARCH FOR DOCUMENTS OF TYPE .docx------------------------------------");
if(results != null){
SResultPage srp = results.getResults();
List<SGraph> sra = results.getResultAnalysis();
if(srp != null){
List<SGraph> items = srp.getItem();
List<DataBagType> types = srp.getType();
System.out.println("------------------------SEARCH RESULTS------------------------------------");
if(items != null && types != null && items.size() > 0){
Hashtable<String, Hashtable<String, String>> regionTypes = new Hashtable<String, Hashtable<String, String>>();
SNode regionNode = sra.get(0).getN().get(0);
for(int i=0; i<types.size(); i++){
Hashtable<String, String> regions = new Hashtable<String, String>();
for(int j=0; j<regionNode.getS().size(); j++){
if (i < results.getType().size()){
regions.put(results.getType().get(i).getStrings().get(j), regionNode.getS().get(j));
}
}
regionTypes.put(types.get(i).getID(), regions);
}
System.out.println("Search Results:"+srp.getListDescription().getListHead()+" to "+srp.getListDescription().getIncludeCount()+" of about "+srp.getListDescription().getActualCount());
/*System.out.println("Number of items:"+items.size());
System.out.println("Number of types:"+types.size());*/
DataBagType type = types.get(0);
Hashtable<String, String> regionNames = regionTypes.get(type.getID());
/*System.out.println("Type ID = " + type.getID());
System.out.println("Type Strings = "+(type.getStrings() != null ? type.getStrings().size() : 0));
System.out.println("Type Integers = "+(type.getInts() != null ? type.getInts().size() : 0));
System.out.println("Type Dates = "+(type.getDates() != null ? type.getDates().size() : 0));
System.out.println("Type Reals = "+(type.getReals() != null ? type.getReals().size() : 0));*/
int itemCount = 0;
for(SGraph item : items){
itemCount++;
System.out.println("Item #"+itemCount+" (ID="+item.getID()+"):");
List<SNode> nodes = item.getN();
String friendlyRegion;
String originalRegion;
for (SNode node : nodes) {
if (node.getS() != null) {
for (int i = 0; i < node.getS().size(); i++) {
originalRegion = type.getStrings().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getS().get(i));
}
}
if (node.getI() != null) {
for (int i = 0; i < node.getI().size(); i++) {
originalRegion = type.getInts().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getI().get(i));
}
}
if (node.getD() != null) {
for (int i = 0; i < node.getD().size(); i++) {
originalRegion = type.getDates().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getD().get(i));
}
}
if (node.getR() != null) {
for (int i = 0; i < node.getR().size(); i++) {
originalRegion = type.getReals().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getR().get(i));
}
}
}
System.out.println("");
}
} else {
System.out.println("No Results found");
}
}
}
System.out.println("------------------------SEARCH COMPLETED------------------------------------");
}
private static void listFieldInfoUsingSearch(SearchService searchService) {
System.out.println("------------------------FIELDINFO LIST------------------------------------");
List<FieldInfo> fieldInfoList = searchService.getFieldInfo("'LES Enterprise'", null);
for(FieldInfo fieldInfo : fieldInfoList){
System.out.println("FieldInfo Name: \""+fieldInfo.getName() +"\" FieldInfo Type: \""+fieldInfo.getType()+"\" FieldInfo isRetrievable: \""+fieldInfo.isRetrievable()+"\" FieldInfo isSearchable: \""+fieldInfo.isSearchable()+"\"");
}
}
private static void listDataCollectionsUsingSearch(SearchService searchService) {
System.out.println("------------------------DATA COLLECTIONS------------------------------------");
List dataCollections = searchService.getDataCollections();
for(Object dataCollection : dataCollections){
System.out.println("dataCollection:"+dataCollection);
}
}
private static void listQueryLanguagesUsingSearch(SearchService searchService) {
System.out.println("------------------------QUERY LANGUAGES------------------------------------");
List queryLanguages = searchService.getSupportedQueryLanguages();
for(Object language : queryLanguages){
System.out.println("queryLanguage:"+language);
}
}
private static void listMetadataLanguageUsingDocMan(DocumentManagement dm) {
System.out.println("------------------------METADATA LANGUAGES------------------------------------");
List<MetadataLanguage> mdlList = dm.getMetadataLanguages();
if(mdlList != null && mdlList.size() > 0){
for(MetadataLanguage mdl: mdlList){
System.out.println("MDL Name:"+mdl.getName());
System.out.println("MDL Language:"+mdl.getLanguageCode());
}
}
}
private static void listUserFavoritesUsingDocMan(DocumentManagement dm) {
List<Node> favorites;
favorites = dm.getAllFavorites();
System.out.println("-----------------------FAVORITES LIST-------------------------------------");
System.out.println("Total number of Favorites for this user are "+favorites.size());
//List the Favorites
int favoriteCounter = 0;
if(favorites.size() > 0){
for(Node node : favorites){
favoriteCounter++;
NodeVersionInfo nvi = node.getVersionInfo();
System.out.print("Favorite "+ favoriteCounter + " is a ");
if(node.isIsContainer()){
System.out.print("FOLDER with ");
} else {
System.out.print("DOCUMENT with ");
}
System.out.print("ID as "+node.getID() +" :: Name is \""+node.getName()+"\"");
if(nvi != null){
System.out.println(" :: Current Version is : "+nvi.getVersionNum());
} else {
System.out.println("");
}
}
} else {
System.out.println("No Favorites");
}
}
private static void listNodesUsingDocMan(DocumentManagement dm) {
GetNodesInContainerOptions gnico = new GetNodesInContainerOptions();
gnico.setMaxDepth(0); //Depth 0 - default listing. Depth 1 - One level down
gnico.setMaxResults(100);
//TODO:Try listNodesByPage method
List<String> rootNodeTypes = dm.getRootNodeTypes();
if(rootNodeTypes.size() > 0){
for (String rootNodeType : rootNodeTypes) {
//Node workSpace = dm.getRootNode("EnterpriseWS"); //"PersonalWS";
Node workSpace = dm.getRootNode(rootNodeType);
if(workSpace.getPermissions().isSeeContentsPermission()){
List<Node> nodeList = dm.getNodesInContainer(workSpace.getID(), gnico);
int documentCount = 0;
int folderCount = 0;
int shortcutCount = 0;
System.out.println("************************************************************************************************************************");
System.out.print("Workspace name is \"" + workSpace.getName() + "\" with ID as " + workSpace.getID() + " and Type as \"" + workSpace.getType() + "\" and Display Type as \"" + workSpace.getDisplayType() + "\"");
if (nodeList.size() > 0) {
System.out.println(" and there are a Total of " + nodeList.size() + " Objects");
System.out.println("");
System.out.println("Listed below are the Documents and Folders available in the " + workSpace.getName() + " workspace");
System.out.println("------------------------------------------------------------");
for (Node node : nodeList) {
if ("Document".equalsIgnoreCase(node.getType())) {
System.out.println("Node is of type DOCUMENT with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\"");
documentCount++;
}
if (node.isIsContainer() && "Folder".equalsIgnoreCase(node.getType())) {
System.out.println("Node is of type FOLDER with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\"");
folderCount++;
}
if (node.isIsReference() && "Alias".equalsIgnoreCase(node.getType())) {
Node originalNode = dm.getNode(node.getReferenceInfo().getOriginalID());
System.out.println("Node is of type SHORTCUT with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\" :: Original ID " + originalNode.getID() + " \t:: Original Parent ID "+ originalNode.getParentID() + " \t:: Original Node Name is \"" + originalNode.getName() + "\" :: Original Type " + originalNode.getType());
shortcutCount++;
}
}
System.out.println("------------------------------------------------------------");
System.out.println("Total number of Documents in this workspace : " + documentCount);
System.out.println("Total number of Folders in this workspace : " + folderCount);
System.out.println("Total number of Shortcuts in this workspace : " + shortcutCount);
/*System.out.println("*************************************************************");
NodePageSpecification nps = new NodePageSpecification();
nps.getIncludeTypes().add("0");
nps.getIncludeTypes().add("144");
nps.setPageNumber(1);
NodePageResult nodeResult = dm.listNodesByPage(workSpace.getID(), nps);
System.out.println("nodeResult size:"+nodeResult.getNodes().size());
System.out.println("*************************************************************");*/
} else {
System.out.println(" and there are ZERO Objects in this workspace");
}
} else {
System.out.println("USER DOES NOT HAVE PERMISSION TO SEE CONTENTS IN \""+workSpace.getName()+"\" WORKSPACE");
}
}
}
}
private static void listNodesUsingNodePageSpecification(DocumentManagement dm) {
NodePageSpecification nps = new NodePageSpecification();
//nps.getIncludeTypes().add("\"Document\"");
nps.getIncludeTypes().add("Folder");
//nps.getIncludeTypes().add("Alias");
nps.setPageSize(100);
nps.setPageNumber(1);
NodePageResult nodeResult = dm.listNodesByPage(2000, nps);
System.out.println("NODE RESULT"+nodeResult.getNodes().size());
List<Node> nodes = nodeResult.getNodes();
int counter = 0;
for(Node node : nodes){
counter++;
System.out.println(counter+" Node ID: "+node.getID()+" :: Node Name:"+node.getName()+" :: Reserved:"+node.getPermissions().isReservePermission()+" :: See Contents:"+node.getPermissions().isSeeContentsPermission()+" :: See:"+node.getPermissions().isSeePermission());
}
}
private static void listNodesUsingDocManListNodes(DocumentManagement dm) {
List<Node> nodes = dm.listNodes(3241, false);
int counter = 0;
for(Node node : nodes){
counter++;
System.out.println(counter+" Node ID: "+node.getID()+" :: Node Name:"+node.getName()+" :: Reserved:"+node.getPermissions().isReservePermission()+" :: See Contents:"+node.getPermissions().isSeeContentsPermission()+" :: See:"+node.getPermissions().isSeePermission()+" :: Num of Version:"+node.getVersionInfo().getVersions().size());
}
}
private static SearchService getSearchService(String authToken) throws Exception{
URL url = null;
URL baseUrl = SearchService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "SearchService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "SearchService?wsdl");
}
SearchService_Service searchService = new SearchService_Service(url, new QName(SEARCH_NAMESPACE, "SearchService"));
SearchService endpoint = searchService.getBasicHttpBindingSearchService();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
/*SearchService_Service searchService = new SearchService_Service();
SearchService endpoint = searchService.getBasicHttpBindingSearchService();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, "");
return endpoint;*/
}
private static ContentService getContentService(String authToken, String contextID, FileAtts fileAtts) throws Exception{
URL url = null;
URL baseUrl = ContentService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "ContentService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "ContentService?wsdl");
}
ContentService_Service contentService = new ContentService_Service(url, new QName(CORE_NAMESPACE, "ContentService"));
ContentService endpoint = contentService.getBasicHttpBindingContentService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, contextID, fileAtts);
return endpoint;
/*ContentService_Service contentService = new ContentService_Service();
ContentService endpoint = contentService.getBasicHttpBindingContentService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, contextID);
return endpoint;*/
}
private static AdminService getAdminService(String authToken) throws Exception{
URL url = null;
URL baseUrl = AdminService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "AdminService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "AdminService?wsdl");
}
AdminService_Service adminService = new AdminService_Service(url, new QName(CORE_NAMESPACE, "AdminService"));
AdminService endpoint = adminService.getBasicHttpBindingAdminService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static Collaboration getCollaborationService(String authToken) throws Exception{
URL url = null;
URL baseUrl = Collaboration_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "Collaboration.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "Collaboration?wsdl");
}
Collaboration_Service collaborationService = new Collaboration_Service(url, new QName(COLLABORATION_NAMESPACE, "Collaboration"));
Collaboration endpoint = collaborationService.getBasicHttpBindingCollaboration(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static ConfigService getConfigService(String authToken) throws Exception{
URL url = null;
URL baseUrl = ConfigService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "ConfigService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "ConfigService?wsdl");
}
ConfigService_Service configService = new ConfigService_Service(url, new QName(CONFIG_NAMESPACE, "ConfigService"));
ConfigService endpoint = configService.getBasicHttpBindingConfigService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static IndexService getIndexService(String authToken) throws Exception{
URL url = null;
URL baseUrl = IndexService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "IndexService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "IndexService?wsdl");
}
IndexService_Service indexService = new IndexService_Service(url, new QName(SEARCH_NAMESPACE, "IndexService"));
IndexService endpoint = indexService.getBasicHttpBindingIndexService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static MemberService getMemberService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "MemberService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "MemberService?wsdl");
}
MemberService_Service memberService = new MemberService_Service(url, new QName(MEMBER_NAMESPACE, "MemberService"));
MemberService endpoint = memberService.getBasicHttpBindingMemberService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static WorkflowService getWorkflowService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "WorkflowService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "WorkflowService?wsdl");
}
WorkflowService_Service workflowService = new WorkflowService_Service(url, new QName(WORKFLOW_NAMESPACE, "WorkflowService"));
WorkflowService endpoint = workflowService.getBasicHttpBindingWorkflowService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static XmlService getXmlService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "XmlService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "XmlService?wsdl");
}
XmlService_Service xmlService = new XmlService_Service(url, new QName(CORE_NAMESPACE, "XmlService"));
XmlService endpoint = xmlService.getBasicHttpBindingXmlService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static DocumentManagement getDMService(String authToken) throws Exception{
URL url = null;
URL baseUrl = DocumentManagement_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "DocumentManagement.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "DocumentManagement?wsdl");
}
DocumentManagement_Service service = new DocumentManagement_Service(url, new QName(DOCMAN_NAMESPACE, "DocumentManagement"));
DocumentManagement endpoint = service.getBasicHttpBindingDocumentManagement();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
/*DocumentManagement_Service service = new DocumentManagement_Service();
DocumentManagement endpoint = service.getBasicHttpBindingDocumentManagement();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, "");
return endpoint;*/
}
public static void setSoapHeader(WSBindingProvider bindingProvider, OTAuthentication otAuth, String contextID, FileAtts fileAtts) throws Exception{
List<Header> headers = new ArrayList<Header>();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
headers.add(getOTAuthenticationHeader(header, otAuth));
if(!"".equals(contextID)){
headers.add(getContentIDElementHeader(header, contextID));
}
if(fileAtts != null){
headers.add(getFileAttsElementHeader(header, fileAtts));
}
bindingProvider.setOutboundHeaders(headers);
}
public static void setSoapHeader(WSBindingProvider bindingProvider, OTAuthentication otAuth) throws Exception{
List<Header> headers = new ArrayList<Header>();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
headers.add(getOTAuthenticationHeader(header, otAuth));
bindingProvider.setOutboundHeaders(headers);
}
public static Header getContentIDElementHeader (SOAPHeader header, String contextID) throws Exception{
SOAPHeaderElement contextIDElement;
contextIDElement = header.addHeaderElement(new QName(CORE_NAMESPACE, "contextID"));
contextIDElement.addTextNode(contextID);
return Headers.create(contextIDElement);
}
public static Header getFileAttsElementHeader (SOAPHeader header, FileAtts fileAtts) throws Exception{
SOAPHeaderElement fileAttsElement;
fileAttsElement = header.addHeaderElement(new QName(CORE_NAMESPACE, "fileAtts"));
SOAPElement createdDateElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "CreatedDate"));
createdDateElement.addTextNode(fileAtts.getCreatedDate().toString());
SOAPElement modifiedDateElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "ModifiedDate"));
modifiedDateElement.addTextNode(fileAtts.getModifiedDate().toString());
SOAPElement fileSizeElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "FileSize"));
fileSizeElement.addTextNode(fileAtts.getFileSize().toString());
SOAPElement fileNameElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "FileName"));
fileNameElement.addTextNode(fileAtts.getFileName());
return Headers.create(fileAttsElement);
}
public static Header getOTAuthenticationHeader(SOAPHeader header, OTAuthentication otAuth) throws Exception{
SOAPHeaderElement otAuthElement;
otAuthElement = header.addHeaderElement(new QName(ECM_API_NAMESPACE, "OTAuthentication"));
otAuthElement.setPrefix("");
SOAPElement authTokenElement;
authTokenElement = otAuthElement.addChildElement(new QName(ECM_API_NAMESPACE, "AuthenticationToken"));
authTokenElement.setPrefix( "" );
authTokenElement.addTextNode(otAuth.getAuthenticationToken());
return Headers.create(otAuthElement);
}
private static String getAuthenticationToken(String userName, String password) throws Exception{
URL url = null;
URL baseUrl = Authentication_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "Authentication.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "Authentication?wsdl");
}
String token;
Authentication endpoint;
Authentication_Service service = new Authentication_Service(url, new QName(CORE_NAMESPACE, "Authentication"));
endpoint = service.getBasicHttpBindingAuthentication();
token = endpoint.authenticateUser(userName, password);
return token;
/*String token;
Authentication endpoint;
Authentication_Service service = new Authentication_Service();
endpoint = service.getBasicHttpBindingAuthentication();
token = endpoint.authenticateUser(userName, password);
return token;*/
}
private static String convertDate(Date date){
try{
SimpleDateFormat sdf = new SimpleDateFormat("dd/Mon/yyyy");
sdf.setCalendar(Calendar.getInstance());
return sdf.parse(date.toString()).toString();
}catch(Exception e){
return date.toString();
}
}
}
I have attached a sample program where i have to get records from livelink content server and i need to sort first based on folder and Documents based on Alphabets
I tried by sortByRegion=OTName&sortByRegion=OTSubType this didnt work is their any way to solve this.
Below is sample code:
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.net.URL;
import javax.xml.soap.*;
import javax.xml.namespace.QName;
import javax.xml.ws.soap.MTOMFeature;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import com.sun.xml.internal.ws.developer.WSBindingProvider;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Headers;
import com.opentext.livelink.service.core.*;
import com.opentext.livelink.service.docman.*;
import com.opentext.livelink.service.docman.Node;
import com.opentext.livelink.service.searchservices.*;
import com.opentext.livelink.service.memberservice.MemberService;
import com.opentext.livelink.service.memberservice.MemberService_Service;
import com.opentext.livelink.service.collaboration.Collaboration;
import com.opentext.livelink.service.collaboration.Collaboration_Service;
import com.opentext.livelink.service.lesconfig.ConfigService;
import com.opentext.livelink.service.lesconfig.ConfigService_Service;
import com.opentext.livelink.service.workflowservice.WorkflowService;
import com.opentext.livelink.service.workflowservice.WorkflowService_Service;
import com.opentext.ecm.api.OTAuthentication;
public class TestLiveLink{
final static String NET_WSDL_LOCATION = " final static String JAVA_WSDL_LOCATION = " //" //"
final static String NET_OR_JAVA = "JAVA"; //".NET" or "JAVA";
final static String CORE_NAMESPACE = "urn:Core.service.livelink.opentext.com";
final static String COLLABORATION_NAMESPACE = "urn:Collaboration.service.livelink.opentext.com";
final static String CONFIG_NAMESPACE = "urn:LesConfig.service.livelink.opentext.com";
final static String MEMBER_NAMESPACE = "urn:MemberService.service.livelink.opentext.com";
final static String WORKFLOW_NAMESPACE = "urn:WorkflowService.service.livelink.opentext.com";
final static String DOCMAN_NAMESPACE = "urnocMan.service.livelink.opentext.com";
final static String SEARCH_NAMESPACE = "urn:SearchServices.service.livelink.opentext.com";
final static String ECM_API_NAMESPACE = "urn:api.ecm.opentext.com";
public static void main(String[] args){
String admToken;
try{
System.out.println("********************** SERVICE USED "+ NET_OR_JAVA + " **********************");
admToken = getAuthenticationToken("Test1", "Password2");
DocumentManagement dm = getDMService(admToken);
SearchService searchService = getSearchService(admToken);
AdminService as = getAdminService(admToken);
Collaboration cs = getCollaborationService(admToken);
MemberService ms = getMemberService(admToken);
ConfigService cons = getConfigService(admToken);
IndexService is = getIndexService(admToken);
WorkflowService ws = getWorkflowService(admToken);
XmlService xs = getXmlService(admToken);
/**
* Node Attributes
* 1. Node ID - Node
* 2. Version - Node - NodeVersionInfo
* 3. Create Date - Node
* 4. File Data Size - Node - NodeVersionInfo
* 5. Created By - Node
* 6. Comments - Node
* 7. Catalog - Node - Value 2 indicates Hidden. Value 0 indicates LIST; 1 indicates FEATURED; 2 indicates HIDDEN.
*/
//DocumentManagement Service
listNodesUsingDocMan(dm);
listNodesUsingNodePageSpecification(dm);
listNodesUsingDocManListNodes(dm);
listUserFavoritesUsingDocMan(dm);
listMetadataLanguageUsingDocMan(dm);
listDocVersionsUsingDocMan(dm);
/**
* OTSubType Details
* 0 - Folder
* 1 - Alias [Shortcut]
* 131 - Category
* 136 - Compound Document
* 140 - URL
* 144 - Document
* 202 - Project
* 204 - Task List
* 207 - Channel
* 215 - Discussion
* 299 - LiveReport
*/
//Search Service
listQueryLanguagesUsingSearch(searchService);
listDataCollectionsUsingSearch(searchService);
listFieldInfoUsingSearch(searchService);
searchBasedOnSubType(searchService);
//DocumentManagement and Content Service
downloadFile(dm, admToken);
uploadFile(dm, admToken);
}catch(Exception e){
e.printStackTrace();
}
}
public static XMLGregorianCalendar getXMLGregorianCalendar(Date date) throws Exception{
XMLGregorianCalendar xmlCalender=null;
GregorianCalendar calender = new GregorianCalendar();
calender.setTime(date);
xmlCalender = DatatypeFactory.newInstance().newXMLGregorianCalendar(calender);
return xmlCalender;
}
private static void uploadFile(DocumentManagement dm, String admToken) {
String name = "TestRJM3.docx";
String comment = "Uploaded through the Web Service";
boolean advancedVersionControl = false;
int parentID = 2000;
String contextId;
String filePath = "E:/Livelink/TestUpload/"+name;
try{
File file = new File(filePath);
if(!file.exists()){
System.out.println("File does not exist at "+filePath);
return;
}
contextId = dm.createDocumentContext(parentID, file.getName(), comment, advancedVersionControl, null);
System.out.println("ContextId is "+contextId);
FileAtts fileAtts = new FileAtts();
fileAtts.setCreatedDate(getXMLGregorianCalendar(new Date(file.lastModified())));
fileAtts.setFileName(file.getName());
fileAtts.setFileSize(file.length());
fileAtts.setModifiedDate(getXMLGregorianCalendar(new Date(file.lastModified())));
ContentService contentService = getContentService(admToken, contextId, fileAtts);
String objectID = contentService.uploadContent(new DataHandler(new FileDataSource(file)));
System.out.println("uploaded object Id:"+objectID);
Node node = dm.getNode(Integer.parseInt(objectID));
System.out.println("Node id is:"+node.getID());
}catch(Exception e){
System.out.println("Upload Failed "+e.getMessage());
}
}
private static void downloadFile(DocumentManagement dm, String admToken) {
//Download the File
int downloadFileId = 5846;
int downloadFileVersion = 2;
String filePath = "E:/";
String fileName = "Issue.xlsx";
System.out.println("------------------------------------------------------------");
System.out.println("Downloading file with ID as "+downloadFileId+" Version "+downloadFileVersion+" to Path \""+filePath+"\" with FileName as \""+fileName+"\"");
try{
String contextID;
contextID = dm.getVersionContentsContext(downloadFileId, downloadFileVersion);
ContentService contentService = getContentService(admToken, contextID, null);
OutputStream os = new FileOutputStream(new File(filePath+fileName));
DataHandler file = contentService.downloadContent(contextID);
file.writeTo(os);
System.out.println("Download SUCCESSFUL");
}catch(Exception ee){
System.out.println("Download Failed "+ee.getMessage());
}
}
private static void listDocVersionsUsingDocMan(DocumentManagement dm) {
//List All Versions based on Node ID
int documentId = 3015;
Node node = dm.getNode(documentId);
if(!node.isIsContainer()){
List<Version> allVersions = node.getVersionInfo().getVersions();
if(allVersions.size() > 1){
for(Version version : allVersions){
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.print("Comment : "+version.getComment());
System.out.print(" : CreateDate : "+convertDate(version.getCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileCreateDate : "+convertDate(version.getFileCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileDataSize : "+version.getFileDataSize()+"bytes");
System.out.print(" : FileModifyDate : "+convertDate(version.getFileModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : FileName : "+version.getFilename());
System.out.print(" : FileType : "+version.getFileType());
System.out.print(" : ID : "+version.getID());
System.out.print(" : MimeType : "+version.getMimeType());
System.out.print(" : ModifyDate : "+convertDate(version.getModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : NodeID : "+version.getNodeID());
System.out.print(" : Number : "+version.getNumber());
System.out.print(" : Owner : "+version.getOwner());
System.out.print(" : VerMajor : "+version.getVerMajor());
System.out.println(" : VerMinor : "+version.getVerMinor());
}
} else {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.print("Comment : "+allVersions.get(0).getComment());
System.out.print(" : CreateDate : "+convertDate(allVersions.get(0).getCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileCreateDate : "+convertDate(allVersions.get(0).getFileCreateDate().toGregorianCalendar().getTime()));
System.out.print(" : FileDataSize : "+allVersions.get(0).getFileDataSize()+"bytes");
System.out.print(" : FileModifyDate : "+convertDate(allVersions.get(0).getFileModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : FileName : "+allVersions.get(0).getFilename());
System.out.print(" : FileType : "+allVersions.get(0).getFileType());
System.out.print(" : ID : "+allVersions.get(0).getID());
System.out.print(" : MimeType : "+allVersions.get(0).getMimeType());
System.out.print(" : ModifyDate : "+convertDate(allVersions.get(0).getModifyDate().toGregorianCalendar().getTime()));
System.out.print(" : NodeID : "+allVersions.get(0).getNodeID());
System.out.print(" : Number : "+allVersions.get(0).getNumber());
System.out.print(" : Owner : "+allVersions.get(0).getOwner());
System.out.print(" : VerMajor : "+allVersions.get(0).getVerMajor());
System.out.println(" : VerMinor : "+allVersions.get(0).getVerMinor());
}
}
}
private static void searchBasedOnSubType(SearchService searchService) {
SingleSearchRequest singleSearchRequest = new SingleSearchRequest();
singleSearchRequest.setDataCollectionSpec("'LES Enterprise'");
singleSearchRequest.setQueryLanguage("Livelink Search API V1");
singleSearchRequest.setFirstResultToRetrieve(1);
singleSearchRequest.setNumResultsToRetrieve(100);
//singleSearchRequest.setResultOrderSpec("sortByRegion=OTCreatedBy"); //sortDirecton=ascending
singleSearchRequest.setResultOrderSpec("sortByRegion=OTName&sortDirection=ascending"); //sortDirecton=ascending
//singleSearchRequest.setResultSetSpec("where1=(\"OTSubType\":0 OR \"OTSubType\":1 OR \"OTSubType\":144) AND OTLocation:* 3349 *");
singleSearchRequest.setResultSetSpec("where1=(\"OTSubType\":0 OR \"OTSubType\":1 OR \"OTSubType\":144) AND \"OTParentID\":2000 AND \"OTModifyDate\":<20140818");
/**
* OTSubType Details
* 0 - Folder
* 1 - Alias [Shortcut]
* 131 - Category
* 136 - Compound Document
* 140 - URL
* 144 - Document
* 202 - Project
* 204 - Task List
* 207 - Channel
* 215 - Discussion
* 299 - LiveReport
*/
//singleSearchRequest.setResultSetSpec("where1=*LITE*");
//singleSearchRequest.getResultTransformationSpec().add("OTAssignedToName"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTCreateDate"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTCreatedByName"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateAssigned"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateCompleted"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateDue"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTDateStarted"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTDCategory");
//singleSearchRequest.getResultTransformationSpec().add("OTDComment"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTFileType");
singleSearchRequest.getResultTransformationSpec().add("OTLocation");
singleSearchRequest.getResultTransformationSpec().add("OTMIMEType");
//singleSearchRequest.getResultTransformationSpec().add("OTModifyDate"); /*NOT RETRIEVABLE*/
singleSearchRequest.getResultTransformationSpec().add("OTName");
singleSearchRequest.getResultTransformationSpec().add("OTObject");
singleSearchRequest.getResultTransformationSpec().add("OTObjectDate");
singleSearchRequest.getResultTransformationSpec().add("OTObjectSize");
singleSearchRequest.getResultTransformationSpec().add("OTDataSize");
singleSearchRequest.getResultTransformationSpec().add("OTDataID");
singleSearchRequest.getResultTransformationSpec().add("OTParentID");
singleSearchRequest.getResultTransformationSpec().add("OTSubTypeName");
singleSearchRequest.getResultTransformationSpec().add("OTSubType");
singleSearchRequest.getResultTransformationSpec().add("OTNodeGUID");
//singleSearchRequest.getResultTransformationSpec().add("OTReservedByName"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTReservedDate"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("OTSubType"); /*NOT RETRIEVABLE*/
//singleSearchRequest.getResultTransformationSpec().add("Score");/*Score not allowed when using sortByRegion*/
singleSearchRequest.getResultTransformationSpec().add("OTDocTitle");
singleSearchRequest.getResultTransformationSpec().add("OTFileType");
singleSearchRequest.getResultTransformationSpec().add("OTVersion");
singleSearchRequest.getResultTransformationSpec().add("OTVersionName");
singleSearchRequest.getResultTransformationSpec().add("OTModifyDate");
SingleSearchResponse results = searchService.search(singleSearchRequest, "");
System.out.println("------------------------SEARCH FOR DOCUMENTS OF TYPE .docx------------------------------------");
if(results != null){
SResultPage srp = results.getResults();
List<SGraph> sra = results.getResultAnalysis();
if(srp != null){
List<SGraph> items = srp.getItem();
List<DataBagType> types = srp.getType();
System.out.println("------------------------SEARCH RESULTS------------------------------------");
if(items != null && types != null && items.size() > 0){
Hashtable<String, Hashtable<String, String>> regionTypes = new Hashtable<String, Hashtable<String, String>>();
SNode regionNode = sra.get(0).getN().get(0);
for(int i=0; i<types.size(); i++){
Hashtable<String, String> regions = new Hashtable<String, String>();
for(int j=0; j<regionNode.getS().size(); j++){
if (i < results.getType().size()){
regions.put(results.getType().get(i).getStrings().get(j), regionNode.getS().get(j));
}
}
regionTypes.put(types.get(i).getID(), regions);
}
System.out.println("Search Results:"+srp.getListDescription().getListHead()+" to "+srp.getListDescription().getIncludeCount()+" of about "+srp.getListDescription().getActualCount());
/*System.out.println("Number of items:"+items.size());
System.out.println("Number of types:"+types.size());*/
DataBagType type = types.get(0);
Hashtable<String, String> regionNames = regionTypes.get(type.getID());
/*System.out.println("Type ID = " + type.getID());
System.out.println("Type Strings = "+(type.getStrings() != null ? type.getStrings().size() : 0));
System.out.println("Type Integers = "+(type.getInts() != null ? type.getInts().size() : 0));
System.out.println("Type Dates = "+(type.getDates() != null ? type.getDates().size() : 0));
System.out.println("Type Reals = "+(type.getReals() != null ? type.getReals().size() : 0));*/
int itemCount = 0;
for(SGraph item : items){
itemCount++;
System.out.println("Item #"+itemCount+" (ID="+item.getID()+"):");
List<SNode> nodes = item.getN();
String friendlyRegion;
String originalRegion;
for (SNode node : nodes) {
if (node.getS() != null) {
for (int i = 0; i < node.getS().size(); i++) {
originalRegion = type.getStrings().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getS().get(i));
}
}
if (node.getI() != null) {
for (int i = 0; i < node.getI().size(); i++) {
originalRegion = type.getInts().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getI().get(i));
}
}
if (node.getD() != null) {
for (int i = 0; i < node.getD().size(); i++) {
originalRegion = type.getDates().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getD().get(i));
}
}
if (node.getR() != null) {
for (int i = 0; i < node.getR().size(); i++) {
originalRegion = type.getReals().get(i);
friendlyRegion = regionNames.containsKey(originalRegion) ? regionNames.get(originalRegion) : originalRegion;
System.out.println(" " + friendlyRegion + " = " + node.getR().get(i));
}
}
}
System.out.println("");
}
} else {
System.out.println("No Results found");
}
}
}
System.out.println("------------------------SEARCH COMPLETED------------------------------------");
}
private static void listFieldInfoUsingSearch(SearchService searchService) {
System.out.println("------------------------FIELDINFO LIST------------------------------------");
List<FieldInfo> fieldInfoList = searchService.getFieldInfo("'LES Enterprise'", null);
for(FieldInfo fieldInfo : fieldInfoList){
System.out.println("FieldInfo Name: \""+fieldInfo.getName() +"\" FieldInfo Type: \""+fieldInfo.getType()+"\" FieldInfo isRetrievable: \""+fieldInfo.isRetrievable()+"\" FieldInfo isSearchable: \""+fieldInfo.isSearchable()+"\"");
}
}
private static void listDataCollectionsUsingSearch(SearchService searchService) {
System.out.println("------------------------DATA COLLECTIONS------------------------------------");
List dataCollections = searchService.getDataCollections();
for(Object dataCollection : dataCollections){
System.out.println("dataCollection:"+dataCollection);
}
}
private static void listQueryLanguagesUsingSearch(SearchService searchService) {
System.out.println("------------------------QUERY LANGUAGES------------------------------------");
List queryLanguages = searchService.getSupportedQueryLanguages();
for(Object language : queryLanguages){
System.out.println("queryLanguage:"+language);
}
}
private static void listMetadataLanguageUsingDocMan(DocumentManagement dm) {
System.out.println("------------------------METADATA LANGUAGES------------------------------------");
List<MetadataLanguage> mdlList = dm.getMetadataLanguages();
if(mdlList != null && mdlList.size() > 0){
for(MetadataLanguage mdl: mdlList){
System.out.println("MDL Name:"+mdl.getName());
System.out.println("MDL Language:"+mdl.getLanguageCode());
}
}
}
private static void listUserFavoritesUsingDocMan(DocumentManagement dm) {
List<Node> favorites;
favorites = dm.getAllFavorites();
System.out.println("-----------------------FAVORITES LIST-------------------------------------");
System.out.println("Total number of Favorites for this user are "+favorites.size());
//List the Favorites
int favoriteCounter = 0;
if(favorites.size() > 0){
for(Node node : favorites){
favoriteCounter++;
NodeVersionInfo nvi = node.getVersionInfo();
System.out.print("Favorite "+ favoriteCounter + " is a ");
if(node.isIsContainer()){
System.out.print("FOLDER with ");
} else {
System.out.print("DOCUMENT with ");
}
System.out.print("ID as "+node.getID() +" :: Name is \""+node.getName()+"\"");
if(nvi != null){
System.out.println(" :: Current Version is : "+nvi.getVersionNum());
} else {
System.out.println("");
}
}
} else {
System.out.println("No Favorites");
}
}
private static void listNodesUsingDocMan(DocumentManagement dm) {
GetNodesInContainerOptions gnico = new GetNodesInContainerOptions();
gnico.setMaxDepth(0); //Depth 0 - default listing. Depth 1 - One level down
gnico.setMaxResults(100);
//TODO:Try listNodesByPage method
List<String> rootNodeTypes = dm.getRootNodeTypes();
if(rootNodeTypes.size() > 0){
for (String rootNodeType : rootNodeTypes) {
//Node workSpace = dm.getRootNode("EnterpriseWS"); //"PersonalWS";
Node workSpace = dm.getRootNode(rootNodeType);
if(workSpace.getPermissions().isSeeContentsPermission()){
List<Node> nodeList = dm.getNodesInContainer(workSpace.getID(), gnico);
int documentCount = 0;
int folderCount = 0;
int shortcutCount = 0;
System.out.println("************************************************************************************************************************");
System.out.print("Workspace name is \"" + workSpace.getName() + "\" with ID as " + workSpace.getID() + " and Type as \"" + workSpace.getType() + "\" and Display Type as \"" + workSpace.getDisplayType() + "\"");
if (nodeList.size() > 0) {
System.out.println(" and there are a Total of " + nodeList.size() + " Objects");
System.out.println("");
System.out.println("Listed below are the Documents and Folders available in the " + workSpace.getName() + " workspace");
System.out.println("------------------------------------------------------------");
for (Node node : nodeList) {
if ("Document".equalsIgnoreCase(node.getType())) {
System.out.println("Node is of type DOCUMENT with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\"");
documentCount++;
}
if (node.isIsContainer() && "Folder".equalsIgnoreCase(node.getType())) {
System.out.println("Node is of type FOLDER with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\"");
folderCount++;
}
if (node.isIsReference() && "Alias".equalsIgnoreCase(node.getType())) {
Node originalNode = dm.getNode(node.getReferenceInfo().getOriginalID());
System.out.println("Node is of type SHORTCUT with ID " + node.getID() + " \t:: Parent ID "+ node.getParentID() + " \t:: Node Name is \"" + node.getName() + "\" :: Original ID " + originalNode.getID() + " \t:: Original Parent ID "+ originalNode.getParentID() + " \t:: Original Node Name is \"" + originalNode.getName() + "\" :: Original Type " + originalNode.getType());
shortcutCount++;
}
}
System.out.println("------------------------------------------------------------");
System.out.println("Total number of Documents in this workspace : " + documentCount);
System.out.println("Total number of Folders in this workspace : " + folderCount);
System.out.println("Total number of Shortcuts in this workspace : " + shortcutCount);
/*System.out.println("*************************************************************");
NodePageSpecification nps = new NodePageSpecification();
nps.getIncludeTypes().add("0");
nps.getIncludeTypes().add("144");
nps.setPageNumber(1);
NodePageResult nodeResult = dm.listNodesByPage(workSpace.getID(), nps);
System.out.println("nodeResult size:"+nodeResult.getNodes().size());
System.out.println("*************************************************************");*/
} else {
System.out.println(" and there are ZERO Objects in this workspace");
}
} else {
System.out.println("USER DOES NOT HAVE PERMISSION TO SEE CONTENTS IN \""+workSpace.getName()+"\" WORKSPACE");
}
}
}
}
private static void listNodesUsingNodePageSpecification(DocumentManagement dm) {
NodePageSpecification nps = new NodePageSpecification();
//nps.getIncludeTypes().add("\"Document\"");
nps.getIncludeTypes().add("Folder");
//nps.getIncludeTypes().add("Alias");
nps.setPageSize(100);
nps.setPageNumber(1);
NodePageResult nodeResult = dm.listNodesByPage(2000, nps);
System.out.println("NODE RESULT"+nodeResult.getNodes().size());
List<Node> nodes = nodeResult.getNodes();
int counter = 0;
for(Node node : nodes){
counter++;
System.out.println(counter+" Node ID: "+node.getID()+" :: Node Name:"+node.getName()+" :: Reserved:"+node.getPermissions().isReservePermission()+" :: See Contents:"+node.getPermissions().isSeeContentsPermission()+" :: See:"+node.getPermissions().isSeePermission());
}
}
private static void listNodesUsingDocManListNodes(DocumentManagement dm) {
List<Node> nodes = dm.listNodes(3241, false);
int counter = 0;
for(Node node : nodes){
counter++;
System.out.println(counter+" Node ID: "+node.getID()+" :: Node Name:"+node.getName()+" :: Reserved:"+node.getPermissions().isReservePermission()+" :: See Contents:"+node.getPermissions().isSeeContentsPermission()+" :: See:"+node.getPermissions().isSeePermission()+" :: Num of Version:"+node.getVersionInfo().getVersions().size());
}
}
private static SearchService getSearchService(String authToken) throws Exception{
URL url = null;
URL baseUrl = SearchService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "SearchService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "SearchService?wsdl");
}
SearchService_Service searchService = new SearchService_Service(url, new QName(SEARCH_NAMESPACE, "SearchService"));
SearchService endpoint = searchService.getBasicHttpBindingSearchService();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
/*SearchService_Service searchService = new SearchService_Service();
SearchService endpoint = searchService.getBasicHttpBindingSearchService();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, "");
return endpoint;*/
}
private static ContentService getContentService(String authToken, String contextID, FileAtts fileAtts) throws Exception{
URL url = null;
URL baseUrl = ContentService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "ContentService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "ContentService?wsdl");
}
ContentService_Service contentService = new ContentService_Service(url, new QName(CORE_NAMESPACE, "ContentService"));
ContentService endpoint = contentService.getBasicHttpBindingContentService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, contextID, fileAtts);
return endpoint;
/*ContentService_Service contentService = new ContentService_Service();
ContentService endpoint = contentService.getBasicHttpBindingContentService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, contextID);
return endpoint;*/
}
private static AdminService getAdminService(String authToken) throws Exception{
URL url = null;
URL baseUrl = AdminService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "AdminService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "AdminService?wsdl");
}
AdminService_Service adminService = new AdminService_Service(url, new QName(CORE_NAMESPACE, "AdminService"));
AdminService endpoint = adminService.getBasicHttpBindingAdminService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static Collaboration getCollaborationService(String authToken) throws Exception{
URL url = null;
URL baseUrl = Collaboration_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "Collaboration.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "Collaboration?wsdl");
}
Collaboration_Service collaborationService = new Collaboration_Service(url, new QName(COLLABORATION_NAMESPACE, "Collaboration"));
Collaboration endpoint = collaborationService.getBasicHttpBindingCollaboration(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static ConfigService getConfigService(String authToken) throws Exception{
URL url = null;
URL baseUrl = ConfigService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "ConfigService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "ConfigService?wsdl");
}
ConfigService_Service configService = new ConfigService_Service(url, new QName(CONFIG_NAMESPACE, "ConfigService"));
ConfigService endpoint = configService.getBasicHttpBindingConfigService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static IndexService getIndexService(String authToken) throws Exception{
URL url = null;
URL baseUrl = IndexService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "IndexService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "IndexService?wsdl");
}
IndexService_Service indexService = new IndexService_Service(url, new QName(SEARCH_NAMESPACE, "IndexService"));
IndexService endpoint = indexService.getBasicHttpBindingIndexService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static MemberService getMemberService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "MemberService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "MemberService?wsdl");
}
MemberService_Service memberService = new MemberService_Service(url, new QName(MEMBER_NAMESPACE, "MemberService"));
MemberService endpoint = memberService.getBasicHttpBindingMemberService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static WorkflowService getWorkflowService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "WorkflowService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "WorkflowService?wsdl");
}
WorkflowService_Service workflowService = new WorkflowService_Service(url, new QName(WORKFLOW_NAMESPACE, "WorkflowService"));
WorkflowService endpoint = workflowService.getBasicHttpBindingWorkflowService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static XmlService getXmlService(String authToken) throws Exception{
URL url = null;
URL baseUrl = MemberService_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "XmlService.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "XmlService?wsdl");
}
XmlService_Service xmlService = new XmlService_Service(url, new QName(CORE_NAMESPACE, "XmlService"));
XmlService endpoint = xmlService.getBasicHttpBindingXmlService(new MTOMFeature());
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
}
private static DocumentManagement getDMService(String authToken) throws Exception{
URL url = null;
URL baseUrl = DocumentManagement_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "DocumentManagement.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "DocumentManagement?wsdl");
}
DocumentManagement_Service service = new DocumentManagement_Service(url, new QName(DOCMAN_NAMESPACE, "DocumentManagement"));
DocumentManagement endpoint = service.getBasicHttpBindingDocumentManagement();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth);
return endpoint;
/*DocumentManagement_Service service = new DocumentManagement_Service();
DocumentManagement endpoint = service.getBasicHttpBindingDocumentManagement();
OTAuthentication otAuth = new OTAuthentication();
otAuth.setAuthenticationToken(authToken);
setSoapHeader((WSBindingProvider) endpoint, otAuth, "");
return endpoint;*/
}
public static void setSoapHeader(WSBindingProvider bindingProvider, OTAuthentication otAuth, String contextID, FileAtts fileAtts) throws Exception{
List<Header> headers = new ArrayList<Header>();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
headers.add(getOTAuthenticationHeader(header, otAuth));
if(!"".equals(contextID)){
headers.add(getContentIDElementHeader(header, contextID));
}
if(fileAtts != null){
headers.add(getFileAttsElementHeader(header, fileAtts));
}
bindingProvider.setOutboundHeaders(headers);
}
public static void setSoapHeader(WSBindingProvider bindingProvider, OTAuthentication otAuth) throws Exception{
List<Header> headers = new ArrayList<Header>();
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
headers.add(getOTAuthenticationHeader(header, otAuth));
bindingProvider.setOutboundHeaders(headers);
}
public static Header getContentIDElementHeader (SOAPHeader header, String contextID) throws Exception{
SOAPHeaderElement contextIDElement;
contextIDElement = header.addHeaderElement(new QName(CORE_NAMESPACE, "contextID"));
contextIDElement.addTextNode(contextID);
return Headers.create(contextIDElement);
}
public static Header getFileAttsElementHeader (SOAPHeader header, FileAtts fileAtts) throws Exception{
SOAPHeaderElement fileAttsElement;
fileAttsElement = header.addHeaderElement(new QName(CORE_NAMESPACE, "fileAtts"));
SOAPElement createdDateElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "CreatedDate"));
createdDateElement.addTextNode(fileAtts.getCreatedDate().toString());
SOAPElement modifiedDateElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "ModifiedDate"));
modifiedDateElement.addTextNode(fileAtts.getModifiedDate().toString());
SOAPElement fileSizeElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "FileSize"));
fileSizeElement.addTextNode(fileAtts.getFileSize().toString());
SOAPElement fileNameElement = fileAttsElement.addChildElement(new QName(CORE_NAMESPACE, "FileName"));
fileNameElement.addTextNode(fileAtts.getFileName());
return Headers.create(fileAttsElement);
}
public static Header getOTAuthenticationHeader(SOAPHeader header, OTAuthentication otAuth) throws Exception{
SOAPHeaderElement otAuthElement;
otAuthElement = header.addHeaderElement(new QName(ECM_API_NAMESPACE, "OTAuthentication"));
otAuthElement.setPrefix("");
SOAPElement authTokenElement;
authTokenElement = otAuthElement.addChildElement(new QName(ECM_API_NAMESPACE, "AuthenticationToken"));
authTokenElement.setPrefix( "" );
authTokenElement.addTextNode(otAuth.getAuthenticationToken());
return Headers.create(otAuthElement);
}
private static String getAuthenticationToken(String userName, String password) throws Exception{
URL url = null;
URL baseUrl = Authentication_Service.class.getResource(".");
if(".NET".equals(NET_OR_JAVA)){
url = new URL(baseUrl, NET_WSDL_LOCATION + "Authentication.svc?wsdl");
} else if("JAVA".equals(NET_OR_JAVA)){
url = new URL(baseUrl, JAVA_WSDL_LOCATION + "Authentication?wsdl");
}
String token;
Authentication endpoint;
Authentication_Service service = new Authentication_Service(url, new QName(CORE_NAMESPACE, "Authentication"));
endpoint = service.getBasicHttpBindingAuthentication();
token = endpoint.authenticateUser(userName, password);
return token;
/*String token;
Authentication endpoint;
Authentication_Service service = new Authentication_Service();
endpoint = service.getBasicHttpBindingAuthentication();
token = endpoint.authenticateUser(userName, password);
return token;*/
}
private static String convertDate(Date date){
try{
SimpleDateFormat sdf = new SimpleDateFormat("dd/Mon/yyyy");
sdf.setCalendar(Calendar.getInstance());
return sdf.parse(date.toString()).toString();
}catch(Exception e){
return date.toString();
}
}
}