From e2005d6babde1a0da3ba66fc507fc6ecf5773052 Mon Sep 17 00:00:00 2001 From: William Cekan Date: Mon, 22 Feb 2021 11:34:54 -0500 Subject: [PATCH] Cleanup unnecessary syntax (#1854) * Cleanup unnecessary syntax * cleanup unnecessary else if * use filter Co-authored-by: wcekan Co-authored-by: Aaron Klish --- .../yahoo/elide/async/hooks/AsyncAPIHook.java | 6 +- .../async/service/dao/DefaultAsyncAPIDAO.java | 4 +- .../FileResultStorageEngine.java | 48 +++++------ .../thread/AsyncAPICancelRunnable.java | 7 +- .../main/java/com/yahoo/elide/core/Path.java | 8 +- .../yahoo/elide/core/PersistentResource.java | 2 +- .../com/yahoo/elide/core/RequestScope.java | 9 +- .../inmemory/InMemoryStoreTransaction.java | 15 ++-- .../elide/core/dictionary/EntityBinding.java | 3 +- .../core/dictionary/EntityDictionary.java | 9 +- .../com/yahoo/elide/core/filter/Operator.java | 25 +++--- .../filter/dialect/RSQLFilterDialect.java | 19 +++-- .../expression/AndFilterExpression.java | 3 +- .../filter/expression/OrFilterExpression.java | 3 +- .../filter/predicates/FilterPredicate.java | 4 +- .../core/security/checks/prefab/Common.java | 3 +- .../executors/ActivePermissionExecutor.java | 26 +++--- .../PermissionToFilterExpressionVisitor.java | 6 +- .../yahoo/elide/core/utils/ClassScanner.java | 2 +- .../elide/core/utils/coerce/CoerceUtil.java | 6 +- .../converters/EpochToDateConverter.java | 12 +-- .../coerce/converters/ISO8601DateSerde.java | 9 +- .../coerce/converters/ToEnumConverter.java | 6 +- .../elide/jsonapi/EntityProjectionMaker.java | 11 +-- .../jsonapi/serialization/KeySerializer.java | 3 +- .../yahoo/elide/core/TestRequestScope.java | 3 +- .../core/dictionary/EntityDictionaryTest.java | 8 +- ...rmissionToFilterExpressionVisitorTest.java | 3 +- .../visitor/MatchesTemplateVisitor.java | 25 +++--- .../visitor/SplitFilterExpressionVisitor.java | 43 +++++----- .../aggregation/metadata/models/Column.java | 22 ++--- .../aggregation/metadata/models/Table.java | 6 +- .../query/ImmutablePagination.java | 6 +- .../sql/dialects/SQLDialectFactory.java | 30 ++++--- .../sql/metadata/SQLReferenceTable.java | 6 +- .../queryengines/sql/metadata/SQLTable.java | 2 +- .../AggregationDataStoreTestHarness.java | 5 +- .../aggregation/framework/SQLUnitTest.java | 83 ++++++++++--------- .../timegrains/serde/DaySerdeTest.java | 6 +- .../timegrains/serde/HourSerdeTest.java | 6 +- .../timegrains/serde/ISOWeekSerdeTest.java | 12 +-- .../timegrains/serde/MinuteSerdeTest.java | 6 +- .../timegrains/serde/MonthSerdeTest.java | 6 +- .../timegrains/serde/QuarterSerdeTest.java | 12 +-- .../timegrains/serde/SecondSerdeTest.java | 6 +- .../timegrains/serde/TimeSerdeTest.java | 6 +- .../timegrains/serde/WeekSerdeTest.java | 12 +-- .../timegrains/serde/YearSerdeTest.java | 6 +- .../hibernate5/AbstractHibernateStore.java | 3 +- .../datastores/jpa/JpaDataStoreHarness.java | 6 +- .../datastores/jpa/JpaDataStoreTest.java | 4 +- .../search/SearchDataTransaction.java | 5 +- .../datastores/search/DependencyBinder.java | 5 +- .../yahoo/elide/graphql/GraphQLScalars.java | 3 +- .../graphql/PersistentResourceFetcher.java | 13 ++- .../parser/GraphQLEntityProjectionMaker.java | 1 - .../graphql/parser/VariableResolver.java | 29 ++++--- .../validator/DynamicConfigValidator.java | 16 +--- .../spring/config/ElideAutoConfiguration.java | 7 +- .../config/ElideStandaloneSettings.java | 10 +-- .../yahoo/elide/swagger/SwaggerBuilder.java | 22 ++--- 61 files changed, 340 insertions(+), 353 deletions(-) diff --git a/elide-async/src/main/java/com/yahoo/elide/async/hooks/AsyncAPIHook.java b/elide-async/src/main/java/com/yahoo/elide/async/hooks/AsyncAPIHook.java index 0cde121060..d28ad0e3d7 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/hooks/AsyncAPIHook.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/hooks/AsyncAPIHook.java @@ -66,11 +66,13 @@ protected void executeHook(LifeCycleHookBinding.Operation operation, LifeCycleHo //ReadPreSecurityHook - Those hooks get evaluated in line with the request processing. executeAsync(query, queryWorker); return; - } else if (operation.equals(CREATE)) { + } + if (operation.equals(CREATE)) { if (phase.equals(POSTCOMMIT)) { completeAsync(query, requestScope); return; - } else if (phase.equals(PRESECURITY)) { + } + if (phase.equals(PRESECURITY)) { updatePrincipalName(query, requestScope); return; } diff --git a/elide-async/src/main/java/com/yahoo/elide/async/service/dao/DefaultAsyncAPIDAO.java b/elide-async/src/main/java/com/yahoo/elide/async/service/dao/DefaultAsyncAPIDAO.java index 9af244e08f..1b4b5462de 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/service/dao/DefaultAsyncAPIDAO.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/service/dao/DefaultAsyncAPIDAO.java @@ -66,9 +66,7 @@ public T updateStatus(String asyncAPIId, QueryStatus status @Override public Iterable updateStatusAsyncAPIByFilter(FilterExpression filterExpression, QueryStatus status, Class type) { - return updateAsyncAPIIterable(filterExpression, (asyncAPI) -> { - asyncAPI.setStatus(status); - }, type); + return updateAsyncAPIIterable(filterExpression, asyncAPI -> asyncAPI.setStatus(status), type); } /** diff --git a/elide-async/src/main/java/com/yahoo/elide/async/service/storageengine/FileResultStorageEngine.java b/elide-async/src/main/java/com/yahoo/elide/async/service/storageengine/FileResultStorageEngine.java index 67523516ba..a23b9d3e72 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/service/storageengine/FileResultStorageEngine.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/service/storageengine/FileResultStorageEngine.java @@ -54,9 +54,8 @@ public TableExport storeResults(TableExport tableExport, Observable resu throwable -> { throw new IllegalStateException(STORE_ERROR, throwable); }, - () -> { - writer.flush(); - } + () -> + writer.flush() ); } catch (IOException e) { throw new IllegalStateException(STORE_ERROR, e); @@ -71,31 +70,28 @@ public Observable getResultsByID(String asyncQueryID) { return Observable.using( () -> getReader(asyncQueryID), - reader -> { - return Observable.fromIterable(() -> { - return new Iterator() { - private String record = null; + reader -> Observable.fromIterable(() -> new Iterator() { + private String record = null; - @Override - public boolean hasNext() { - try { - record = reader.readLine(); - return record != null; - } catch (IOException e) { - throw new IllegalStateException(RETRIEVE_ERROR, e); - } - } + @Override + public boolean hasNext() { + try { + record = reader.readLine(); + return record != null; + } catch (IOException e) { + throw new IllegalStateException(RETRIEVE_ERROR, e); + } + } - @Override - public String next() { - if (record != null) { - return record; - } - throw new IllegalStateException("null line found."); - } - }; - }); - }, BufferedReader::close); + @Override + public String next() { + if (record != null) { + return record; + } + throw new IllegalStateException("null line found."); + } + }), + BufferedReader::close); } private BufferedReader getReader(String asyncQueryID) { diff --git a/elide-async/src/main/java/com/yahoo/elide/async/service/thread/AsyncAPICancelRunnable.java b/elide-async/src/main/java/com/yahoo/elide/async/service/thread/AsyncAPICancelRunnable.java index 5d1e3abb55..ec760f83f1 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/service/thread/AsyncAPICancelRunnable.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/service/thread/AsyncAPICancelRunnable.java @@ -89,12 +89,11 @@ protected void cancelAsyncAPI(Class type) { //AsyncAPI IDs that need to be cancelled Set queryIDsToCancel = queryUUIDsToCancel.stream() - .map(uuid -> { - return StreamSupport.stream(asyncAPIIterable.spliterator(), false) + .map(uuid -> StreamSupport + .stream(asyncAPIIterable.spliterator(), false) .filter(query -> query.getRequestId().equals(uuid.toString())) .map(T::getId) - .findFirst().orElseThrow(IllegalStateException::new); - }) + .findFirst().orElseThrow(IllegalStateException::new)) .collect(Collectors.toSet()); //Cancel Transactions diff --git a/elide-core/src/main/java/com/yahoo/elide/core/Path.java b/elide-core/src/main/java/com/yahoo/elide/core/Path.java index 8dbe676e8d..6f847dc3c0 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/Path.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/Path.java @@ -130,12 +130,12 @@ private PathElement resolvePathAttribute(Type entityClass, || fieldName.equals(dictionary.getIdFieldName(entityClass))) { Type attributeClass = dictionary.getType(entityClass, fieldName); return new PathElement(entityClass, attributeClass, fieldName, alias, arguments); - } else if ("this".equals(fieldName)) { + } + if ("this".equals(fieldName)) { return new PathElement(entityClass, null, fieldName); - } else { - String entityAlias = dictionary.getJsonAliasFor(entityClass); - throw new InvalidValueException(entityAlias + " does not contain the field " + fieldName); } + String entityAlias = dictionary.getJsonAliasFor(entityClass); + throw new InvalidValueException(entityAlias + " does not contain the field " + fieldName); } /** diff --git a/elide-core/src/main/java/com/yahoo/elide/core/PersistentResource.java b/elide-core/src/main/java/com/yahoo/elide/core/PersistentResource.java index 5f32d1e63b..25024f344b 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/PersistentResource.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/PersistentResource.java @@ -1331,7 +1331,7 @@ public Resource toResource() { * @return The Resource */ public Resource toResource(EntityProjection projection) { - return toResource(() -> { return getRelationships(projection); }, this::getAttributes); + return toResource(() -> getRelationships(projection), this::getAttributes); } /** diff --git a/elide-core/src/main/java/com/yahoo/elide/core/RequestScope.java b/elide-core/src/main/java/com/yahoo/elide/core/RequestScope.java index 204ee29a39..92828b2500 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/RequestScope.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/RequestScope.java @@ -322,10 +322,8 @@ private static MultivaluedMap getFilterParams(MultivaluedMap entry.getKey().startsWith("filter")) - .forEach((entry) -> { - returnMap.put(entry.getKey(), entry.getValue()); - }); + .filter(entry -> entry.getKey().startsWith("filter")) + .forEach(entry -> returnMap.put(entry.getKey(), entry.getValue())); return returnMap; } @@ -506,8 +504,7 @@ private void registerPreSecurityObservers() { public String getRequestHeaderByName(String headerName) { if (this.requestHeaders.get(headerName) == null) { return null; - } else { - return this.requestHeaders.get(headerName).get(0); } + return this.requestHeaders.get(headerName).get(0); } } diff --git a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransaction.java b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransaction.java index 630e5120f4..8aa8df1201 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransaction.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/InMemoryStoreTransaction.java @@ -47,15 +47,17 @@ public class InMemoryStoreTransaction implements DataStoreTransaction { private static final Comparator NULL_SAFE_COMPARE = (a, b) -> { if (a == null && b == null) { return 0; - } else if (a == null) { + } + if (a == null) { return -1; - } else if (b == null) { + } + if (b == null) { return 1; - } else if (a instanceof Comparable) { + } + if (a instanceof Comparable) { return ((Comparable) a).compareTo(b); - } else { - throw new IllegalStateException("Trying to comparing non-comparable types!"); } + throw new IllegalStateException("Trying to comparing non-comparable types!"); }; /** @@ -113,9 +115,8 @@ public Object loadObject(EntityProjection projection, if (projection.getFilterExpression() == null || tx.supportsFiltering(scope, Optional.empty(), projection) == FeatureSupport.FULL) { return tx.loadObject(projection, id, scope); - } else { - return DataStoreTransaction.super.loadObject(projection, id, scope); } + return DataStoreTransaction.super.loadObject(projection, id, scope); } @Override diff --git a/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityBinding.java b/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityBinding.java index 2afc1a2ea0..e2fae9685f 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityBinding.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityBinding.java @@ -514,9 +514,8 @@ public static Type getFieldType(Type parentClass, Type type; if (fieldOrMethod instanceof Field) { return ((Field) fieldOrMethod).getParameterizedType(parentClass, index); - } else { - return ((Method) fieldOrMethod).getParameterizedReturnType(parentClass, index); } + return ((Method) fieldOrMethod).getParameterizedReturnType(parentClass, index); } private void bindTriggerIfPresent(AccessibleObject fieldOrMethod) { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityDictionary.java b/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityDictionary.java index 214a0a8887..0b2367ba97 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityDictionary.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/dictionary/EntityDictionary.java @@ -1832,12 +1832,10 @@ public String getAnnotatedColumnName(Type cls, String fieldName) { if (column == null || column.length == 0) { if (joinColumn == null || joinColumn.length == 0) { return fieldName; - } else { - return joinColumn[0].name(); } - } else { - return column[0].name(); + return joinColumn[0].name(); } + return column[0].name(); } /** @@ -1870,9 +1868,8 @@ public static String getEntityName(Type modelClass) { Entity entity = (Entity) getFirstAnnotation(declaringClass, Arrays.asList(Entity.class)); if (entity == null || "".equals(entity.name())) { return StringUtils.uncapitalize(declaringClass.getSimpleName()); - } else { - return entity.name(); } + return entity.name(); } public static Type getType(T object) { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/filter/Operator.java b/elide-core/src/main/java/com/yahoo/elide/core/filter/Operator.java index 25c072a68e..70bfce1a54 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/filter/Operator.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/filter/Operator.java @@ -444,11 +444,10 @@ private static Predicate getComparator(Path fieldPath, List value if (fieldVal instanceof Collection) { return ((Collection) fieldVal).stream() - .anyMatch((fieldValueElement) -> { - return fieldValueElement != null - && values.stream() - .anyMatch(testVal -> condition.test(compare(fieldValueElement, testVal))); - }); + .anyMatch(fieldValueElement -> + fieldValueElement != null + && values.stream() + .anyMatch(testVal -> condition.test(compare(fieldValueElement, testVal)))); } return fieldVal != null @@ -474,16 +473,14 @@ private static boolean evaluate(Object entity, Path fieldPath, List valu if (leftHandSide instanceof Collection && !valueClass.isAssignableFrom(COLLECTION_TYPE)) { return ((Collection) leftHandSide).stream() - .anyMatch((leftHandSideElement) -> { - return values.stream() - .map(value -> CoerceUtil.coerce(value, valueClass)) - .anyMatch(value -> predicate.test(leftHandSideElement, value)); - }); - } else { - return leftHandSide != null && values.stream() - .map(value -> CoerceUtil.coerce(value, valueClass)) - .anyMatch(value -> predicate.test(leftHandSide, value)); + .anyMatch(leftHandSideElement -> + values.stream() + .map(value -> CoerceUtil.coerce(value, valueClass)) + .anyMatch(value -> predicate.test(leftHandSideElement, value))); } + return leftHandSide != null && values.stream() + .map(value -> CoerceUtil.coerce(value, valueClass)) + .anyMatch(value -> predicate.test(leftHandSide, value)); } public Operator negate() { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/filter/dialect/RSQLFilterDialect.java b/elide-core/src/main/java/com/yahoo/elide/core/filter/dialect/RSQLFilterDialect.java index 320f7d7405..bd8853479c 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/filter/dialect/RSQLFilterDialect.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/filter/dialect/RSQLFilterDialect.java @@ -294,9 +294,8 @@ private Path buildAttribute(Type rootEntityType, String attributeName) { if (attribute != null) { return new Path(rootEntityType, dictionary, attribute.getName(), attribute.getAlias(), attribute.getArguments()); - } else { - return buildPath(rootEntityType, attributeName); } + return buildPath(rootEntityType, attributeName); } private Path buildPath(Type rootEntityType, String selector) { @@ -435,13 +434,17 @@ public FilterExpression visit(ComparisonNode node, Type entityType) { .collect(Collectors.toList()); if (op.equals(RSQLOperators.EQUAL) || op.equals(RSQLOperators.IN)) { return equalityExpression(arguments.get(0), path, values, true); - } else if (op.equals(INI)) { + } + if (op.equals(INI)) { return equalityExpression(arguments.get(0), path, values, false); - } else if (op.equals(RSQLOperators.NOT_EQUAL) || op.equals(RSQLOperators.NOT_IN)) { + } + if (op.equals(RSQLOperators.NOT_EQUAL) || op.equals(RSQLOperators.NOT_IN)) { return new NotFilterExpression(equalityExpression(arguments.get(0), path, values, true)); - } else if (op.equals(NOT_INI)) { + } + if (op.equals(NOT_INI)) { return new NotFilterExpression(equalityExpression(arguments.get(0), path, values, false)); - } else if (OPERATOR_MAP.containsKey(op)) { + } + if (OPERATOR_MAP.containsKey(op)) { return new FilterPredicate(path, OPERATOR_MAP.get(op), values); } @@ -475,8 +478,8 @@ private FilterExpression equalityExpression(String argument, Path path, } Boolean isStringLike = path.lastElement() - .map(e -> e.getFieldType().isAssignableFrom(STRING_TYPE)) - .orElse(false); + .filter(e -> e.getFieldType().isAssignableFrom(STRING_TYPE)) + .isPresent(); if (isStringLike) { Operator op = caseSensitive ? caseSensitivityStrategy.mapOperator(Operator.IN) diff --git a/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/AndFilterExpression.java b/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/AndFilterExpression.java index 4c87ef7a42..503bfacb44 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/AndFilterExpression.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/AndFilterExpression.java @@ -37,7 +37,8 @@ public class AndFilterExpression implements FilterExpression { public static FilterExpression fromPair(FilterExpression left, FilterExpression right) { if (left != null && right != null) { return new AndFilterExpression(left, right); - } else if (left == null) { + } + if (left == null) { return right; } return left; diff --git a/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/OrFilterExpression.java b/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/OrFilterExpression.java index 90f5e628ef..a364e28f79 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/OrFilterExpression.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/filter/expression/OrFilterExpression.java @@ -38,7 +38,8 @@ public class OrFilterExpression implements FilterExpression { public static FilterExpression fromPair(FilterExpression left, FilterExpression right) { if (left != null && right != null) { return new OrFilterExpression(left, right); - } else if (left == null) { + } + if (left == null) { return right; } return left; diff --git a/elide-core/src/main/java/com/yahoo/elide/core/filter/predicates/FilterPredicate.java b/elide-core/src/main/java/com/yahoo/elide/core/filter/predicates/FilterPredicate.java index c13707bfcd..e71ceb3047 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/filter/predicates/FilterPredicate.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/filter/predicates/FilterPredicate.java @@ -61,11 +61,11 @@ public static boolean toManyInPathExceptLastPathElement(EntityDictionary diction public static boolean isLastPathElementAssignableFrom(EntityDictionary dictionary, Path path, Type clz) { return path.lastElement() - .map(last -> + .filter(last -> clz.isAssignableFrom( dictionary.getType(last.getType(), last.getFieldName()) )) - .orElse(false); + .isPresent(); } public FilterPredicate(PathElement pathElement, Operator op, List values) { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/security/checks/prefab/Common.java b/elide-core/src/main/java/com/yahoo/elide/core/security/checks/prefab/Common.java index 988cdcd050..55c5643373 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/security/checks/prefab/Common.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/security/checks/prefab/Common.java @@ -25,8 +25,7 @@ public class Common { public static class FieldSetToNull extends OperationCheck { @Override public boolean ok(T record, RequestScope requestScope, Optional changeSpec) { - return changeSpec.map((c) -> { return c.getModified() == null; }) - .orElse(false); + return changeSpec.filter(c -> c.getModified() == null).isPresent(); } } } diff --git a/elide-core/src/main/java/com/yahoo/elide/core/security/executors/ActivePermissionExecutor.java b/elide-core/src/main/java/com/yahoo/elide/core/security/executors/ActivePermissionExecutor.java index 237ecde330..cb6fc05c15 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/security/executors/ActivePermissionExecutor.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/security/executors/ActivePermissionExecutor.java @@ -165,13 +165,11 @@ public ExpressionResult checkSpecificFieldPermissions(Per ChangeSpec changeSpec, Class annotationClass, String field) { - Supplier expressionSupplier = () -> { - return expressionBuilder.buildSpecificFieldExpressions(resource, annotationClass, field, changeSpec); - }; + Supplier expressionSupplier = () -> + expressionBuilder.buildSpecificFieldExpressions(resource, annotationClass, field, changeSpec); - Function expressionExecutor = (expression) -> { - return executeExpressions(expression, annotationClass, Expression.EvaluationMode.INLINE_CHECKS_ONLY); - }; + Function expressionExecutor = expression -> + executeExpressions(expression, annotationClass, Expression.EvaluationMode.INLINE_CHECKS_ONLY); return checkPermissions( resource.getResourceType(), @@ -202,12 +200,12 @@ public ExpressionResult checkSpecificFieldPermissionsDefe ? CreatePermission.class : annotationClass; - Supplier expressionSupplier = () -> { - return expressionBuilder.buildSpecificFieldExpressions(resource, + Supplier expressionSupplier = () -> + expressionBuilder.buildSpecificFieldExpressions( + resource, expressionAnnotation, field, changeSpec); - }; Function expressionExecutor = (expression) -> { if (requestScope.getNewPersistentResources().contains(resource)) { @@ -234,12 +232,11 @@ public ExpressionResult checkSpecificFieldPermissionsDefe @Override public ExpressionResult checkUserPermissions(Type resourceClass, Class annotationClass) { - Supplier expressionSupplier = () -> { - return expressionBuilder.buildUserCheckAnyExpression( + Supplier expressionSupplier = () -> + expressionBuilder.buildUserCheckAnyExpression( resourceClass, annotationClass, requestScope); - }; return checkOnlyUserPermissions( resourceClass, @@ -499,13 +496,12 @@ public boolean isVerbose() { public ExpressionResult checkUserPermissions(Type resourceClass, Class annotationClass, String field) { - Supplier expressionSupplier = () -> { - return expressionBuilder.buildUserCheckFieldExpressions( + Supplier expressionSupplier = () -> + expressionBuilder.buildUserCheckFieldExpressions( resourceClass, requestScope, annotationClass, field); - }; return checkOnlyUserPermissions( resourceClass, diff --git a/elide-core/src/main/java/com/yahoo/elide/core/security/visitors/PermissionToFilterExpressionVisitor.java b/elide-core/src/main/java/com/yahoo/elide/core/security/visitors/PermissionToFilterExpressionVisitor.java index a411bb54b1..c396145bdf 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/security/visitors/PermissionToFilterExpressionVisitor.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/security/visitors/PermissionToFilterExpressionVisitor.java @@ -95,9 +95,11 @@ public FilterExpression visitNOT(ExpressionParser.NOTContext ctx) { FilterExpression expression = visit(ctx.expression()); if (Objects.equals(expression, TRUE_USER_CHECK_EXPRESSION)) { return FALSE_USER_CHECK_EXPRESSION; - } else if (Objects.equals(expression, FALSE_USER_CHECK_EXPRESSION)) { + } + if (Objects.equals(expression, FALSE_USER_CHECK_EXPRESSION)) { return TRUE_USER_CHECK_EXPRESSION; - } else if (Objects.equals(expression, NO_EVALUATION_EXPRESSION)) { + } + if (Objects.equals(expression, NO_EVALUATION_EXPRESSION)) { return NO_EVALUATION_EXPRESSION; } return new NotFilterExpression(expression); diff --git a/elide-core/src/main/java/com/yahoo/elide/core/utils/ClassScanner.java b/elide-core/src/main/java/com/yahoo/elide/core/utils/ClassScanner.java index 603d1f3b90..f5c52d7766 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/utils/ClassScanner.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/utils/ClassScanner.java @@ -75,7 +75,7 @@ static public Set> getAnnotatedClasses(List * @return The classes */ static public Set> getAnnotatedClasses(List> annotations) { - return getAnnotatedClasses(annotations, (clazz) -> { return true; }); + return getAnnotatedClasses(annotations, clazz -> true); } @SafeVarargs diff --git a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/CoerceUtil.java b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/CoerceUtil.java index 2fca5cd759..58dde6a070 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/CoerceUtil.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/CoerceUtil.java @@ -117,11 +117,11 @@ private static BeanUtilsBean setup() { public Converter lookup(Class sourceType, Class targetType) { if (targetType.isEnum()) { return TO_ENUM_CONVERTER; - } else if (Map.class.isAssignableFrom(sourceType)) { + } + if (Map.class.isAssignableFrom(sourceType)) { return FROM_MAP_CONVERTER; - } else { - return super.lookup(sourceType, targetType); } + return super.lookup(sourceType, targetType); } }); } diff --git a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/EpochToDateConverter.java b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/EpochToDateConverter.java index 5ee64d7646..e54c990646 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/EpochToDateConverter.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/EpochToDateConverter.java @@ -55,15 +55,17 @@ public Object serialize(T val) { private static T numberToDate(Class cls, Number epoch) throws ReflectiveOperationException { if (ClassUtils.isAssignable(cls, java.sql.Date.class)) { return cls.cast(new java.sql.Date(epoch.longValue())); - } else if (ClassUtils.isAssignable(cls, Timestamp.class)) { + } + if (ClassUtils.isAssignable(cls, Timestamp.class)) { return cls.cast(new Timestamp(epoch.longValue())); - } else if (ClassUtils.isAssignable(cls, Time.class)) { + } + if (ClassUtils.isAssignable(cls, Time.class)) { return cls.cast(new Time(epoch.longValue())); - } else if (ClassUtils.isAssignable(cls, Date.class)) { + } + if (ClassUtils.isAssignable(cls, Date.class)) { return cls.cast(new Date(epoch.longValue())); - } else { - throw new UnsupportedOperationException("Cannot convert to " + cls.getSimpleName()); } + throw new UnsupportedOperationException("Cannot convert to " + cls.getSimpleName()); } private static T stringToDate(Class cls, String epoch) throws ReflectiveOperationException { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ISO8601DateSerde.java b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ISO8601DateSerde.java index de7c8e11b9..85a297013e 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ISO8601DateSerde.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ISO8601DateSerde.java @@ -53,13 +53,14 @@ public Date deserialize(String val) { if (ClassUtils.isAssignable(targetType, java.sql.Date.class)) { return new java.sql.Date(date.getTime()); - } else if (ClassUtils.isAssignable(targetType, java.sql.Timestamp.class)) { + } + if (ClassUtils.isAssignable(targetType, java.sql.Timestamp.class)) { return new java.sql.Timestamp(date.getTime()); - } else if (ClassUtils.isAssignable(targetType, java.sql.Time.class)) { + } + if (ClassUtils.isAssignable(targetType, java.sql.Time.class)) { return new java.sql.Time(date.getTime()); - } else { - return date; } + return date; } @Override diff --git a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ToEnumConverter.java b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ToEnumConverter.java index 4748e77656..246cdf001e 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ToEnumConverter.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/utils/coerce/converters/ToEnumConverter.java @@ -27,11 +27,11 @@ public T convert(Class cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); - } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { + } + if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); - } else { - throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } + throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); diff --git a/elide-core/src/main/java/com/yahoo/elide/jsonapi/EntityProjectionMaker.java b/elide-core/src/main/java/com/yahoo/elide/jsonapi/EntityProjectionMaker.java index 159087cdb7..e79bebabda 100644 --- a/elide-core/src/main/java/com/yahoo/elide/jsonapi/EntityProjectionMaker.java +++ b/elide-core/src/main/java/com/yahoo/elide/jsonapi/EntityProjectionMaker.java @@ -119,17 +119,13 @@ public Function, NamedEntityProjection> visitSubCollectionRelationship( @Override public Function, NamedEntityProjection> visitRootCollectionLoadEntity( CoreParser.RootCollectionLoadEntityContext ctx) { - return (unused) -> { - return ctx.entity().accept(this).apply(null); - }; + return unused -> ctx.entity().accept(this).apply(null); } @Override public Function, NamedEntityProjection> visitSubCollectionReadEntity( CoreParser.SubCollectionReadEntityContext ctx) { - return (parentClass) -> { - return ctx.entity().accept(this).apply(parentClass); - }; + return parentClass -> ctx.entity().accept(this).apply(parentClass); } @Override @@ -181,9 +177,8 @@ protected Function, NamedEntityProjection> aggregateResult( if (aggregate == null) { return nextResult; - } else { - return aggregate; } + return aggregate; } public EntityProjection visitIncludePath(Path path) { diff --git a/elide-core/src/main/java/com/yahoo/elide/jsonapi/serialization/KeySerializer.java b/elide-core/src/main/java/com/yahoo/elide/jsonapi/serialization/KeySerializer.java index 3fc2e80b8b..b73204d2aa 100644 --- a/elide-core/src/main/java/com/yahoo/elide/jsonapi/serialization/KeySerializer.java +++ b/elide-core/src/main/java/com/yahoo/elide/jsonapi/serialization/KeySerializer.java @@ -33,8 +33,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi str = ((Class) value).getName(); } else if (cls.isEnum()) { str = ((Enum) value).name(); - } - else { + } else { str = value.toString(); } jgen.writeFieldName(str); diff --git a/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java b/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java index f4a9e6e1e6..311f14f62e 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java @@ -63,8 +63,7 @@ public void setQueryParams(MultivaluedMap queryParams) { public Optional> getQueryParams() { if (queryParamOverrides != null) { return Optional.of(queryParamOverrides); - } else { - return super.getQueryParams(); } + return super.getQueryParams(); } } diff --git a/elide-core/src/test/java/com/yahoo/elide/core/dictionary/EntityDictionaryTest.java b/elide-core/src/test/java/com/yahoo/elide/core/dictionary/EntityDictionaryTest.java index 2fdef844d2..5be9b19f2d 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/dictionary/EntityDictionaryTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/dictionary/EntityDictionaryTest.java @@ -213,7 +213,7 @@ class EntityWithDateId { EntityDictionary testDictionary = new EntityDictionary( new HashMap<>(), null, - (unused) -> { return new ISO8601DateSerde(); }); + unused -> new ISO8601DateSerde()); testDictionary.bindEntity(EntityWithDateId.class); @@ -752,9 +752,9 @@ class SubsubclassBinding extends SubclassBinding { assertEquals(new ClassType(SuperclassBinding.class), getEntityBinding(new ClassType(SubclassBinding.class)).entityClass); assertEquals(new ClassType(SuperclassBinding.class), getEntityBinding(new ClassType(SuperclassBinding.class)).entityClass); - assertThrows(IllegalArgumentException.class, () -> { - getEntityBinding(new ClassType(SubsubclassBinding.class)); - }); + assertThrows(IllegalArgumentException.class, () -> + getEntityBinding(new ClassType(SubsubclassBinding.class)) + ); assertEquals(new ClassType(SuperclassBinding.class), lookupIncludeClass(new ClassType(SuperclassBinding.class))); assertEquals(new ClassType(SuperclassBinding.class), lookupIncludeClass(new ClassType(SubclassBinding.class))); diff --git a/elide-core/src/test/java/com/yahoo/elide/parsers/expression/PermissionToFilterExpressionVisitorTest.java b/elide-core/src/test/java/com/yahoo/elide/parsers/expression/PermissionToFilterExpressionVisitorTest.java index ce25da10d5..790fbe8056 100644 --- a/elide-core/src/test/java/com/yahoo/elide/parsers/expression/PermissionToFilterExpressionVisitorTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/parsers/expression/PermissionToFilterExpressionVisitorTest.java @@ -259,7 +259,8 @@ private static boolean containsOnlyFilterableExpressions(FilterExpression expr) left = or.getLeft(); right = or.getRight(); return containsOnlyFilterableExpressions(left) && containsOnlyFilterableExpressions(right); - } else if (expr instanceof AndFilterExpression) { + } + if (expr instanceof AndFilterExpression) { AndFilterExpression and = (AndFilterExpression) expr; left = and.getLeft(); right = and.getRight(); diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/MatchesTemplateVisitor.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/MatchesTemplateVisitor.java index 096eeeecdf..97bd71be9e 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/MatchesTemplateVisitor.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/MatchesTemplateVisitor.java @@ -69,28 +69,29 @@ private static boolean matches(FilterExpression a, FilterExpression b) { AndFilterExpression andB = (AndFilterExpression) b; return matches(andA.getLeft(), andB.getLeft()) && matches(andA.getRight(), andB.getRight()); - } else if (a instanceof OrFilterExpression) { + } + if (a instanceof OrFilterExpression) { OrFilterExpression orA = (OrFilterExpression) a; OrFilterExpression orB = (OrFilterExpression) b; return matches(orA.getLeft(), orB.getLeft()) && matches(orA.getRight(), orB.getRight()); - } else if (a instanceof NotFilterExpression) { + } + if (a instanceof NotFilterExpression) { NotFilterExpression notA = (NotFilterExpression) a; NotFilterExpression notB = (NotFilterExpression) b; return matches(notA.getNegated(), notB.getNegated()); - } else { - FilterPredicate predicateA = (FilterPredicate) a; - FilterPredicate predicateB = (FilterPredicate) b; + } + FilterPredicate predicateA = (FilterPredicate) a; + FilterPredicate predicateB = (FilterPredicate) b; - boolean valueMatches = predicateA.getValues().equals(predicateB.getValues()); - boolean usingTemplate = predicateA.getValues().stream() - .anyMatch((value -> value.toString().matches(TEMPLATE_REGEX))); + boolean valueMatches = predicateA.getValues().equals(predicateB.getValues()); + boolean usingTemplate = predicateA.getValues().stream() + .anyMatch((value -> value.toString().matches(TEMPLATE_REGEX))); - return predicateA.getPath().equals(predicateB.getPath()) - && predicateA.getOperator().equals(predicateB.getOperator()) - && (usingTemplate || valueMatches); - } + return predicateA.getPath().equals(predicateB.getPath()) + && predicateA.getOperator().equals(predicateB.getOperator()) + && (usingTemplate || valueMatches); } /** diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/SplitFilterExpressionVisitor.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/SplitFilterExpressionVisitor.java index bdb4cab099..cfbeb18244 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/SplitFilterExpressionVisitor.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/filter/visitor/SplitFilterExpressionVisitor.java @@ -178,21 +178,20 @@ public FilterConstraints visitOrExpression(final OrFilterExpression expression) right.getWhereExpression() ) ); - } else { - // all of the rests are pure-H - return FilterConstraints.pureHaving( - OrFilterExpression.fromPair( - AndFilterExpression.fromPair( - left.getWhereExpression(), - left.getHavingExpression() - ), - AndFilterExpression.fromPair( - right.getWhereExpression(), - right.getHavingExpression() - ) - ) - ); } + // all of the rests are pure-H + return FilterConstraints.pureHaving( + OrFilterExpression.fromPair( + AndFilterExpression.fromPair( + left.getWhereExpression(), + left.getHavingExpression() + ), + AndFilterExpression.fromPair( + right.getWhereExpression(), + right.getHavingExpression() + ) + ) + ); } @Override @@ -201,21 +200,21 @@ public FilterConstraints visitNotExpression(NotFilterExpression expression) { if (normalized instanceof AndFilterExpression) { return visitAndExpression((AndFilterExpression) normalized); - } else if (normalized instanceof OrFilterExpression) { + } + if (normalized instanceof OrFilterExpression) { return visitOrExpression((OrFilterExpression) normalized); - } else if (normalized instanceof NotFilterExpression) { + } + if (normalized instanceof NotFilterExpression) { FilterConstraints negatedConstraint = visitNotExpression((NotFilterExpression) normalized); if (negatedConstraint.isPureWhere()) { return FilterConstraints.pureWhere(new NotFilterExpression(negatedConstraint.getWhereExpression())); - } else { - // It is not possible to have a mixed where/having for a NotFilterExpression after normalization - // so this must be a pure HAVING - return FilterConstraints.pureHaving(new NotFilterExpression(negatedConstraint.getHavingExpression())); } - } else { - return visitPredicate((FilterPredicate) normalized); + // It is not possible to have a mixed where/having for a NotFilterExpression after normalization + // so this must be a pure HAVING + return FilterConstraints.pureHaving(new NotFilterExpression(negatedConstraint.getHavingExpression())); } + return visitPredicate((FilterPredicate) normalized); } /** diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java index 30d3910aa3..0c2e33ceaa 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java @@ -143,23 +143,23 @@ protected static String constructColumnName(Type tableClass, String fieldName public static ValueType getValueType(Type tableClass, String fieldName, EntityDictionary dictionary) { if (dictionary.isRelation(tableClass, fieldName)) { return ValueType.RELATIONSHIP; - } else { - Type fieldClass = dictionary.getType(tableClass, fieldName); - - if (fieldName.equals(dictionary.getIdFieldName(tableClass))) { - return ValueType.ID; - } else if (ClassType.DATE_TYPE.isAssignableFrom(fieldClass)) { - return ValueType.TIME; - } else { - return ValueType.getScalarType(fieldClass); - } } + Type fieldClass = dictionary.getType(tableClass, fieldName); + + if (fieldName.equals(dictionary.getIdFieldName(tableClass))) { + return ValueType.ID; + } + if (ClassType.DATE_TYPE.isAssignableFrom(fieldClass)) { + return ValueType.TIME; + } + return ValueType.getScalarType(fieldClass); } private ValueSourceType getValueSourceType() { if (values != null && !values.isEmpty()) { return ValueSourceType.ENUM; - } else if (tableSource != null) { + } + if (tableSource != null) { return ValueSourceType.TABLE; } return ValueSourceType.NONE; diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Table.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Table.java index dd48f7974d..38c751801c 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Table.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Table.java @@ -169,11 +169,11 @@ private Set constructColumns(Type cls, EntityDictionary dictionary) { .map(field -> { if (isMetricField(dictionary, cls, field)) { return constructMetric(field, dictionary); - } else if (dictionary.attributeOrRelationAnnotationExists(cls, field, Temporal.class)) { + } + if (dictionary.attributeOrRelationAnnotationExists(cls, field, Temporal.class)) { return constructTimeDimension(field, dictionary); - } else { - return constructDimension(field, dictionary); } + return constructDimension(field, dictionary); }) .collect(Collectors.toSet()); diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/query/ImmutablePagination.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/query/ImmutablePagination.java index dd72f8f5b6..bed35df257 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/query/ImmutablePagination.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/query/ImmutablePagination.java @@ -23,12 +23,12 @@ public class ImmutablePagination implements Pagination { public static ImmutablePagination from(Pagination src) { if (src instanceof ImmutablePagination) { return (ImmutablePagination) src; - } else if (src != null) { + } + if (src != null) { return new ImmutablePagination( src.getOffset(), src.getLimit(), src.isDefaultInstance(), src.returnPageTotals()); - } else { - return null; } + return null; } @Override diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/dialects/SQLDialectFactory.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/dialects/SQLDialectFactory.java index d42c3bf3b7..cc21d88e76 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/dialects/SQLDialectFactory.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/dialects/SQLDialectFactory.java @@ -55,24 +55,28 @@ public static SQLDialect getDruidDialect() { public static SQLDialect getDialect(String type) { if (type.equalsIgnoreCase(H2_DIALECT.getDialectType())) { return H2_DIALECT; - } else if (type.equalsIgnoreCase(HIVE_DIALECT.getDialectType())) { + } + if (type.equalsIgnoreCase(HIVE_DIALECT.getDialectType())) { return HIVE_DIALECT; - } else if (type.equalsIgnoreCase(PRESTODB_DIALECT.getDialectType())) { + } + if (type.equalsIgnoreCase(PRESTODB_DIALECT.getDialectType())) { return PRESTODB_DIALECT; - } else if (type.equalsIgnoreCase(MYSQL_DIALECT.getDialectType())) { + } + if (type.equalsIgnoreCase(MYSQL_DIALECT.getDialectType())) { return MYSQL_DIALECT; - } else if (type.equalsIgnoreCase(POSTGRES_DIALECT.getDialectType())) { + } + if (type.equalsIgnoreCase(POSTGRES_DIALECT.getDialectType())) { return POSTGRES_DIALECT; - } else if (type.equalsIgnoreCase(DRUID_DIALECT.getDialectType())) { + } + if (type.equalsIgnoreCase(DRUID_DIALECT.getDialectType())) { return DRUID_DIALECT; - } else { - try { - return (SQLDialect) Class.forName(type).getConstructor().newInstance(); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Unsupported SQL Dialect: " + type, e); - } catch (Exception e) { - throw new IllegalArgumentException("Failed to instantiate SQL Dialect: " + type, e); - } + } + try { + return (SQLDialect) Class.forName(type).getConstructor().newInstance(); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Unsupported SQL Dialect: " + type, e); + } catch (Exception e) { + throw new IllegalArgumentException("Failed to instantiate SQL Dialect: " + type, e); } } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLReferenceTable.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLReferenceTable.java index 5d5d0bc3a5..7a34fad25f 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLReferenceTable.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLReferenceTable.java @@ -342,11 +342,11 @@ private static String resolveTableAnnotation(javax.persistence.Table table) { private static String applyQuotes(String str, char beginQuote, char endQuote) { if (str == null || str.trim().isEmpty()) { return str; - } else if (str.contains(PERIOD)) { + } + if (str.contains(PERIOD)) { return beginQuote + str.trim().replace(PERIOD, endQuote + PERIOD + beginQuote) + endQuote; - } else { - return beginQuote + str.trim() + endQuote; } + return beginQuote + str.trim() + endQuote; } /** diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLTable.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLTable.java index 09ed86f3c3..e1a5b93961 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLTable.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLTable.java @@ -171,7 +171,7 @@ public Set getTimeDimensionProjections() { public Set getColumnProjections() { return super.getColumns() .stream() - .map((column) -> { return getColumnProjection(column.getName()); }) + .map(column -> getColumnProjection(column.getName())) .collect(Collectors.toSet()); } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/AggregationDataStoreTestHarness.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/AggregationDataStoreTestHarness.java index d4880a9256..b88915c82a 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/AggregationDataStoreTestHarness.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/AggregationDataStoreTestHarness.java @@ -62,16 +62,17 @@ public DataStore getDataStore() { .queryLogger(new Slf4jQueryLogger()) .build(); - Consumer txCancel = (em) -> { em.unwrap(Session.class).cancelQuery(); }; + Consumer txCancel = em -> em.unwrap(Session.class).cancelQuery(); DataStore jpaStore = new JpaDataStore( () -> entityManagerFactory.createEntityManager(), - (em) -> { return new NonJtaTransaction(em, txCancel); } + em -> new NonJtaTransaction(em, txCancel) ); return new MultiplexManager(jpaStore, metaDataStore, aggregationDataStore); } + @Override public void cleanseTestData() { } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/SQLUnitTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/SQLUnitTest.java index fcedd1b6ba..9f4b4675dc 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/SQLUnitTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/framework/SQLUnitTest.java @@ -103,16 +103,16 @@ public abstract class SQLUnitTest { // Standard set of test queries used in dialect tests protected enum TestQuery { - WHERE_DIMS_ONLY (() -> { - return Query.builder() + WHERE_DIMS_ONLY (() -> + Query.builder() .source(playerStatsTable) .dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")) .whereFilter(new FilterPredicate( new Path(PlayerStats.class, dictionary, "overallRating"), Operator.NOTNULL, new ArrayList())) - .build(); - }), + .build() + ), WHERE_AND (() -> { FilterPredicate ratingFilter = new FilterPredicate( new Path(PlayerStats.class, dictionary, "overallRating"), @@ -143,26 +143,26 @@ protected enum TestQuery { .whereFilter(new OrFilterExpression(ratingFilter, highScoreFilter)) .build(); }), - HAVING_METRICS_ONLY (() -> { - return Query.builder() + HAVING_METRICS_ONLY (() -> + Query.builder() .source(playerStatsTable) .metricProjection(playerStatsTable.getMetricProjection("lowScore")) .havingFilter(new FilterPredicate( new Path(PlayerStats.class, dictionary, "lowScore"), Operator.GT, Arrays.asList(9000))) - .build(); - }), - HAVING_DIMS_ONLY (() -> { - return Query.builder() + .build() + ), + HAVING_DIMS_ONLY (() -> + Query.builder() .source(playerStatsTable) .dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")) .havingFilter(new FilterPredicate( new Path(PlayerStats.class, dictionary, "overallRating"), Operator.NOTNULL, new ArrayList())) - .build(); - }), + .build() + ), HAVING_METRICS_AND_DIMS (() -> { FilterPredicate ratingFilter = new FilterPredicate( new Path(PlayerStats.class, dictionary, "overallRating"), @@ -193,15 +193,15 @@ protected enum TestQuery { .havingFilter(new OrFilterExpression(ratingFilter, highScoreFilter)) .build(); }), - PAGINATION_TOTAL (() -> { - return Query.builder() + PAGINATION_TOTAL (() -> + Query.builder() .source(playerStatsTable) .metricProjection(playerStatsTable.getMetricProjection("lowScore")) .dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")) .timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")) .pagination(new ImmutablePagination(0, 1, false, true)) - .build(); - }), + .build() + ), SORT_METRIC_ASC (() -> { Map sortMap = new TreeMap<>(); sortMap.put("lowScore", Sorting.SortOrder.asc); @@ -256,13 +256,13 @@ protected enum TestQuery { .sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)) .build(); }), - PAGINATION_METRIC_ONLY (() -> { - return Query.builder() + PAGINATION_METRIC_ONLY (() -> + Query.builder() .source(playerStatsTable) .metricProjection(playerStatsTable.getMetricProjection("lowScore")) .pagination(new ImmutablePagination(10, 5, false, true)) - .build(); - }), + .build() + ), COMPLICATED (() -> { // Sorting Map sortMap = new TreeMap<>(); @@ -396,30 +396,30 @@ protected enum TestQuery { .sorting(new SortingImpl(sortMap, playerStatsType, sortAttributes, dictionary)) .build(); }), - LEFT_JOIN (() -> { - return Query.builder() + LEFT_JOIN (() -> + Query.builder() .source(videoGameTable) .dimensionProjection(videoGameTable.getDimensionProjection("playerName")) - .build(); - }), - INNER_JOIN (() -> { - return Query.builder() + .build() + ), + INNER_JOIN (() -> + Query.builder() .source(videoGameTable) .dimensionProjection(videoGameTable.getDimensionProjection("playerNameInnerJoin")) - .build(); - }), - CROSS_JOIN (() -> { - return Query.builder() + .build() + ), + CROSS_JOIN (() -> + Query.builder() .source(videoGameTable) .dimensionProjection(videoGameTable.getDimensionProjection("playerNameCrossJoin")) - .build(); - }), - METRIC_JOIN(() -> { - return Query.builder() + .build() + ), + METRIC_JOIN(() -> + Query.builder() .source(videoGameTable) .metricProjection(videoGameTable.getMetricProjection("normalizedHighScore")) - .build(); - }); + .build() + ); private Provider queryProvider; @@ -491,7 +491,8 @@ public static void init(SQLDialect sqlDialect) { private static String getCompatabilityMode(String dialectType) { if (dialectType.equals(SQLDialectFactory.getMySQLDialect().getDialectType())) { return ";MODE=MySQL"; - } else if (dialectType.equals(SQLDialectFactory.getPostgresDialect().getDialectType())) { + } + if (dialectType.equals(SQLDialectFactory.getPostgresDialect().getDialectType())) { return ";MODE=PostgreSQL"; } @@ -537,10 +538,14 @@ protected void compareQueryLists(String expected, List actual) { protected void compareQueryLists(List expected, List actual) { if (expected == null && actual == null) { return; - } else if (expected == null) { + } + if (expected == null) { fail("Expected a null query List, but actual was non-null"); - } else if (actual == null) { + return; + } + if (actual == null) { fail("Expected a non-null query List, but actual was null"); + return; } assertEquals(expected.size(), actual.size(), "Query List sizes do not match"); diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/DaySerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/DaySerdeTest.java index d9f60316e8..dd4beb037c 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/DaySerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/DaySerdeTest.java @@ -55,8 +55,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January-01-2020"; Serde serde = new Day.DaySerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/HourSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/HourSerdeTest.java index ae4bb4a9b1..37a3add422 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/HourSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/HourSerdeTest.java @@ -56,8 +56,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "00 2020-01-01"; Serde serde = new Hour.HourSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/ISOWeekSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/ISOWeekSerdeTest.java index 3e7b4235ef..ae8e173057 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/ISOWeekSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/ISOWeekSerdeTest.java @@ -45,9 +45,9 @@ public void testDeserializeTimestampNotMonday() throws ParseException { LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00); ISOWeek timestamp = new ISOWeek(localDate); Serde serde = new ISOWeek.ISOWeekSerde(); - assertThrows(IllegalArgumentException.class, () -> { - serde.deserialize(timestamp); - }); + assertThrows(IllegalArgumentException.class, () -> + serde.deserialize(timestamp) + ); } @Test @@ -65,8 +65,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January-2020-01"; Serde serde = new ISOWeek.ISOWeekSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MinuteSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MinuteSerdeTest.java index 76cd72de5b..3f536ff1e2 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MinuteSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MinuteSerdeTest.java @@ -57,8 +57,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "00:18 2020-01-01"; Serde serde = new Minute.MinuteSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MonthSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MonthSerdeTest.java index 4cc5a5c466..715abb5fcd 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MonthSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/MonthSerdeTest.java @@ -53,8 +53,8 @@ public void testDeserializeTimestamp() throws ParseException { public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January-2020"; Serde serde = new Month.MonthSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/QuarterSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/QuarterSerdeTest.java index d1b91f0e10..99f784a821 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/QuarterSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/QuarterSerdeTest.java @@ -43,9 +43,9 @@ public void testDeserializeTimestampNotQuarterMonth() throws ParseException { LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(02), 01, 00, 00, 00); Quarter quarter = new Quarter(localDate); Serde serde = new Quarter.QuarterSerde(); - assertThrows(IllegalArgumentException.class, () -> { - serde.deserialize(quarter); - }); + assertThrows(IllegalArgumentException.class, () -> + serde.deserialize(quarter) + ); } @Test @@ -63,8 +63,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January-2020"; Serde serde = new Quarter.QuarterSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/SecondSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/SecondSerdeTest.java index 9c116147f8..ab53104d2c 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/SecondSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/SecondSerdeTest.java @@ -57,8 +57,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "00:18:19 2020-01-01"; Serde serde = new Second.SecondSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/TimeSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/TimeSerdeTest.java index 07cc619938..e957ebbdf7 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/TimeSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/TimeSerdeTest.java @@ -86,8 +86,8 @@ public void testTimeDeserializeSecond() throws ParseException { @Test public void testInvalidDeserialization() throws ParseException { Serde serde = new Time.TimeSerde(); - assertThrows(IllegalArgumentException.class, () -> { - serde.deserialize("2020R1"); - }); + assertThrows(IllegalArgumentException.class, () -> + serde.deserialize("2020R1") + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/WeekSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/WeekSerdeTest.java index 273a4ce811..44af427f60 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/WeekSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/WeekSerdeTest.java @@ -45,9 +45,9 @@ public void testDeserializeTimestampNotSunday() throws ParseException { Week expectedDate = new Week(localDate); Serde serde = new Week.WeekSerde(); - assertThrows(IllegalArgumentException.class, () -> { - serde.deserialize(expectedDate); - }); + assertThrows(IllegalArgumentException.class, () -> + serde.deserialize(expectedDate) + ); } @Test @@ -66,8 +66,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January-2020-01"; Serde serde = new Week.WeekSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/YearSerdeTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/YearSerdeTest.java index 99628e5e05..2852e3bb1e 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/YearSerdeTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/timegrains/serde/YearSerdeTest.java @@ -56,8 +56,8 @@ public void testDeserializeDateInvalidFormat() throws ParseException { String dateInString = "January"; Serde serde = new Year.YearSerde(); - assertThrows(DateTimeParseException.class, () -> { - serde.deserialize(dateInString); - }); + assertThrows(DateTimeParseException.class, () -> + serde.deserialize(dateInString) + ); } } diff --git a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/AbstractHibernateStore.java b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/AbstractHibernateStore.java index 6612bc955c..af091a2a63 100644 --- a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/AbstractHibernateStore.java +++ b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/AbstractHibernateStore.java @@ -95,7 +95,8 @@ public Builder withScrollMode(final ScrollMode scrollMode) { public AbstractHibernateStore build() { if (sessionFactory != null) { return new HibernateSessionFactoryStore(sessionFactory, isScrollEnabled, scrollMode); - } else if (emf != null) { + } + if (emf != null) { return new HibernateEntityManagerStore(emf, isScrollEnabled, scrollMode); } throw new IllegalStateException("Either an EntityManager or SessionFactory is required!"); diff --git a/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreHarness.java b/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreHarness.java index 19a9e6fe16..f8889464d1 100644 --- a/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreHarness.java +++ b/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreHarness.java @@ -45,7 +45,7 @@ public class JpaDataStoreHarness implements DataStoreTestHarness { private DataStore store; private MetadataImplementor metadataImplementor; - private final Consumer txCancel = (em) -> { em.unwrap(Session.class).cancelQuery(); }; + private final Consumer txCancel = em -> em.unwrap(Session.class).cancelQuery(); public JpaDataStoreHarness() { Map options = new HashMap<>(); @@ -99,8 +99,8 @@ public JpaDataStoreHarness() { resetSchema(); store = new JpaDataStore( - () -> { return emf.createEntityManager(); }, - (entityManager) -> { return new NonJtaTransaction(entityManager, txCancel); } + () -> emf.createEntityManager(), + entityManager -> new NonJtaTransaction(entityManager, txCancel) ); } diff --git a/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreTest.java b/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreTest.java index e804c53bb2..0600921f5f 100644 --- a/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreTest.java +++ b/elide-datastore/elide-datastore-jpa/src/test/java/com/yahoo/elide/datastores/jpa/JpaDataStoreTest.java @@ -59,7 +59,7 @@ class Test { EntityManager managerMock = mock(EntityManager.class); when(managerMock.getMetamodel()).thenReturn(mockModel); - JpaDataStore store = new JpaDataStore(() -> { return managerMock; }, (unused) -> { return null; }); + JpaDataStore store = new JpaDataStore(() -> managerMock, unused -> null); EntityDictionary dictionary = new EntityDictionary(new HashMap<>()); @@ -90,7 +90,7 @@ class Test { EntityManager managerMock = mock(EntityManager.class); when(managerMock.getMetamodel()).thenReturn(mockModel); - JpaDataStore store = new JpaDataStore(() -> { return managerMock; }, (unused) -> { return null; }, getClassType(Test.class)); + JpaDataStore store = new JpaDataStore(() -> managerMock, unused -> null, getClassType(Test.class)); EntityDictionary dictionary = new EntityDictionary(new HashMap<>()); store.populateEntityDictionary(dictionary); diff --git a/elide-datastore/elide-datastore-search/src/main/java/com/yahoo/elide/datastores/search/SearchDataTransaction.java b/elide-datastore/elide-datastore-search/src/main/java/com/yahoo/elide/datastores/search/SearchDataTransaction.java index 69fecc26a9..e98c713aac 100644 --- a/elide-datastore/elide-datastore-search/src/main/java/com/yahoo/elide/datastores/search/SearchDataTransaction.java +++ b/elide-datastore/elide-datastore-search/src/main/java/com/yahoo/elide/datastores/search/SearchDataTransaction.java @@ -281,9 +281,8 @@ private List search(Type entityType, FilterExpression filterExpression } return results.stream() - .map((result) -> { - return result[0]; - }).collect(Collectors.toList()); + .map(result -> result[0]) + .collect(Collectors.toList()); } private boolean fieldIsIndexed(Type entityClass, FilterPredicate predicate) { diff --git a/elide-datastore/elide-datastore-search/src/test/java/com/yahoo/elide/datastores/search/DependencyBinder.java b/elide-datastore/elide-datastore-search/src/test/java/com/yahoo/elide/datastores/search/DependencyBinder.java index 8db272d1fa..9cbfdf10a3 100644 --- a/elide-datastore/elide-datastore-search/src/test/java/com/yahoo/elide/datastores/search/DependencyBinder.java +++ b/elide-datastore/elide-datastore-search/src/test/java/com/yahoo/elide/datastores/search/DependencyBinder.java @@ -46,12 +46,11 @@ protected void configure() { indexOnStartup = true; } - Consumer txCancel = (em) -> { em.unwrap(Session.class).cancelQuery(); }; + Consumer txCancel = em -> em.unwrap(Session.class).cancelQuery(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("searchDataStoreTest"); DataStore jpaStore = new JpaDataStore( emf::createEntityManager, - (em) -> { return new NonJtaTransaction(em, txCancel); } - ); + em -> new NonJtaTransaction(em, txCancel)); EntityDictionary dictionary = new EntityDictionary(new HashMap<>()); diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLScalars.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLScalars.java index d54db8cd5a..33c8ae4b01 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLScalars.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLScalars.java @@ -77,7 +77,8 @@ public String parseValue(Object o) { public String parseLiteral(Object o) { if (o instanceof StringValue) { return ((StringValue) o).getValue(); - } else if (o instanceof IntValue) { + } + if (o instanceof IntValue) { return ((IntValue) o).getValue().toString(); } // Unexpected object, try to use the toString. diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/PersistentResourceFetcher.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/PersistentResourceFetcher.java index 1032081457..62ec732c43 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/PersistentResourceFetcher.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/PersistentResourceFetcher.java @@ -434,14 +434,13 @@ private PersistentResource updateObject(Entity entity, Environment context) { if (!id.isPresent()) { throw new BadRequestException("UPDATE data objects must include ids"); - } else { - Set loadedResource = fetchObject( - requestScope, - entity.getProjection(), - Optional.of(Collections.singletonList(id.get())) - ).getPersistentResources(); - updatedResource = loadedResource.iterator().next(); } + Set loadedResource = fetchObject( + requestScope, + entity.getProjection(), + Optional.of(Collections.singletonList(id.get())) + ).getPersistentResources(); + updatedResource = loadedResource.iterator().next(); return updateAttributes(updatedResource, entity, attributes); } diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectionMaker.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectionMaker.java index 39dae6805e..b57acfff79 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectionMaker.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/GraphQLEntityProjectionMaker.java @@ -262,7 +262,6 @@ private void addField(Field field, EntityProjectionBuilder projectionBuilder) { addRelationship(field, projectionBuilder); } else if (TYPENAME.equals(fieldName)) { // '__typename' would not be handled by entityProjection - return; } else if (PAGE_INFO.equals(fieldName)) { // only 'totalRecords' needs to be added into the projection's pagination if (field.getSelectionSet().getSelections().stream() diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/VariableResolver.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/VariableResolver.java index 58a26ece44..d8d58a5e46 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/VariableResolver.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/parser/VariableResolver.java @@ -69,10 +69,9 @@ private void addVariable(VariableDefinition definition) { if (variableType instanceof NonNullType && scopeVariables.get(variableName) == null) { // value of non-null variable must be resolvable throw new BadRequestException("Undefined non-null variable " + variableName); - } else { - // this would put 'null' for this variable if it is not stored in the map - scopeVariables.put(variableName, scopeVariables.get(variableName)); } + // this would put 'null' for this variable if it is not stored in the map + scopeVariables.put(variableName, scopeVariables.get(variableName)); } else { if (!scopeVariables.containsKey(variableName)) { // create a new variable with default value @@ -90,25 +89,33 @@ private void addVariable(VariableDefinition definition) { public Object resolveValue(Value value) { if (value instanceof BooleanValue) { return ((BooleanValue) value).isValue(); - } else if (value instanceof EnumValue) { + } + if (value instanceof EnumValue) { // TODO throw new BadRequestException("Enum value is not supported."); - } else if (value instanceof FloatValue) { + } + if (value instanceof FloatValue) { return ((FloatValue) value).getValue(); - } else if (value instanceof IntValue) { + } + if (value instanceof IntValue) { return ((IntValue) value).getValue(); - } else if (value instanceof NullValue) { + } + if (value instanceof NullValue) { return null; - } else if (value instanceof StringValue) { + } + if (value instanceof StringValue) { return ((StringValue) value).getValue(); - } else if (value instanceof ObjectValue) { + } + if (value instanceof ObjectValue) { return ((ObjectValue) value).getObjectFields().stream() .collect(Collectors.toMap(ObjectField::getName, ObjectField::getValue)); - } else if (value instanceof ArrayValue) { + } + if (value instanceof ArrayValue) { return ((ArrayValue) value).getValues().stream() .map(this::resolveValue) .collect(Collectors.toList()); - } else if (value instanceof VariableReference) { + } + if (value instanceof VariableReference) { String variableName = ((VariableReference) value).getName(); if (!scopeVariables.containsKey(variableName)) { throw new BadRequestException("Can't resolve variable reference " + variableName); diff --git a/elide-model-config/src/main/java/com/yahoo/elide/modelconfig/validator/DynamicConfigValidator.java b/elide-model-config/src/main/java/com/yahoo/elide/modelconfig/validator/DynamicConfigValidator.java index 8ce9e0c759..48446374cf 100644 --- a/elide-model-config/src/main/java/com/yahoo/elide/modelconfig/validator/DynamicConfigValidator.java +++ b/elide-model-config/src/main/java/com/yahoo/elide/modelconfig/validator/DynamicConfigValidator.java @@ -325,33 +325,25 @@ private T getInheritedAttribute(Inheritance action, T property) { } private String getInheritedSchema(Table table, String schema) { - Inheritance action = () -> { - return table.getSchema(); - }; + Inheritance action = () -> table.getSchema(); return getInheritedAttribute(action, schema); } private String getInheritedConnection(Table table, String connection) { - Inheritance action = () -> { - return table.getDbConnectionName(); - }; + Inheritance action = () -> table.getDbConnectionName(); return getInheritedAttribute(action, connection); } private String getInheritedSql(Table table, String sql) { - Inheritance action = () -> { - return table.getSql(); - }; + Inheritance action = () -> table.getSql(); return getInheritedAttribute(action, sql); } private String getInheritedTable(Table table, String tableName) { - Inheritance action = () -> { - return table.getTable(); - }; + Inheritance action = () -> table.getTable(); return getInheritedAttribute(action, tableName); } diff --git a/elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/config/ElideAutoConfiguration.java b/elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/config/ElideAutoConfiguration.java index 9935bf98ab..baae73cb3c 100644 --- a/elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/config/ElideAutoConfiguration.java +++ b/elide-spring/elide-spring-boot-autoconfigure/src/main/java/com/yahoo/elide/spring/config/ElideAutoConfiguration.java @@ -79,7 +79,7 @@ public class ElideAutoConfiguration { @Autowired(required = false) private MeterRegistry meterRegistry; - private final Consumer txCancel = (em) -> { em.unwrap(Session.class).cancelQuery(); }; + private final Consumer txCancel = em -> em.unwrap(Session.class).cancelQuery(); /** * Creates dynamic configuration for models, security roles, and database connections. @@ -295,8 +295,9 @@ public DataStore buildDataStore(EntityManagerFactory entityManagerFactory, @Autowired(required = false) QueryLogger querylogger) throws ClassNotFoundException { - JpaDataStore jpaDataStore = new JpaDataStore(entityManagerFactory::createEntityManager, - (em) -> { return new NonJtaTransaction(em, txCancel); }); + JpaDataStore jpaDataStore = new JpaDataStore( + entityManagerFactory::createEntityManager, + em -> new NonJtaTransaction(em, txCancel)); if (isAggregationStoreEnabled(settings)) { AggregationDataStore.AggregationDataStoreBuilder aggregationDataStoreBuilder = diff --git a/elide-standalone/src/main/java/com/yahoo/elide/standalone/config/ElideStandaloneSettings.java b/elide-standalone/src/main/java/com/yahoo/elide/standalone/config/ElideStandaloneSettings.java index 263ba2514d..c859655eff 100644 --- a/elide-standalone/src/main/java/com/yahoo/elide/standalone/config/ElideStandaloneSettings.java +++ b/elide-standalone/src/main/java/com/yahoo/elide/standalone/config/ElideStandaloneSettings.java @@ -68,7 +68,7 @@ public interface ElideStandaloneSettings { /* Elide settings */ - public final Consumer TXCANCEL = (em) -> { em.unwrap(Session.class).cancelQuery(); }; + public final Consumer TXCANCEL = em -> em.unwrap(Session.class).cancelQuery(); /** * A map containing check mappings for security across Elide. If not provided, then an empty map is used. @@ -394,8 +394,8 @@ default DataSourceConfiguration getDataSourceConfiguration() { default DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore aggregationDataStore, EntityManagerFactory entityManagerFactory) { DataStore jpaDataStore = new JpaDataStore( - () -> { return entityManagerFactory.createEntityManager(); }, - (em) -> { return new NonJtaTransaction(em, TXCANCEL); }); + () -> entityManagerFactory.createEntityManager(), + em -> new NonJtaTransaction(em, TXCANCEL)); DataStore dataStore = new MultiplexManager(jpaDataStore, metaDataStore, aggregationDataStore); @@ -409,8 +409,8 @@ default DataStore getDataStore(MetaDataStore metaDataStore, AggregationDataStore */ default DataStore getDataStore(EntityManagerFactory entityManagerFactory) { DataStore jpaDataStore = new JpaDataStore( - () -> { return entityManagerFactory.createEntityManager(); }, - (em) -> { return new NonJtaTransaction(em, TXCANCEL); }); + () -> entityManagerFactory.createEntityManager(), + em -> new NonJtaTransaction(em, TXCANCEL)); return jpaDataStore; } diff --git a/elide-swagger/src/main/java/com/yahoo/elide/swagger/SwaggerBuilder.java b/elide-swagger/src/main/java/com/yahoo/elide/swagger/SwaggerBuilder.java index 0286957666..502b63a974 100644 --- a/elide-swagger/src/main/java/com/yahoo/elide/swagger/SwaggerBuilder.java +++ b/elide-swagger/src/main/java/com/yahoo/elide/swagger/SwaggerBuilder.java @@ -209,9 +209,8 @@ public Path getRelationshipPath() { Path path = new Path(); /* The path parameter apply for all operations */ - lineage.stream().forEach((item) -> { - path.addParameter(item.getPathParameter()); - }); + lineage.stream().forEach(item -> + path.addParameter(item.getPathParameter())); String typeName = dictionary.getJsonAliasFor(type); @@ -298,11 +297,8 @@ public Path getCollectionPath() { Path path = new Path(); /* The path parameter apply for all operations */ - if (! lineage.isEmpty()) { - lineage.stream().forEach((item) -> { - path.addParameter(item.getPathParameter()); - }); - } + lineage.stream().forEach(item -> + path.addParameter(item.getPathParameter())); Response okSingularResponse = new Response() .description("Successful response") @@ -361,9 +357,8 @@ public Path getInstancePath() { Path path = new Path(); /* The path parameter apply for all operations */ - getFullLineage().stream().forEach((item) -> { - path.addParameter(item.getPathParameter()); - }); + getFullLineage().stream().forEach(item -> + path.addParameter(item.getPathParameter())); Response okSingularResponse = new Response() .description("Successful response") @@ -404,9 +399,8 @@ public Path getInstancePath() { * @return the decorated path */ private Path decorateGlobalParameters(Path path) { - globalParams.forEach((param) -> { - path.addParameter(param); - }); + globalParams.forEach(param -> + path.addParameter(param)); return path; }