2022-02-04 10:12:15 +01:00
|
|
|
package eu.dnetlib.openaire.context;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
2022-08-19 15:21:40 +02:00
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2023-03-31 14:53:52 +02:00
|
|
|
import eu.dnetlib.openaire.exporter.exceptions.ContextException;
|
|
|
|
import eu.dnetlib.openaire.exporter.model.context.CategorySummary;
|
|
|
|
import eu.dnetlib.openaire.exporter.model.context.ConceptSummary;
|
|
|
|
import eu.dnetlib.openaire.exporter.model.context.ContextSummary;
|
2022-08-19 15:21:40 +02:00
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2022-02-04 10:12:15 +01:00
|
|
|
|
|
|
|
@RestController
|
2022-08-19 15:21:40 +02:00
|
|
|
@CrossOrigin(origins = {
|
|
|
|
"*"
|
|
|
|
})
|
2022-02-04 10:12:15 +01:00
|
|
|
@ConditionalOnProperty(value = "openaire.exporter.enable.context", havingValue = "true")
|
2022-08-19 15:21:40 +02:00
|
|
|
@Tag(name = "OpenAIRE Context API", description = "the OpenAIRE Context API")
|
2022-02-04 10:12:15 +01:00
|
|
|
public class ContextApiController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ContextApiCore contextApiCore;
|
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
@RequestMapping(value = "/contexts", produces = {
|
|
|
|
"application/json"
|
|
|
|
}, method = RequestMethod.GET)
|
|
|
|
@Operation(summary = "list brief information about all the context profiles", description = "list brief information about all the context profiles")
|
2022-02-04 10:12:15 +01:00
|
|
|
@ApiResponses(value = {
|
2022-08-19 15:21:40 +02:00
|
|
|
@ApiResponse(responseCode = "200", description = "OK"),
|
|
|
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
|
|
|
})
|
|
|
|
public List<ContextSummary> listContexts(@RequestParam(required = false, defaultValue = "") final List<String> type) throws ContextException {
|
2022-02-04 10:12:15 +01:00
|
|
|
return contextApiCore.listContexts(type);
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
@RequestMapping(value = "/context/{contextId}", produces = {
|
|
|
|
"application/json"
|
|
|
|
}, method = RequestMethod.GET)
|
|
|
|
@Operation(summary = "list the categories defined within a context", description = "list the categories defined within a context")
|
2022-02-04 10:12:15 +01:00
|
|
|
@ApiResponses(value = {
|
2022-08-19 15:21:40 +02:00
|
|
|
@ApiResponse(responseCode = "200", description = "OK"),
|
|
|
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
|
|
|
})
|
2022-02-04 10:12:15 +01:00
|
|
|
public List<CategorySummary> listCategories(
|
2022-08-19 15:21:40 +02:00
|
|
|
@PathVariable final String contextId,
|
|
|
|
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
2022-02-04 10:12:15 +01:00
|
|
|
return contextApiCore.listCategories(contextId, allFilter);
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
@RequestMapping(value = "/context/category/{categoryId}", produces = {
|
|
|
|
"application/json"
|
|
|
|
}, method = RequestMethod.GET)
|
|
|
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
2022-02-04 10:12:15 +01:00
|
|
|
@ApiResponses(value = {
|
2022-08-19 15:21:40 +02:00
|
|
|
@ApiResponse(responseCode = "200", description = "OK"),
|
|
|
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
|
|
|
})
|
2022-02-04 10:12:15 +01:00
|
|
|
public List<ConceptSummary> listConcepts(
|
2022-08-19 15:21:40 +02:00
|
|
|
@PathVariable final String categoryId,
|
|
|
|
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
2022-02-04 10:12:15 +01:00
|
|
|
return contextApiCore.listConcepts(categoryId, allFilter);
|
|
|
|
}
|
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
@RequestMapping(value = "/context/category/concept/{conceptId}", produces = {
|
|
|
|
"application/json"
|
|
|
|
}, method = RequestMethod.GET)
|
|
|
|
@Operation(summary = "list the concepts defined within a category", description = "list the concepts defined within a category")
|
2022-02-04 10:12:15 +01:00
|
|
|
@ApiResponses(value = {
|
2022-08-19 15:21:40 +02:00
|
|
|
@ApiResponse(responseCode = "200", description = "OK"),
|
|
|
|
@ApiResponse(responseCode = "500", description = "unexpected error")
|
|
|
|
})
|
2022-02-04 10:12:15 +01:00
|
|
|
public List<ConceptSummary> listSubConcepts(
|
2022-08-19 15:21:40 +02:00
|
|
|
@PathVariable final String conceptId,
|
|
|
|
@RequestParam(required = false, defaultValue = "false") final Boolean all) throws ContextException {
|
2022-02-04 10:12:15 +01:00
|
|
|
|
2022-08-19 15:21:40 +02:00
|
|
|
final Boolean allFilter = Optional.ofNullable(all).orElse(false);
|
2022-02-04 10:12:15 +01:00
|
|
|
return contextApiCore.listSubConcepts(conceptId, allFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|