Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Description: Resource Code
Submitted on May 18, 2015 at 07:11 AM

Section 1 (Java)

/**
 * 
 */
package org.openmrs.module.temmodule.web.resource;

import org.openmrs.api.context.Context;
import org.openmrs.module.teammodule.Team;
import org.openmrs.module.teammodule.api.TeamService;
import org.openmrs.module.teammodule.rest.v1_0.resource.TeamModuleResourceController;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.response.ResponseException;

/**
 * @author Muhammad Safwan
 * 
 */
@Resource(name = RestConstants.VERSION_1 + TeamModuleResourceController.TEAMMODULE_NAMESPACE + "/team", supportedClass = Team.class, supportedOpenmrsVersions = { "1.8.*", "1.9.*, 1.10.*, 1.11.*",
		"1.12.*" })
public class TeamRequestResource extends DataDelegatingCrudResource<Team> {

	@Override
	public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
		DelegatingResourceDescription description = null;

		if (Context.isAuthenticated()) {
			description = new DelegatingResourceDescription();
			if (rep instanceof DefaultRepresentation) {
				//description.addProperty("teamId");
				description.addProperty("display", findMethod("getDisplayString"));
				description.addProperty("teamIdentifier");
				description.addProperty("teamName");
				description.addProperty("uuid");
				description.addProperty("dateCreated");
				description.addProperty("location");
				description.addProperty("memberCount");
				description.addSelfLink();
				description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
				//System.out.println("Default");
			} else if (rep instanceof FullRepresentation) {
				description.addProperty("display", findMethod("getDisplayString"));
				description.addProperty("teamId");
				description.addProperty("teamIdentifier");
				description.addProperty("teamName");
				description.addProperty("uuid");
				description.addProperty("dateCreated");
				description.addProperty("location");
				description.addProperty("memberCount");
				description.addSelfLink();
				description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_REF);
			}
		}

		return description;
	}

	@Override
	public Team newDelegate() {
		return new Team();
	}

	@Override
	public Team save(Team team) {
		/*
		 * Context.getService(TeamService.class).saveTeam(team); return team;
		 */
		return null;
	}

	@Override
	protected void delete(Team team, String reason, RequestContext context) throws ResponseException {
		/*
		 * Context.getService(TeamService.class).getTeam(team.getTeamId());
		 * Context.getService(TeamService.class).purgeTeam(team);
		 * team.setVoidReason(reason);
		 */

	}

	@Override
	public Team getByUniqueId(String uuid) {
		return Context.getService(TeamService.class).getTeam(uuid);
	}

	@Override
	public void purge(Team arg0, RequestContext arg1) throws ResponseException {
		// TODO Auto-generated method stub

	}
	
	@Override
	protected NeedsPaging<Team> doSearch(RequestContext context) {
		System.out.println("Got inside");
		System.out.println(context.getParameter("teamName"));
		return new NeedsPaging<Team>(Context.getService(TeamService.class).searchTeam(context.getParameter("teamName")), context);
	}
	
	public String getDisplayString(Team team) {
		if (team.getTeamName() == null)
			return "";
		
		return team.getTeamName();
	}

}