Commit 10b4ddb8 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

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

427: Make grammar compilation available from within container (OPENED)

See merge request !21
parents 126d0fc3 f733e3c5
Pipeline #23491 failed with stages
in 3 minutes and 8 seconds
......@@ -9,7 +9,7 @@ allprojects {
apply plugin: 'eclipse'
group = 'eu.dariah.de.minfba'
version = '4.0-SNAPSHOT'
version = '4.1-SNAPSHOT'
repositories {
mavenLocal()
......@@ -19,10 +19,10 @@ allprojects {
}
ext {
coreVersion = "6.2-SNAPSHOT"
gtfVersion = "2.0.0-SNAPSHOT"
processingVersion = "4.1.0-SNAPSHOT"
gtfVersion = "2.1.0-SNAPSHOT"
processingVersion = "4.2.0-SNAPSHOT"
colregModelVersion = "4.3.4-RELEASE"
dariahSpVersion = "2.1.6-RELEASE"
dariahSpVersion = "2.1.7-RELEASE"
jsonAssertVersion = "1.5.0"
jodaTimeVersion = "2.10.10"
......
......@@ -11,6 +11,4 @@ public interface IndexClient extends BaseEsClient {
public String[] getIndexNames();
public String getIndexNameForDatamodelId(String modelId);
public String getIndexConfigPath();
}
......@@ -30,11 +30,7 @@ public class IndexClientImpl extends BaseEsClientImpl implements IndexClient, In
private Pattern indexNamePattern;
@Autowired private File indexConfigFile;
@Override public String getIndexConfigPath() {
return indexConfigFile.getAbsolutePath();
}
@Autowired private Settings indexConfigSettings;
@Override
public void afterPropertiesSet() throws Exception {
......@@ -55,20 +51,13 @@ public class IndexClientImpl extends BaseEsClientImpl implements IndexClient, In
@Override
public boolean createIndex(String indexName) {
Assert.notNull(indexName, "Index name cannot be null");
Settings settings = null;
try {
if (this.indexExists(indexName)) {
throw new ElasticsearchAdminException(String.format("Index [%s] already exists and needs to be deleted manually", indexName));
}
if (this.getIndexConfigPath()!=null) {
settings = Settings.builder().loadFromPath(Paths.get(getIndexConfigPath())).build();
}
CreateIndexRequest request = new CreateIndexRequest(indexName);
if (settings==null) {
logger.warn("No index configuration available. Please check configuration of this search instance");
}
request.settings(settings);
request.settings(indexConfigSettings);
return client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged();
} catch (Exception e) {
logger.error("Failed to create index settings", e);
......
......@@ -29,6 +29,6 @@ public class BaseEsClientTest extends BaseEsIntegrationTest {
@BeforeEach
public void setup() throws Exception {
Mockito.when(indexClient.getIndexConfigPath()).thenReturn(indexConfig.getAbsolutePath());
//Mockito.when(indexClient.getIndexConfigPath()).thenReturn(indexConfig.getAbsolutePath());
}
}
......@@ -9,6 +9,7 @@ import java.security.NoSuchAlgorithmException;
import javax.annotation.PostConstruct;
import org.elasticsearch.common.settings.Settings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
......@@ -111,15 +112,12 @@ public class MainConfig extends MainConfigProperties {
}
@Bean
public File indexConfigFile() throws ConfigurationException, IOException {
public Settings indexConfigSettings() throws ConfigurationException, IOException {
File indexConfig = new File(this.getPaths().getConfig() + File.separator + this.getIndexing().getIndexConfigFile());
if (!indexConfig.exists()) {
indexConfig = resourceLoader.getResource("classpath:conf/" + this.getIndexing().getIndexConfigFile()).getFile();
if (indexConfig.exists()) {
return Settings.builder().loadFromPath(Paths.get(indexConfig.getAbsolutePath())).build();
}
if (!indexConfig.exists()) {
throw new ConfigurationException("Index config (index_config.json) not provided or does not exist");
}
return indexConfig;
return Settings.builder().loadFromStream("index_config.json", resourceLoader.getResource("classpath:conf/" + this.getIndexing().getIndexConfigFile()).getInputStream(), true).build();
}
@Bean
......
......@@ -62,10 +62,10 @@ public class WebConfig implements WebMvcConfigurer {
@Bean
public Navigation navigation(ObjectMapper objectMapper) throws IOException {
File navigation = new File(mainConfig.getPaths().getConfig() + File.separator + "navigation.json");
if (!navigation.exists()) {
navigation = resourceLoader.getResource("classpath:conf/navigation.json").getFile();
}
return objectMapper.readValue(navigation, Navigation.class);
if (navigation.exists()) {
return objectMapper.readValue(navigation, Navigation.class);
}
return objectMapper.readValue(resourceLoader.getResource("classpath:conf/navigation.json").getInputStream(), Navigation.class);
}
@Bean
......
package eu.dariah.de.search.controller;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import eu.dariah.de.dariahsp.config.SecurityConfig;
import eu.dariah.de.dariahsp.error.RequiredAttributesException;
/**
* Error controller for the sample application
*
* @author Tobias Gradl
*/
@Controller
@RequestMapping({"${server.error.path:${error.path:/error}}"})
public class ErrorController extends BasicErrorController {
@Autowired private SecurityConfig securityConfig;
/**
* Constructor with autowired ErrorAttributes
*
* @param errorAttributes
*/
@Autowired
public ErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes, new ErrorProperties());
}
/**
* Error handling method dispatching all errors as messages to the default index view.
* Particular attention lies on the treatment of the {@link RequiredAttributesException}
*/
@Override
@RequestMapping(produces = {"text/html"})
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> attr = getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.ALL));
HttpStatus status = getStatus(request);
this.assembleMap(attr, status);
// This is an error that needs special treatment in DARIAH/CLARIAH
Object ex = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (ex!=null && RequiredAttributesException.class.isAssignableFrom(ex.getClass())) {
StringBuilder errorStrBldr = new StringBuilder();
errorStrBldr.append("Your IdP did not provide all required attributes. ");
if (securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl()!=null) {
errorStrBldr
.append("Please visit ")
.append("<a href='").append(securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl()).append("'>")
.append(securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl())
.append("</a> to validate your profile setup.");
}
attr.put("hint", errorStrBldr.toString());
attr.put("error", HttpStatus.FORBIDDEN.value());
attr.put("reason", HttpStatus.FORBIDDEN.getReasonPhrase());
}
return new ModelAndView("common/error", attr);
}
/* Do not do this in production as users should not see all reasons openly */
@Override
protected boolean isIncludeMessage(HttpServletRequest request, MediaType produces) {
return true;
}
private void assembleMap(Map<String, Object> map, HttpStatus status) {
map.put("error", status.value());
map.put("reason", status.getReasonPhrase());
map.put("localEnabled", securityConfig.getLocal().isEnabled());
map.put("samlEnabled", securityConfig.getSaml().isEnabled());
}
}
\ No newline at end of file
Subproject commit 7274639e8461b8c5970617dcdeb6305f7c819fb9
Subproject commit ca479bb95e8f7dac66ac4718192f1374710bb06e
......@@ -76,9 +76,14 @@
</definition>
<!-- Errors -->
<definition name="*/error" extends="{1}/template_simple">
<definition name="*/common/error" extends="{1}/template_simple">
<put-attribute name="fluidLayout" cascade="true" value="false" />
<put-attribute name="content" value="/WEB-INF/view/jsp/_search-commons/common/error.jsp" />
</definition>
<definition name="*/error/404" extends="{1}/template_simple">
<put-attribute name="fluidLayout" cascade="true" value="false" />
<put-attribute name="content" value="/WEB-INF/view/jsp/_search-commons/common/error404.jsp" />
</definition>
<!-- User profile -->
<definition name="*/user" extends="{1}/template_simple">
......
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