123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
/**
*
*/
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();
}
}