added filter options to list item queries
This commit is contained in:
@ -228,7 +228,7 @@
|
||||
|
||||
<!-- user/group definition, returned by sharepoint when calling usergroup service -->
|
||||
<execution>
|
||||
<id>usergroup</id>
|
||||
<id>usergroup2010</id>
|
||||
<goals>
|
||||
<goal>xjc</goal>
|
||||
</goals>
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package de.muehlencord.shared.sharepoint.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public abstract class AbstractSpJaxbObject extends SPObject {
|
||||
|
||||
public AbstractSpJaxbObject(SPContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static Node createSharePointCAMLNode(String xmlString) throws ParserConfigurationException, SAXException, IOException, JAXBException {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setValidating(false);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(new InputSource(new StringReader(xmlString)));
|
||||
Node node = document.getDocumentElement();
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* History:
|
||||
*
|
||||
* $$Log$$
|
||||
*
|
||||
*/
|
||||
@ -26,7 +26,7 @@ import org.xml.sax.SAXException;
|
||||
* @author joern.muehlencord
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class SPJaxbObject<T> extends SPObject {
|
||||
public abstract class SPJaxbObject<T> extends AbstractSpJaxbObject {
|
||||
|
||||
private static JAXBContext jaxbContext = null;
|
||||
|
||||
@ -112,12 +112,7 @@ public abstract class SPJaxbObject<T> extends SPObject {
|
||||
|
||||
public Node createSharePointCAMLNode() throws ParserConfigurationException, SAXException, IOException, JAXBException {
|
||||
String xmlString = getValueXmlString();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setValidating(false);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(new InputSource(new StringReader(xmlString)));
|
||||
Node node = document.getDocumentElement();
|
||||
return node;
|
||||
return AbstractSpJaxbObject.createSharePointCAMLNode(xmlString);
|
||||
}
|
||||
|
||||
protected T getValue() {
|
||||
|
||||
@ -6,6 +6,7 @@ import com.microsoft.schemas.sharepoint.soap.lists.GetListItemsResponse;
|
||||
import com.microsoft.schemas.sharepoint.soap.lists.GetListResponse;
|
||||
import com.microsoft.schemas.sharepoint.soap.lists.ListsSoap;
|
||||
import com.microsoft.schemas.sharepoint.soap.lists.UpdateListItems;
|
||||
import de.muehlencord.shared.sharepoint.api.AbstractSpJaxbObject;
|
||||
import de.muehlencord.shared.sharepoint.api.SPContext;
|
||||
import de.muehlencord.shared.sharepoint.api.SPJaxbObject;
|
||||
import de.muehlencord.shared.sharepoint.api.SPObject;
|
||||
@ -45,7 +46,7 @@ public class SPList extends SPJaxbObject<List> {
|
||||
@Override
|
||||
protected java.util.List getSchemaLocation() {
|
||||
java.util.List<String> schemaList = new ArrayList();
|
||||
schemaList.add("/xsd/list.xsd");
|
||||
schemaList.add("/xsd/lists.xsd");
|
||||
return schemaList;
|
||||
}
|
||||
|
||||
@ -65,12 +66,23 @@ public class SPList extends SPJaxbObject<List> {
|
||||
/* *** queries *** */
|
||||
public java.util.List<java.util.List<String>> getListItems(java.util.List<String> listColumnNames, String rowLimit) throws NoSuchAlgorithmException,
|
||||
KeyManagementException, JAXBException, MalformedURLException,
|
||||
SAXException {
|
||||
SAXException, ParserConfigurationException, IOException {
|
||||
return getListItems(listColumnNames, rowLimit, null);
|
||||
}
|
||||
|
||||
public java.util.List<java.util.List<String>> getListItems(java.util.List<String> listColumnNames, String rowLimit, String queryString) throws
|
||||
NoSuchAlgorithmException, KeyManagementException, JAXBException, MalformedURLException,
|
||||
SAXException, ParserConfigurationException, IOException {
|
||||
|
||||
//Here are additional parameters that may be set
|
||||
String viewName = null;
|
||||
GetListItems.ViewFields viewFields = null;
|
||||
|
||||
GetListItems.Query query = null;
|
||||
if (queryString != null) {
|
||||
query = new GetListItems.Query();
|
||||
query.getContent().add(AbstractSpJaxbObject.createSharePointCAMLNode(queryString));
|
||||
}
|
||||
QueryOptions queryOptions = new QueryOptions();
|
||||
String webId = null;
|
||||
|
||||
@ -153,7 +165,7 @@ public class SPList extends SPJaxbObject<List> {
|
||||
|
||||
/* *** information & tools *** */
|
||||
public Map<String, String> getLookupValueMap(String value, String rowLimit) throws NoSuchAlgorithmException,
|
||||
KeyManagementException, JAXBException, MalformedURLException, SAXException {
|
||||
KeyManagementException, JAXBException, MalformedURLException, SAXException, ParserConfigurationException, IOException {
|
||||
|
||||
// get list values from sharepoint
|
||||
java.util.List<String> listColumnNames = new ArrayList<>();
|
||||
@ -204,14 +216,18 @@ public class SPList extends SPJaxbObject<List> {
|
||||
private ListsSoap getListsPort() throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
||||
java.net.URL contextURL = getContext().getSiteURL();
|
||||
java.net.URL wsURL = new java.net.URL(contextURL.toString() + "/_vti_bin/Lists.asmx");
|
||||
java.net.URL wsdlURL = new java.net.URL(SPContext.class.getResource("/2010/wsdl/lists.wsdl").toExternalForm());
|
||||
java.net.URL wsdlURL = new java.net.URL(SPContext.class
|
||||
.getResource("/2010/wsdl/lists.wsdl").toExternalForm());
|
||||
com.microsoft.schemas.sharepoint.soap.lists.Lists service = new com.microsoft.schemas.sharepoint.soap.lists.Lists(wsdlURL);
|
||||
ListsSoap listsPort = service.getListsSoap();
|
||||
|
||||
((BindingProvider) listsPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsURL.toString());
|
||||
|
||||
// log all incoming and outgoing communication - TODO make this configurable by DEBUG switch
|
||||
java.util.List<Handler> handlers = ((BindingProvider) listsPort).getBinding().getHandlerChain();
|
||||
handlers.add(new ServiceLogHandler());
|
||||
|
||||
handlers.add(
|
||||
new ServiceLogHandler());
|
||||
((BindingProvider) listsPort).getBinding().setHandlerChain(handlers);
|
||||
|
||||
return listsPort;
|
||||
|
||||
@ -106,7 +106,31 @@ public class SPListTest extends BaseTest {
|
||||
assertEquals("Size smallList", 30, smallList.size());
|
||||
java.util.List<java.util.List<String>> bigList = list.getListItems(columns, "300");
|
||||
assertNotNull(bigList);
|
||||
assertEquals("Size bigList", 250, bigList.size());
|
||||
assertEquals("Size bigList", 249, bigList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // Depends on available sharepoint currently
|
||||
public void testGetListItemsQuery() throws Exception {
|
||||
SPLists instance = new SPLists(context);
|
||||
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
||||
assertNotNull(list);
|
||||
java.util.List<String> columns = new ArrayList<>();
|
||||
columns.add("Title");
|
||||
columns.add("ID");
|
||||
|
||||
// create query
|
||||
String queryString = "<Query><Where><Eq>"
|
||||
+ "<FieldRef Name=\"Title\" />"
|
||||
+ "<Value Type=\"Text\">DE</Value>"
|
||||
+ "</Eq></Where></Query>";
|
||||
|
||||
java.util.List<java.util.List<String>> smallList = list.getListItems(columns, "30",queryString);
|
||||
// the list contains more than one item but title is a unique value, so it can only
|
||||
// return one row if filtered to one country
|
||||
assertNotNull(smallList);
|
||||
assertEquals("Size smallList", 1, smallList.size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user