92 lines
2.9 KiB
Java
92 lines
2.9 KiB
Java
package eu.dnetlib.is;
|
|
|
|
import java.util.Optional;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
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.is.context.model.Context;
|
|
import eu.dnetlib.is.context.model.repository.ContextRepository;
|
|
import eu.dnetlib.is.resource.model.ResourceType;
|
|
import eu.dnetlib.is.resource.repository.ResourceTypeRepository;
|
|
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
|
import eu.dnetlib.is.vocabulary.repository.VocabularyRepository;
|
|
import eu.dnetlib.is.wfs.WfHistoryAjaxController;
|
|
|
|
@Controller
|
|
public class MainController {
|
|
|
|
@Autowired
|
|
private ContextRepository contextRepository;
|
|
|
|
@Autowired
|
|
private VocabularyRepository vocabularyRepository;
|
|
|
|
@Autowired
|
|
private ResourceTypeRepository resourceTypeRepository;
|
|
|
|
@Value("${logging.file.name:not specified}")
|
|
private String logFile;
|
|
|
|
@GetMapping("/main")
|
|
public void mainPage() {}
|
|
|
|
@GetMapping("/resources")
|
|
public String listResources(@RequestParam final String type, final ModelMap map) {
|
|
|
|
if (type.equalsIgnoreCase("vocabulary")) {
|
|
return "vocabularies";
|
|
} else if (type.equalsIgnoreCase("context")) {
|
|
return "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("/contextEditor")
|
|
public void contextEditor(@RequestParam final String id, final ModelMap map) {
|
|
final Context ctx = contextRepository.getById(id);
|
|
map.put("ctxId", ctx.getId());
|
|
map.put("ctxLabel", ctx.getLabel());
|
|
map.put("ctxType", ctx.getType());
|
|
map.put("ctxParams", ctx.getParameters());
|
|
}
|
|
|
|
@GetMapping("/vocabularyEditor")
|
|
public void vocabularyEditor(@RequestParam final String id, final ModelMap map) {
|
|
final Vocabulary voc = vocabularyRepository.getById(id);
|
|
map.put("vocId", voc.getId());
|
|
map.put("vocName", voc.getName());
|
|
map.put("vocDesc", voc.getDescription());
|
|
}
|
|
|
|
@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();
|
|
}
|
|
}
|