Skip to content

Instantly share code, notes, and snippets.

@james-d
Last active March 12, 2018 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save james-d/f5ab7472b471e8dc28d5 to your computer and use it in GitHub Desktop.
Save james-d/f5ab7472b471e8dc28d5 to your computer and use it in GitHub Desktop.
Rest controllers for the Laboratory information management system. See also https://gist.github.com/james-d/ab72b487b7b12bb7a3bc
package edu.marshall.genomics.lims.web;
import java.util.List;
import javax.inject.Inject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import edu.marshall.genomics.lims.entities.Investigator;
import edu.marshall.genomics.lims.service.LimsService;
@RestController
@RequestMapping("/investigators")
public class InvestigatorController {
private LimsService limsService ;
public LimsService getLimsService() {
return limsService;
}
@Inject
public void setLimsService(LimsService limsService) {
this.limsService = limsService;
}
@RequestMapping(method=RequestMethod.GET, produces="application/json")
public List<Investigator> getInvestigators() {
return limsService.getAllInvestigators() ;
}
@RequestMapping(method=RequestMethod.POST, consumes="application/json", produces="application/json")
public void addInvestigators(@RequestBody List<Investigator> investigators) {
limsService.addInvestigators(investigators);
}
@RequestMapping(method=RequestMethod.PUT, consumes="application/json")
public void updateInvestigator(@RequestBody Investigator investigator) {
limsService.updateInvestigator(investigator);
}
}
package edu.marshall.genomics.lims.web;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import edu.marshall.genomics.lims.entities.Investigator;
import edu.marshall.genomics.lims.entities.Project;
import edu.marshall.genomics.lims.service.LimsService;
@RestController
@RequestMapping("/projects")
public class ProjectController {
private LimsService limsService ;
public LimsService getLimsService() {
return limsService;
}
@Inject
public void setLimsService(LimsService limsService) {
this.limsService = limsService;
}
@RequestMapping(method=RequestMethod.GET, produces="application/json")
public List<Project> getAllProjects() {
return limsService.getAllProjects() ;
}
@RequestMapping(value="/{investigatorId}", method=RequestMethod.GET, produces="application/json")
public List<Project> getProjectsByinvestigatorId(
@PathVariable("investigatorId") int investigatorId
) {
Investigator investigator = limsService.getInvestigatorById(investigatorId);
return limsService.getProjectsByInvestigator(investigator);
}
@RequestMapping(method=RequestMethod.POST, consumes="application/json")
public List<Integer> addProjects(@RequestBody List<Project> projects) {
limsService.addProjects(projects);
return projects.stream().map(Project::getId).collect(Collectors.toList());
}
@RequestMapping(method=RequestMethod.PUT, consumes="application/json")
public void updateProject(@RequestBody Project project) {
limsService.updateProject(project);
}
}
package edu.marshall.genomics.lims.web;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import edu.marshall.genomics.lims.entities.Project;
import edu.marshall.genomics.lims.entities.Sample;
import edu.marshall.genomics.lims.service.LimsService;
@RestController
@RequestMapping("/samples")
public class SampleController {
private LimsService limsService ;
private Logger logger = LoggerFactory.getLogger(getClass());
public LimsService getLimsService() {
return limsService;
}
@Inject
public void setLimsService(LimsService limsService) {
this.limsService = limsService;
}
@RequestMapping(method=RequestMethod.GET, value="/{projectId}", produces="application/json")
public List<Sample> getSamplesByProject(@PathVariable("projectId") int projectId) {
Project project = limsService.getProjectById(projectId);
return limsService.getSamplesByProject(project);
}
@RequestMapping(method=RequestMethod.POST, consumes="application/json")
public List<Integer> addSamples(@RequestBody ArrayList<Sample> samples) {
System.out.println("adding "+samples);
logger.trace("adding "+samples);
limsService.addSamples(samples);
return samples.stream().map(Sample::getId).collect(Collectors.toList());
}
@RequestMapping(method=RequestMethod.PUT, consumes="application/json")
public void updateSample(@RequestBody Sample sample) {
limsService.updateSample(sample);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment