Example | Description | Highlights |
---|
GSH template WS mship counts - V1 - basic | Basic GSH template WS with template inputs and result packed into template output. This is not recommended since the inputs are awkward and the output is difficult to parse. | Inputs
"inputs":[
{ "name":"gsh_input_groupName",
"value":"test:testGroup" } ]
Outputs
"gshOutputLines":[
{ "messageType":"success",
"text":"{\"totalMembershipCount\":3,\"immediateMembershipCount\":3}"
} ]
|
GSH template WS mship counts - V1 - json inputs / outputs | Use template inputs, but use a more sensible JSON input structure. JSON output | Inputs
"wsInput":{
"gsh_input_groupName":"test:testGroup"
}
Output
"wsOutput": {
"totalMembershipCount": 12,
"immediateMembershipCount": 10
}
|
GSH template WS mship counts - V1 - arbitrary inputs map | Does not use template inputs, arbitrary JSON inputs | No GSH template inputs Inputs (note its arbitrary, does not start with gsh_input_ )
"wsInput":{
"groupName":"test:testGroup"
}
Output same as previous Input JSON is read from Map
Map<String, Object> wsInput = gsh_builtin_gshTemplateRuntime.getWsInput();
String groupName = (String)wsInput.get("groupName");
|
GSH template WS mship counts - V1 - bean inputs | Convert the arbitrary input JSON to a bean, convert a bean to the output. This is nice since the code will compile and auto-marshal. This is the ideal way to go for V1, though V2 is better since you can have tests. | Same as previous, though the input is read into a bean Click here to expand...
public class WsInputBean {
private String groupName;
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}
// skip to reading inputs
Map<String, Object> wsInput = gsh_builtin_gshTemplateRuntime.getWsInput();
WsInputBean wsInputBean = GrouperUtil.jsonConvertFromMap(wsInput, WsInputBean.class);
String groupName = wsInputBean.getGroupName();
Output is sent via a bean Click here to expand...
public class WsOutputBean {
private int totalMembershipCount;
private int immediateMembershipCount;
public int getTotalMembershipCount() {
return totalMembershipCount;
}
public void setTotalMembershipCount(int totalMembershipCount) {
this.totalMembershipCount = totalMembershipCount;
}
public int getImmediateMembershipCount() {
return immediateMembershipCount;
}
public void setImmediateMembershipCount(int immediateMembershipCount) {
this.immediateMembershipCount = immediateMembershipCount;
}
}
// skip to writing output
WsOutputBean wsOutputBean = new WsOutputBean();
wsOutputBean.setTotalMembershipCount(GrouperUtil.intValue(effectiveCount));
wsOutputBean.setImmediateMembershipCount(GrouperUtil.intValue(immediateCount));
gsh_builtin_gshTemplateOutput.setWsOutput(wsOutputBean);
|
GSH template WS mship counts - V2 - basic | Convert the V1 basic template into V2 | Extend the V2 class and have a gshRulLogic method Click here to expand...
public class Test25membershipCountV2basic extends GshTemplateV2 {
@Override
public void gshRunLogic(GshTemplateV2input gshTemplateV2input, GshTemplateV2output gshTemplateV2output) {
String gsh_input_groupName = gshTemplateV2input.getGsh_builtin_inputString("gsh_input_groupName");
GrouperSession gsh_builtin_grouperSession = gshTemplateV2input.getGsh_builtin_grouperSession();
Subject gsh_builtin_subject = gshTemplateV2input.getGsh_builtin_subject();
GshTemplateOutput gsh_builtin_gshTemplateOutput = gshTemplateV2output.getGsh_builtin_gshTemplateOutput();
|
GSH template WS mship counts - V2 - json inputs / outputs | V2, use template inputs, but use a more sensible JSON input structure. JSON output | Inputs
"wsInput":{
"gsh_input_groupName":"test:testGroup"
}
Output
"wsOutput": {
"totalMembershipCount": 12,
"immediateMembershipCount": 10
}
|
GSH template WS mship counts - V2 - arbitrary inputs map | V2, does not use template inputs, arbitrary JSON inputs | No GSH template inputs Inputs (note its arbitrary, does not start with gsh_input_ )
"wsInput":{
"groupName":"test:testGroup"
}
Output same as previous Input JSON is read from Map
Map<String, Object> wsInput = gsh_builtin_gshTemplateRuntime.getWsInput();
String groupName = (String)wsInput.get("groupName");
|
GSH template WS mship counts - V2 - bean inputs | V2, convert the arbitrary input JSON to a bean, convert a bean to the output | Same as previous, though the input is read into a bean Click here to expand...
public class WsInputBean {
private String groupName;
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}
// skip to reading inputs
Map<String, Object> wsInput = gsh_builtin_gshTemplateRuntime.getWsInput();
WsInputBean wsInputBean = GrouperUtil.jsonConvertFromMap(wsInput, WsInputBean.class);
String groupName = wsInputBean.getGroupName();
Output is sent via a bean Click here to expand...
public class WsOutputBean {
private int totalMembershipCount;
private int immediateMembershipCount;
public int getTotalMembershipCount() {
return totalMembershipCount;
}
public void setTotalMembershipCount(int totalMembershipCount) {
this.totalMembershipCount = totalMembershipCount;
}
public int getImmediateMembershipCount() {
return immediateMembershipCount;
}
public void setImmediateMembershipCount(int immediateMembershipCount) {
this.immediateMembershipCount = immediateMembershipCount;
}
}
// skip to writing output
WsOutputBean wsOutputBean = new WsOutputBean();
wsOutputBean.setTotalMembershipCount(GrouperUtil.intValue(effectiveCount));
wsOutputBean.setImmediateMembershipCount(GrouperUtil.intValue(immediateCount));
gsh_builtin_gshTemplateOutput.setWsOutput(wsOutputBean);
|
GSH template WS mship counts - V2 - bean inputs with test | V2, convert the arbitrary input JSON to a bean, convert a bean to the output, test the logic. This is nice since the code will compile and auto-marshal. This is the ideal way to go. | Extend the V2 test class Click here to expand...
public static class TestQueries extends GshTemplateV2test {
@Override
protected void setUp() {
WsInputBean wsInputBean = new WsInputBean();
wsInputBean.setGroupName("test:testGroup10");
this.setGshWsInput(wsInputBean);
this.assignGshSubjectUsingApp("g:isa", "GrouperSystem");
this.setGshTemplateConfigId("membershipCountV2beanInputsWithTest");
Subject subject0 = SubjectFinder.findByIdAndSource("test.subject.0", "jdbc", true);
Subject subject1 = SubjectFinder.findByIdAndSource("test.subject.1", "jdbc", true);
Group testGroup11 = new GroupSave().assignName("test:testGroup11").assignCreateParentStemsIfNotExist(true).save();
Group testGroup10 = new GroupSave().assignName("test:testGroup10").assignCreateParentStemsIfNotExist(true).save();
testGroup11.replaceMembers(GrouperUtil.toList(subject0));
testGroup10.replaceMembers(GrouperUtil.toList(subject1, testGroup11.toSubject()));
}
@Override
public void gshCheckResult() {
WsOutputBean wsOutputBean = (WsOutputBean)this.getGshTemplateOutput().getWsOutput();
assertEquals(2, wsOutputBean.getImmediateMembershipCount());
assertEquals(3, wsOutputBean.getTotalMembershipCount());
}
}
Register the test (method that starts with "test")
public GshTemplateV2test testQueries() {
return new TestQueries();
}
|