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.
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
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
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);
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
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
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);
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
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();
}