2023-01-13 11:39:49 +01:00
|
|
|
package eu.dnetlib.dsm;
|
2022-12-13 12:15:34 +01:00
|
|
|
|
2023-01-12 15:09:14 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedHashMap;
|
2022-12-13 12:15:34 +01:00
|
|
|
import java.util.List;
|
2023-01-12 15:09:14 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
2022-12-13 12:15:34 +01:00
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-12-15 15:13:32 +01:00
|
|
|
import org.springframework.data.domain.Page;
|
2022-12-13 12:15:34 +01:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
2022-12-20 13:37:40 +01:00
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
2022-12-13 12:15:34 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
2022-12-13 15:24:47 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
2022-12-13 12:15:34 +01:00
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
2023-02-06 15:31:21 +01:00
|
|
|
import eu.dnetlib.dsm.model.Api;
|
|
|
|
import eu.dnetlib.dsm.model.BrowseTerm;
|
|
|
|
import eu.dnetlib.dsm.model.readonly.SimpleDsWithApis;
|
2023-01-13 11:39:49 +01:00
|
|
|
import eu.dnetlib.dsm.utils.DsmBrowsableFields;
|
2023-02-06 15:53:07 +01:00
|
|
|
import eu.dnetlib.errors.DsmException;
|
2023-01-12 15:09:14 +01:00
|
|
|
import eu.dnetlib.is.info.KeyValue;
|
2023-01-13 15:03:12 +01:00
|
|
|
import eu.dnetlib.is.protocol.ProtocolService;
|
2023-02-06 15:31:21 +01:00
|
|
|
import eu.dnetlib.is.vocabulary.repository.VocabularyTermRepository;
|
2022-12-13 12:15:34 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/ajax/dsm")
|
|
|
|
public class DsmAjaxController extends AbstractDnetController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private DsmService dsmService;
|
|
|
|
|
2023-01-12 15:09:14 +01:00
|
|
|
@Autowired
|
|
|
|
private VocabularyTermRepository vocabularyTermRepository;
|
|
|
|
|
2023-01-13 15:03:12 +01:00
|
|
|
@Autowired
|
|
|
|
private ProtocolService protocolService;
|
|
|
|
|
2023-01-12 15:09:14 +01:00
|
|
|
@GetMapping("/browsableFields")
|
2023-03-21 12:13:23 +01:00
|
|
|
public List<KeyValue<String>> browsableFields() {
|
2023-01-12 15:09:14 +01:00
|
|
|
return Arrays.stream(DsmBrowsableFields.values())
|
2023-03-21 12:13:23 +01:00
|
|
|
.map(f -> new KeyValue<>(f.name(), f.desc))
|
2023-01-12 15:09:14 +01:00
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:03:12 +01:00
|
|
|
@GetMapping("/conf")
|
2023-01-16 14:45:10 +01:00
|
|
|
public Map<String, Iterable<?>> configuration() {
|
|
|
|
final Map<String, Iterable<?>> map = new LinkedHashMap<>();
|
2023-01-13 15:03:12 +01:00
|
|
|
map.put("protocols", protocolService.listProtocols());
|
2023-01-12 15:09:14 +01:00
|
|
|
map.put("compatibilityLevels", vocabularyTermRepository.findTermsByVocabulary("dnet:compatibilityLevel"));
|
|
|
|
map.put("contentDescTypes", vocabularyTermRepository.findTermsByVocabulary("dnet:content_description_typologies"));
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:15:34 +01:00
|
|
|
@GetMapping("/browse/{field}")
|
|
|
|
public List<BrowseTerm> browse(@PathVariable final String field) {
|
|
|
|
return dsmService.browseTerm(DsmBrowsableFields.valueOf(field));
|
|
|
|
}
|
2022-12-13 15:24:47 +01:00
|
|
|
|
2022-12-15 14:19:30 +01:00
|
|
|
@GetMapping("/searchByField/{field}/{page}/{size}")
|
2022-12-15 15:13:32 +01:00
|
|
|
public Page<SimpleDsWithApis> searchByField(@PathVariable final String field,
|
|
|
|
@PathVariable final int page,
|
|
|
|
@PathVariable final int size,
|
|
|
|
@RequestParam final String value) {
|
|
|
|
return dsmService.searchByField(DsmBrowsableFields.valueOf(field), value, page, size);
|
2022-12-13 15:24:47 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 15:13:32 +01:00
|
|
|
@GetMapping("/search/{page}/{size}")
|
|
|
|
public Page<SimpleDsWithApis> search(@RequestParam final String value, @PathVariable final int page, @PathVariable final int size) {
|
|
|
|
return dsmService.search(value, page, size);
|
2022-12-13 15:24:47 +01:00
|
|
|
}
|
|
|
|
|
2022-12-20 09:13:47 +01:00
|
|
|
@GetMapping("/api")
|
|
|
|
public Api findApi(@RequestParam final String id) throws DsmException {
|
|
|
|
return dsmService.findApi(id);
|
|
|
|
}
|
|
|
|
|
2022-12-20 13:37:40 +01:00
|
|
|
@PostMapping("/api")
|
|
|
|
public Api saveApi(@RequestBody final Api api) throws DsmException {
|
|
|
|
throw new DsmException("TO BE IMPLEMENTED");
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:15:34 +01:00
|
|
|
}
|