From d81a72b896d3d80ad52c25809cd692c9343a4ab8 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 17 Nov 2022 09:53:09 +0100 Subject: [PATCH] ui --- .../java/eu/dnetlib/is/MainController.java | 89 +++++++++++++++++++ .../is/context/ContextUIController.java | 32 ------- .../eu/dnetlib/is/main/MainController.java | 14 --- .../is/resources/ResourcesRestController.java | 23 +++++ .../is/resources/ResourcesUIController.java | 29 ------ .../is/vocabulary/VocabularyUIController.java | 31 ------- .../dnetlib/is/wfs/WfHistoryController.java | 19 ---- .../templates/fragments/mainParts.html | 9 +- .../resources/templates/simpleResources.html | 6 +- .../dnetlib/is/common/ReadOnlyRepository.java | 22 +++++ .../is/resource/model/SimpleResourceType.java | 45 ++++++++-- .../SimpleResourceTypeRepository.java | 5 +- .../src/main/resources/sql/schema.sql | 16 +++- 13 files changed, 197 insertions(+), 143 deletions(-) create mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/context/ContextUIController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/main/MainController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java delete mode 100644 apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryController.java create mode 100644 libs/dnet-is-common/src/main/java/eu/dnetlib/is/common/ReadOnlyRepository.java diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java new file mode 100644 index 00000000..1b181ed4 --- /dev/null +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/MainController.java @@ -0,0 +1,89 @@ +package eu.dnetlib.is; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +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.SimpleResourceType; +import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository; +import eu.dnetlib.is.vocabulary.model.Vocabulary; +import eu.dnetlib.is.vocabulary.repository.VocabularyRepository; +import eu.dnetlib.is.wfs.WfHistoryRestController; + +@Controller +public class MainController { + + @Autowired + private ContextRepository contextRepository; + + @Autowired + private VocabularyRepository vocabularyRepository; + + @Autowired + private SimpleResourceTypeRepository simpleResourceTypeRepository; + + @GetMapping("/main") + public void mainPage() {} + + @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("/contexts") + public void contexts() {} + + @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("/vocabularies") + public void vocabularies() {} + + @GetMapping("/simpleResources") + public void simpleResources(@RequestParam final String type, final ModelMap map) { + + System.out.println("TYPE: " + type); + + final Optional restype = simpleResourceTypeRepository.findById(type); + + System.out.println("OP TYPE: " + restype); + System.out.println("OP TYPE: " + restype.isPresent()); + + if (restype.isPresent()) { + map.addAttribute("type", restype.get()); + } else { + map.addAttribute("type", new SimpleResourceType("not_present", "???", 0)); + } + + } + + @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", WfHistoryRestController.MAX_NUMBER_OF_RECENT_WFS); + map.put("fromDate", from); + map.put("toDate", to); + } + + @ModelAttribute("resTypes") + public Iterable resourceTypes() { + return simpleResourceTypeRepository.findAll(); + } +} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/context/ContextUIController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/context/ContextUIController.java deleted file mode 100644 index 1a788ae3..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/context/ContextUIController.java +++ /dev/null @@ -1,32 +0,0 @@ -package eu.dnetlib.is.context; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import eu.dnetlib.is.context.model.Context; -import eu.dnetlib.is.context.model.repository.ContextRepository; - -@Controller -public class ContextUIController { - - @Autowired - private ContextRepository contextRepository; - - @GetMapping("/contextEditor") - public void vocabularyEditor(@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("/contexts") - public void contexts(final ModelMap map) { - - } -} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/main/MainController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/main/MainController.java deleted file mode 100644 index 87448aef..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/main/MainController.java +++ /dev/null @@ -1,14 +0,0 @@ -package eu.dnetlib.is.main; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class MainController { - - @GetMapping("/main") - public void vocabularies(final ModelMap map) { - - } -} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java index fae5ebd2..45f77d60 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesRestController.java @@ -1,6 +1,29 @@ package eu.dnetlib.is.resources; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import eu.dnetlib.is.resource.model.SimpleResource; +import eu.dnetlib.is.resource.repository.SimpleResourceRepository; + +@RestController +@RequestMapping("/api/resources") public class ResourcesRestController { + @Autowired + private SimpleResourceRepository simpleResourceRepository; + + @GetMapping("/") + public List listVocs() { + return simpleResourceRepository.findAll() + .stream() + .sorted((r1, r2) -> StringUtils.compareIgnoreCase(r1.getName(), r2.getName())) + .collect(Collectors.toList()); + } } diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java deleted file mode 100644 index bfd58609..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourcesUIController.java +++ /dev/null @@ -1,29 +0,0 @@ -package eu.dnetlib.is.resources; - -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import eu.dnetlib.is.resource.model.SimpleResourceType; -import eu.dnetlib.is.resource.repository.SimpleResourceTypeRepository; - -@Controller -public class ResourcesUIController { - - @Autowired - private SimpleResourceTypeRepository simpleResourceTypeRepository; - - @GetMapping("/simpleResources") - public void simpleResources(@RequestParam final String type, final ModelMap map) { - map.addAttribute("type", type); - map.addAttribute("types", simpleResourceTypeRepository.findAll() - .stream() - .map(SimpleResourceType::getType) - .sorted() - .collect(Collectors.toList())); - } -} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java deleted file mode 100644 index d873aae8..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/vocabulary/VocabularyUIController.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.dnetlib.is.vocabulary; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import eu.dnetlib.is.vocabulary.model.Vocabulary; -import eu.dnetlib.is.vocabulary.repository.VocabularyRepository; - -@Controller -public class VocabularyUIController { - - @Autowired - private VocabularyRepository vocabularyRepository; - - @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("/vocabularies") - public void vocabularies(final ModelMap map) { - - } -} diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryController.java deleted file mode 100644 index 5e58c41d..00000000 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryController.java +++ /dev/null @@ -1,19 +0,0 @@ -package eu.dnetlib.is.wfs; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Controller -public class WfHistoryController { - - @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", WfHistoryRestController.MAX_NUMBER_OF_RECENT_WFS); - map.put("fromDate", from); - map.put("toDate", to); - } -} diff --git a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html index d3952ae7..b35293d4 100644 --- a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html +++ b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html @@ -33,8 +33,13 @@