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 -->
|
<!-- user/group definition, returned by sharepoint when calling usergroup service -->
|
||||||
<execution>
|
<execution>
|
||||||
<id>usergroup</id>
|
<id>usergroup2010</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>xjc</goal>
|
<goal>xjc</goal>
|
||||||
</goals>
|
</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
|
* @author joern.muehlencord
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public abstract class SPJaxbObject<T> extends SPObject {
|
public abstract class SPJaxbObject<T> extends AbstractSpJaxbObject {
|
||||||
|
|
||||||
private static JAXBContext jaxbContext = null;
|
private static JAXBContext jaxbContext = null;
|
||||||
|
|
||||||
@ -112,12 +112,7 @@ public abstract class SPJaxbObject<T> extends SPObject {
|
|||||||
|
|
||||||
public Node createSharePointCAMLNode() throws ParserConfigurationException, SAXException, IOException, JAXBException {
|
public Node createSharePointCAMLNode() throws ParserConfigurationException, SAXException, IOException, JAXBException {
|
||||||
String xmlString = getValueXmlString();
|
String xmlString = getValueXmlString();
|
||||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
return AbstractSpJaxbObject.createSharePointCAMLNode(xmlString);
|
||||||
documentBuilderFactory.setValidating(false);
|
|
||||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
|
||||||
Document document = documentBuilder.parse(new InputSource(new StringReader(xmlString)));
|
|
||||||
Node node = document.getDocumentElement();
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T getValue() {
|
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.GetListResponse;
|
||||||
import com.microsoft.schemas.sharepoint.soap.lists.ListsSoap;
|
import com.microsoft.schemas.sharepoint.soap.lists.ListsSoap;
|
||||||
import com.microsoft.schemas.sharepoint.soap.lists.UpdateListItems;
|
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.SPContext;
|
||||||
import de.muehlencord.shared.sharepoint.api.SPJaxbObject;
|
import de.muehlencord.shared.sharepoint.api.SPJaxbObject;
|
||||||
import de.muehlencord.shared.sharepoint.api.SPObject;
|
import de.muehlencord.shared.sharepoint.api.SPObject;
|
||||||
@ -45,7 +46,7 @@ public class SPList extends SPJaxbObject<List> {
|
|||||||
@Override
|
@Override
|
||||||
protected java.util.List getSchemaLocation() {
|
protected java.util.List getSchemaLocation() {
|
||||||
java.util.List<String> schemaList = new ArrayList();
|
java.util.List<String> schemaList = new ArrayList();
|
||||||
schemaList.add("/xsd/list.xsd");
|
schemaList.add("/xsd/lists.xsd");
|
||||||
return schemaList;
|
return schemaList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,12 +66,23 @@ public class SPList extends SPJaxbObject<List> {
|
|||||||
/* *** queries *** */
|
/* *** queries *** */
|
||||||
public java.util.List<java.util.List<String>> getListItems(java.util.List<String> listColumnNames, String rowLimit) throws NoSuchAlgorithmException,
|
public java.util.List<java.util.List<String>> getListItems(java.util.List<String> listColumnNames, String rowLimit) throws NoSuchAlgorithmException,
|
||||||
KeyManagementException, JAXBException, MalformedURLException,
|
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
|
//Here are additional parameters that may be set
|
||||||
String viewName = null;
|
String viewName = null;
|
||||||
GetListItems.ViewFields viewFields = null;
|
GetListItems.ViewFields viewFields = null;
|
||||||
|
|
||||||
GetListItems.Query query = null;
|
GetListItems.Query query = null;
|
||||||
|
if (queryString != null) {
|
||||||
|
query = new GetListItems.Query();
|
||||||
|
query.getContent().add(AbstractSpJaxbObject.createSharePointCAMLNode(queryString));
|
||||||
|
}
|
||||||
QueryOptions queryOptions = new QueryOptions();
|
QueryOptions queryOptions = new QueryOptions();
|
||||||
String webId = null;
|
String webId = null;
|
||||||
|
|
||||||
@ -153,7 +165,7 @@ public class SPList extends SPJaxbObject<List> {
|
|||||||
|
|
||||||
/* *** information & tools *** */
|
/* *** information & tools *** */
|
||||||
public Map<String, String> getLookupValueMap(String value, String rowLimit) throws NoSuchAlgorithmException,
|
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
|
// get list values from sharepoint
|
||||||
java.util.List<String> listColumnNames = new ArrayList<>();
|
java.util.List<String> listColumnNames = new ArrayList<>();
|
||||||
@ -204,14 +216,18 @@ public class SPList extends SPJaxbObject<List> {
|
|||||||
private ListsSoap getListsPort() throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
private ListsSoap getListsPort() throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
||||||
java.net.URL contextURL = getContext().getSiteURL();
|
java.net.URL contextURL = getContext().getSiteURL();
|
||||||
java.net.URL wsURL = new java.net.URL(contextURL.toString() + "/_vti_bin/Lists.asmx");
|
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);
|
com.microsoft.schemas.sharepoint.soap.lists.Lists service = new com.microsoft.schemas.sharepoint.soap.lists.Lists(wsdlURL);
|
||||||
ListsSoap listsPort = service.getListsSoap();
|
ListsSoap listsPort = service.getListsSoap();
|
||||||
|
|
||||||
((BindingProvider) listsPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsURL.toString());
|
((BindingProvider) listsPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsURL.toString());
|
||||||
|
|
||||||
// log all incoming and outgoing communication - TODO make this configurable by DEBUG switch
|
// log all incoming and outgoing communication - TODO make this configurable by DEBUG switch
|
||||||
java.util.List<Handler> handlers = ((BindingProvider) listsPort).getBinding().getHandlerChain();
|
java.util.List<Handler> handlers = ((BindingProvider) listsPort).getBinding().getHandlerChain();
|
||||||
handlers.add(new ServiceLogHandler());
|
|
||||||
|
handlers.add(
|
||||||
|
new ServiceLogHandler());
|
||||||
((BindingProvider) listsPort).getBinding().setHandlerChain(handlers);
|
((BindingProvider) listsPort).getBinding().setHandlerChain(handlers);
|
||||||
|
|
||||||
return listsPort;
|
return listsPort;
|
||||||
|
|||||||
@ -106,7 +106,31 @@ public class SPListTest extends BaseTest {
|
|||||||
assertEquals("Size smallList", 30, smallList.size());
|
assertEquals("Size smallList", 30, smallList.size());
|
||||||
java.util.List<java.util.List<String>> bigList = list.getListItems(columns, "300");
|
java.util.List<java.util.List<String>> bigList = list.getListItems(columns, "300");
|
||||||
assertNotNull(bigList);
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user