diff --git a/build.gradle b/build.gradle index 18ef774b83448edfe6eaf493052438ca0aacca48..37abf264dedd0452add242400a36dc4a74f09959 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ allprojects { apply plugin: 'eclipse' group = 'eu.dariah.de.minfba' - version = '4.3.1-SNAPSHOT' + version = '4.3.2-SNAPSHOT' repositories { mavenLocal() diff --git a/search-core/src/main/java/eu/dariah/de/search/api/client/base/BaseApiClientImpl.java b/search-core/src/main/java/eu/dariah/de/search/api/client/base/BaseApiClientImpl.java index f9b557d5362e8b1de630cc59c202a65ca0c67a44..0ad6be7bf2897f3d67ab84f5ae3e0979dfeb1dfe 100644 --- a/search-core/src/main/java/eu/dariah/de/search/api/client/base/BaseApiClientImpl.java +++ b/search-core/src/main/java/eu/dariah/de/search/api/client/base/BaseApiClientImpl.java @@ -1,5 +1,6 @@ package eu.dariah.de.search.api.client.base; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -109,7 +110,23 @@ public abstract class BaseApiClientImpl implements ApiClient { ApiStatusPojo result = new ApiStatusPojo(); Stopwatch sw = new Stopwatch().start(); try { - HttpURLConnection connection = (HttpURLConnection)new URL(this.getPingUrl()).openConnection(); + String location; + URL baseURL = new URL(this.getPingUrl()); + URL nextURL; + HttpURLConnection connection = (HttpURLConnection)baseURL.openConnection(); + int redirects = 0; + + while(connection.getResponseCode()==HttpURLConnection.HTTP_MOVED_PERM || + connection.getResponseCode()==HttpURLConnection.HTTP_MOVED_TEMP) { + if (++redirects > 10) { + throw new IOException("Too many redirects; connect cancelled"); + } + location = connection.getHeaderField("Location"); + nextURL = new URL(baseURL, location); // Handle relative URLs + baseURL = nextURL; + connection = (HttpURLConnection)baseURL.openConnection(); + } + result.setStatusCode(connection.getResponseCode()); result.setRoundtime(sw.getElapsedTime()); result.setAccessible(true); diff --git a/search-core/src/main/java/eu/dariah/de/search/controller/search/ItemController.java b/search-core/src/main/java/eu/dariah/de/search/controller/search/ItemController.java index 999d367dbc97073a12d3ae578b8c2f09779c48fd..27de4adf0b6e6875b65355ab18b67509348616ca 100755 --- a/search-core/src/main/java/eu/dariah/de/search/controller/search/ItemController.java +++ b/search-core/src/main/java/eu/dariah/de/search/controller/search/ItemController.java @@ -2,6 +2,7 @@ package eu.dariah.de.search.controller.search; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -17,11 +18,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestAttribute; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -44,7 +44,6 @@ import eu.dariah.de.search.model.ExtendedDatamodelContainer; import eu.dariah.de.search.query.Query; import eu.dariah.de.search.query.execution.ItemService; import eu.dariah.de.search.query.execution.QueryExecutionServiceImpl; -import eu.dariah.de.search.query.results.FieldHighlight; import eu.dariah.de.search.query.results.QueryResult; import eu.dariah.de.search.query.results.ResultElement; import eu.dariah.de.search.service.CollectionService; @@ -54,7 +53,7 @@ import eu.dariah.de.search.service.DatamodelService; @RequestMapping("/item/{type}/{itemId}") public class ItemController extends BaseController { private static final String ITEM_404_VIEW = "item/404"; - + @Autowired private CollectionService collectionService; @Autowired private DatamodelService datamodelService; @Autowired private ItemService itemService; @@ -72,11 +71,6 @@ public class ItemController extends BaseController { @GetMapping(value = "/") public String getItem(@PathVariable String type, @PathVariable String itemId, Model model, Locale locale, HttpServletResponse response) throws IOException { - return this.postItem(type, itemId, null, model, locale, response); - } - - @PostMapping(value = "/") - public String postItem(@PathVariable String type, @PathVariable String itemId, @RequestParam(required= false, name="query") String jsonQuery, Model model, Locale locale, HttpServletResponse response) throws IOException { model.addAttribute("itemId", itemId); if (itemId==null || type==null) { return ITEM_404_VIEW; @@ -87,14 +81,15 @@ public class ItemController extends BaseController { } Query query = null; - if (jsonQuery!=null && !jsonQuery.isBlank()) { + if (model.asMap().containsKey("jsonQuery") && model.asMap().get("jsonQuery")!=null) { try { - query = queryExecutionService.deserializeQuery(jsonQuery); + query = queryExecutionService.deserializeQuery(String.class.cast(model.asMap().get("jsonQuery"))); } catch (QueryExecutionException e) { logger.error("Failed to deserialize query", e); } } + JsonNode itemSource = null; ResultElement item = null; if (query!=null) { @@ -127,12 +122,34 @@ public class ItemController extends BaseController { List titles = ResourceHelper.findRecursive(res, "Title"); List links = ResourceHelper.findRecursive(res, "Link"); List images = ResourceHelper.findRecursive(res, "Images.Resource"); + + + Map> contentElements = new HashMap<>(); + List audio = ResourceHelper.findRecursive(res, "MultimediaContent.Audio"); + if (!audio.isEmpty()) { + contentElements.put("Audio", audio); + } + + List video = ResourceHelper.findRecursive(res, "MultimediaContent.Video"); + if (!audio.isEmpty()) { + contentElements.put("Video", video); + } + + List info = ResourceHelper.findRecursive(res, "PrimaryInfo"); + if (!audio.isEmpty()) { + contentElements.put("Info", info); + } List frames = ResourceHelper.findRecursive(res, "EmbeddedFrame"); + if (!frames.isEmpty()) { + contentElements.put("Frame", frames); + } model.addAttribute("titles", titles); model.addAttribute("links", links); model.addAttribute("images", images); - model.addAttribute("frames", frames); + //model.addAttribute("frames", frames); + //model.addAttribute("primaryInfos", primaryInfos); + model.addAttribute("contentElements", contentElements); if (titles!=null && !titles.isEmpty()) { itemIdTitleMap.put(itemId, titles); @@ -159,6 +176,14 @@ public class ItemController extends BaseController { return "item/view"; } + @PostMapping(value = "/") + public String postItem(@PathVariable String type, @PathVariable String itemId, @RequestParam(required= false, name="query") String jsonQuery, Model model, Locale locale, RedirectAttributes attributes, HttpServletResponse response) throws IOException { + if (jsonQuery!=null) { + attributes.addFlashAttribute("jsonQuery", jsonQuery); + } + return String.format("redirect:/item/%s/%s/", type, itemId); + } + private void findReferencingParents(List rootedParents, ResultElement item, ResultElementRelationTypes relationType) { rootedParents.add(0, item); diff --git a/search-core/src/main/java/eu/dariah/de/search/controller/search/SimpleSearchController.java b/search-core/src/main/java/eu/dariah/de/search/controller/search/SimpleSearchController.java index 02e42f02bf2177783a00b9daa0b5c63d90991ff3..09f2999227832615a78055c3ee14103421b87492 100644 --- a/search-core/src/main/java/eu/dariah/de/search/controller/search/SimpleSearchController.java +++ b/search-core/src/main/java/eu/dariah/de/search/controller/search/SimpleSearchController.java @@ -38,19 +38,8 @@ public class SimpleSearchController extends BaseSimpleSearchController { return new ModelAndView("redirect:/search/simple/"); } - @SuppressWarnings("unchecked") @GetMapping(value="/") public ModelAndView getViewAndQuery(@RequestParam(required=false, name="q") String expression, @RequestParam(required=false, name="sourceId") List sourceIds, RedirectAttributes attributes, Model model, HttpServletRequest request, Locale locale) { - if (this.isNeedsRedirect(expression, sourceIds, attributes)) { - return new ModelAndView("redirect:/search/simple/"); - } - if (model.asMap().containsKey("redirectExpression") && model.asMap().get("redirectExpression")!=null) { - expression = (String)model.asMap().get("redirectExpression"); - } - if (model.asMap().containsKey("redirectSourceIds") && model.asMap().get("redirectSourceIds")!=null) { - sourceIds = (List)model.asMap().get("redirectSourceIds"); - } - List notifications = new ArrayList<>(); List collections = collectionService.getAll(); @@ -59,7 +48,6 @@ public class SimpleSearchController extends BaseSimpleSearchController { model.addAttribute("availableFilters", filterService.getAllAvailableFilters()); model.addAttribute("searchNotifications", notifications); - return super.getViewAndQuery(expression, sourceIds, model, locale); } diff --git a/search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSimpleSearchController.java b/search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSimpleSearchController.java index c9d82e26ac2bbbe87cc6a381d9e9fce2648084c1..bdb7ac9bd9895c56ff506414a31c76be97fc3821 100755 --- a/search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSimpleSearchController.java +++ b/search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSimpleSearchController.java @@ -5,7 +5,6 @@ import java.util.Locale; import org.springframework.ui.Model; import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; import eu.dariah.de.search.query.SimpleQueryImpl; @@ -24,17 +23,4 @@ public abstract class BaseSimpleSearchController extends BaseSearchController { return new ModelAndView("search/simple", model.asMap()); } - - protected boolean isNeedsRedirect(String expression, List sourceIds, RedirectAttributes attributes) { - if (expression!=null || (sourceIds!=null && !sourceIds.isEmpty())) { - if (expression!=null) { - attributes.addFlashAttribute("redirectExpression", expression); - } - if (sourceIds!=null && !sourceIds.isEmpty()) { - attributes.addFlashAttribute("redirectSourceIds", sourceIds); - } - return true; - } - return false; - } } diff --git a/search-core/src/main/java/eu/dariah/de/search/query/execution/base/BaseQueryService.java b/search-core/src/main/java/eu/dariah/de/search/query/execution/base/BaseQueryService.java index b7ca0ca8396101649e3641b513d6580e562a07bc..906fd4b7ebccad5b86c68fecd2318d4edb906fdb 100755 --- a/search-core/src/main/java/eu/dariah/de/search/query/execution/base/BaseQueryService.java +++ b/search-core/src/main/java/eu/dariah/de/search/query/execution/base/BaseQueryService.java @@ -48,11 +48,12 @@ public abstract class BaseQueryService extends BaseResultService { sourceHighlightBuilder = new HighlightBuilder(); sourceHighlightBuilder.numOfFragments(3); + sourceHighlightBuilder.encoder("html"); sourceHighlightBuilder.fragmentSize(150); sourceHighlightBuilder.requireFieldMatch(false); sourceHighlightBuilder.order(Order.SCORE); sourceHighlightBuilder.field("_all").preTags("").postTags(""); - sourceHighlightBuilder.field(Constants.ELEMENT_KEY_ALL).numOfFragments(20); + sourceHighlightBuilder.field(Constants.ELEMENT_KEY_ALL).numOfFragments(20); } public static QueryBuilder getCollectionIdQueryBuilder(List collectionIds) { diff --git a/search-ui/src/main/resources/i18n b/search-ui/src/main/resources/i18n index 6cbfa384269321c75742825c82d9c73c99b8afad..767b9dbea83f7fccc29f539937fc572a38e5d628 160000 --- a/search-ui/src/main/resources/i18n +++ b/search-ui/src/main/resources/i18n @@ -1 +1 @@ -Subproject commit 6cbfa384269321c75742825c82d9c73c99b8afad +Subproject commit 767b9dbea83f7fccc29f539937fc572a38e5d628 diff --git a/search-ui/src/main/webapp/WEB-INF/view/jsp/_search-commons b/search-ui/src/main/webapp/WEB-INF/view/jsp/_search-commons index 255e23de4b3262402bd623ef7ca3a09f3016f03d..9f7b5581481f783778f33b94dc15f7be479ecc0a 160000 --- a/search-ui/src/main/webapp/WEB-INF/view/jsp/_search-commons +++ b/search-ui/src/main/webapp/WEB-INF/view/jsp/_search-commons @@ -1 +1 @@ -Subproject commit 255e23de4b3262402bd623ef7ca3a09f3016f03d +Subproject commit 9f7b5581481f783778f33b94dc15f7be479ecc0a diff --git a/search-ui/src/main/webapp/resources b/search-ui/src/main/webapp/resources index 45dab02681cc7a853e706618f76344d22d3f445b..af2a4c85bcf339986256c41090cbf4fac7c4aaa2 160000 --- a/search-ui/src/main/webapp/resources +++ b/search-ui/src/main/webapp/resources @@ -1 +1 @@ -Subproject commit 45dab02681cc7a853e706618f76344d22d3f445b +Subproject commit af2a4c85bcf339986256c41090cbf4fac7c4aaa2