Skip to content

Commit c4cc1b9

Browse files
moizarafatAaron Klish
authored andcommitted
Fixes - Honor Doc Version in SwaggerController and Use ISO8601Dates Serde Format in Date Formatting (#1336)
* misc_fixes * review comments * Review Comments * DyFixes * DyFixes
1 parent 40e5bad commit c4cc1b9

10 files changed

Lines changed: 57 additions & 18 deletions

File tree

elide-async/src/main/java/com/yahoo/elide/async/service/AsyncExecutorService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public synchronized static AsyncExecutorService getInstance() {
8585
* Execute Query asynchronously.
8686
* @param queryObj Query Object
8787
* @param user User
88+
* @param apiVersion api version
8889
*/
8990
public void executeQuery(AsyncQuery queryObj, User user, String apiVersion) {
9091
QueryRunner runner = runners.get(apiVersion);

elide-async/src/test/java/com/yahoo/elide/async/service/AsyncQueryCleanerThreadTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313
import static org.mockito.Mockito.verify;
1414

1515
import com.yahoo.elide.Elide;
16+
import com.yahoo.elide.ElideSettingsBuilder;
17+
import com.yahoo.elide.async.models.AsyncQuery;
1618
import com.yahoo.elide.async.models.QueryStatus;
19+
import com.yahoo.elide.core.EntityDictionary;
20+
import com.yahoo.elide.core.datastore.inmemory.HashMapDataStore;
21+
import com.yahoo.elide.security.checks.Check;
1722

1823
import org.junit.jupiter.api.BeforeEach;
1924
import org.junit.jupiter.api.Test;
2025

26+
import java.util.HashMap;
27+
import java.util.Map;
28+
import java.util.TimeZone;
29+
2130
public class AsyncQueryCleanerThreadTest {
2231

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

2736
@BeforeEach
2837
public void setupMocks() {
29-
elide = mock(Elide.class);
38+
HashMapDataStore inMemoryStore = new HashMapDataStore(AsyncQuery.class.getPackage());
39+
Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
40+
41+
elide = new Elide(
42+
new ElideSettingsBuilder(inMemoryStore)
43+
.withEntityDictionary(new EntityDictionary(checkMappings))
44+
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
45+
.build());
46+
3047
asyncQueryDao = mock(DefaultAsyncQueryDAO.class);
3148
cleanerThread = new AsyncQueryCleanerThread(7, elide, 7, asyncQueryDao);
3249
}

elide-contrib/elide-dynamic-config-helpers/pom.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,11 @@
153153
<artifactId>maven-checkstyle-plugin</artifactId>
154154
</plugin>
155155
<plugin>
156-
<artifactId>maven-assembly-plugin</artifactId>
157-
<executions>
158-
<execution>
159-
<phase>package</phase>
160-
<goals>
161-
<goal>single</goal>
162-
</goals>
163-
</execution>
164-
</executions>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-compiler-plugin</artifactId>
165158
<configuration>
166-
<descriptorRefs>
167-
<descriptorRef>jar-with-dependencies</descriptorRef>
168-
</descriptorRefs>
159+
<source>1.8</source>
160+
<target>1.8</target>
169161
</configuration>
170162
</plugin>
171163
</plugins>

elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/config/ElideAsyncConfiguration.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import static com.yahoo.elide.annotation.LifeCycleHookBinding.TransactionPhase.PRESECURITY;
1111

1212
import com.yahoo.elide.Elide;
13+
import com.yahoo.elide.ElideSettings;
14+
import com.yahoo.elide.ElideSettingsBuilder;
1315
import com.yahoo.elide.async.hooks.ExecuteQueryHook;
1416
import com.yahoo.elide.async.hooks.UpdatePrincipalNameHook;
1517
import com.yahoo.elide.async.models.AsyncQuery;
@@ -27,6 +29,8 @@
2729
import org.springframework.context.annotation.Bean;
2830
import org.springframework.context.annotation.Configuration;
2931

32+
import java.util.TimeZone;
33+
3034
/**
3135
* Async Configuration For Elide Services. Override any of the beans (by defining your own)
3236
* and setting flags to disable in properties to change the default behavior.
@@ -88,6 +92,13 @@ public AsyncCleanerService buildAsyncCleanerService(Elide elide, ElideConfigProp
8892
@ConditionalOnMissingBean
8993
@ConditionalOnProperty(prefix = "elide.async", name = "defaultAsyncQueryDAO", matchIfMissing = true)
9094
public AsyncQueryDAO buildAsyncQueryDAO(Elide elide) {
91-
return new DefaultAsyncQueryDAO(elide, elide.getDataStore());
95+
// Creating a new ElideSettings and Elide object for Async services
96+
// which will have ISO8601 Dates. Used for DefaultAsyncQueryDAO.
97+
ElideSettings asyncElideSettings = new ElideSettingsBuilder(elide.getDataStore())
98+
.withEntityDictionary(elide.getElideSettings().getDictionary())
99+
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
100+
.build();
101+
Elide asyncElide = new Elide(asyncElideSettings);
102+
return new DefaultAsyncQueryDAO(asyncElide, asyncElide.getDataStore());
92103
}
93104
}

elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/controllers/GraphqlController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public GraphqlController(Elide elide) {
6262
/**
6363
* Single entry point for GraphQL requests.
6464
*
65+
* @param requestHeaders request headers
6566
* @param graphQLDocument post data as json document
6667
* @param principal The user principal
6768
* @return response

elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/controllers/SwaggerController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ public SwaggerController(List<SwaggerRegistration> docs) {
7777
public SwaggerController(Swagger doc) {
7878
log.debug("Started ~~");
7979
documents = new HashMap<>();
80+
String apiVersion = doc.getInfo().getVersion();
81+
apiVersion = apiVersion == null ? NO_VERSION : apiVersion;
8082

81-
documents.put(Pair.of(NO_VERSION, ""), SwaggerBuilder.getDocument(doc));
83+
documents.put(Pair.of(apiVersion, ""), SwaggerBuilder.getDocument(doc));
8284
}
8385

8486
@GetMapping(value = {"/", ""}, produces = JSON_CONTENT_TYPE)
@@ -111,6 +113,7 @@ public ResponseEntity<String> call() throws Exception {
111113
/**
112114
* Read handler.
113115
*
116+
* @param requestHeaders request headers
114117
* @param name document name
115118
* @return response The Swagger JSON document
116119
*/

elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/models/jpa/v2/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Licensed under the Apache License, Version 2.0
44
* See LICENSE file in project root for terms.
55
*/
6+
/**
7+
* Models Package V2.
8+
*/
69
@ApiVersion(version = "1.0")
710
package example.models.jpa.v2;
811

elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/ControllerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ public void swaggerDocumentTest() {
363363
.statusCode(HttpStatus.SC_OK)
364364
.body("tags.name", containsInAnyOrder("group", "functionArgument", "metric",
365365
"metricFunction", "dimension", "column", "table", "asyncQuery", "asyncQueryResult",
366-
"timeDimensionGrain", "timeDimension"));
366+
"timeDimensionGrain", "timeDimension", "product", "playerCountry", "version", "playerStats",
367+
"stats"));
367368
}
368369

369370
@Test

elide-spring/elide-spring-boot-autoconfigure/src/test/resources/application.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ elide:
1212
swagger:
1313
path: /doc
1414
enabled: true
15-
version: "1.0"
1615
async:
1716
enabled: true
1817
threadPoolSize: 7

elide-standalone/src/main/java/com/yahoo/elide/standalone/config/ElideResourceConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.yahoo.elide.Elide;
1313
import com.yahoo.elide.ElideSettings;
14+
import com.yahoo.elide.ElideSettingsBuilder;
1415
import com.yahoo.elide.async.hooks.ExecuteQueryHook;
1516
import com.yahoo.elide.async.hooks.UpdatePrincipalNameHook;
1617
import com.yahoo.elide.async.models.AsyncQuery;
@@ -39,6 +40,7 @@
3940
import java.util.List;
4041
import java.util.Optional;
4142
import java.util.Set;
43+
import java.util.TimeZone;
4244
import java.util.function.Consumer;
4345
import javax.inject.Inject;
4446
import javax.persistence.EntityManagerFactory;
@@ -113,9 +115,18 @@ protected void configure() {
113115

114116
// Binding async service
115117
if (settings.enableAsync()) {
118+
// Creating a new ElideSettings and Elide object for Async services
119+
// which will have ISO8601 Dates. Used for DefaultAsyncQueryDAO.
120+
ElideSettings asyncElideSettings = new ElideSettingsBuilder(elideSettings.getDataStore())
121+
.withEntityDictionary(elideSettings.getDictionary())
122+
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
123+
.build();
124+
125+
Elide asyncElide = new Elide(asyncElideSettings);
126+
116127
AsyncQueryDAO asyncQueryDao = settings.getAsyncQueryDAO();
117128
if (asyncQueryDao == null) {
118-
asyncQueryDao = new DefaultAsyncQueryDAO(elide, elide.getDataStore());
129+
asyncQueryDao = new DefaultAsyncQueryDAO(asyncElide, asyncElide.getDataStore());
119130
}
120131
bind(asyncQueryDao).to(AsyncQueryDAO.class);
121132

0 commit comments

Comments
 (0)