Commit 6e66f499 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Better exceptions

- Fixed filtering accessions by institute owner
- Removed unused ResourceNotFoundException
parent fb378836
...@@ -32,6 +32,7 @@ import org.genesys2.server.api.ApiBaseController; ...@@ -32,6 +32,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.PleaseRetryException; import org.genesys2.server.api.PleaseRetryException;
import org.genesys2.server.api.model.AccessionHeaderJson; import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException; import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.elastic.AccessionDetails; import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
...@@ -53,7 +54,6 @@ import org.genesys2.server.service.impl.SearchException; ...@@ -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;
import org.genesys2.server.service.worker.AccessionOpResponse.UpsertResult; import org.genesys2.server.service.worker.AccessionOpResponse.UpsertResult;
import org.genesys2.server.service.worker.AccessionUploader; import org.genesys2.server.service.worker.AccessionUploader;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
...@@ -152,7 +152,7 @@ public class AccessionController extends ApiBaseController { ...@@ -152,7 +152,7 @@ public class AccessionController extends ApiBaseController {
NonUniqueAccessionException { NonUniqueAccessionException {
final FaoInstitute institute = instituteService.getInstitute(instCode); final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException("No institute " + instCode); throw new NotFoundElement("No institute " + instCode);
} }
final List<String> batch = new ArrayList<String>(); final List<String> batch = new ArrayList<String>();
...@@ -220,7 +220,7 @@ public class AccessionController extends ApiBaseController { ...@@ -220,7 +220,7 @@ public class AccessionController extends ApiBaseController {
// BatchRESTService. // BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode); final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
for (int tryCount = 0; tryCount < UPLOAD_RETRIES; tryCount++) { for (int tryCount = 0; tryCount < UPLOAD_RETRIES; tryCount++) {
...@@ -306,7 +306,7 @@ public class AccessionController extends ApiBaseController { ...@@ -306,7 +306,7 @@ public class AccessionController extends ApiBaseController {
// BatchRESTService. // BatchRESTService.
final FaoInstitute institute = instituteService.getInstitute(instCode); final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
try { try {
...@@ -363,7 +363,7 @@ public class AccessionController extends ApiBaseController { ...@@ -363,7 +363,7 @@ public class AccessionController extends ApiBaseController {
throws SearchException { throws SearchException {
FaoInstitute institute = instituteService.getInstitute(instCode); FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
query = StringUtils.defaultIfBlank(query, "*"); query = StringUtils.defaultIfBlank(query, "*");
// TODO filer by inst // TODO filer by inst
...@@ -375,7 +375,7 @@ public class AccessionController extends ApiBaseController { ...@@ -375,7 +375,7 @@ public class AccessionController extends ApiBaseController {
final AccessionDetails ad = genesysService.getAccessionDetails(accessionId); final AccessionDetails ad = genesysService.getAccessionDetails(accessionId);
if (ad == null) { if (ad == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
return ad; return ad;
......
...@@ -28,6 +28,7 @@ import org.genesys2.server.api.ApiBaseController; ...@@ -28,6 +28,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException; import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.api.OAuth2Cleanup; import org.genesys2.server.api.OAuth2Cleanup;
import org.genesys2.server.exception.AuthorizationException; import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Parameter; import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule; import org.genesys2.server.model.impl.CropRule;
...@@ -35,7 +36,6 @@ import org.genesys2.server.model.impl.CropTaxonomy; ...@@ -35,7 +36,6 @@ import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService; import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService; import org.genesys2.server.service.TraitService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -181,7 +181,7 @@ public class CropsController extends ApiBaseController { ...@@ -181,7 +181,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName); LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName); final Crop crop = cropService.getCrop(shortName);
if (crop == null) if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName); throw new NotFoundElement("No crop " + shortName);
cropService.setCropRules(crop, rules); cropService.setCropRules(crop, rules);
...@@ -225,7 +225,7 @@ public class CropsController extends ApiBaseController { ...@@ -225,7 +225,7 @@ public class CropsController extends ApiBaseController {
LOG.info("Updating crop rules for {}", shortName); LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName); final Crop crop = cropService.getCrop(shortName);
if (crop == null) if (crop == null)
throw new ResourceNotFoundException("No crop " + shortName); throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop); cropService.rebuildTaxonomies(crop);
} }
...@@ -235,7 +235,7 @@ public class CropsController extends ApiBaseController { ...@@ -235,7 +235,7 @@ public class CropsController extends ApiBaseController {
public void downloadExcel(ModelMap model, @PathVariable(value = "shortName") String shortName, HttpServletResponse response) throws IOException { public void downloadExcel(ModelMap model, @PathVariable(value = "shortName") String shortName, HttpServletResponse response) throws IOException {
final Crop crop = cropService.getCrop(shortName); final Crop crop = cropService.getCrop(shortName);
if (crop == null) { if (crop == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.debug("Downloading descriptors for crop {}", shortName); LOG.debug("Downloading descriptors for crop {}", shortName);
......
...@@ -57,7 +57,6 @@ import org.genesys2.server.service.InstituteService; ...@@ -57,7 +57,6 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TraitService; import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.impl.DownloadServiceImpl; import org.genesys2.server.service.impl.DownloadServiceImpl;
import org.genesys2.server.service.impl.NonUniqueAccessionException; import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Direction;
...@@ -231,7 +230,7 @@ public class DatasetController extends ApiBaseController { ...@@ -231,7 +230,7 @@ public class DatasetController extends ApiBaseController {
} }
final FaoInstitute faoInstitute = instituteService.getInstitute(metadataJson.institute); final FaoInstitute faoInstitute = instituteService.getInstitute(metadataJson.institute);
if (faoInstitute == null) { if (faoInstitute == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
final Metadata metadata = datasetService.addDataset(faoInstitute, metadataJson.title, metadataJson.description); final Metadata metadata = datasetService.addDataset(faoInstitute, metadataJson.title, metadataJson.description);
...@@ -258,7 +257,7 @@ public class DatasetController extends ApiBaseController { ...@@ -258,7 +257,7 @@ public class DatasetController extends ApiBaseController {
final Metadata metadata = genesysService.getMetadata(metadataId); final Metadata metadata = genesysService.getMetadata(metadataId);
if (metadata == null) { if (metadata == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
// Write dataset to the stream. // Write dataset to the stream.
...@@ -280,7 +279,7 @@ public class DatasetController extends ApiBaseController { ...@@ -280,7 +279,7 @@ public class DatasetController extends ApiBaseController {
final Metadata metadata = genesysService.getMetadata(metadataId); final Metadata metadata = genesysService.getMetadata(metadataId);
if (metadata == null) { if (metadata == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
// Write dataset to the stream. // Write dataset to the stream.
...@@ -308,7 +307,7 @@ public class DatasetController extends ApiBaseController { ...@@ -308,7 +307,7 @@ public class DatasetController extends ApiBaseController {
LOG.info("Getting metadata methods for {}", metadataId); LOG.info("Getting metadata methods for {}", metadataId);
final Metadata metadata = datasetService.getDataset(metadataId); final Metadata metadata = datasetService.getDataset(metadataId);
if (metadata == null) { if (metadata == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
return OAuth2Cleanup.clean(genesysService.listMethods(metadata)); return OAuth2Cleanup.clean(genesysService.listMethods(metadata));
} }
...@@ -326,7 +325,7 @@ public class DatasetController extends ApiBaseController { ...@@ -326,7 +325,7 @@ public class DatasetController extends ApiBaseController {
Object upsertMetadataData(@PathVariable("metadataId") Long metadataId, @RequestBody JsonNode json) throws AuthorizationException, IOException, NonUniqueAccessionException { Object upsertMetadataData(@PathVariable("metadataId") Long metadataId, @RequestBody JsonNode json) throws AuthorizationException, IOException, NonUniqueAccessionException {
final Metadata metadata = datasetService.getDataset(metadataId); final Metadata metadata = datasetService.getDataset(metadataId);
if (metadata == null) { if (metadata == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
// Check for 'WRITE' permission // Check for 'WRITE' permission
......
...@@ -30,13 +30,13 @@ import org.genesys.filerepository.NoSuchRepositoryFileException; ...@@ -30,13 +30,13 @@ import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery; import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage; import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteFilesService; import org.genesys2.server.service.InstituteFilesService;
import org.genesys2.server.service.InstituteService; import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.impl.NonUniqueAccessionException; import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -86,7 +86,7 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -86,7 +86,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Listing galleries for institute={}", institute); LOG.info("Listing galleries for institute={}", institute);
...@@ -111,14 +111,14 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -111,14 +111,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Listing image uuids for gallery institute={} accn={}", institute, accession); LOG.info("Listing image uuids for gallery institute={} accn={}", institute, accession);
final ImageGallery imageGallery = this.instituteFilesService.loadImageGallery(institute, accession); final ImageGallery imageGallery = this.instituteFilesService.loadImageGallery(institute, accession);
if (imageGallery == null) { 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()); final List<UUID> uuids = imageGallery.getImages().stream().map(image -> image.getUuid()).collect(Collectors.toList());
...@@ -143,7 +143,7 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -143,7 +143,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Updating image metadata in gallery institute={} accn={} uuid={}", institute, accession, uuid); LOG.info("Updating image metadata in gallery institute={} accn={} uuid={}", institute, accession, uuid);
...@@ -152,14 +152,14 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -152,14 +152,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage existingRepositoryImage = this.instituteFilesService.getImage(institute, accession, uuid); final RepositoryImage existingRepositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (existingRepositoryImage == null) { if (existingRepositoryImage == null) {
throw new ResourceNotFoundException("No such thing"); throw new NotFoundElement("No such thing");
} }
return this.instituteFilesService.updateImageMetadata(institute, accession, existingRepositoryImage.getUuid(), imageData); return this.instituteFilesService.updateImageMetadata(institute, accession, existingRepositoryImage.getUuid(), imageData);
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", 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 { ...@@ -177,7 +177,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Getting image metadata from gallery institute={} accn={} uuid={}", institute, accession, uuid); LOG.info("Getting image metadata from gallery institute={} accn={} uuid={}", institute, accession, uuid);
...@@ -186,14 +186,14 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -186,14 +186,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid); final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) { if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing"); throw new NotFoundElement("No such thing");
} }
return repositoryImage; return repositoryImage;
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", 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 { ...@@ -211,7 +211,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Getting image from gallery institute={} accn={} uuid={}", institute, accession, uuid); LOG.info("Getting image from gallery institute={} accn={} uuid={}", institute, accession, uuid);
...@@ -220,7 +220,7 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -220,7 +220,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid); final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) { if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing"); throw new NotFoundElement("No such thing");
} }
final byte[] data = this.instituteFilesService.getFileBytes(institute, accession, repositoryImage); final byte[] data = this.instituteFilesService.getFileBytes(institute, accession, repositoryImage);
...@@ -234,7 +234,7 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -234,7 +234,7 @@ public class InstituteGalleriesController extends ApiBaseController {
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", 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 { ...@@ -252,7 +252,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Deleting image from gallery institute={} accn={} uuid={}", institute, accession, uuid); LOG.info("Deleting image from gallery institute={} accn={} uuid={}", institute, accession, uuid);
...@@ -261,14 +261,14 @@ public class InstituteGalleriesController extends ApiBaseController { ...@@ -261,14 +261,14 @@ public class InstituteGalleriesController extends ApiBaseController {
final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid); final RepositoryImage repositoryImage = this.instituteFilesService.getImage(institute, accession, uuid);
if (repositoryImage == null) { if (repositoryImage == null) {
throw new ResourceNotFoundException("No such thing"); throw new NotFoundElement("No such thing");
} }
this.instituteFilesService.deleteImage(institute, accession, repositoryImage); this.instituteFilesService.deleteImage(institute, accession, repositoryImage);
} catch (final NoSuchRepositoryFileException e) { } catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", 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 { ...@@ -292,7 +292,7 @@ public class InstituteGalleriesController extends ApiBaseController {
final FaoInstitute institute = this.instituteService.findInstitute(instCode); final FaoInstitute institute = this.instituteService.findInstitute(instCode);
final Accession accession = this.genesysService.getAccession(instCode, acceNumb); final Accession accession = this.genesysService.getAccession(instCode, acceNumb);
if (institute == null || accession == null) { if (institute == null || accession == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
LOG.info("Adding image to gallery institute={} accn={}", institute, accession); LOG.info("Adding image to gallery institute={} accn={}", institute, accession);
......
...@@ -27,12 +27,12 @@ import javax.xml.bind.ValidationException; ...@@ -27,12 +27,12 @@ import javax.xml.bind.ValidationException;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.ModelValidationException; import org.genesys2.server.api.ModelValidationException;
import org.genesys2.server.exception.AuthorizationException; 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.Article;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization; import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.CRMException; import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.OrganizationService; import org.genesys2.server.service.OrganizationService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -182,7 +182,7 @@ public class OrganizationController extends ApiBaseController { ...@@ -182,7 +182,7 @@ public class OrganizationController extends ApiBaseController {
// TODO Check user's permissions to update this organization. // TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug); final Organization organization = organizationService.getOrganization(slug);
if (organization == null) { if (organization == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
return organizationService.addOrganizationInstitutes(organization, instituteList); return organizationService.addOrganizationInstitutes(organization, instituteList);
...@@ -202,7 +202,7 @@ public class OrganizationController extends ApiBaseController { ...@@ -202,7 +202,7 @@ public class OrganizationController extends ApiBaseController {
// TODO Check user's permissions to update this organization. // TODO Check user's permissions to update this organization.
final Organization organization = organizationService.getOrganization(slug); final Organization organization = organizationService.getOrganization(slug);
if (organization == null) { if (organization == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
return organizationService.setOrganizationInstitutes(organization, instituteList); return organizationService.setOrganizationInstitutes(organization, instituteList);
......
...@@ -27,12 +27,12 @@ import org.genesys.blocks.security.UserException; ...@@ -27,12 +27,12 @@ import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException; import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.model.UserChangedDataJson; import org.genesys2.server.api.model.UserChangedDataJson;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.User; import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.EMailVerificationService; import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.TeamService; import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService; import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.model.UserList; import org.genesys2.server.servlet.model.UserList;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -98,7 +98,7 @@ public class UsersController extends ApiBaseController { ...@@ -98,7 +98,7 @@ public class UsersController extends ApiBaseController {
final User user = userService.getUserByUuid(userData.getUuid()); final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) { if (user == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
try { try {
...@@ -128,7 +128,7 @@ public class UsersController extends ApiBaseController { ...@@ -128,7 +128,7 @@ public class UsersController extends ApiBaseController {
public void updateRoles(@RequestBody UserChangedDataJson userData) { public void updateRoles(@RequestBody UserChangedDataJson userData) {
final User user = userService.getUserByUuid(userData.getUuid()); final User user = userService.getUserByUuid(userData.getUuid());
if (user == null) { if (user == null) {
throw new ResourceNotFoundException(); throw new NotFoundElement();
} }
userService.setRoles(user, userData.getRoles()); userService.setRoles(user, userData.getRoles());
......
...@@ -38,6 +38,7 @@ import org.genesys2.server.api.ApiBaseController; ...@@ -38,6 +38,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage; import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination; import org.genesys2.server.api.Pagination;
import org.genesys2.server.api.model.AccessionHeaderJson; 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.Accession;
import org.genesys2.server.model.genesys.AccessionGeo; import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.impl.AccessionIdentifier3; import org.genesys2.server.model.impl.AccessionIdentifier3;
...@@ -413,7 +414,7 @@ public class AccessionController { ...@@ -413,7 +414,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter); final long countFiltered = accessionService.countAccessions(filterInfo.filter);
// LOG.info("Attempting to download KML for {} accessions", countFiltered); // LOG.info("Attempting to download KML for {} accessions", countFiltered);
if (countFiltered > DOWNLOAD_LIMIT) { 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"); response.setContentType("application/vnd.google-earth.kml+xml");
...@@ -476,7 +477,7 @@ public class AccessionController { ...@@ -476,7 +477,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter); final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) { 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. // Write MCPD to the stream.
...@@ -503,7 +504,7 @@ public class AccessionController { ...@@ -503,7 +504,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter); final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) { 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. // Write PDCI to the stream.
...@@ -528,7 +529,7 @@ public class AccessionController { ...@@ -528,7 +529,7 @@ public class AccessionController {
final long countFiltered = accessionService.countAccessions(filterInfo.filter); final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) { 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. // Write Darwin Core Archive to the stream.
......
...@@ -28,13 +28,13 @@ import org.genesys2.server.api.ApiBaseController; ...@@ -28,13 +28,13 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.PleaseRetryException; import org.genesys2.server.api.PleaseRetryException;
import org.genesys2.server.api.model.AccessionHeaderJson; import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.exception.InvalidApiUsageException; import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.InstituteService; import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.impl.RESTApiException; import org.genesys2.server.service.impl.RESTApiException;