Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes - Honor Doc Version in SwaggerController and Use ISO8601Dates S…
Browse files Browse the repository at this point in the history
…erde Format in Date Formatting (#1336)

* misc_fixes

* review comments

* Review Comments

* DyFixes

* DyFixes
moizarafat authored Jun 4, 2020
1 parent 46f83b0 commit 2853ad4
Showing 10 changed files with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ public synchronized static AsyncExecutorService getInstance() {
* Execute Query asynchronously.
* @param queryObj Query Object
* @param user User
* @param apiVersion api version
*/
public void executeQuery(AsyncQuery queryObj, User user, String apiVersion) {
QueryRunner runner = runners.get(apiVersion);
Original file line number Diff line number Diff line change
@@ -13,11 +13,20 @@
import static org.mockito.Mockito.verify;

import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettingsBuilder;
import com.yahoo.elide.async.models.AsyncQuery;
import com.yahoo.elide.async.models.QueryStatus;
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.core.datastore.inmemory.HashMapDataStore;
import com.yahoo.elide.security.checks.Check;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

public class AsyncQueryCleanerThreadTest {

private AsyncQueryCleanerThread cleanerThread;
@@ -26,7 +35,15 @@ public class AsyncQueryCleanerThreadTest {

@BeforeEach
public void setupMocks() {
elide = mock(Elide.class);
HashMapDataStore inMemoryStore = new HashMapDataStore(AsyncQuery.class.getPackage());
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();

elide = new Elide(
new ElideSettingsBuilder(inMemoryStore)
.withEntityDictionary(new EntityDictionary(checkMappings))
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
.build());

asyncQueryDao = mock(DefaultAsyncQueryDAO.class);
cleanerThread = new AsyncQueryCleanerThread(7, elide, 7, asyncQueryDao);
}
16 changes: 4 additions & 12 deletions elide-contrib/elide-dynamic-config-helpers/pom.xml
Original file line number Diff line number Diff line change
@@ -153,19 +153,11 @@
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
import static com.yahoo.elide.annotation.LifeCycleHookBinding.TransactionPhase.PRESECURITY;

import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettings;
import com.yahoo.elide.ElideSettingsBuilder;
import com.yahoo.elide.async.hooks.ExecuteQueryHook;
import com.yahoo.elide.async.hooks.UpdatePrincipalNameHook;
import com.yahoo.elide.async.models.AsyncQuery;
@@ -27,6 +29,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.TimeZone;

/**
* Async Configuration For Elide Services. Override any of the beans (by defining your own)
* and setting flags to disable in properties to change the default behavior.
@@ -88,6 +92,13 @@ public AsyncCleanerService buildAsyncCleanerService(Elide elide, ElideConfigProp
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "elide.async", name = "defaultAsyncQueryDAO", matchIfMissing = true)
public AsyncQueryDAO buildAsyncQueryDAO(Elide elide) {
return new DefaultAsyncQueryDAO(elide, elide.getDataStore());
// Creating a new ElideSettings and Elide object for Async services
// which will have ISO8601 Dates. Used for DefaultAsyncQueryDAO.
ElideSettings asyncElideSettings = new ElideSettingsBuilder(elide.getDataStore())
.withEntityDictionary(elide.getElideSettings().getDictionary())
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
.build();
Elide asyncElide = new Elide(asyncElideSettings);
return new DefaultAsyncQueryDAO(asyncElide, asyncElide.getDataStore());
}
}
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ public GraphqlController(Elide elide) {
/**
* Single entry point for GraphQL requests.
*
* @param requestHeaders request headers
* @param graphQLDocument post data as json document
* @param principal The user principal
* @return response
Original file line number Diff line number Diff line change
@@ -77,8 +77,10 @@ public SwaggerController(List<SwaggerRegistration> docs) {
public SwaggerController(Swagger doc) {
log.debug("Started ~~");
documents = new HashMap<>();
String apiVersion = doc.getInfo().getVersion();
apiVersion = apiVersion == null ? NO_VERSION : apiVersion;

documents.put(Pair.of(NO_VERSION, ""), SwaggerBuilder.getDocument(doc));
documents.put(Pair.of(apiVersion, ""), SwaggerBuilder.getDocument(doc));
}

@GetMapping(value = {"/", ""}, produces = JSON_CONTENT_TYPE)
@@ -111,6 +113,7 @@ public ResponseEntity<String> call() throws Exception {
/**
* Read handler.
*
* @param requestHeaders request headers
* @param name document name
* @return response The Swagger JSON document
*/
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
/**
* Models Package V2.
*/
@ApiVersion(version = "1.0")
package example.models.jpa.v2;

Original file line number Diff line number Diff line change
@@ -363,7 +363,8 @@ public void swaggerDocumentTest() {
.statusCode(HttpStatus.SC_OK)
.body("tags.name", containsInAnyOrder("group", "functionArgument", "metric",
"metricFunction", "dimension", "column", "table", "asyncQuery", "asyncQueryResult",
"timeDimensionGrain", "timeDimension"));
"timeDimensionGrain", "timeDimension", "product", "playerCountry", "version", "playerStats",
"stats"));
}

@Test
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ elide:
swagger:
path: /doc
enabled: true
version: "1.0"
async:
enabled: true
threadPoolSize: 7
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettings;
import com.yahoo.elide.ElideSettingsBuilder;
import com.yahoo.elide.async.hooks.ExecuteQueryHook;
import com.yahoo.elide.async.hooks.UpdatePrincipalNameHook;
import com.yahoo.elide.async.models.AsyncQuery;
@@ -39,6 +40,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.function.Consumer;
import javax.inject.Inject;
import javax.persistence.EntityManagerFactory;
@@ -113,9 +115,18 @@ protected void configure() {

// Binding async service
if (settings.enableAsync()) {
// Creating a new ElideSettings and Elide object for Async services
// which will have ISO8601 Dates. Used for DefaultAsyncQueryDAO.
ElideSettings asyncElideSettings = new ElideSettingsBuilder(elideSettings.getDataStore())
.withEntityDictionary(elideSettings.getDictionary())
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
.build();

Elide asyncElide = new Elide(asyncElideSettings);

AsyncQueryDAO asyncQueryDao = settings.getAsyncQueryDAO();
if (asyncQueryDao == null) {
asyncQueryDao = new DefaultAsyncQueryDAO(elide, elide.getDataStore());
asyncQueryDao = new DefaultAsyncQueryDAO(asyncElide, asyncElide.getDataStore());
}
bind(asyncQueryDao).to(AsyncQueryDAO.class);

0 comments on commit 2853ad4

Please sign in to comment.