You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/02/03 20:30:16 UTC
[3/3] logging-log4j-audit git commit: Required attribute in event
uses attribute's required value as default
Required attribute in event uses attribute's required value as default
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/6cf96b62
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/6cf96b62
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/6cf96b62
Branch: refs/heads/master
Commit: 6cf96b6289e630526de76644960ed17b67760e31
Parents: 1fcf810
Author: Ralph Goers <rg...@apache.org>
Authored: Sat Feb 3 13:30:08 2018 -0700
Committer: Ralph Goers <rg...@apache.org>
Committed: Sat Feb 3 13:30:08 2018 -0700
----------------------------------------------------------------------
.../src/main/resources/sql/hsql/schema.sql | 2 +-
.../main/resources/sql/postgresql/schema.sql | 2 +-
.../api/annotation/JdbcUrlCondition.java | 2 +-
.../jpa/converter/BooleanToStringConverter.java | 8 ++-
.../catalog/jpa/converter/EventConverter.java | 6 +-
.../catalog/jpa/model/EventAttributeModel.java | 6 +-
.../src/test/resources/sql/hsql/schema.sql | 2 +-
.../log4j/catalog/config/WebMvcAppContext.java | 59 +++++++++++++++++++-
.../catalog/controller/EventController.java | 2 +
.../src/main/resources/sql/hsql/schema.sql | 2 +-
10 files changed, 79 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-audit/log4j-audit-war/src/main/resources/sql/hsql/schema.sql
----------------------------------------------------------------------
diff --git a/log4j-audit/log4j-audit-war/src/main/resources/sql/hsql/schema.sql b/log4j-audit/log4j-audit-war/src/main/resources/sql/hsql/schema.sql
index 78e5475..df55275 100644
--- a/log4j-audit/log4j-audit-war/src/main/resources/sql/hsql/schema.sql
+++ b/log4j-audit/log4j-audit-war/src/main/resources/sql/hsql/schema.sql
@@ -85,7 +85,7 @@ CREATE TABLE EVENT_ATTRIBUTES
ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
EVENT_ID BIGINT NOT NULL,
ATTRIBUTE_ID BIGINT NOT NULL,
- IS_REQUIRED CHAR NOT NULL,
+ IS_REQUIRED CHAR,
FOREIGN KEY (EVENT_ID) REFERENCES CATALOG_EVENT(ID),
FOREIGN KEY (ATTRIBUTE_ID) REFERENCES EVENT_ATTRIBUTE(ID)
);
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-audit/log4j-audit-war/src/main/resources/sql/postgresql/schema.sql
----------------------------------------------------------------------
diff --git a/log4j-audit/log4j-audit-war/src/main/resources/sql/postgresql/schema.sql b/log4j-audit/log4j-audit-war/src/main/resources/sql/postgresql/schema.sql
index 4ec242d..1ca5e12 100644
--- a/log4j-audit/log4j-audit-war/src/main/resources/sql/postgresql/schema.sql
+++ b/log4j-audit/log4j-audit-war/src/main/resources/sql/postgresql/schema.sql
@@ -81,7 +81,7 @@ CREATE TABLE EVENT_ATTRIBUTES
ID SERIAL8 UNIQUE PRIMARY KEY,
EVENT_ID BIGINT REFERENCES CATALOG_EVENT (ID),
ATTRIBUTE_ID BIGINT REFERENCES EVENT_ATTRIBUTE (ID),
- IS_REQUIRED CHAR NOT NULL
+ IS_REQUIRED CHAR
);
CREATE TABLE CATALOG_CATEGORY
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/annotation/JdbcUrlCondition.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/annotation/JdbcUrlCondition.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/annotation/JdbcUrlCondition.java
index 11bfbac..ceeca50 100644
--- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/annotation/JdbcUrlCondition.java
+++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/annotation/JdbcUrlCondition.java
@@ -38,7 +38,7 @@ public class JdbcUrlCondition implements Condition {
if (value.equals("hsqldb")) {
return jdbcUrl == null || isEmbedded;
}
- if (jdbcUrl == null) {
+ if (jdbcUrl == null || isEmbedded) {
return false;
}
if (!jdbcUrl.startsWith("jdbc:")) {
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/BooleanToStringConverter.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/BooleanToStringConverter.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/BooleanToStringConverter.java
index 1d694f9..7139a6d 100644
--- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/BooleanToStringConverter.java
+++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/BooleanToStringConverter.java
@@ -27,11 +27,17 @@ import javax.persistence.Converter;
public class BooleanToStringConverter implements AttributeConverter<Boolean, String> {
@Override
public String convertToDatabaseColumn(Boolean value) {
- return (value != null && value) ? "Y" : "N";
+ if (value == null) {
+ return null;
+ }
+ return value ? "Y" : "N";
}
@Override
public Boolean convertToEntityAttribute(String value) {
+ if (value == null) {
+ return null;
+ }
return "Y".equals(value);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
index cf77f1b..388252b 100644
--- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
+++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
@@ -72,12 +72,14 @@ public class EventConverter extends AbstractConverter<Event, EventModel> {
for (EventAttribute eventAttribute : eventAttributes) {
EventAttributeModel eventAttributeModel = model.getAttribute(eventAttribute.getName());
if (eventAttributeModel != null) {
- eventAttributeModel.setRequired(eventAttribute.isRequired());
+ eventAttributeModel.setRequired(eventAttribute != null ? eventAttribute.isRequired() : null);
} else {
Optional<AttributeModel> optional = getAttribute(event.getCatalogId(), eventAttribute.getName());
if (optional.isPresent()) {
eventAttributeModel = new EventAttributeModel();
- eventAttributeModel.setRequired(eventAttribute.isRequired());
+ if (eventAttribute != null) {
+ eventAttributeModel.setRequired(eventAttribute.isRequired());
+ }
eventAttributeModel.setEvent(model);
eventAttributeModel.setAttribute(optional.get());
eventAttributeModels.add(eventAttributeModel);
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java
index 5f01dcd..2edb385 100644
--- a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java
+++ b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/model/EventAttributeModel.java
@@ -51,7 +51,7 @@ public class EventAttributeModel implements Serializable {
@Column(name = "is_required")
@Convert(converter=BooleanToStringConverter.class)
- private boolean isRequired;
+ private Boolean isRequired;
/**
* Return the identifier for this event.
@@ -85,11 +85,11 @@ public class EventAttributeModel implements Serializable {
this.attribute = attribute;
}
- public boolean isRequired() {
+ public Boolean isRequired() {
return isRequired;
}
- public void setRequired(boolean required) {
+ public void setRequired(Boolean required) {
isRequired = required;
}
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-jpa/src/test/resources/sql/hsql/schema.sql
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-jpa/src/test/resources/sql/hsql/schema.sql b/log4j-catalog/log4j-catalog-jpa/src/test/resources/sql/hsql/schema.sql
index 1618e73..5deec7c 100644
--- a/log4j-catalog/log4j-catalog-jpa/src/test/resources/sql/hsql/schema.sql
+++ b/log4j-catalog/log4j-catalog-jpa/src/test/resources/sql/hsql/schema.sql
@@ -75,7 +75,7 @@ CREATE TABLE EVENT_ATTRIBUTES
ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
EVENT_ID BIGINT NOT NULL,
ATTRIBUTE_ID BIGINT NOT NULL,
- IS_REQUIRED CHAR NOT NULL,
+ IS_REQUIRED CHAR,
FOREIGN KEY (EVENT_ID) REFERENCES CATALOG_EVENT(ID),
FOREIGN KEY (ATTRIBUTE_ID) REFERENCES EVENT_ATTRIBUTE(ID)
);
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java b/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java
index 7836b41..1e1627a 100644
--- a/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java
+++ b/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.catalog.config;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -53,7 +54,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ResourceBundleMessageSource;
+import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -65,6 +68,11 @@ import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
+import org.thymeleaf.spring4.SpringTemplateEngine;
+import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
+import org.thymeleaf.spring4.view.ThymeleafView;
+import org.thymeleaf.spring4.view.ThymeleafViewResolver;
+import org.thymeleaf.templatemode.TemplateMode;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@@ -136,6 +144,7 @@ public class WebMvcAppContext extends WebMvcConfigurerAdapter implements Applica
return proxyCreator;
}
+ /*
@Bean
public ViewResolver internalResourceViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
@@ -144,7 +153,7 @@ public class WebMvcAppContext extends WebMvcConfigurerAdapter implements Applica
viewResolver.setSuffix(".jsp");
viewResolver.setOrder(10);
return viewResolver;
- }
+ } */
@Bean
public MessageSource messageSource() {
@@ -276,4 +285,52 @@ public class WebMvcAppContext extends WebMvcConfigurerAdapter implements Applica
}
return dataSource;
}
+
+ public SpringResourceTemplateResolver templateResolver(){
+ // SpringResourceTemplateResolver automatically integrates with Spring's own
+ // resource resolution infrastructure, which is highly recommended.
+ SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
+ templateResolver.setApplicationContext(this.applicationContext);
+ templateResolver.setPrefix("/WEB-INF/templates/");
+ templateResolver.setSuffix(".html");
+ // HTML is the default value, added here for the sake of clarity.
+ templateResolver.setTemplateMode(TemplateMode.HTML);
+ // Template cache is true by default. Set to false if you want
+ // templates to be automatically updated when modified.
+ templateResolver.setCacheable(true);
+ return templateResolver;
+ }
+
+ public SpringTemplateEngine templateEngine(){
+ // SpringTemplateEngine automatically applies SpringStandardDialect and
+ // enables Spring's own MessageSource message resolution mechanisms.
+ SpringTemplateEngine templateEngine = new SpringTemplateEngine();
+ templateEngine.setTemplateResolver(templateResolver());
+ // Enabling the SpringEL compiler with Spring 4.2.4 or newer can
+ // speed up execution in most scenarios, but might be incompatible
+ // with specific cases when expressions in one template are reused
+ // across different data types, so this flag is "false" by default
+ // for safer backwards compatibility.
+ templateEngine.setEnableSpringELCompiler(true);
+ return templateEngine;
+ }
+
+ @Bean
+ public ViewResolver thymeleafViewResolver(){
+ ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
+ viewResolver.setTemplateEngine(templateEngine());
+ // NOTE 'order' and 'viewNames' are optional
+ viewResolver.setOrder(1);
+ viewResolver.setViewNames(new String[] {"products", "categories", "events", "attributes"});
+ return viewResolver;
+ }
+
+ @Bean
+ @Scope("prototype")
+ public ThymeleafView mainView() {
+ ThymeleafView view = new ThymeleafView("index"); // templateName = 'main'
+ view.setStaticVariables(
+ Collections.singletonMap("footer", "The Apache Software Foundation"));
+ return view;
+ }
}
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java b/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java
index b3a5ade..0dd8295 100644
--- a/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java
+++ b/log4j-catalog/log4j-catalog-war/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java
@@ -116,6 +116,7 @@ public class EventController {
} catch (Exception ex) {
response.put("Result", "FAILURE");
response.put("Message", ex.getMessage());
+ LOGGER.warn("Unable to create event named {}", event.getName(), ex);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
@@ -131,6 +132,7 @@ public class EventController {
} catch (Exception ex) {
response.put("Result", "FAILURE");
response.put("Message", ex.getMessage());
+ LOGGER.warn("Unable to update event named {}", event.getName(), ex);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/6cf96b62/log4j-catalog/log4j-catalog-war/src/main/resources/sql/hsql/schema.sql
----------------------------------------------------------------------
diff --git a/log4j-catalog/log4j-catalog-war/src/main/resources/sql/hsql/schema.sql b/log4j-catalog/log4j-catalog-war/src/main/resources/sql/hsql/schema.sql
index 8525361..772d65b 100644
--- a/log4j-catalog/log4j-catalog-war/src/main/resources/sql/hsql/schema.sql
+++ b/log4j-catalog/log4j-catalog-war/src/main/resources/sql/hsql/schema.sql
@@ -75,7 +75,7 @@ CREATE TABLE EVENT_ATTRIBUTES
ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
EVENT_ID BIGINT NOT NULL,
ATTRIBUTE_ID BIGINT NOT NULL,
- IS_REQUIRED CHAR NOT NULL,
+ IS_REQUIRED CHAR,
FOREIGN KEY (EVENT_ID) REFERENCES CATALOG_EVENT(ID),
FOREIGN KEY (ATTRIBUTE_ID) REFERENCES EVENT_ATTRIBUTE(ID)
);