java.lang.Object
com.avoka.component.sharepoint.AbstractService
com.avoka.component.sharepoint.service.Lists

public class Lists extends AbstractService
Provides a Lists SharePoint web service class.

Lists SharePoint Example

The Groovy script example below illustrates using the Lists service to create an List SharePoint web service object. In this examples configuration Service Parameters are accessed via the serviceParameters map object.

 import com.avoka.component.sharepoint.SPClient
 import com.avoka.component.sharepoint.service.Lists
 import com.avoka.component.sharepoint.type.RowData

 // Create a SharePoint client using the Service Parameters map with the configured connection details
 def spClient = new SPClient(serviceParameters)

 // Create a List web service
 def listService = spClient.getLists()

 // Get a List collection map
 def listItemRowData = listService.getListItems(serviceParameters.siteContext, serviceParameters.listName)

 // Iterate through rows
 Listinvalid input: '<'Map<String, String>> rowList = listItemRowData.getRowList()
 Iterator rowListIter = rowList.iterator()
 while (rowListIter.hasNext()) {
     Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next()
     Set rowKeySet = rowMap.keySet()
     Iterator rowKeyIter = rowKeySet.iterator()
     while (rowKeyIter.hasNext()) {
         def name = (String) rowKeyIter.next()
         def value = rowMap.get(name)
         // Use name, value
      }
 } 
Since:
3.5.0
  • Constructor Details

    • Lists

      public Lists(SPConnection sharePointConnection)
      Instantiate the Lists Interface wrapper with SharePoint Connection context
      Parameters:
      sharePointConnection - SharePoint connection context
  • Method Details

    • getServiceName

      public String getServiceName()
      Return the web service name.
      Specified by:
      getServiceName in class AbstractService
      Returns:
      the web service name
    • getListItems

      public RowData getListItems(String siteContext, String listName) throws SPException
      Get information on a List's Items.

      Groovy Example

      The Groovy script example below illustrates using the Lists service to create an List SharePoint web service object. In this examples configuration Service Parameters are accessed via the serviceParameters map object.

       import com.avoka.component.sharepoint.SPClient
       import com.avoka.component.sharepoint.service.Lists
       import com.avoka.component.sharepoint.type.RowData
      
       // Create a SharePoint client using the service parameters map with the configured connection details
       def spClient = new SPClient(serviceParameters)
      
       // Create a List web service
       def listService = spClient.getLists()
      
       // Get a List collection map
       def listItemRowData = listService.getListItems(serviceParameters.siteContext, serviceParameters.listName)
      
       // Iterate through rows
       Listinvalid input: '<'Map<String, String>> rowList = listItemRowData.getRowList()
       Iterator rowListIter = rowList.iterator()
       while (rowListIter.hasNext()) {
           Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next()
           Set rowKeySet = rowMap.keySet()
           Iterator rowKeyIter = rowKeySet.iterator()
           while (rowKeyIter.hasNext()) {
               def name = (String) rowKeyIter.next()
               def value = rowMap.get(name)
               // Use name, value
            }
       } 

      Web Service Method

      The Microsoft SharePoint Web Service SOAP Method:

      http://schemas.microsoft.com/sharepoint/soap/GetListItems

      The MSDN Method Reference:

      http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx

       

      Parameters:
      siteContext - Provide SharePoint Site context if accessing a non-default site (Optional).
      listName - Either the name or the Id for the List. Id must be surrounded by curly braces.
      Returns:
      Row Data representing the SharePoint listitems fragment.
      Throws:
      SPException - in case of SharePoint error response
    • getListCollection

      public Map<String,String> getListCollection(String siteContext) throws SPException
      Get all Lists within a specified Site.

      Groovy Example

      The Groovy script example below illustrates using the Lists object to create an List SharePoint web service object. In this examples configuration Service Parameters are accessed via the serviceParameters map object.

       import com.avoka.component.sharepoint.SPClient
       import com.avoka.component.sharepoint.service.Lists
      
       // Create a SharePoint client using the service parameters map with the configured connection details
       def spClient = new SPClient(serviceParameters)
      
       // Create a List web service
       def listService = spClient.getLists()
      
       // Get a List collection map
       def collectionMap = listService.getListCollection(serviceParameters.siteContext)
      
       // Iterate through collection map
       Iterator attrKeyIter = collectionMap.keySet().iterator();
       while (attrKeyIter.hasNext()) {
           def listId = (String) attrKeyIter.next()
           def listTitle = collectionMap.get(listId)
           // Use list id, title
       } 

      Web Service Method

      The Microsoft SharePoint Web Service SOAP Method:

      http://schemas.microsoft.com/sharepoint/soap/GetListCollection

      The MSDN Method Reference:

      http://msdn.microsoft.com/en-us/library/lists.lists.getlistcollection.aspx

       

      Parameters:
      siteContext - (Optional) Provide SharePoint Site context if accessing a non-default site.
      Returns:
      Mapinvalid input: '<'String,String> representing pairs of the List's invalid input: '<'Id, Title>
      Throws:
      SPException - in case of SharePoint error response
    • updateListItems

      public RowData updateListItems(String siteContext, String listName, String updateXml) throws SPException
      Adds, deletes, or updates the specified Items in a List on the specified site. An Update XML Fragment must be provided, as per the original SharePoint Interface (Refer to MSDN).

      An example XML Fragment creates a new item;

       
           <Batch OnError="Continue" ListVersion="1"
           ViewName="270C0508-A54F-4387-8AD0-49686D685EB2">
           <Method ID="1" Cmd="New">
               <Field Name='ID'>New</Field>
               <Field Name="Title">Value</Field>
           </Method>
       </Batch>
        

      Groovy Example

      The Groovy script example below illustrates using the Lists service to update a SharePoint List's Items. In this example the List Item configuration parameters are accessed via the serviceParameters map object. The updateListItems method returns a RowData object containing added/updated/deleted item details. Eg: Use the loop algorithm in the example to check for generated ID numbers of new added items.

       import com.avoka.component.sharepoint.SPClient
       import com.avoka.component.sharepoint.service.Lists
      
       // Create a SharePoint client using the service params map with the configured connection details
       def spClient = new SPClient(serviceParameters)
      
       // Create a List web service
       def listService = spClient.getLists()
      
       // Update a List's Items.
       def updatedRowData = listService.updateListItems(serviceParameters.siteContext, serviceParameters.listName, serviceParameters.updateXml)
      
       // Iterate through added/updated/deleted rows in the method call result
       Listinvalid input: '<'Map<String, String>> rowList = updatedRowData.getRowList()
       Iterator rowListIter = rowList.iterator()
       while (rowListIter.hasNext()) {
           Mapinvalid input: '<'String, String> rowMap = (Mapinvalid input: '<'String, String>) rowListIter.next()
           Set rowKeySet = rowMap.keySet()
           Iterator rowKeyIter = rowKeySet.iterator()
           while (rowKeyIter.hasNext()) {
               def name = (String) rowKeyIter.next()
               def value = rowMap.get(name)
               // Use name, value
            }
       } 

      Web Service Method

      The Microsoft SharePoint Web Service SOAP Method:

      http://schemas.microsoft.com/sharepoint/soap/UpdateListItems

      The MSDN Method Reference:

      http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx

       

      Parameters:
      siteContext - (Optional) Provide SharePoint Site context if accessing a non-default site.
      listName - Either the name or the Id for the List. Id must be surrounded by curly braces.
      updateXml - A Batch XML Element containing add, modify or delete items as per the SharePoint Interface.
      Returns:
      RowData representing the operation result as per the SharePoint Results Interface.
      Throws:
      SPException - in case of SharePoint error response
    • checkInFile

      public void checkInFile(String pageUrl, String comment, String checkinType) throws SPException
      Check a file into SharePoint from a remote URL.

      Groovy Example

      The Groovy script example below illustrates using the Lists object to check a file into SharePoint using a remote URL. In this example the check in file parameters are accessed via the serviceParameters map object.

       import com.avoka.component.sharepoint.SPClient
       import com.avoka.component.sharepoint.service.Lists
      
       // Create a SharePoint client using the service parameters map with the configured connection details
       def spClient = new SPClient(serviceParameters)
      
       // Create a List web service
       def listService = spClient.getLists()
      
       // Check in file
       listService.checkInFile(serviceParameters.pageUrl, serviceParameters.comment, serviceParameters.checkinType) 

      Web Service Method

      The Microsoft SharePoint Web Service SOAP Method:

      http://schemas.microsoft.com/sharepoint/soap/checkInFile

      http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile.aspx

      Parameters:
      pageUrl - Absolute URL of the document to be checked in.
      comment - Check-in comments.
      checkinType - 0 = MinorCheckIn, 1 = MajorCheckIn, and 2 = OverwriteCheckIn.
      Throws:
      SPException - in case of SharePoint error response
    • addAttachment

      public String addAttachment(String siteContext, String listName, String listItemId, String fileName, byte[] attachment) throws SPException
      Adds an attachment to the specified list item in the specified list.

      Groovy Example

      The Groovy script example below illustrates using the Lists object to create a new List Item and adding an attachment to it.

       import com.avoka.component.sharepoint.SPClient
       import com.avoka.component.sharepoint.service.Lists
      
       // Create a SharePoint client using the service params map with the configured connection details
       def spClient = new SPClient(serviceParameters)
      
       // Create a List web service
       def listService = spClient.getLists()
      
       // Create a new List Item
       def updatedRowData = listService.updateListItems(serviceParameters.siteContext, serviceParameters.listName, serviceParameters.updateXml)
      
       def newListItemId = null
       // Iterate through rows and find the ID of the new List Item the attachment will be added to
       List rowList = rowData.getRowList()
       Iterator rowListIter = rowList.iterator()
       while (rowListIter.hasNext()) {
         def rowMap = (Map) rowListIter.next()
         while (rowListIter.hasNext()) {
           def rowMap = (Map) rowListIter.next()
           if (rowMap['ows_Title'] == itemTitle ){
           // or use a different Item detail to identify your new added Item if there is more Items added in serviceParameters.updateXml
             newListItemId = rowMap['ows_ID'];
           }
         }
       }
       if (newListItemId != null ){
         def attachmentUrl = listService.addAttachment(null, serviceParameters.itemListName, newListItemId, fileName, receiptPDF)
       }

      Web Service Method

      The Microsoft SharePoint Web Service SOAP Method:

      http://schemas.microsoft.com/sharepoint/soap/AddAttachment

      http://msdn.microsoft.com/en-us/library/lists.lists.addattachment.aspx

      Parameters:
      siteContext - Provide SharePoint Site context if accessing a non-default site (Optional).
      listName - A string that contains either the title or the GUID for the list.
      listItemId - A string that contains the ID of the item to which attachments are added. This value does not correspond to the index of the item within the collection of list items.
      fileName - A string that contains the name of the file to add as an attachment.
      attachment - A byte array that contains the file to attach
      Returns:
      A string that contains the URL for the attachment, which can subsequently be used to reference the attachment or null if there is no result from the AddAttachment operation call.
      Throws:
      SPException - in case of SharePoint error response
      Since:
      4.1.0