package eu.eudat.controllers; import eu.eudat.data.entities.Registry; import eu.eudat.logic.managers.RegistryManager; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.registries.RegistryModel; import eu.eudat.models.data.security.Principal; import eu.eudat.types.ApiMessageCode; import org.apache.regexp.RE; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @RestController @CrossOrigin @RequestMapping(value = {"/api"}) public class Registries extends BaseController { private RegistryManager registryManager; @Autowired public Registries(ApiContext apiContext, RegistryManager registryManager) { super(apiContext); this.registryManager = registryManager; } @RequestMapping(method = RequestMethod.GET, value = {"/external/registries"}, produces = "application/json") public @ResponseBody ResponseEntity>>> listExternalRegistries(@RequestParam(value = "query", required = false) String query , @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound { List> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getRegistries(query, type); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>>().payload(remoteRepos).status(ApiMessageCode.NO_MESSAGE)); } @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception { Registry registry = this.registryManager.create(this.getApiContext(), registryModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE)); } }