Skip to main content
Mitratech Success Center

Client Support Center

Need help? Click a product group below to select your application and get access to knowledge articles, webinars, training content, and release notes or to contact our support team.

Authorized users - log in to create a ticket, view tickets status and check your success plan details.

 

Document Records

The following .JAVA code samples show how you can use TeamConnect® Enterprise Web Services for functions related to document records.

Creating document records

There are four types of document records: file, folder, hyperlink, shortcut. The following samples create a file. Separate ContactRepository methods are provided to create folders and shortcuts.

Code Snippet for creating a document file

Date date = new Date();
protected DocumentRepository documentRepository;
String uniqueKey = documentRepository.insertDocument(document); 
private void createDocument() {
    DocumentCreate document = new DocumentCreate(); 
    document.setName("test_document.txt");
    document.setContent("test document content".getBytes()); 
    document.setType(DocumentType.FILE); 
    document.setParentFolderUniqueKey("DOCU_11"); 
    document.setContentTypeUniqueKey("Text");
    return document;
}

Updating documents

The following samples show how to update documents for the available types (file, folder, hyperlink, shortcut).

Code Snippet for updating a document file

Date date = new Date();
protected DocumentRepository documentRepository; 
documentRepository.updateDocument(document); 
private void updateDocument() {
    DocumentUpdate document = new DocumentUpdate(); 
    document.setUniqueKey("DOCU_2010"); 
    document.setContent(byte[] value); 
    document.setName("receipt012109");
    return document;
}

Code Snippet for updating a document folder

Code Snippet for updating a document folder
Date date = new Date();
protected DocumentRepository documentRepository;
documentRepository.updateDocument(document);
private void updateDocument() {
    DocumentUpdate document = new DocumentUpdate();
    document.setUniqueKey("DOCU_2011");
    document.setName("Correspondence_Jan09");
    document.setParentFolderUniqueKey("DOCU_3005");
    return document;
}

Code Snippet for updating a document hyperlink

​​​​​Date date = new Date();
protected DocumentRepository documentRepository;
documentRepository.updateDocument(document);
private void updateDocument() {
    DocumentUpdate document = new DocumentUpdate();
    document.setUniqueKey("DOCU_2011");
    document.setName("BusinessWeek_URL");
    document.setUrl("http://businessweek.com");
    return document;
}

Code Snippet for updating a document shortcut

Date date = new Date();
protected DocumentRepository documentRepository; 
documentRepository.updateDocument(document); 
private void updateDocument() {
    DocumentUpdate document = new DocumentUpdate(); 
    document.setUniqueKey("DOCU_2010"); 
    document.setName("shortcutToWorksheet");
    return document;
} 

Reading documents

The following samples show how to read documents. Note that certain properties you can request to be returned are only relevant to particular document types (for example, the url property is only relevant to the document type, hyperlink). Comments are provided for properties that are document type-specific.

Code Snippet

private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your searches, 
    you can omit unnecessary properties from your application and those values will not be returned
    props.add("version"); 
    props.add("subject"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy"); 
    props.add("modifiedOn"); 
    props.add("name"); 
    props.add("author"); 
    props.add("authorDate"); 
    props.add("size");
    //the contentType is only relevant to a document of type FILE props.add("contentType");
    //the contentType is only relevant to a document of type FILE props.add("content");
    props.add("type"); 
    props.add("parentFolder"); 
    props.add("checkedOutBy"); 
    props.add("checkedOutOn");
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText");
    //the url is only relevant to a document of type HYPERLINK props.add("url");
    //the contentType is only relevant to a document of type SHORTCUT props.add("shortcutToDocument");
    return props;
}
private Document readDocument() throws Exception {
    Document readDocument = documentRepository.readDocument(uniqueKey, 
    getPropertiesToRead());
    return readDocument;
}

Reading child documents for a document

Performs one of the following:

  • Gets child documents (files) for a given document folder.
  • Gets previous versions of a document (files) for a given document file.

For both operations, documents are returned with only specified property values. For a list of available properties, see the type class, Document.

Code Snippet

private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your searches, you can omit 
    unnecessary properties from your application and those values will not be returned
    props.add("version"); props.add("subject"); props.add("categories"); props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy"); 
    props.add("modifiedOn"); 
    props.add("name"); 
    props.add("author"); 
    props.add("authorDate"); 
    props.add("size");
    //the contentType is only relevant to a document of type FILE props.add("contentType");
    //the contentType is only relevant to a document of type FILE props.add("content");
    props.add("type"); 
    props.add("parentFolder"); 
    props.add("checkedOutBy"); 
    props.add("checkedOutOn"); 
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText");
    //the url is only relevant to a document of type HYPERLINK props.add("url");
    //the contentType is only relevant to a document of type SHORTCUT props.add("shortcutToDocument");
    return props;
}
private Document readChildDocument() throws Exception {
    //the first parameter, parentUniqueKey, identifies the unique key of the 
    parent folder whose child documents' properties to 
    return; where child documents would include files, subfolders, hyperlinks, 
    and shortcuts included in the parent 
    folder recursively
    List<Document> readChildDocument = documentRepository.readChildDocuments("DOCU_2534",
    getPropertiesToRead()); return readChildDocument;
}

Reading documents by path

Retrieves a Document from the repository based on a folder path.

Code Snippet

private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your searches, you can omit 
    unnecessary properties from your application and those values will not be returned
    props.add("version"); 
    props.add("subject"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy"); 
    props.add("modifiedOn"); 
    props.add("name"); 
    props.add("author"); 
    props.add("authorDate"); 
    props.add("size");
    //the contentType is only relevant to a document of type FILE
    props.add("contentType");
    //the contentType is only relevant to a document of type FILE props.add("content");
    props.add("type"); 
    props.add("parentFolder"); 
    props.add("checkedOutBy"); 
    props.add("checkedOutOn"); 
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText");
    //the url is only relevant to a document of type HYPERLINK props.add("url");
    //the contentType is only relevant to a document of type SHORTCUT props.add("shortcutToDocument");
    return props;
}
private Document readDocumentByPath() throws Exception {
    //the first parameter, path, identifies the document folder path to the target 
    document whose specified properties to return
    Document document = documentRepository.readDocumentByPath("TopLevel_Users_john",
    getPropertiesToRead()); 
    return document;
}

Reading the child document of a parent folder

Retrieves a document from the repository given the file name and the unique ID of its parent folder.

Code Snippet

private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency 
    in your searches, you can omit unnecessary 
    properties from your application and those values will not be returned
    props.add("version"); 
    props.add("subject"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy"); 
    props.add("modifiedOn"); 
    props.add("name"); 
    props.add("author"); 
    props.add("authorDate");
    props.add("size");
    //the contentType is only relevant to a document of type FILE props.add("contentType");
    //the contentType is only relevant to a document of type FILE props.add("content");
    props.add("type"); 
    props.add("parentFolder"); 
    props.add("checkedOutBy"); 
    props.add("checkedOutOn"); 
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText");
    //the url is only relevant to a document of type HYPERLINK props.add("url");
    //the contentType is only relevant to a document of type SHORTCUT props.add("shortcutToDocument");
    return props;
}
private Document readChildDocumentForName() throws Exception {
    //the first parameter, parentUniqueKey, identifies the unique key of the parent folder 
    whose child documents' properties to 
    return; where child documents would include files, subfolders, hyperlinks, and shortcuts included in the parent 
    folder recursively
    //the second parameter identifies the target document file name, including file extension
    List<Document> readChildDocumentForName = documentRepository.readChildDocuments("DOCU_2789", 
    "invoice101009_4009_attachment.doc", getPropertiesToRead());
    return readChildDocument;
}

Reading the Document Folder for a User

Retrieves a document folder from the repository given the unique key of the folder's owner (user).

Code Snippet

private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your 
    searches, you can omit unnecessary properties from your application and those values will not be returned
    props.add("version"); 
    props.add("subject"); 
    props.add("categories"); 
    props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy");
    props.add("modifiedOn"); 
    props.add("name"); 
    props.add("author"); 
    props.add("authorDate"); 
    props.add("size"); 
    props.add("content"); 
    props.add("type"); 
    props.add("parentFolder"); 
    props.add("checkedOutBy"); 
    props.add("checkedOutOn"); 
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText"); 
    return props;
}
private Document readDocumentFolderForDocumentOwner() throws Exception {
    //the first parameter, uniqueKey, identifies the unique key of the user 
    whose TeamConnect Documents area user folder to 
    return (for example, the path to the user folder for Al would look like Top Level\Users\al)
    document readDocumentFolderForDocumentOwner = documentRepository.readDocumentFolderForDocumentOwner("USER_1223", 
    getPropertiesToRead());
    return readUserFolder;
}

Searching documents

The following samples show how to search documents by name, parent folder, date last modified, and author.

Code Snippet

\\for this sample it is assumed that a Date variable, date, exists representing a past date
protected DocumentRepository documentRepository; 
StringFieldCriterion fieldCriterion1 = new StringFieldCriterion(); 
fieldCriterion1.setComparator(StringComparator.CONTAINS);
LegacySearchFieldPathExpression fieldPathExpression1 = new LegacySearchFieldPathExpression();
fieldPathExpression1.setSearchKeyPath("name"); fieldCriterion1.setFieldPath(fieldPathExpression); 
fieldCriterion1.getValue().add("Invoice_10508"); StringFieldCriterion fieldCriterion2 = new StringFieldCriterion(); 
fieldCriterion2.setComparator(StringComparator.EQUALS);
LegacySearchFieldPathExpression fieldPathExpression2 = new LegacySearchFieldPathExpression();
fieldPathExpression2.setSearchKeyPath("parentFolder.uniqueKey"); 
fieldCriterion2.setFieldPath(fieldPathExpression);
fieldCriterion2.getValue().add("DOCU_1099"); 
DateFieldCriterion fieldCriterion3 = new DateFieldCriterion(); 
fieldCriterion3.setComparator(DateComparator.EQUALS);
LegacySearchFieldPathExpression fieldPathExpression3 = new LegacySearchFieldPathExpression();
fieldPathExpression3.setSearchKeyPath("modifiedOn"); 
fieldCriterion3.setFieldPath(fieldPathExpression); 
fieldCriterion3.getValue().add(date);
StringFieldCriterion fieldCriterion4 = new StringFieldCriterion(); 
fieldCriterion4.setComparator(StringComparator.EQUALS);
LegacySearchFieldPathExpression fieldPathExpression4 = new LegacySearchFieldPathExpression();
fieldPathExpression4.setSearchKeyPath("author.uniqueKey"); 
fieldCriterion4.setFieldPath(fieldPathExpression); fieldCriterion4.getValue().add("CONT_1015"); 
FieldSearchClause searchCriteria = new FieldSearchClause(); 
searchCriteria.setOperator(LogicOperator.AND); 
searchCriteria.getCriteria().add(fieldCriterion1); 
searchCriteria.getCriteria().add(fieldCriterion2); 
searchCriteria.getCriteria().add(fieldCriterion3); 
searchCriteria.getCriteria().add(fieldCriterion4);
List<Document> searchDocument = documentRepository.readDocumentsByCriteria(searchCriteria, 100, getPropertiesToRead());
private List<String> getPropertiesToRead() { 
    List<String> props = new List<String>();
    //the list of all available properties displays below but to increase efficiency in your searches, 
    you can omit unnecessary properties from your application and those values will not be returned
    props.add("version"); props.add("subject"); props.add("categories"); 
    props.add("createdOn"); 
    props.add("createdBy"); 
    props.add("modifiedBy"); 
    props.add("modifiedOn"); 
    props.add("name"); props.add("author"); props.add("authorDate"); props.add("size");
    //the contentType is only relevant to a document of type FILE props.add("contentType");
    //the contentType is only relevant to a document of type FILE props.add("content");
    props.add("type"); props.add("parentFolder");
    props.add("checkedOutBy"); 
    props.add("checkedOutOn"); 
    props.add("checkedInBy"); 
    props.add("checkedInOn"); 
    props.add("versionText");
    //the url is only relevant to a document of type HYPERLINK props.add("url");
    //the contentType is only relevant to a document of type SHORTCUT props.add("shortcutToDocument");
    return props;
}

Creating document shortcuts

Creates a shortcut or link to a document (file, folder, or existing shortcut) with a given unique key. The parentFolderUniqueKey defines the folder where the shortcut will be created. The unique key of the resulting shortcut (type of document record) is returned.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies an existing document to create a link to
//the second parameter, parentFolderUniqueKey, identifies the folder where the shortcut will be created
String uniqueKey = documentRepository.createShortcut("DOCU_1451", "DOCU_1771");

Creating subfolders

Creates a sub-folder with given name in given parent folder. The unique key of the resulting folder (type of document record) is returned.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, name, sets the subfolder name
//the second parameter, parentUniqueKey, identifies the folder where the folder will be created
String uniqueKey = documentRepository.createSubFolder("Child Folder", "DOCU_1010");
Creating hyperlinks w ith the default Document category
Creates a hyperlink and sets its category to the default Document category.
Code Snippet
protected DocumentRepository documentRepository;
//the first parameter, parentFolderUniqueKey, 
identifies the folder where the hyperlink will be created name, sets the subfolder name
//the second parameter, url, sets the website URL target for the hyperlink
//the third parameter, name, sets the hyperlink name that displays in the application UI
//the fourth parameter, contactUniqueKey, identifies the hyperlink record author
String uniqueKey = documentRepository.createHyperlinkDefaultCategory("DOCU_1753", 
"http://www.mitratech.com", "Mitratech URL", "CONT_1005");

Creating hyperlinks

Creates a hyperlink.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, parentFolderUniqueKey, identifies the folder where the hyperlink will be created name, 
sets the subfolder name
//the second parameter, url, sets the website URL target for the hyperlink
//the third parameter, name, sets the hyperlink name that displays in the application UI
//the fourth parameter, documentCategoryUniqueKey, identifies the document category to set as the hyperlink category
//the fifth parameter, contactUniqueKey, identifies the hyperlink record author
String uniqueKey = documentRepository.createHyperlinkDefaultCategory("DOCU_1753", "http://www.mitratech.com", 
"Mitratech URL", "DOCU_1855", "CONT_1005");

Copying documents

Copies a document to a new parent folder.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies an existing document to copy
//the second parameter, parentFolderUniqueKey, identifies the folder where the document copy will be created
documentRepository.copyDocument("DOCU_1700", "DOCU_1811");

Moving documents

Moves a document to a new parent folder.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies an existing document to move
//the second parameter, newParentFolderUniqueKey, identifies the folder where the document will be moved
documentRepository.moveDocument("DOCU_1900", "DOCU_1024");

Checking out documents

Attempts to check out a document with a given unique key.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies an existing document to check out
documentRepository.checkOut("DOCU_2900");

Undoing a document checkout

Cancels a checkout operation on a document with a given unique key.

Code Snippet

protected DocumentRepository documentRepository;
//the parameter, documentUniqueKey, identifies an existing document to undo the checkout operation for
documentRepository.undoCheckOut("DOCU_2900");

Checking in documents

Attempts to check in a document (of type file) with a given unique key.

Code Snippet

byte[] docContent = "test document content".getBytes(); protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies an existing document to check in a new version for
//the second parameter, content, contains the updated file content to check in
//the third parameter, version, identifies the numeric version of the file you are checking in
documentRepository.checkIn("DOCU_2901", docContent, "1.3");

Reverting a document to a previous version

Attempts to revert a given document to a given old version.

Code Snippet

protected DocumentRepository documentRepository;
//the first parameter, documentUniqueKey, identifies the version of the document file (for example the current version) 
to replace
//the second parameter, oldKey, identifies the version of the document file to revert to 
(sets this file to the current version)
documentRepository.revert("DOCU_2902", "DOCU_2892");

Deleting documents

The following sample deletes a document. You must get the unique key value for record to delete.

Code Snippet

//for this sample it is assumed that a document exists with the unique key equal to a String, uniqueKey
protected DocumentRepository documentRepository; documentRepository.deleteDocument(uniqueKey);
  • Was this article helpful?