Commit e18b62fe authored by Matija Obreza's avatar Matija Obreza
Browse files

Moved REST controllers to package .api.v0

parent 277b8460
......@@ -21,10 +21,12 @@ import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.impl.RESTApiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
......@@ -32,6 +34,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
public abstract class RestController {
protected final Logger LOG = LoggerFactory.getLogger(getClass());
......@@ -93,4 +96,13 @@ public abstract class RestController {
return new ExceptionJson(ex);
}
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundElement.class)
@ResponseBody
public ExceptionJson handleNotFound(final Exception e, final HttpServletRequest request) {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LOG.warn("{} {} for {}", request.getRequestURI(), e.getMessage(), (authentication != null ? ((UserDetails) authentication.getPrincipal()).getUsername() : "null"));
return new ExceptionJson(e);
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.io.IOException;
import java.util.ArrayList;
......@@ -46,6 +46,8 @@ 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.server.service.worker.InvalidApiUsageException;
import org.genesys2.server.servlet.controller.rest.PleaseRetryException;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Set;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.List;
......@@ -31,6 +31,9 @@ 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.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.OAuth2Cleanup;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.io.IOException;
import java.text.MessageFormat;
......@@ -47,6 +47,9 @@ import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.OAuth2Cleanup;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
......
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.ArrayList;
import java.util.List;
......@@ -6,6 +6,7 @@ import java.util.List;
import org.genesys2.server.model.impl.GeoRegion;
import org.genesys2.server.persistence.domain.CountryRepository;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.server.servlet.controller.rest.model.GeoJsData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.io.IOException;
import java.util.List;
......@@ -35,6 +35,7 @@ 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.server.servlet.controller.rest.RestController;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.Collection;
import java.util.HashMap;
......@@ -34,6 +34,8 @@ import org.genesys2.server.model.kpi.ExecutionDimension;
import org.genesys2.server.model.kpi.KPIParameter;
import org.genesys2.server.model.kpi.Observation;
import org.genesys2.server.service.KPIService;
import org.genesys2.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.server.servlet.controller.rest.model.ExecutionDimensionJson;
import org.genesys2.server.servlet.controller.rest.model.ExecutionJson;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.List;
import java.util.Locale;
......@@ -27,6 +27,7 @@ import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.io.IOException;
import java.util.HashSet;
......@@ -32,6 +32,8 @@ 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.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.HashMap;
import java.util.Map;
......@@ -26,6 +26,7 @@ import org.genesys.blocks.security.model.AclSid;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.genesys2.server.servlet.model.PermissionJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import org.genesys2.server.model.genesys.MaterialRequest;
import org.genesys2.server.model.genesys.MaterialSubRequest;
......@@ -23,6 +23,7 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.RequestService;
import org.genesys2.server.service.RequestService.NoPidException;
import org.genesys2.server.service.impl.EasySMTAException;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.List;
......@@ -35,6 +35,9 @@ import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.OAuth2Cleanup;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.List;
......@@ -31,6 +31,9 @@ import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.controller.rest.ModelValidationException;
import org.genesys2.server.servlet.controller.rest.OAuth2Cleanup;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.servlet.controller.rest.api.v0;
import java.util.HashMap;
import java.util.Map;
......@@ -27,6 +27,7 @@ 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.controller.rest.RestController;
import org.genesys2.server.servlet.controller.rest.model.UserChangedDataJson;
import org.genesys2.server.servlet.model.UserList;
import org.genesys2.spring.ResourceNotFoundException;
......
......@@ -33,6 +33,8 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Sets;
/**
* Ensure that deleted accessions end up as {@link AccessionHistoric} entities.
*/
......@@ -87,8 +89,7 @@ public class AccessionHistoryTest extends GenesysServicesTest {
accession.setInstitute(faoInstitute);
accession.setTaxonomy(taxonomy2);
accession.setCountryOfOrigin(country);
accession.getAccessionId().getStorage().add(10);
accession.getAccessionId().getStorage().add(20);
accession.getAccessionId().setStorage(Sets.newHashSet(10, 20));
genesysService.saveAccessions(faoInstitute, Collections.singletonList(accession));
......
......@@ -75,74 +75,25 @@ import org.genesys2.server.persistence.domain.UserRepository;
import org.genesys2.server.persistence.domain.kpi.KPIParameterRepository;
import org.genesys2.server.persistence.domain.kpi.ObservationRepository;
import org.genesys2.server.persistence.domain.mock.TraitServiceMock;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.EMailService;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.EasySMTA;
import org.genesys2.server.service.ElasticSearchManagementService;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysRESTService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoRegionService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.InstituteFilesService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.KPIService;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.RequestService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.TokenVerificationService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.service.impl.ContentServiceImpl;
import org.genesys2.server.service.impl.CropServiceImpl;
import org.genesys2.server.service.impl.EMailServiceImpl;
import org.genesys2.server.service.impl.EMailVerificationServiceImpl;
import org.genesys2.server.service.impl.EasySMTAMockConnector;
import org.genesys2.server.service.impl.ElasticSearchManagementServiceImpl;
import org.genesys2.server.service.impl.ElasticsearchSearchServiceImpl;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl;
import org.genesys2.server.service.impl.GenesysRESTServiceImpl;
import org.genesys2.server.service.impl.GenesysServiceImpl;
import org.genesys2.server.service.impl.GeoRegionServiceImpl;
import org.genesys2.server.service.impl.GeoServiceImpl;
import org.genesys2.server.service.impl.InstituteFilesServiceImpl;
import org.genesys2.server.service.impl.InstituteServiceImpl;
import org.genesys2.server.service.impl.KPIServiceImpl;
import org.genesys2.server.service.impl.MappingServiceImpl;
import org.genesys2.server.service.impl.OWASPSanitizer;
import org.genesys2.server.service.impl.OrganizationServiceImpl;
import org.genesys2.server.service.impl.RequestServiceImpl;
import org.genesys2.server.service.impl.TaxonomyManager;
import org.genesys2.server.service.impl.TaxonomyServiceImpl;
import org.genesys2.server.service.impl.TeamServiceImpl;
import org.genesys2.server.service.impl.TokenVerificationServiceImpl;
import org.genesys2.server.service.impl.UserServiceImpl;
import org.genesys2.server.service.worker.AccessionCounter;
import org.genesys2.server.service.worker.AccessionUploader;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.*;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.service.worker.GeoRegionDataCLDR;
import org.genesys2.server.servlet.controller.admin.OAuthManagementController;
import org.genesys2.server.servlet.controller.rest.AccessionController;
import org.genesys2.server.servlet.controller.rest.CacheController;
import org.genesys2.server.servlet.controller.rest.CropsController;
import org.genesys2.server.servlet.controller.rest.DatasetController;
import org.genesys2.server.servlet.controller.rest.InstituteGalleriesController;
import org.genesys2.server.servlet.controller.rest.KPIController;
import org.genesys2.server.servlet.controller.rest.LookupController;
import org.genesys2.server.servlet.controller.rest.OrganizationController;
import org.genesys2.server.servlet.controller.rest.PermissionController;
import org.genesys2.server.servlet.controller.rest.RequestsController;
import org.genesys2.server.servlet.controller.rest.TraitsController;
import org.genesys2.server.servlet.controller.rest.UserController;
import org.genesys2.server.servlet.controller.rest.UsersController;
import org.genesys2.server.servlet.controller.rest.api.v0.AccessionController;
import org.genesys2.server.servlet.controller.rest.api.v0.CacheController;
import org.genesys2.server.servlet.controller.rest.api.v0.CropsController;
import org.genesys2.server.servlet.controller.rest.api.v0.DatasetController;
import org.genesys2.server.servlet.controller.rest.api.v0.InstituteGalleriesController;
import org.genesys2.server.servlet.controller.rest.api.v0.KPIController;
import org.genesys2.server.servlet.controller.rest.api.v0.LookupController;
import org.genesys2.server.servlet.controller.rest.api.v0.OrganizationController;
import org.genesys2.server.servlet.controller.rest.api.v0.PermissionController;
import org.genesys2.server.servlet.controller.rest.api.v0.RequestsController;
import org.genesys2.server.servlet.controller.rest.api.v1.SubsetRestController;
import org.genesys2.server.servlet.controller.rest.api.v0.TraitsController;
import org.genesys2.server.servlet.controller.rest.api.v0.UserController;
import org.genesys2.server.servlet.controller.rest.api.v0.UsersController;
import org.genesys2.server.test.PropertyPlacholderInitializer;
import org.genesys2.tests.BaseSpringTest;
import org.junit.runner.RunWith;
......@@ -190,6 +141,11 @@ public abstract class AbstractRestTest extends BaseSpringTest {
@DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL, classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public static class Config {
@Bean
public SubsetService subsetService() {
return new SubsetServiceImpl();
}
@Bean
public GenesysImageGalleryAspects imageGalleryAspects() {
// This thing makes galleries auto-fill with images
......@@ -228,6 +184,11 @@ public abstract class AbstractRestTest extends BaseSpringTest {
return fsss;
}
@Bean
public SubsetRestController subsetRestController() {
return new SubsetRestController();
}
@Bean
public RequestsController requestsController() {
return new RequestsController();
......
......@@ -13,7 +13,7 @@ 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.servlet.controller.rest.OrganizationController;
import org.genesys2.server.servlet.controller.rest.api.v0.OrganizationController;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......
......@@ -18,7 +18,7 @@ import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.servlet.controller.rest.OAuth2Cleanup;
import org.genesys2.server.servlet.controller.rest.TraitsController;
import org.genesys2.server.servlet.controller.rest.api.v0.TraitsController;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
......
......@@ -16,7 +16,7 @@ import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyExceptio
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.servlet.controller.rest.UserController;
import org.genesys2.server.servlet.controller.rest.api.v0.UserController;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment