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

105 lines
6.3 KiB
Java
Raw Normal View History

2023-10-18 17:05:39 +02:00
package eu.eudat.controllers.v2;
import eu.eudat.controllers.BaseController;
import eu.eudat.data.old.DataRepository;
import eu.eudat.data.old.Registry;
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
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.logic.services.externalreferences.ExternalReferencesService;
import eu.eudat.logic.services.externalreferences.FunderService;
import eu.eudat.logic.services.externalreferences.ProjectService;
import eu.eudat.models.data.ExternalReference;
import eu.eudat.models.data.ExternalReference2;
import eu.eudat.models.data.datarepository.DataRepositoryModel;
import eu.eudat.models.data.funder.Funder;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.project.Project;
import eu.eudat.models.data.registries.RegistryModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
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 javax.management.InvalidApplicationException;
2023-10-18 17:05:39 +02:00
import java.util.List;
@RestController
@CrossOrigin
@RequestMapping(path = {"api/external-references"})
public class ExternalReferencesController extends BaseController {
private final FunderService funderService;
private final ExternalReferencesService externalReferencesService;
private final ProjectService projectService;
@Autowired
public ExternalReferencesController(
ApiContext apiContext,
FunderService funderService,
ExternalReferencesService externalReferencesService,
ProjectService projectService
) {
super(apiContext);
this.funderService = funderService;
this.externalReferencesService = externalReferencesService;
this.projectService = projectService;
}
@PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
2023-10-18 17:05:39 +02:00
List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
@PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
2023-10-18 17:05:39 +02:00
List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
@GetMapping(path = {"data-repo/{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type, Principal principal
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
2023-10-18 17:05:39 +02:00
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalType, query, type, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
}
@Transactional
@PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference, Principal principal) throws Exception {
ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
}
@GetMapping(path = {"{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
@RequestParam(value = "type", required = false) String type, Principal principal
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
2023-10-18 17:05:39 +02:00
List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
}
@Transactional
@PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference, Principal principal) throws Exception {
ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
}
}