argos/dmp-backend/web/src/main/java/eu/eudat/controllers/Registries.java

60 lines
2.8 KiB
Java
Raw Normal View History

2017-12-15 00:01:26 +01:00
package eu.eudat.controllers;
2017-10-06 19:20:05 +02:00
import eu.eudat.authorization.Permission;
import eu.eudat.data.old.Registry;
2018-09-04 11:36:18 +02:00
import eu.eudat.logic.managers.RegistryManager;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext;
2018-08-31 16:12:31 +02:00
import eu.eudat.models.data.helpers.responses.ResponseItem;
2018-09-04 11:36:18 +02:00
import eu.eudat.models.data.registries.RegistryModel;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
2017-10-06 19:20:05 +02:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
2018-09-04 11:36:18 +02:00
import org.springframework.transaction.annotation.Transactional;
2018-02-16 11:34:02 +01:00
import org.springframework.web.bind.annotation.*;
2017-10-06 19:20:05 +02:00
import javax.management.InvalidApplicationException;
2018-02-16 11:34:02 +01:00
import java.util.List;
2017-10-06 19:20:05 +02:00
@RestController
@CrossOrigin
2018-02-09 16:54:41 +01:00
@RequestMapping(value = {"/api"})
2018-02-16 11:34:02 +01:00
public class Registries extends BaseController {
private RegistryManager registryManager;
private final AuthorizationService authorizationService;
2018-02-16 11:34:02 +01:00
@Autowired
public Registries(ApiContext apiContext, RegistryManager registryManager, AuthorizationService authorizationService) {
2018-02-16 11:34:02 +01:00
super(apiContext);
this.registryManager = registryManager;
this.authorizationService = authorizationService;
2018-02-16 11:34:02 +01:00
}
@RequestMapping(method = RequestMethod.GET, value = {"/external/registries"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<RegistryModel>>> listExternalRegistries(@RequestParam(value = "query", required = false) String query
, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
List<RegistryModel> registryModels = this.registryManager.getRegistries(query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RegistryModel>>().payload(registryModels).status(ApiMessageCode.NO_MESSAGE));
2018-02-16 11:34:02 +01:00
}
2018-09-04 11:36:18 +02:00
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
2018-09-04 11:36:18 +02:00
public @ResponseBody
ResponseEntity<ResponseItem<RegistryModel>> create(@RequestBody RegistryModel registryModel) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
Registry registry = this.registryManager.create(registryModel);
RegistryModel registryModel1 = new RegistryModel().fromDataModel(registry);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistryModel>().payload(registryModel1).status(ApiMessageCode.SUCCESS_MESSAGE));
2018-09-04 11:36:18 +02:00
}
2017-10-06 19:20:05 +02:00
}