Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.collabnet.ce.webservices;
  
  import  com.collabnet.ce.soap50.webservices.ClientSoapStubFactory;
  
  import  com.collabnet.ce.soap50.webservices.docman.IDocumentAppSoap;
  import  com.collabnet.ce.soap50.webservices.docman.DocumentFolderSoapDO;
  import  com.collabnet.ce.soap50.webservices.docman.DocumentFolderSoapList;
  import  com.collabnet.ce.soap50.webservices.docman.DocumentFolderSoapRow;
  import  com.collabnet.ce.soap50.webservices.docman.DocumentSoapDO;
 import  com.collabnet.ce.soap50.webservices.docman.DocumentSoapList;
 import  com.collabnet.ce.soap50.webservices.docman.DocumentSoapRow;
 
 import  com.collabnet.ce.soap50.types.SoapFilter;
 
 import java.util.Date;

Class to hold the document-related methods. Wraps a collabNetApp.
 
 public class DocumentApp {
     private CollabNetApp collabNetApp;
     private IDocumentAppSoap da;

    
Construct a new DocumentApp.

Parameters:
collabNetApp a valid (logged-in) collabNetApp.
 
     public DocumentApp(CollabNetApp collabNetApp) {
         this. = collabNetApp;
         this. = this.getDocumentAppSoap();
     }

    

Returns:
a Client Soap stub for the DocumentApp.
 
     private IDocumentAppSoap getDocumentAppSoap() {
         String soapURL = this.getUrl() + . +
             "DocumentApp?wsdl";
         return (IDocumentAppSoap) ClientSoapStubFactory.
             getSoapStub(IDocumentAppSoap.classsoapURL);
     }

    
Find or create a document folder path.

Parameters:
projectId to get the root folder for the project.
documentPath string with folders separated by '/'. The path may or may not include the root folder.
Returns:
folder id for the found/created folder.
Throws:
RemoteException
 
     public String findOrCreatePath(String projectIdString documentPath
         throws RemoteException {
         this.checkValidSessionId();
         String[] folderNames = documentPath.split("/");
         int i = 0;
         // find the root folder since the first document path may or may not
         // match this.
         DocumentFolderSoapRow rootRow = this.getRootFolder(projectId);
         if (rootRow.getTitle().equals(folderNames[i])) {
             i++;
         }
         String currentFolderId = rootRow.getId();
         String subFolderId = null;
         for (; i < folderNames.lengthi++) {
             DocumentFolderSoapList dfsList = this..
                 getDocumentFolderList(this.getSessionId(), currentFolderId
                                       false);
             String folderList = "";
             for (DocumentFolderSoapRow rowdfsList.getDataRows()) {
                 folderList += row.getTitle() + ", ";
             }
             for (DocumentFolderSoapRow rowdfsList.getDataRows()) {
                 if (row.getTitle().equals(folderNames[i])) {
                     subFolderId = row.getId();
                     break;
                 }
             }
             if (subFolderId == null) {
                 break;
             } else {
                 currentFolderId = subFolderId;
                 subFolderId = null;
                 }
         }
         // create any missing folders
         for (; i < folderNames.lengthi++) {
             DocumentFolderSoapDO dfsd = this..
                 createDocumentFolder(this.getSessionId(), currentFolderId
                                      folderNames[i], "Hudson Document " +
                                      "creation of " + folderNames[i]);
             currentFolderId = dfsd.getId();
         }
         return currentFolderId;
     }

    

Parameters:
projectId
Returns:
the folder row for the topmost folder.
Throws:
RemoteException
    private DocumentFolderSoapRow getRootFolder(String projectId
        throws RemoteException {
        DocumentFolderSoapList dfsList = this.
            .getDocumentFolderList(this.getSessionId(), projectId
                                     false);
        if (dfsList.getDataRows().length < 1) {
            throw new CollabNetApp.
                CollabNetAppException("getRootFolder for projectId " + 
                                      projectId + 
                                      " failed to find any folders");
        }
        else if (dfsList.getDataRows().length > 1) {
            StringBuffer rowNames = new StringBuffer("");
            for (DocumentFolderSoapRow rowdfsList.getDataRows()) {
                rowNames.append(row.getTitle() + ", ");
            }
            throw new CollabNetApp.
                CollabNetAppException("getRootFolder returned unexpected " +
                                      "number of folders: " + 
                                      rowNames.toString());
        } else {
            return dfsList.getDataRows()[0];
        }
    }

    
Verify a document folder path. If at any point the folder is missing, return the name of the first missing folder.

Parameters:
projectId to get the root folder for the project.
documentPath string with folders separated by '/'.
Returns:
the first missing folder, or null if all are found.
Throws:
RemoteException
     public String verifyPath(String projectIdString documentPath
        throws RemoteException {
        this.checkValidSessionId();
        String[] folderNames = documentPath.split("/");
        int i = 0;
        DocumentFolderSoapRow rootRow = this.getRootFolder(projectId);
        if (rootRow.getTitle().equals(folderNames[i])) {
            i++;
        }
        String currentFolderId = rootRow.getId();
        String subFolderId = null;
        for (; i < folderNames.lengthi++) {
            DocumentFolderSoapList dfsList = this..
                getDocumentFolderList(this.getSessionId(), currentFolderId
                                      false);
            for (DocumentFolderSoapRow rowdfsList.getDataRows()) {
                if (row.getTitle().equals(folderNames[i])) {
                    subFolderId = row.getId();
                    break;
                }
            }
            if (subFolderId == null) {
                return folderNames[i];
            } else {
                currentFolderId = subFolderId;
                subFolderId = null;
            }
        }
        return null;
     }

    
Find the url path for the folder.

Parameters:
folderId
Returns:
path to the folder.
Throws:
RemoteException
    public String getFolderPath(String folderIdthrows RemoteException {
        this.checkValidSessionId();
        DocumentFolderSoapDO folderSoap = this..
            getDocumentFolderData(this.getSessionId(), folderId);
        return folderSoap.getPath();
    }

    
Find the latest version of the document in the folder which has a matching title.

Parameters:
folderId
title
Returns:
id for the document, if found. Otherwise, null.
    public String findDocumentId(String folderIdString title
        throws RemoteException {
        this.checkValidSessionId();
        // someday we'll do this with filters, but for now, they're not
        // supported :P
        //SoapFilter[] filters = new SoapFilter[1];
        //filters[0] = new SoapFilter("title", title);
        
        DocumentSoapList dsList = this..getDocumentList(this.getSessionId(), 
                                                          folderIdnull);
        if (dsList.getDataRows().length < 1) {
            return null;
        }
        Date latest = null;
        String lastId = null;
        for (DocumentSoapRow rowdsList.getDataRows()) {
            if (row.getTitle().equals(title)) {
                if (latest == null) {
                    latest = row.getDateVersionCreated();
                    lastId = row.getId();
                    continue;
                }
                if (row.getDateVersionCreated().after(latest)) {
                    latest = row.getDateVersionCreated();
                    lastId = row.getId();
                }
            }
        }
        return lastId;
    }

    
Update document with new version.
 
    public void updateDoc(String docIdString fileIdthrows RemoteException {
        this.checkValidSessionId();
        DocumentSoapDO docData = this..getDocumentData(this.getSessionId(),
                                                         docId, 0);
        this..setDocumentData(this.getSessionId(), docDatafileId);
    }
    
    
Create a new document.

Parameters:
parentId
title
description
versionComment
status
createLocked
fileName
mimeType
fileId
associationId
associationDesc
Returns:
newly created Document Soap DO.
Throws:
RemoteException
    public DocumentSoapDO createDocument(String parentIdString title
                                         String description
                                         String versionComment
                                         String statusboolean createLocked
                                         String fileNameString mimeType
                                         String fileIdString associationId
                                         String associationDesc
        throws RemoteException{
        return this..createDocument(this.getSessionId(), parentIdtitle
                               descriptionversionCommentstatus
                               createLockedfileNamemimeTypefileId
                               associationIdassociationDesc);        
    } 

    
Below are wrapping functions, to make the code neater and in case, something changes. /
    private void checkValidSessionId() {
        this..checkValidSessionId();
    }
    
    private String getSessionId() {
        return this..getSessionId();
    }
    
    private String getUrl() {
        return this..getServerUrl();
    }
New to GrepCode? Check out our FAQ X