added delete command to lists and to usergroups
This commit is contained in:
@ -40,6 +40,7 @@ public class ServiceLogHandler implements SOAPHandler<SOAPMessageContext> {
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(SOAPMessageContext arg0) {
|
||||
/* // TODO make configrable via logger
|
||||
SOAPMessage message = arg0.getMessage();
|
||||
boolean isOutboundMessage = (Boolean) arg0.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
|
||||
if (isOutboundMessage) {
|
||||
@ -52,7 +53,8 @@ public class ServiceLogHandler implements SOAPHandler<SOAPMessageContext> {
|
||||
System.out.println();
|
||||
} catch (SOAPException | IOException e) {
|
||||
// TODO add error handling
|
||||
}
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -138,8 +138,7 @@ public class SPList extends SPJaxbObject<List> {
|
||||
KeyManagementException, JAXBException, MalformedURLException, SAXException, ParserConfigurationException, IOException {
|
||||
|
||||
SPBatch batch = new SPBatch(getContext());
|
||||
for (Integer batchId = 1; batchId <= dataList.size();
|
||||
batchId++) {
|
||||
for (Integer batchId = 1; batchId <= dataList.size(); batchId++) {
|
||||
Method method = new Method();
|
||||
method.setID(batchId);
|
||||
method.setCmd(MethodType.NEW);
|
||||
@ -156,11 +155,22 @@ public class SPList extends SPJaxbObject<List> {
|
||||
});
|
||||
batch.addMethod(method);
|
||||
}
|
||||
UpdateListItems.Updates updates = new UpdateListItems.Updates();
|
||||
Node node = batch.createSharePointCAMLNode();
|
||||
updates.getContent().add(node);
|
||||
|
||||
getListsPort().updateListItems(getValue().name, updates);
|
||||
executeUpdate(batch);
|
||||
|
||||
}
|
||||
|
||||
public void removeListItem(Map<String, String> dataMap) throws JAXBException, ParserConfigurationException, NoSuchAlgorithmException,
|
||||
SAXException, KeyManagementException, IOException {
|
||||
java.util.List<Map<String, String>> dataList = new ArrayList<>();
|
||||
dataList.add(dataMap);
|
||||
removeListItems(dataList);
|
||||
}
|
||||
|
||||
public void removeListItems(java.util.List<Map<String, String>> dataList) throws JAXBException, ParserConfigurationException, NoSuchAlgorithmException,
|
||||
SAXException, KeyManagementException, IOException {
|
||||
SPBatch batch = createBatch(dataList, MethodType.DELETE);
|
||||
executeUpdate(batch);
|
||||
}
|
||||
|
||||
/* *** information & tools *** */
|
||||
@ -249,6 +259,37 @@ public class SPList extends SPJaxbObject<List> {
|
||||
}
|
||||
}
|
||||
|
||||
private SPBatch createBatch(java.util.List<Map<String, String>> dataList, MethodType methodType) throws JAXBException {
|
||||
SPBatch batch = new SPBatch(getContext());
|
||||
for (Integer batchId = 1; batchId <= dataList.size(); batchId++) {
|
||||
Method method = new Method();
|
||||
method.setID(batchId);
|
||||
method.setCmd(methodType);
|
||||
Map<String, String> data = dataList.get(batchId - 1);
|
||||
data.keySet().stream().
|
||||
map((String key) -> {
|
||||
Field field = new Field();
|
||||
field.setName(key.replace(" ", "_x0020_"));
|
||||
field.setContent(data.get(key));
|
||||
return field;
|
||||
}).
|
||||
forEach((Field field) -> {
|
||||
method.getFields().add(field);
|
||||
});
|
||||
batch.addMethod(method);
|
||||
}
|
||||
return batch;
|
||||
}
|
||||
|
||||
private void executeUpdate(SPBatch batch) throws ParserConfigurationException, NoSuchAlgorithmException, SAXException, KeyManagementException, IOException,
|
||||
JAXBException {
|
||||
UpdateListItems.Updates updates = new UpdateListItems.Updates();
|
||||
Node node = batch.createSharePointCAMLNode();
|
||||
updates.getContent().add(node);
|
||||
|
||||
getListsPort().updateListItems(getValue().name, updates);
|
||||
}
|
||||
|
||||
/* *** unsorted *** */
|
||||
}
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ public class SPLists extends SPJaxbObject<de.muehlencord.shared.sharepoint.api.l
|
||||
// Parse XML file
|
||||
Element rootElement = (Element) content;
|
||||
String listsString = SPObject.xmlToString(rootElement.getOwnerDocument());
|
||||
System.out.println(listsString);
|
||||
// System.out.println(listsString);
|
||||
this.setValue(listsString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ public class SPSite extends SPObject {
|
||||
public void getRootWeb() throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
||||
String rootWebUrl = StringUtils.removeEndIgnoreCase(getContext().getSiteURL().toString(), "/");
|
||||
GetWebResponse.GetWebResult result = getWebsPort(getContext().getSiteURL()).getWeb(rootWebUrl);
|
||||
System.out.println (result);
|
||||
// System.out.println (result);
|
||||
}
|
||||
|
||||
private WebsSoap getWebsPort(URL webUrl) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.muehlencord.shared.sharepoint.api.usergroup;
|
||||
|
||||
import com.microsoft.schemas.sharepoint.soap.usergroup.GetUserCollectionFromGroupResponse;
|
||||
import com.microsoft.schemas.sharepoint.soap.usergroup.GetUserInfoResponse;
|
||||
import com.microsoft.schemas.sharepoint.soap.usergroup.UserGroup;
|
||||
import com.microsoft.schemas.sharepoint.soap.usergroup.UserGroupSoap;
|
||||
@ -15,6 +16,9 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
import javax.xml.ws.handler.Handler;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
@ -31,11 +35,45 @@ public class SPUserGroup extends SPObject {
|
||||
NoSuchAlgorithmException, IOException, KeyManagementException {
|
||||
SPUser user = getUser(userLoginName);
|
||||
if (user == null) {
|
||||
throw new SAXException ("User not found");
|
||||
throw new SAXException("User not found");
|
||||
}
|
||||
getUserGroupPort().addUserToGroup(groupName, user.getUserName(), user.getUserLoginName(), user.getUserEmail(), user.getUserNotes());
|
||||
}
|
||||
|
||||
public void removeUserFromGroup(String userLoginName, String groupName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException,
|
||||
JAXBException, SAXException {
|
||||
SPUser user = getUser(userLoginName);
|
||||
if (user == null) {
|
||||
throw new SAXException("User not found");
|
||||
}
|
||||
getUserGroupPort().removeUserFromGroup(groupName, user.getUserLoginName());
|
||||
}
|
||||
|
||||
public boolean isUserMemberOfGroup(String userLoginName, String groupName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
|
||||
GetUserCollectionFromGroupResponse.GetUserCollectionFromGroupResult result = getUserGroupPort().getUserCollectionFromGroup(groupName);
|
||||
|
||||
if ((result != null) && (result.getContent() != null) && (!result.getContent().isEmpty())) {
|
||||
Object value = result.getContent().get(0);
|
||||
if (value instanceof Element) {
|
||||
Element rootElement = (Element) value;
|
||||
Node usersNode = rootElement.getFirstChild(); // users node
|
||||
NodeList userNodeList = usersNode.getChildNodes(); // all user nodes
|
||||
for (int i = 0; i < userNodeList.getLength(); i++) {
|
||||
Node userNode = userNodeList.item(i);
|
||||
NamedNodeMap attributes = userNode.getAttributes();
|
||||
if ((attributes.getNamedItem("LoginName") != null)
|
||||
&& (attributes.getNamedItem("LoginName").getNodeValue().equals("i:0#.w|" + userLoginName))) {
|
||||
return true; // user found
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUserId(String userLoginName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, JAXBException, SAXException {
|
||||
SPUser user = getUser(userLoginName);
|
||||
if (user == null) {
|
||||
@ -45,6 +83,15 @@ public class SPUserGroup extends SPObject {
|
||||
}
|
||||
}
|
||||
|
||||
public String getUserName(String userLoginName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, JAXBException, SAXException {
|
||||
SPUser user = getUser(userLoginName);
|
||||
if (user == null) {
|
||||
return null;
|
||||
} else {
|
||||
return user.getUserName();
|
||||
}
|
||||
}
|
||||
|
||||
private SPUser getUser(String userLoginName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, JAXBException, SAXException {
|
||||
GetUserInfoResponse.GetUserInfoResult result = getUserGroupPort().getUserInfo("i:0#.w|" + userLoginName);
|
||||
// TODO why is i:0#.w| in front?
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromSiteResult">
|
||||
<s:complexType mixed="true">
|
||||
<s:sequence>
|
||||
<s:any/>
|
||||
<s:any processContents='skip' />
|
||||
</s:sequence>
|
||||
</s:complexType>
|
||||
</s:element>
|
||||
@ -27,7 +27,7 @@
|
||||
<s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromWebResult">
|
||||
<s:complexType mixed="true">
|
||||
<s:sequence>
|
||||
<s:any/>
|
||||
<s:any processContents='skip' />
|
||||
</s:sequence>
|
||||
</s:complexType>
|
||||
</s:element>
|
||||
@ -43,7 +43,7 @@
|
||||
<s:element minOccurs="0" maxOccurs="1" name="GetAllUserCollectionFromWebResult">
|
||||
<s:complexType mixed="true">
|
||||
<s:sequence>
|
||||
<s:any/>
|
||||
<s:any processContents='skip' />
|
||||
</s:sequence>
|
||||
</s:complexType>
|
||||
</s:element>
|
||||
@ -63,7 +63,7 @@
|
||||
<s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromGroupResult">
|
||||
<s:complexType mixed="true">
|
||||
<s:sequence>
|
||||
<s:any/>
|
||||
<s:any processContents='skip' />
|
||||
</s:sequence>
|
||||
</s:complexType>
|
||||
</s:element>
|
||||
@ -83,7 +83,7 @@
|
||||
<s:element minOccurs="0" maxOccurs="1" name="GetUserCollectionFromRoleResult">
|
||||
<s:complexType mixed="true">
|
||||
<s:sequence>
|
||||
<s:any/>
|
||||
<s:any processContents='skip' />
|
||||
</s:sequence>
|
||||
</s:complexType>
|
||||
</s:element>
|
||||
|
||||
@ -36,4 +36,12 @@ public class SPUserGroupTest extends BaseTest {
|
||||
ug.addUserToGroup("wincor-nixdorf\\joern.muehlencord", "Test Group");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsUserMemberOfGroup() throws Exception {
|
||||
SPUserGroup ug = new SPUserGroup(context);
|
||||
boolean result = ug.isUserMemberOfGroup("wincor-nixdorf\\joern.muehlencord", "HQ All Members");
|
||||
assertEquals ("HQ All membership", true, result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user