Commit 7d2aaeae authored by Matija Obreza's avatar Matija Obreza
Browse files

REST controller /a/exists/{instCode}/{genus}?{acceNumb}

parent 05923237
......@@ -88,6 +88,8 @@ public interface GenesysService {
Accession getAccession(AccessionIdentifier3 aid3);
Accession getAccession(String instCode, String genus, String acceNumb);
Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute faoInstitute, Pageable pageable);
......@@ -113,4 +115,5 @@ public interface GenesysService {
void saveSvalbards(List<SvalbardData> svalbards);
long countAvailable(Set<Long> accessionIds);
}
......@@ -199,6 +199,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
return accessionRepository.findByInstituteCodeAndAccessionNameAndGenus(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
}
@Override
public Accession getAccession(String instCode, String genus, String acceNumb) {
return accessionRepository.findByInstituteCodeAndAccessionNameAndGenus(instCode, acceNumb, genus);
}
@Override
public Accession getAccession(long accessionId) {
return accessionRepository.findOne(accessionId);
......
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller("restAccessionController")
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = { "/api/v0/a", "/json/v0/a" })
public class AccessionController extends RestController {
@Autowired
GenesysService genesysService;
/**
* Check if accessions exists in the system
*
* @return
*/
@RequestMapping(value = "/exists/{instCode}/{genus}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
boolean exists(@PathVariable("instCode") String instCode, @PathVariable("genus") String genus, @RequestParam("acceNumb") String acceNumb) {
LOG.info("Checking if accn exists " + instCode + "." + acceNumb + " genus=" + genus);
Accession accession = genesysService.getAccession(instCode, genus, acceNumb);
return accession != null;
}
}
......@@ -67,7 +67,7 @@ public class CropsController extends RestController {
*/
@RequestMapping(value = "/crops", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Object listCrops() throws AuthorizationException {
Object listCrops() {
LOG.info("Listing crops");
List<Crop> crops = cropService.list(LocaleContextHolder.getLocale());
return OAuth2Cleanup.clean(crops);
......
......@@ -10,7 +10,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
public class RestController {
public abstract class RestController {
protected final Log LOG = LogFactory.getLog(getClass());
public RestController() {
......
......@@ -27,7 +27,7 @@ log4j.rootLogger=info, stdout
#log4j.category.org.genesys2=debug
#log4j.category.org.hibernate.search=debug
log4j.category.org.apache.tomcat.jdbc.pool=debug
log4j.category.org.springframework.security.oauth2=trace
#log4j.category.org.springframework.security.oauth2=trace
#log4j.category.org.springframework.security.access=trace
#log4j.category.org.springframework.security.acl=trace
#log4j.category.org.springframework.expression=trace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment