Commit d4a56a3c authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Obsolete API v0

- updated methods with pagination parameters
parent 06d4187a
......@@ -67,7 +67,9 @@ import io.swagger.annotations.Api;
*
* @author Andrey Lugovskoy
* @author Matija Obreza
* @deprecated Use {@link org.genesys2.server.api.v1.DatasetController}
*/
@Deprecated
@RestController("catalogDatasetApi0")
@RequestMapping(DatasetController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......@@ -310,9 +312,9 @@ public class DatasetController {
*/
@GetMapping(value = CREATOR_URL + "/list")
public Page<DatasetCreator> listDatasetCreators(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("UUID") final UUID uuid) {
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @PathVariable("UUID") final UUID uuid) {
return datasetService.listDatasetCreators(uuid, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
......@@ -456,8 +458,6 @@ public class DatasetController {
public List<RepositoryFile> getList(@PathVariable("UUID") final UUID datasetUuid) throws NotFoundElement {
return datasetService.listDatasetFiles(datasetService.loadDataset(datasetUuid));
}
/**
* List location.
......
......@@ -58,7 +58,9 @@ import javax.servlet.http.HttpServletResponse;
* The Class DescriptorController.
*
* @author Maxym Borodenko
* @deprecated Use {@link org.genesys2.server.api.v1.DescriptorController}
*/
@Deprecated
@RestController("catalogDescriptorApi0")
@RequestMapping(DescriptorController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......
......@@ -59,7 +59,9 @@ import io.swagger.annotations.Api;
* The Class DescriptorListController.
*
* @author Matija Obreza
* @deprecated Use {@link org.genesys2.server.api.v1.DescriptorListController}
*/
@Deprecated
@RestController("catalogDescriptorListApi0")
@RequestMapping(DescriptorListController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......
......@@ -38,7 +38,9 @@ import io.swagger.annotations.ApiOperation;
* The Class GeoController.
*
* @author Maxym Borodenko
* @deprecated Use {@link org.genesys2.server.api.v1.GeoController}
*/
@Deprecated
@RestController("cataloGeoApi0")
@RequestMapping(GeoController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......
......@@ -43,7 +43,9 @@ import io.swagger.annotations.Api;
* The Class LanguagesController.
*
* @author Maxym Borodenko
* @deprecated Use {@link org.genesys2.server.api.v1.LanguagesController}
*/
@Deprecated
@RestController("languageApi0")
@RequestMapping(LanguagesController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......
......@@ -59,7 +59,9 @@ import io.swagger.annotations.Api;
* The Class MeController.
*
* @author Andrey Lugovskoy.
* @deprecated Use {@link org.genesys2.server.api.v1.MeController}
*/
@Deprecated
@RestController("catalogMeApi0")
@RequestMapping(MeController.API_URL)
@PreAuthorize("isAuthenticated() && hasRole('USER')") // Don't allow OAuth clients here
......@@ -233,7 +235,7 @@ public class MeController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param descriptorListFilter the descriptor list filter
* @param filter the descriptor list filter
* @return the page
* @throws IOException
* @deprecated Moved to DescriptorListController
......
......@@ -44,7 +44,9 @@ import io.swagger.annotations.Api;
* Rest controller for Partner.
*
* @author Andrey Lugovskoy.
* @deprecated Use {@link org.genesys2.server.api.v1.PartnerController}
*/
@Deprecated
@RestController("partnerApi0")
@RequestMapping(PartnerController.CONTROLLER_URL)
@Api(tags = { "partner" })
......@@ -65,9 +67,6 @@ public class PartnerController {
* My partners.
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param partnerFilter the partner filter
* @return the page
*/
......@@ -81,9 +80,6 @@ public class PartnerController {
* List partners.
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filter the partner filter
* @return the page
* @throws IOException
......@@ -126,8 +122,6 @@ public class PartnerController {
/**
* Update partner.
*
* @param uuid the uuid
* @param version the version
* @param source the source
* @return the partner
*/
......
......@@ -38,6 +38,7 @@ import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.SearchResults;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -54,7 +55,9 @@ import com.fasterxml.jackson.annotation.JsonView;
* API to search the Catalog.
*
* @author Matija Obreza
* @deprecated Use {@link org.genesys2.server.api.v1.SearchController}
*/
@Deprecated
@RestController("catalogSearchApi0")
@RequestMapping(value = { "/api/v0/search" })
public class SearchController {
......@@ -126,24 +129,3 @@ public class SearchController {
return searchQuery.replaceAll("[^\\w\\d\\s]+", "").replaceAll("\\s\\s+", " ").trim();
}
}
/**
* Wrapper for search results
*/
class SearchResults<T extends BasicModel> {
public List<String> filters;
public String key = "uuid";
public List<T> hits;
public static <T extends BasicModel> SearchResults<T> from(String key, List<String> filters, List<T> list) {
if (list == null || list.isEmpty())
return null;
SearchResults<T> sr = new SearchResults<T>();
sr.filters = filters;
sr.key = key;
sr.hits = list;
return sr;
}
}
......@@ -45,7 +45,9 @@ import io.swagger.annotations.Api;
* The Class VocabularyController.
*
* @author Matija Obreza
* @deprecated Use {@link org.genesys2.server.api.v1.VocabularyController}
*/
@Deprecated
@RestController("vocabularyApi0")
@RequestMapping(VocabularyController.CONTROLLER_URL)
@Api(tags = { "vocabulary" })
......
......@@ -24,7 +24,6 @@ import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.catalog.service.worker.WiewsVocabularyUpdater;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.model.impl.FaoInstitute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -43,10 +42,10 @@ import io.swagger.annotations.Api;
/**
* The Class WiewsController.
*
* TODO Use {@link FaoInstitute} here?
*
* @author Maxym Borodenko
* @deprecated Use {@link org.genesys2.server.api.v1.WiewsController}
*/
@Deprecated
@RestController("wiewsApi0")
@RequestMapping(WiewsController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
......
......@@ -35,7 +35,9 @@ import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
......@@ -55,7 +57,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -153,9 +154,6 @@ public class AccessionController {
* List accessions by filterCode or filter
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code
* @param filter the filter
* @return the page
......@@ -163,10 +161,7 @@ public class AccessionController {
*/
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Public.class })
public FilteredPage<Accession> list(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestParam(name = "f", required = false) String filterCode,
public FilteredPage<Accession> list(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException {
if (filterCode != null) {
......@@ -174,7 +169,8 @@ public class AccessionController {
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, accessionService.list(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.list(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
}
/**
......
......@@ -24,7 +24,9 @@ import java.util.Map;
import io.swagger.annotations.Api;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
......@@ -37,7 +39,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -152,20 +153,13 @@ public class CMSController {
* List articles by filterCode or filter
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code
* @param filter the article filter
* @return the page
* @throws IOException
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<Article> listArticles(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
public FilteredPage<Article> listArticles(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) ArticleFilter filter) throws IOException {
if (filterCode != null) {
......@@ -173,7 +167,8 @@ public class CMSController {
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, contentService.listArticles(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
FilterInfo<ArticleFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, ArticleFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, contentService.listArticles(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
}
/**
......
......@@ -70,18 +70,31 @@ public class CropsController extends ApiBaseController {
CropService cropService;
/**
* List all crops
* List of Crop details
* @return
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<CropService.CropDetails> listCrops() {
LOG.info("Listing crops");
public List<CropService.CropDetails> listCropDetails() {
LOG.info("Listing crop details");
return cropService.listDetails(LocaleContextHolder.getLocale());
}
/**
* List all crops
* @return
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Crop> listCrops() {
LOG.info("Listing crops");
return cropService.list(LocaleContextHolder.getLocale());
}
/**
* Add a crop
* @return
......
......@@ -16,12 +16,19 @@
package org.genesys2.server.api.v1;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.catalog.service.worker.ISO3166VocabularyUpdater;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.GeoRegion;
import org.genesys2.server.service.GeoRegionService;
......@@ -30,9 +37,13 @@ import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;
@RestController("geoApi1")
......@@ -42,6 +53,21 @@ public class GeoController extends ApiBaseController {
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/geo";
/** The Constant ISO3166_2ALPHA. */
public static final UUID ISO3166_2ALPHA = ISO3166VocabularyUpdater.ISO3166_2ALPHA;
/** The Constant ISO3166_3ALPHA. */
public static final UUID ISO3166_3ALPHA = ISO3166VocabularyUpdater.ISO3166_3ALPHA;
/** The Constant ISO3166_NUMERIC. */
public static final UUID ISO3166_NUMERIC = ISO3166VocabularyUpdater.ISO3166_NUMERIC;
@Autowired
private ISO3166VocabularyUpdater iso3166VocabularyUpdater;
@Autowired
private VocabularyService vocabularyService;
@Autowired
private GeoService geoService;
......@@ -82,4 +108,55 @@ public class GeoController extends ApiBaseController {
LOG.info("Getting region {}", isoCode);
return geoRegionService.getDetails(isoCode);
}
/**
* Update countries codes.
*
* @return the string
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/update")
@ApiOperation("Triggers update of ISO country code vocabularies")
public String updateCountriesCodes() throws IOException {
LOG.info("Updating ISO country codes");
vocabularyService.autoUpdateOrCreateVocabulary(ISO3166_2ALPHA, iso3166VocabularyUpdater.getISO3166Alpha2Vocabulary());
vocabularyService.autoUpdateOrCreateVocabulary(ISO3166_3ALPHA, iso3166VocabularyUpdater.getISO3166Alpha3Vocabulary());
vocabularyService.autoUpdateOrCreateVocabulary(ISO3166_NUMERIC, iso3166VocabularyUpdater.getISO3166NumericVocabulary());
return "OK";
}
/**
* Gets the.
*
* @param code the code
* @return the vocabulary term
*/
@GetMapping(value = "/iso3166/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Lookup ISO-3166 country by code")
public VocabularyTerm get(@PathVariable("code") final String code) {
final boolean isNumeric = code.chars().allMatch(Character::isDigit);
if (isNumeric) {
return vocabularyService.getVocabularyTerm(ISO3166_NUMERIC, code);
} else if (code.length() == 2) {
return vocabularyService.getVocabularyTerm(ISO3166_2ALPHA, code);
} else if (code.length() == 3) {
return vocabularyService.getVocabularyTerm(ISO3166_3ALPHA, code);
}
throw new NotFoundElement("Code is not in valid format: 3-letter | 2-letter | numeric");
}
/**
* Autocomplete.
*
* @param text the text
* @return the list
* @throws IOException Signals that an I/O exception has occurred.
*/
@GetMapping(value = "/iso3166/autocomplete", produces = MediaType.APPLICATION_JSON_VALUE)
public List<VocabularyTerm> autocompleteGeoTerm(@RequestParam("c") final String text) throws IOException {
return vocabularyService.autocompleteTerms(ISO3166_3ALPHA, text);
}
}
\ No newline at end of file
......@@ -25,7 +25,9 @@ import java.util.Map;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.impl.Article;
......@@ -34,7 +36,6 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.server.service.impl.SearchException;
......@@ -42,7 +43,6 @@ import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -71,22 +71,19 @@ public class InstituteController {
/** The Constant API_BASE. */
public static final String API_BASE = ApiBaseController.APIv1_BASE + "/wiews";
private static final Logger LOG = LoggerFactory.getLogger(InstituteController.class);
private static final Logger LOG = LoggerFactory.getLogger(InstituteController.class);
@Autowired
@Autowired
private InstituteService instituteService;
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private GenesysService genesysService;
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private StatisticsService statisticsService;
@Autowired
private GenesysService genesysService;
@Autowired
private ContentService contentService;
@Autowired
private ContentService contentService;
/** The short filter service. */
@Autowired
......@@ -96,9 +93,6 @@ public class InstituteController {
* List institutes by filterCode or filter
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code
* @param filter the filter
* @return the page
......@@ -106,11 +100,7 @@ public class InstituteController {
*/
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Public.class })
public FilteredPage<FaoInstitute> list(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
public FilteredPage<FaoInstitute> list(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) InstituteFilter filter) throws IOException {
if (filterCode != null) {
......@@ -118,7 +108,8 @@ public class InstituteController {
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, instituteService.list(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
FilterInfo<InstituteFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, InstituteFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, instituteService.list(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
}
@GetMapping(value ="/{code:[A-Z]+[0-9]+}", produces = MediaType.APPLICATION_JSON_VALUE)
......
/*
* Copyright 2018 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.api.v1;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import io.swagger.annotations.Api;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.catalog.service.worker.ISO639VocabularyUpdater;
import org.genesys2.server.api.ApiBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* The Class LanguagesController.
*
* @author Maxym Borodenko
*/
@RestController("languageApi1")
@RequestMapping(org.genesys2.server.api.v1.LanguagesController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "vocabulary" })
public class LanguagesController extends ApiBaseController {
/** The Constant API_BASE. */
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/lang";
/** The Constant ISO639_3. */
public static final UUID ISO639_3 = ISO639VocabularyUpdater.ISO639_3;
@Autowired
private ISO639VocabularyUpdater iso639VocabularyUpdater;
@Autowired
private VocabularyService vocabularyService;
/**
* Update languages.
*
* @return the string
* @throws IOException Signals that an I/O exception has occurred.
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/update")
public String updateLanguageVocabulary() throws IOException {
LOG.info("Updating ISO language codes");
vocabularyService.autoUpdateOrCreateVocabulary(ISO639_3, iso639VocabularyUpdater.getISO639Vocabulary());
return "OK";
}
/**
* Gets the.
*
* @param code the code
* @return the vocabulary term
*/
@GetMapping(value = "/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
public VocabularyTerm getLanguageTerm(@PathVariable("code") final String code) {
return vocabularyService.getVocabularyTerm(ISO639_3, code);
}
/**
* Autocomplete.
*
* @param text the text
* @return the list
* @throws IOException Signals that an I/O exception has occurred.
*/
@GetMapping(value = "/autocomplete", produces = MediaType.APPLICATION_JSON_VALUE)
public List<VocabularyTerm> autocompleteLanguageTerm(@RequestParam("l") final String text) throws IOException {
if (text.length() < 3) {
return Collections.emptyList();
}
return vocabularyService.autocompleteTerms(ISO639_3, text);
}
}
/*
* Copyright 2018 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.api.v1;
import java.util.UUID;
import io.swagger.annotations.Api;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.lockout.AccountLockoutManager;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;