Commit 473423bf authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

Merge branch 'v4.2-dev' into 'v4.x-master'

441: Fix issues related to deployment of upcoming v4-release (OPENED)

See merge request !29
parents d449734e 8e0b509d
Pipeline #25517 passed with stages
in 4 minutes and 13 seconds
......@@ -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()
......
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<TBase, TExt> 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);
......
......@@ -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<Resource> titles = ResourceHelper.findRecursive(res, "Title");
List<Resource> links = ResourceHelper.findRecursive(res, "Link");
List<Resource> images = ResourceHelper.findRecursive(res, "Images.Resource");
Map<String, List<Resource>> contentElements = new HashMap<>();
List<Resource> audio = ResourceHelper.findRecursive(res, "MultimediaContent.Audio");
if (!audio.isEmpty()) {
contentElements.put("Audio", audio);
}
List<Resource> video = ResourceHelper.findRecursive(res, "MultimediaContent.Video");
if (!audio.isEmpty()) {
contentElements.put("Video", video);
}
List<Resource> info = ResourceHelper.findRecursive(res, "PrimaryInfo");
if (!audio.isEmpty()) {
contentElements.put("Info", info);
}
List<Resource> 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<ResultElement> rootedParents, ResultElement item, ResultElementRelationTypes relationType) {
rootedParents.add(0, item);
......
......@@ -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<String> 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<String>)model.asMap().get("redirectSourceIds");
}
List<String> notifications = new ArrayList<>();
List<Collection> 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);
}
......
......@@ -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<String> 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;
}
}
......@@ -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("<span class=\"result-highlight\">").postTags("</span>");
sourceHighlightBuilder.field(Constants.ELEMENT_KEY_ALL).numOfFragments(20);
sourceHighlightBuilder.field(Constants.ELEMENT_KEY_ALL).numOfFragments(20);
}
public static QueryBuilder getCollectionIdQueryBuilder(List<String> collectionIds) {
......
Subproject commit 6cbfa384269321c75742825c82d9c73c99b8afad
Subproject commit 767b9dbea83f7fccc29f539937fc572a38e5d628
Subproject commit 255e23de4b3262402bd623ef7ca3a09f3016f03d
Subproject commit 9f7b5581481f783778f33b94dc15f7be479ecc0a
Subproject commit 45dab02681cc7a853e706618f76344d22d3f445b
Subproject commit af2a4c85bcf339986256c41090cbf4fac7c4aaa2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment