87 lines
2.7 KiB
Java
87 lines
2.7 KiB
Java
package eu.dnetlib.is;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Optional;
|
|
import java.util.stream.Collectors;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import eu.dnetlib.data.is.context.repository.ContextRepository;
|
|
import eu.dnetlib.data.is.resource.model.ResourceType;
|
|
import eu.dnetlib.data.is.resource.repository.ResourceTypeRepository;
|
|
import eu.dnetlib.data.is.vocabulary.repository.VocabularyRepository;
|
|
import eu.dnetlib.is.info.KeyValue;
|
|
import eu.dnetlib.is.wfs.WfHistoryAjaxController;
|
|
import eu.dnetlib.openaire.dsm.utils.DsmBrowsableFields;
|
|
|
|
@Controller
|
|
public class MainController {
|
|
|
|
@Autowired
|
|
private ContextRepository contextRepository;
|
|
|
|
@Autowired
|
|
private VocabularyRepository vocabularyRepository;
|
|
|
|
@Autowired
|
|
private ResourceTypeRepository resourceTypeRepository;
|
|
|
|
@GetMapping("/main")
|
|
public void mainPage() {}
|
|
|
|
@GetMapping("/dsm")
|
|
public void searchDsApi(final ModelMap map) {
|
|
map.addAttribute("pageSize", 100);
|
|
map.addAttribute("browsableFields", Arrays.stream(DsmBrowsableFields.values())
|
|
.map(f -> new KeyValue(f.name(), f.desc))
|
|
.collect(Collectors.toList()));
|
|
}
|
|
|
|
@GetMapping("/resources")
|
|
public String listResources(@RequestParam final String type, final ModelMap map) {
|
|
|
|
if (type.equalsIgnoreCase("vocabulary")) {
|
|
return "redirect:vocs";
|
|
} else if (type.equalsIgnoreCase("context")) {
|
|
return "redirect:contexts";
|
|
} else {
|
|
final Optional<ResourceType> restype = resourceTypeRepository.findById(type);
|
|
if (restype.isPresent() && restype.get().isSimple()) {
|
|
map.addAttribute("type", restype.get());
|
|
} else {
|
|
map.addAttribute("type", new ResourceType("not_present", "???", MediaType.TEXT_PLAIN_VALUE, 0));
|
|
}
|
|
return "simpleResources";
|
|
}
|
|
}
|
|
|
|
@GetMapping("/vocs")
|
|
public void vocabularies() {}
|
|
|
|
@GetMapping("/contexts")
|
|
public void contexts() {}
|
|
|
|
@GetMapping("/wf_history")
|
|
public void wfHistory(final ModelMap map,
|
|
@RequestParam(required = false, defaultValue = "-1") final Long from,
|
|
@RequestParam(required = false, defaultValue = "-1") final Long to) {
|
|
map.put("maxNumberOfRecentWfs", WfHistoryAjaxController.MAX_NUMBER_OF_RECENT_WFS);
|
|
map.put("fromDate", from);
|
|
map.put("toDate", to);
|
|
}
|
|
|
|
@GetMapping("/info")
|
|
public void wfHistory() throws Exception {}
|
|
|
|
@ModelAttribute("resTypes")
|
|
public Iterable<ResourceType> resourceTypes() {
|
|
return resourceTypeRepository.findAll();
|
|
}
|
|
}
|