Commit 4addf186 authored by Matija Obreza's avatar Matija Obreza

API controllers annotated

- Using ApiBaseController.APIv?_BASE in controller mapping
- Added OpenAPI grouping (@Api)
parent 678a1e96
......@@ -15,6 +15,7 @@
*/
package org.genesys.catalog.api.v0;
import org.genesys2.server.api.ApiBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......@@ -24,6 +25,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import java.net.UnknownHostException;
/**
......@@ -32,14 +35,15 @@ import java.net.UnknownHostException;
* @author Andrey Lugovskoy.
*/
@RestController
@RequestMapping(ApiInfoController.API_BASE)
@RequestMapping(ApiInfoController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "api-info" })
public class ApiInfoController implements InitializingBean {
private static final Logger LOG = LoggerFactory.getLogger(ApiInfoController.class);
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/info";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/info";
@Value("${build.version}")
private String version;
......
......@@ -24,6 +24,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,6 +33,8 @@ import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import java.io.IOException;
import java.util.Set;
import java.util.UUID;
......@@ -43,13 +46,14 @@ import java.util.stream.Collectors;
* @author Andrey Lugovskoy
* @author Matija Obreza
*/
@RestController("catalogDatasetController")
@RequestMapping(DatasetController.API_BASE)
@RestController("catalogDatasetApi0")
@RequestMapping(DatasetController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "dataset" })
public class DatasetController {
/** The Constant API_BASE. */
protected static final String API_BASE = "/api/v0/dataset";
// Rest controller base URL
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/dataset";
private static final Logger LOG = LoggerFactory.getLogger(DatasetController.class);
......
......@@ -16,6 +16,9 @@
package org.genesys.catalog.api.v0;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -39,13 +42,14 @@ import java.util.UUID;
*
* @author Andrey Lugovskoy.
*/
@RestController
@RestController("catalogDatasetCreatorApi0")
@PreAuthorize("isAuthenticated()")
@RequestMapping(DatasetCreatorController.API_BASE)
@RequestMapping(DatasetCreatorController.CONTROLLER_URL)
@Api(tags = { "dataset" })
public class DatasetCreatorController {
/** The Constant API_BASE. */
protected static final String API_BASE = DatasetController.API_BASE + "/{UUID}/datasetcreator";
protected static final String CONTROLLER_URL = DatasetController.CONTROLLER_URL + "/{UUID}/datasetcreator";
/** The dataset service. */
@Autowired
......
......@@ -29,6 +29,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
......@@ -38,13 +40,14 @@ import java.util.UUID;
*
* @author Andrey Lugovskoy.
*/
@RestController
@RequestMapping(DatasetFilesController.API_BASE)
@RestController("catalogDatasetFilesApi0")
@RequestMapping(DatasetFilesController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "dataset" })
public class DatasetFilesController {
/** The Constant API_BASE. */
protected static final String API_BASE = DatasetController.API_BASE + "/{UUID}/files";
protected static final String CONTROLLER_URL = DatasetController.CONTROLLER_URL + "/{UUID}/files";
private static final Logger LOG = LoggerFactory.getLogger(DatasetFilesController.class);
......
......@@ -16,6 +16,9 @@
package org.genesys.catalog.api.v0;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -24,6 +27,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
......@@ -39,13 +43,14 @@ import java.util.UUID;
*
* @author Maxym Borodenko
*/
@RestController("catalogDescriptorController")
@RequestMapping(DescriptorController.API_BASE)
@RestController("catalogDescriptorApi0")
@RequestMapping(DescriptorController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "descriptor" })
public class DescriptorController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/descriptor";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/descriptor";
@Autowired
private DescriptorService descriptorService;
......
......@@ -25,6 +25,7 @@ import org.genesys.catalog.mvc.DescriptorListExporter;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
......@@ -36,6 +37,8 @@ import org.springframework.web.bind.annotation.*;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
......@@ -48,13 +51,14 @@ import java.util.stream.Collectors;
*
* @author Matija Obreza
*/
@RestController
@RequestMapping(DescriptorListController.API_BASE)
@RestController("catalogDescriptorListApi0")
@RequestMapping(DescriptorListController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "descriptor-list" })
public class DescriptorListController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/descriptorlist";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/descriptorlist";
@Autowired
private DescriptorService descriptorService;
......
......@@ -15,28 +15,42 @@
*/
package org.genesys.catalog.api.v0;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.genesys.catalog.service.FileMetadataService;
import org.genesys2.server.api.ApiBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.annotations.Api;
/**
* The Class FileMetadataController.
*
* @author Maxym Borodenko
*/
@RestController
@RequestMapping(FileMetadataController.API_BASE)
@RestController("catalogFileMetadataApi0")
@RequestMapping(FileMetadataController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "repository" })
public class FileMetadataController {
/**
* The Constant API_BASE.
*/
protected static final String API_BASE = "/api/v0/metadata";
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/api/v0/fileinfo";
/**
* The Constant LOG.
......@@ -56,17 +70,17 @@ public class FileMetadataController {
* @return the object node
* @throws IOException Signals that an I/O exception has occurred.
*/
// @PostMapping(consumes = { "multipart/form-data" })
// public ObjectNode metadata(@RequestParam("file") final MultipartFile file) throws IOException {
//
// // TODO store the file to the repository
//
// if (APPLICATION_MS_EXCEL.equals(file.getContentType()) || APPLICATION_OXML_SHEET.equals(file.getContentType())) {
// return excelMetadata(file);
// } else {
// throw new UnsupportedOperationException(file.getContentType());
// }
// }
@PostMapping(consumes = { "multipart/form-data" })
public ObjectNode metadata(@RequestParam("file") final MultipartFile file) throws IOException {
// TODO store the file to the repository
if (APPLICATION_MS_EXCEL.equals(file.getContentType()) || APPLICATION_OXML_SHEET.equals(file.getContentType())) {
return excelMetadata(file);
} else {
throw new UnsupportedOperationException(file.getContentType());
}
}
/**
* Excel metadata.
......@@ -75,16 +89,16 @@ public class FileMetadataController {
* @return the object node
* @throws IOException Signals that an I/O exception has occurred.
*/
// @PostMapping(consumes = { APPLICATION_MS_EXCEL, APPLICATION_OXML_SHEET })
// public ObjectNode excelMetadata(@RequestBody final MultipartFile file) throws IOException {
// LOG.info("Analyzing Excel file {}", file.getOriginalFilename());
//
// final File tempFile = File.createTempFile("metadata", ".xlsx");
// try {
// FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
// return fileMetadataService.getExcelMetadata(tempFile);
// } finally {
// FileUtils.deleteQuietly(tempFile);
// }
// }
@PostMapping(consumes = { APPLICATION_MS_EXCEL, APPLICATION_OXML_SHEET })
public ObjectNode excelMetadata(@RequestBody final MultipartFile file) throws IOException {
LOG.info("Analyzing Excel file {}", file.getOriginalFilename());
final File tempFile = File.createTempFile("metadata", ".xlsx");
try {
FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
return fileMetadataService.getExcelMetadata(tempFile);
} finally {
FileUtils.deleteQuietly(tempFile);
}
}
}
......@@ -22,6 +22,7 @@ import org.genesys.catalog.exceptions.NotFoundElement;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,18 +35,22 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* The Class GeoController.
*
* @author Maxym Borodenko
*/
@RestController("cataloGeoController")
@RequestMapping(GeoController.API_BASE)
@RestController("cataloGeoApi0")
@RequestMapping(GeoController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "geo" })
public class GeoController {
/** The Constant API_BASE. */
protected static final String API_BASE = "/api/v0/geo";
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/geo";
/** The Constant ISO3166_2ALPHA. */
public static final UUID ISO3166_2ALPHA = ISO3166VocabularyUpdater.ISO3166_2ALPHA;
......@@ -72,6 +77,7 @@ public class GeoController {
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/update")
@ApiOperation("Triggers update of ISO country code vocabularies")
public @ResponseBody String updateCountriesCodes() throws IOException {
LOG.info("Updating ISO country codes");
vocabularyService.autoUpdateOrCreateVocabulary(ISO3166_2ALPHA, iso3166VocabularyUpdater.getISO3166Alpha2Vocabulary());
......@@ -87,6 +93,7 @@ public class GeoController {
* @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);
......
......@@ -23,6 +23,7 @@ import java.util.UUID;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -36,18 +37,21 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
/**
* The Class LanguagesController.
*
* @author Maxym Borodenko
*/
@RestController
@RequestMapping(LanguagesController.API_BASE)
@RestController("languageApi0")
@RequestMapping(LanguagesController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "vocabulary" })
public class LanguagesController {
/** The Constant API_BASE. */
protected static final String API_BASE = "/api/v0/lang";
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/lang";
/** The Constant ISO639_3. */
public static final UUID ISO639_3 = ISO639VocabularyUpdater.ISO639_3;
......
......@@ -36,6 +36,7 @@ import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
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;
......@@ -53,18 +54,21 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
/**
* The Class MeController.
*
* @author Andrey Lugovskoy.
*/
@RestController
@RestController("catalogMeApi0")
@RequestMapping(MeController.API_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "me" })
public class MeController {
/** The Constant API_URL. */
public static final String API_URL = "/api/v0/me";
public static final String API_URL = ApiBaseController.APIv0_BASE + "/me";
@Autowired
private PartnerService partnerService;
......
......@@ -20,12 +20,15 @@ import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import java.io.IOException;
import java.util.UUID;
......@@ -34,12 +37,13 @@ import java.util.UUID;
*
* @author Andrey Lugovskoy.
*/
@RestController
@RequestMapping(PartnerController.API_BASE)
@RestController("partnerApi0")
@RequestMapping(PartnerController.CONTROLLER_URL)
@Api(tags = { "partner" })
public class PartnerController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/partner";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/partner";
@Autowired
private PartnerService partnerService;
......
......@@ -16,6 +16,9 @@
package org.genesys.catalog.api.v0;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
......@@ -25,6 +28,7 @@ import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -43,13 +47,14 @@ import java.util.UUID;
*
* @author Matija Obreza
*/
@RestController
@RequestMapping(RepositoryController.API_BASE)
@RestController("repositoryApi0")
@RequestMapping(RepositoryController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "repository" })
public class RepositoryController {
/** The Constant API_BASE. */
protected static final String API_BASE = "/api/v0/repository";
protected static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/repository";
private static final Logger LOG = LoggerFactory.getLogger(RepositoryController.class);
......
......@@ -25,6 +25,7 @@ import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.VocabularyService;
import org.genesys2.server.api.ApiBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -38,17 +39,20 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
/**
* The Class VocabularyController.
*
* @author Matija Obreza
*/
@RestController
@RequestMapping(VocabularyController.API_BASE)
@RestController("vocabularyApi0")
@RequestMapping(VocabularyController.CONTROLLER_URL)
@Api(tags = { "vocabulary" })
public class VocabularyController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/vocabulary";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/vocabulary";
@Autowired
private VocabularyService vocabularyService;
......
......@@ -23,6 +23,7 @@ import java.util.UUID;
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;
......@@ -37,6 +38,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
/**
* The Class WiewsController.
*
......@@ -45,12 +48,13 @@ import org.springframework.web.bind.annotation.RestController;
* @author Maxym Borodenko
*/
@RestController("wiewsApi0")
@RequestMapping(WiewsController.API_BASE)
@RequestMapping(WiewsController.CONTROLLER_URL)
@PreAuthorize("isAuthenticated()")
@Api(tags = { "vocabulary" })
public class WiewsController {
/** The Constant API_BASE. */
public static final String API_BASE = "/api/v0/wiews";
public static final String CONTROLLER_URL = ApiBaseController.APIv0_BASE + "/wiews";
/** The Constant FAO_WIEWS_UUID. */
public static final UUID FAO_WIEWS_UUID = WiewsVocabularyUpdater.FAO_WIEWS_UUID;
......
......@@ -26,6 +26,13 @@ public abstract class ApiBaseController {
protected static final ApiResult JSON_OK = new ApiResult(true);
public static final String APIv0_BASE = "/api/v0";
public static final String APIv0_ADMIN_BASE = APIv0_BASE + "/admin";
public static final String APIv1_BASE = "/api/v1";
public static final String APIv1_ADMIN_BASE = APIv1_BASE + "/admin";
@Value("${paginator.api.maxPageSize}")
protected int maxPageSize;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.api.v0;
package org.genesys2.server.api.admin.v0;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -39,9 +39,12 @@ import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.monitor.LocalMapStats;
@Controller("restCacheController")
import io.swagger.annotations.Api;
@Controller("adminCacheApi0")
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = { "/api/v0/cache", "/json/v0/cache" })
@RequestMapping(value = { "/api/v0/admin/cache", "/json/v0/cache" })
@Api(tags = { "admin" })
public class CacheController extends ApiBaseController {
@Autowired
......