Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is similar to REST, except it doesnt use HTTP methods, and it doesnt use the URL to convey request information (though you could use request params)

Request:

Code Block
{{
  "groupHasMemberRequest":{
    "groupLookup":{
      "handle":"someHandle"
    },
    "subjectLookup":{
      "id":"someId"
    }
  }
}

...

POX (plan old xml)

Request:

Code Block
{<groupHasMemberRequest>
  <groupLookup>
    <handle>someHandle</handle>
  </groupLookup>
  <subjectLookup>
    <id>someId</id>
  </subjectLookup>
</groupHasMemberRequest>

...

Code Block
package org.jasig.fifer.fiferServer.grouper;

import org.apache.commons.lang.StringUtils;
import org.jasig.fifer.fiferServer.coreapi.GroupHasMemberResponse;
import org.jasig.fifer.fiferServer.coreapi.GroupLookup;
import org.jasig.fifer.fiferServer.coreapi.ResponseMetadata;
import org.jasig.fifer.fiferServer.coreapi.SubjectLookup;
import org.jasig.fifer.fiferServer.group.MembershipImmediacy;
import org.jasig.fifer.fiferServer.logic.FiferGroupLogicInterface;

import edu.internet2.middleware.grouperClient.api.GcHasMember;
import edu.internet2.middleware.grouperClient.ws.WsMemberFilter;
import edu.internet2.middleware.grouperClient.ws.beans.WsHasMemberResults;
import edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup;

/**
 * Implement the fifer group service for Grouper
 * @author mchyzer
 *
 */
public class GrouperGroupLogic implements FiferGroupLogicInterface {

  /**
   * convert from handle to group name
   * @param handle
   * @return the group name
   */
  private String convertFromGroupHandleToGroupName(String handle) {
    //TODO translate from handle to group name
    return handle;
  }

  /**
   * @see FiferGroupLogicInterface#hasMember(GroupLookup, SubjectLookup, MembershipImmediacy)
   */
  @Override
  public GroupHasMemberResponse hasMember(GroupLookup groupLookup, SubjectLookup subjectLookup,
      MembershipImmediacy membershipImmediacy) {

    GcHasMember gcHasMember = new GcHasMember();

    {
      if (!StringUtils.isBlank(groupLookup.getId())) {
        gcHasMember.assignGroupUuid(groupLookup.getId());
      }
      if (!StringUtils.isBlank(groupLookup.getHandle())) {
        gcHasMember.assignGroupName(convertFromGroupHandleToGroupName(groupLookup.getHandle()));
      }

    }

    {
      WsSubjectLookup wsSubjectLookup = new WsSubjectLookup();
      if (!StringUtils.isBlank(subjectLookup.getHandle())) {
        wsSubjectLookup.setSubjectIdentifier(subjectLookup.getHandle());
      }
      if (!StringUtils.isBlank(subjectLookup.getId())) {
        wsSubjectLookup.setSubjectId(subjectLookup.getId());
      }
      if (!StringUtils.isBlank(subjectLookup.getIdOrHandle())) {
        //set both of these for id or identifier
        wsSubjectLookup.setSubjectId(subjectLookup.getIdOrHandle());
        wsSubjectLookup.setSubjectIdentifier(subjectLookup.getIdOrHandle());
      }

    }

    {

      if (membershipImmediacy == MembershipImmediacy.any) {
        gcHasMember.assignMemberFilter(WsMemberFilter.All);
      }
      if (membershipImmediacy == MembershipImmediacy.immediate) {
        gcHasMember.assignMemberFilter(WsMemberFilter.Immediate);
      }
      if (membershipImmediacy == MembershipImmediacy.nonimmediate) {
        gcHasMember.assignMemberFilter(WsMemberFilter.NonImmediate);
      }
    }

    WsHasMemberResults wsHasMemberResults = gcHasMember.execute();

    GroupHasMemberResponse groupHasMemberResponse = new GroupHasMemberResponse();
    ResponseMetadata responseMetadata = new ResponseMetadata();
    groupHasMemberResponse.setResponseMetadata(responseMetadata);


    if (StringUtils.equals(wsHasMemberResults.getResultMetadata().getSuccess(), "T")
        || StringUtils.equals(wsHasMemberResults.getResultMetadata().getResultCode(), "SUBJECT_NOT_FOUND")) {
      responseMetadata.setSuccess(true);

      if (StringUtils.equals(wsHasMemberResults.getResultMetadata().getResultCode(), "SUBJECT_NOT_FOUND")
          || StringUtils.equals(wsHasMemberResults.getResultMetadata().getResultCode(), "IS_NOT_MEMBER")) {
        groupHasMemberResponse.setHasMember(false);
      } else if (StringUtils.equals(wsHasMemberResults.getResultMetadata().getResultCode(), "IS_MEMBER")) {
        groupHasMemberResponse.setHasMember(true);
      } else {
        throw new RuntimeException("Note expecting Grouper result code: " + wsHasMemberResults.getResultMetadata().getResultCode());
      }
    }
    return groupHasMemberResponse;

  }

}

Note, the service implementor only needs to worry about the current version of the FIFER API, the reference implementation will degrade gracefully to all previous versions of the API for all formats.