edu.internet2.middleware.grouperClient.api.GcGroupDelete Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grouperClient Show documentation
Show all versions of grouperClient Show documentation
Client for Grouper LDAP and Web Services
/**
* Copyright 2014 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author mchyzer
* $Id: GcGroupDelete.java,v 1.3 2008-12-08 02:55:52 mchyzer Exp $
*/
package edu.internet2.middleware.grouperClient.api;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import edu.internet2.middleware.grouperClient.util.GrouperClientUtils;
import edu.internet2.middleware.grouperClient.ws.GcTransactionType;
import edu.internet2.middleware.grouperClient.ws.GrouperClientWs;
import edu.internet2.middleware.grouperClient.ws.beans.WsGroupDeleteResults;
import edu.internet2.middleware.grouperClient.ws.beans.WsGroupLookup;
import edu.internet2.middleware.grouperClient.ws.beans.WsParam;
import edu.internet2.middleware.grouperClient.ws.beans.WsRestGroupDeleteRequest;
import edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup;
import edu.internet2.middleware.morphString.Crypto;
/**
* class to run a group delete web service call
*/
public class GcGroupDelete {
/**
* endpoint to grouper WS, e.g. https://server.school.edu/grouper-ws/servicesRest
*/
private String wsEndpoint;
/**
* endpoint to grouper WS, e.g. https://server.school.edu/grouper-ws/servicesRest
* @param theWsEndpoint
* @return this for chaining
*/
public GcGroupDelete assignWsEndpoint(String theWsEndpoint) {
this.wsEndpoint = theWsEndpoint;
return this;
}
/**
* ws user
*/
private String wsUser;
/**
* ws user
* @param theWsUser
* @return this for chaining
*/
public GcGroupDelete assignWsUser(String theWsUser) {
this.wsUser = theWsUser;
return this;
}
/**
* ws pass
*/
private String wsPass;
/**
* ws pass
* @param theWsPass
* @return this for chaining
*/
public GcGroupDelete assignWsPass(String theWsPass) {
this.wsPass = theWsPass;
return this;
}
/**
* ws pass
* @param theWsPass
* @return this for chaining
*/
public GcGroupDelete assignWsPassEncrypted(String theWsPassEncrypted) {
String encryptKey = GrouperClientUtils.encryptKey();
return this.assignWsPass(new Crypto(encryptKey).decrypt(theWsPassEncrypted));
}
/**
* ws pass
* @param theWsPass
* @return this for chaining
*/
public GcGroupDelete assignWsPassFile(File theFile) {
return this.assignWsPass(GrouperClientUtils.readFileIntoString(theFile));
}
/**
* ws pass
* @param theWsPass
* @return this for chaining
*/
public GcGroupDelete assignWsPassFileEncrypted(File theFile) {
return this.assignWsPassEncrypted(GrouperClientUtils.readFileIntoString(theFile));
}
/** delete group lookups */
private List groupLookups = new ArrayList();
/**
* add group lookup
* @param wsGroupLookup
* @return this for chaining
*/
public GcGroupDelete addGroupLookup(WsGroupLookup wsGroupLookup) {
this.groupLookups.add(wsGroupLookup);
return this;
}
/** params */
private List params = new ArrayList();
/**
* add a param to the list
* @param paramName
* @param paramValue
* @return this for chaining
*/
public GcGroupDelete addParam(String paramName, String paramValue) {
this.params.add(new WsParam(paramName, paramValue));
return this;
}
/**
* add a param to the list
* @param wsParam
* @return this for chaining
*/
public GcGroupDelete addParam(WsParam wsParam) {
this.params.add(wsParam);
return this;
}
/** act as subject if any */
private WsSubjectLookup actAsSubject;
/**
* assign the act as subject if any
* @param theActAsSubject
* @return this for chaining
*/
public GcGroupDelete assignActAsSubject(WsSubjectLookup theActAsSubject) {
this.actAsSubject = theActAsSubject;
return this;
}
/**
* validate this call
*/
private void validate() {
if (GrouperClientUtils.length(this.groupLookups) == 0) {
throw new RuntimeException("Need at least one group to delete: " + this);
}
}
/** tx type for request */
private GcTransactionType txType;
/**
* assign the tx type
* @param gcTransactionType
* @return self for chaining
*/
public GcGroupDelete assignTxType(GcTransactionType gcTransactionType) {
this.txType = gcTransactionType;
return this;
}
/** if the group detail should be sent back */
private Boolean includeGroupDetail;
/**
* assign if the group detail should be included
* @param theIncludeGroupDetail
* @return this for chaining
*/
public GcGroupDelete assignIncludeGroupDetail(Boolean theIncludeGroupDetail) {
this.includeGroupDetail = theIncludeGroupDetail;
return this;
}
/** client version */
private String clientVersion;
/**
* assign client version
* @param theClientVersion
* @return this for chaining
*/
public GcGroupDelete assignClientVersion(String theClientVersion) {
this.clientVersion = theClientVersion;
return this;
}
/** content type for post request */
private String contentType;
/**
* content type for post request
* @param theContentType
* @return this for chaining
*/
public GcGroupDelete assignContentType(String theContentType) {
this.contentType = theContentType;
return this;
}
/**
* execute the call and return the results. If there is a problem calling the service, an
* exception will be thrown
*
* @return the results
*/
public WsGroupDeleteResults execute() {
this.validate();
WsGroupDeleteResults wsGroupDeleteResults = null;
try {
//Make the body of the request, in this case with beans and marshaling, but you can make
//your request document in whatever language or way you want
WsRestGroupDeleteRequest groupDelete = new WsRestGroupDeleteRequest();
groupDelete.setActAsSubjectLookup(this.actAsSubject);
groupDelete.setTxType(this.txType == null ? null : this.txType.name());
if (this.includeGroupDetail != null) {
groupDelete.setIncludeGroupDetail(this.includeGroupDetail ? "T" : "F");
}
groupDelete.setWsGroupLookups(GrouperClientUtils.toArray(this.groupLookups,
WsGroupLookup.class));
//add params if there are any
if (this.params.size() > 0) {
groupDelete.setParams(GrouperClientUtils.toArray(this.params, WsParam.class));
}
GrouperClientWs grouperClientWs = new GrouperClientWs();
grouperClientWs.assignWsUser(this.wsUser);
grouperClientWs.assignWsPass(this.wsPass);
grouperClientWs.assignWsEndpoint(this.wsEndpoint);
//kick off the web service
wsGroupDeleteResults = (WsGroupDeleteResults)
grouperClientWs.executeService("groups", groupDelete, "groupDelete",
this.clientVersion, this.contentType, false);
String resultMessage = wsGroupDeleteResults.getResultMetadata().getResultMessage();
grouperClientWs.handleFailure(wsGroupDeleteResults, wsGroupDeleteResults.getResults(), resultMessage);
} catch (Exception e) {
GrouperClientUtils.convertToRuntimeException(e);
}
return wsGroupDeleteResults;
}
}