Commit a5d4f5e5 authored by Matija Obreza's avatar Matija Obreza

Merge branch '415-better-exceptions' into 'master'

Resolve "Better exceptions"

Closes #415

See merge request genesys-pgr/genesys-server!357
parents fb378836 6e66f499
......@@ -32,6 +32,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.PleaseRetryException;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -53,7 +54,6 @@ import org.genesys2.server.service.impl.SearchException;
import org.genesys2.server.service.worker.AccessionOpResponse;
import org.genesys2.server.service.worker.AccessionOpResponse.UpsertResult;
import org.genesys2.server.service.worker.AccessionUploader;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException;
......@@ -152,7 +152,7 @@ public class AccessionController extends ApiBaseController {
NonUniqueAccessionException {
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException("No institute " + instCode);
throw new NotFoundElement("No institute " + instCode);
}
final List<String> batch = new ArrayList<String>();
......@@ -220,7 +220,7 @@ public class AccessionController extends ApiBaseController {
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
for (int tryCount = 0; tryCount < UPLOAD_RETRIES; tryCount++) {
......@@ -306,7 +306,7 @@ public class AccessionController extends ApiBaseController {
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
try {
......@@ -363,7 +363,7 @@ public class AccessionController extends ApiBaseController {
throws SearchException {
FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
query = StringUtils.defaultIfBlank(query, "*");
// TODO filer by inst
......@@ -375,7 +375,7 @@ public class AccessionController extends ApiBaseController {
final AccessionDetails ad = genesysService.getAccessionDetails(accessionId);
if (ad == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return ad;
......
......@@ -28,6 +28,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
......@@ -35,7 +36,6 @@ import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
......@@ -181,7 +181,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName);
throw new NotFoundElement("No crop " + shortName);
cropService.setCropRules(crop, rules);
......@@ -225,7 +225,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName);
throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop);
}
......@@ -235,7 +235,7 @@ public class CropsController extends ApiBaseController {
public void downloadExcel(ModelMap model, @PathVariable(value = "shortName") String shortName, HttpServletResponse response) throws IOException {
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.debug("Downloading descriptors for crop {}", shortName);
......
......@@ -57,7 +57,6 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.impl.DownloadServiceImpl;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
......@@ -231,7 +230,7 @@ public class DatasetController extends ApiBaseController {
}
final FaoInstitute faoInstitute = instituteService.getInstitute(metadataJson.institute);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
final Metadata metadata = datasetService.addDataset(faoInstitute, metadataJson.title, metadataJson.description);
......@@ -258,7 +257,7 @@ public class DatasetController extends ApiBaseController {
final Metadata metadata = genesysService.getMetadata(metadataId);
if (metadata == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
// Write dataset to the stream.
......@@ -280,7 +279,7 @@ public class DatasetController extends ApiBaseController {
final Metadata metadata = genesysService.getMetadata(metadataId);
if (metadata == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
// Write dataset to the stream.
......@@ -308,7 +307,7 @@ public class DatasetController extends ApiBaseController {
LOG.info("Getting metadata methods for {}", metadataId);
final Metadata metadata = datasetService.getDataset(metadataId);
if (metadata == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return OAuth2Cleanup.clean(genesysService.listMethods(metadata));
}
......@@ -326,7 +325,7 @@ public class DatasetController extends ApiBaseController {
Object upsertMetadataData(@PathVariable("metadataId") Long metadataId, @RequestBody JsonNode json) throws AuthorizationException, IOException, NonUniqueAccessionException {
final Metadata metadata = datasetService.getDataset(metadataId);
if (metadata == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
// Check for 'WRITE' permission
......
......@@ -30,13 +30,13 @@ import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteFilesService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -86,7 +86,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Listing galleries for institute={}", institute);
......@@ -111,14 +111,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Listing image uuids for gallery institute={} accn={}", institute, accession);
final ImageGallery imageGallery = this.instituteFilesService.loadImageGallery(institute, accession);
if (imageGallery == null) {
throw new ResourceNotFoundException("No image gallery");
throw new NotFoundElement("No image gallery");
}
final List<UUID> uuids = imageGallery.getImages().stream().map(image -> image.getUuid()).collect(Collectors.toList());
......@@ -143,7 +143,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Updating image metadata in gallery institute={} accn={} uuid={}", institute, accession, uuid);
......@@ -152,14 +152,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage existingRepositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (existingRepositoryImage == null) {
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
return this.instituteFilesService.updateImageMetadata(institute, accession, existingRepositoryImage.getUuid(), imageData);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
}
......@@ -177,7 +177,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Getting image metadata from gallery institute={} accn={} uuid={}", institute, accession, uuid);
......@@ -186,14 +186,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
return repositoryImage;
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
}
......@@ -211,7 +211,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Getting image from gallery institute={} accn={} uuid={}", institute, accession, uuid);
......@@ -220,7 +220,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
final byte[] data = this.instituteFilesService.getFileBytes(institute, accession, repositoryImage);
......@@ -234,7 +234,7 @@ public class InstituteGalleriesController extends ApiBaseController {
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
}
......@@ -252,7 +252,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Deleting image from gallery institute={} accn={} uuid={}", institute, accession, uuid);
......@@ -261,14 +261,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
this.instituteFilesService.deleteImage(institute, accession, repositoryImage);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
throw new NotFoundElement("No such thing");
}
}
......@@ -292,7 +292,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.info("Adding image to gallery institute={} accn={}", institute, accession);
......
......@@ -27,12 +27,12 @@ import javax.xml.bind.ValidationException;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
......@@ -182,7 +182,7 @@ public class OrganizationController extends ApiBaseController {
// TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return organizationService.addOrganizationInstitutes(organization, instituteList);
......@@ -202,7 +202,7 @@ public class OrganizationController extends ApiBaseController {
// TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug);
if (organization == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return organizationService.setOrganizationInstitutes(organization, instituteList);
......
......@@ -27,12 +27,12 @@ import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.model.UserChangedDataJson;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.model.UserList;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -98,7 +98,7 @@ public class UsersController extends ApiBaseController {
final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
try {
......@@ -128,7 +128,7 @@ public class UsersController extends ApiBaseController {
public void updateRoles(@RequestBody UserChangedDataJson userData) {
final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
userService.setRoles(user, userData.getRoles());
......
......@@ -38,6 +38,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.impl.AccessionIdentifier3;
......@@ -413,7 +414,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter);
// LOG.info("Attempting to download KML for {} accessions", countFiltered);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
throw new InvalidApiUsageException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
response.setContentType("application/vnd.google-earth.kml+xml");
......@@ -476,7 +477,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
throw new InvalidApiUsageException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
// Write MCPD to the stream.
......@@ -503,7 +504,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
throw new InvalidApiUsageException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
// Write PDCI to the stream.
......@@ -528,7 +529,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
throw new InvalidApiUsageException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
// Write Darwin Core Archive to the stream.
......
......@@ -28,13 +28,13 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.PleaseRetryException;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.impl.RESTApiException;
import org.genesys2.server.service.worker.AccessionOpResponse;
import org.genesys2.server.service.worker.AccessionOpResponse.UpsertResult;
import org.genesys2.server.service.worker.AccessionUploader;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -104,7 +104,7 @@ public class AccessionUploadController {
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
for (int tryCount = 0; tryCount < UPLOAD_RETRIES; tryCount++) {
......@@ -185,7 +185,7 @@ public class AccessionUploadController {
// BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
try {
......
......@@ -21,7 +21,7 @@ import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.spring.ResourceNotFoundException;
import org.genesys2.server.exception.NotFoundElement;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
......@@ -76,7 +76,7 @@ public class AsciiDocController {
InputStream resourceStream = classLoader.getResourceAsStream(docPath);
if (resourceStream == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
String html = IOUtils.toString(resourceStream);
......@@ -144,7 +144,7 @@ public class AsciiDocController {
InputStream inputStream = classLoader.getResourceAsStream(imgPath);
if (inputStream == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return IOUtils.toByteArray(inputStream);
......
......@@ -43,7 +43,6 @@ import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.filter.ActivityPostFilter;
import org.genesys2.server.service.filter.ArticleFilter;
import org.genesys2.spring.ResourceNotFoundException;
import org.genesys2.transifex.client.TransifexException;
import org.genesys2.transifex.client.TransifexService;
import org.jsoup.Jsoup;
......@@ -380,7 +379,7 @@ public class CMSController {
public Article postToTransifex(@RequestParam("slug") String slug,
@RequestParam(value = "targetId", required = false) Long targetId, @RequestParam("classPkShortName") String classPkShortName) throws IOException {
if (transifexService == null) {
throw new ResourceNotFoundException("translationService not enabled");
throw new NotFoundElement("translationService not enabled");
}
Article article;
......@@ -409,7 +408,7 @@ public class CMSController {
public Boolean deleteFromTransifex(@RequestParam("slug") String slug,
@RequestParam(value = "targetId", required = false) Long targetId, @RequestParam("classPkShortName") String classPkShortName) throws TransifexException {
if (transifexService == null) {
throw new ResourceNotFoundException("translationService not enabled");
throw new NotFoundElement("translationService not enabled");
}
String resourceName;
......@@ -434,7 +433,7 @@ public class CMSController {
public Map<String, String> fetchAllFromTransifex(@RequestParam("slug") String slug, @RequestParam(value = "targetId", required = false) Long targetId,
@RequestParam(value = "classPkShortName", required = false) String classPkShortName, @RequestParam(name = "template", defaultValue = "false") Boolean template) throws Exception {
if (transifexService == null) {
throw new ResourceNotFoundException("translationService not enabled");
throw new NotFoundElement("translationService not enabled");
}
String resourceName;
......
......@@ -26,13 +26,13 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.TraitService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
......@@ -207,7 +207,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName);
throw new NotFoundElement("No crop " + shortName);
cropService.setCropRules(crop, rules);
......@@ -253,7 +253,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName);
throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop);
}
......@@ -270,7 +270,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Linking accessions to crop {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName);
throw new NotFoundElement("No crop " + shortName);
threadPoolTaskExecutor.execute(() -> {
cropService.unlinkAccessionsForCrop(crop);
......
......@@ -29,7 +29,6 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.GeoRegion;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.service.GeoService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.MediaType;
......@@ -71,7 +70,7 @@ public class GeoController extends ApiBaseController {
LOG.info("Getting country {}", iso3code);
Country country = geoService.getCountry(iso3code);
if (country == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
return country;
}
......
......@@ -32,6 +32,7 @@ import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.impl.Article;
......@@ -44,7 +45,6 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -133,7 +133,7 @@ public class InstituteController {
FaoInstitute faoInstitute = instituteService.getInstitute(code);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
AccessionFilter byInstituteFilter = new AccessionFilter();
......@@ -153,7 +153,7 @@ public class InstituteController {
public void downloadDwca(@PathVariable(value = "wiewsCode", required = true) String wiewsCode, HttpServletResponse response) throws IOException {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.warn("Downloading DwC-A accessions of: {}", faoInstitute);
......@@ -175,7 +175,7 @@ public class InstituteController {
public void downloadPdci(@PathVariable(value = "wiewsCode", required = true) String wiewsCode, HttpServletResponse response) throws IOException {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.warn("Downloading PDCI for: {}", faoInstitute);
......@@ -202,7 +202,7 @@ public class InstituteController {
public void downloadMcpd(@PathVariable(value = "wiewsCode", required = true) String wiewsCode, HttpServletResponse response) throws IOException {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
throw new NotFoundElement();
}
LOG.warn("Downloading MCPD accessions of: {}", faoInstitute);
......
......@@ -40,7 +40,6 @@ import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.impl.FilesMetadataInfo;
import org.genesys2.server.service.impl.FilesMetadataUpdate;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -177,16 +176,16 @@ public class RepositoryController {
*
* @param request the request
* @param response the response
* @throws ResourceNotFoundException the no such repository folder
* @throws NotFoundElement the no such repository folder
* @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@GetMapping(value = "/download/folder-metadata/**")
public void downloadFolderMetadata(final HttpServletRequest request, final HttpServletResponse response) throws ResourceNotFoundException, IOException, InvalidRepositoryPathException {
public void downloadFolderMetadata(final HttpServletRequest request, final HttpServletResponse response) throws NotFoundElement, IOException, InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/download/folder-metadata").length());
final RepositoryFolder folder = repositoryService.getFolder(Paths.get(folderPath));
if (folder == null) {
throw new ResourceNotFoundException("No folder with path=" + folderPath);
throw new NotFoundElement("No folder with path=" + folderPath);
}
response.setContentType("text/csv;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + folder.getName() + "_files_metadata.csv ");
......@@ -253,7 +252,7 @@ public class RepositoryController {
public FolderDetails renameFolder(@PathVariable("folderUuid") final UUID folderUuid, @RequestBody(required = true) String fullPath) throws InvalidRepositoryPathException {
RepositoryFolder folder = repositoryService.getFolder(folderUuid);
if (folder == null) {
throw new ResourceNotFoundException("No folder with uuid=" + folderUuid);
throw new NotFoundElement("No folder with uuid=" + folderUuid);
}
return folderDetails(repositoryService.renamePath(folder.getFolderPath(), Paths.get(fullPath)).getFolderPath());
}
......@@ -366,7 +365,7 @@ public class RepositoryController {
fd.folder = repositoryService.getFolder(path);
fd.subFolders = repositoryService.listFolders(path, Pagination.toPageRequest(50, RepositoryFolder.DEFAULT_SORT));
if (fd.folder == null && !path.toAbsolutePath().toString().equals("/")) {
throw new ResourceNotFoundException("No such folder");
throw new NotFoundElement("No such folder");
}
fd.files = repositoryService.listFiles(path, Pagination.toPageRequest(50, RepositoryFile.DEFAULT_SORT));
fd.gallery = imagegalleryService.loadImageGallery(path);
......
......@@ -32,7 +32,6 @@ import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -132,10 +131,10 @@ public class RepositoryDownloadController {
} catch (final NumberFormatException e) {
LOG.warn("404 - UUID in wrong format.");
throw new ResourceNotFoundException("No such thing", e);
throw new NotFoundElement("No such thing", e);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing", e);
throw new NotFoundElement("No such thing", e);
}
}