Skip to content

Commit

Permalink
Expose audit logger in standalone (#1075)
Browse files Browse the repository at this point in the history
* Expose audit logger in standalone

* Update test

* Increase coverage
  • Loading branch information
patelh authored and aklish committed Nov 16, 2019
1 parent 1625319 commit cba356a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.yahoo.elide.ElideSettings;
import com.yahoo.elide.ElideSettingsBuilder;

import com.yahoo.elide.audit.AuditLogger;
import com.yahoo.elide.audit.Slf4jLogger;
import com.yahoo.elide.core.DataStore;
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.core.filter.dialect.RSQLFilterDialect;
Expand Down Expand Up @@ -72,7 +74,8 @@ default ElideSettings getElideSettings(ServiceLocator injector) {
.withUseFilterExpressions(true)
.withEntityDictionary(dictionary)
.withJoinFilterDialect(new RSQLFilterDialect(dictionary))
.withSubqueryFilterDialect(new RSQLFilterDialect(dictionary));
.withSubqueryFilterDialect(new RSQLFilterDialect(dictionary))
.withAuditLogger(getAuditLogger());

if (enableIS06081Dates()) {
builder = builder.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"));
Expand Down Expand Up @@ -229,4 +232,13 @@ default Properties getDatabaseProperties() {
default void updateServletContextHandler(ServletContextHandler servletContextHandler) {
// Do nothing
}

/**
* Gets the audit logger for elide
*
* @return Default: Slf4jLogger
*/
default AuditLogger getAuditLogger() {
return new Slf4jLogger();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public void init() throws Exception {
elide = new ElideStandalone(new ElideStandaloneSettings() {

@Override
public ElideSettings getElideSettings(ServiceLocator injector) {
EntityDictionary dictionary = new EntityDictionary(getCheckMappings());

public Properties getDatabaseProperties() {
Properties options = new Properties();

options.put("hibernate.show_sql", "true");
Expand All @@ -63,21 +61,12 @@ public ElideSettings getElideSettings(ServiceLocator injector) {
options.put("javax.persistence.jdbc.url", "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE;");
options.put("javax.persistence.jdbc.user", "sa");
options.put("javax.persistence.jdbc.password", "");
return options;
}

EntityManagerFactory entityManagerFactory = Util.getEntityManagerFactory(Post.class.getPackage().getName(), options);
DataStore dataStore = new JpaDataStore(
() -> { return entityManagerFactory.createEntityManager(); },
(em -> { return new NonJtaTransaction(em); }));

dataStore.populateEntityDictionary(dictionary);

ElideSettingsBuilder builder = new ElideSettingsBuilder(dataStore)
.withUseFilterExpressions(true)
.withEntityDictionary(dictionary)
.withJoinFilterDialect(new RSQLFilterDialect(dictionary))
.withSubqueryFilterDialect(new RSQLFilterDialect(dictionary));

return builder.build();
@Override
public String getModelPackageName() {
return Post.class.getPackage().getName();
}

@Override
Expand Down Expand Up @@ -115,7 +104,7 @@ public void testJsonAPIPost() {
" \"id\": \"1\",\n" +
" \"attributes\": {\n" +
" \"content\": \"This is my first post. woot.\",\n" +
" \"date\" : \"0\"\n" +
" \"date\" : \"2019-01-01T00:00Z\"\n" +
" }\n" +
" }\n" +
" }")
Expand Down

0 comments on commit cba356a

Please sign in to comment.