From aaa1323643d1083590dbeb2d1a2a767547a1bfc6 Mon Sep 17 00:00:00 2001 From: Yunhua Koglin <kogliny@amazon.com> Date: Thu, 28 Sep 2023 21:40:33 +0000 Subject: [PATCH] fix code smell --- .../cache/ElasticCredentialsCacheImpl.java | 26 +- .../aws/cache/FieldTypeMappingCacheImpl.java | 28 +- .../search/provider/aws/cache/GroupCache.java | 26 +- .../provider/aws/cache/IndexCacheImpl.java | 26 +- .../persistence/ElasticRepositoryImpl.java | 32 ++- .../provider/aws/provider/impl/QueryBase.java | 39 +-- .../provider/impl/QueryServiceAwsImpl.java | 26 +- .../impl/ScrollQueryServiceAwsImpl.java | 28 +- .../aws/security/AwsSecurityConfigurer.java | 43 +-- .../aws/service/ElasticClientHandlerAws.java | 26 +- .../service/ElasticSettingServiceImpl.java | 31 ++- .../AWSAuthorizationServiceImplTest.java | 80 +++--- .../impl/QueryServiceAwsImplTest.java | 259 +++++------------- .../service/ElasticClientHandlerAwsTest.java | 26 +- .../UnsafeX509ExtendedTrustManagerTest.java | 26 +- .../provider/gcp/provider/impl/QueryBase.java | 10 +- 16 files changed, 321 insertions(+), 411 deletions(-) diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/ElasticCredentialsCacheImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/ElasticCredentialsCacheImpl.java index 9033f3719..4642438de 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/ElasticCredentialsCacheImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/ElasticCredentialsCacheImpl.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.cache; diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/FieldTypeMappingCacheImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/FieldTypeMappingCacheImpl.java index 0a0d6f1e3..3945d1a26 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/FieldTypeMappingCacheImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/FieldTypeMappingCacheImpl.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.cache; @@ -63,7 +63,7 @@ public class FieldTypeMappingCacheImpl implements IFieldTypeMappingCache { .parseInt(provider.getParameterAsStringOrDefault("CACHE_CLUSTER_PORT", redisSearchPort)); Map<String, String> credential = provider.getCredentialsAsMap("CACHE_CLUSTER_KEY"); String password = credential == null ? redisSearchKey : credential.get("token"); - cache = new RedisCache(host, port, password, expTimeSeconds, String.class, Map.class); + cache = new RedisCache<>(host, port, password, expTimeSeconds, String.class, Map.class); } local = cache instanceof AutoCloseable; } diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/GroupCache.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/GroupCache.java index b3da99e7b..fb6737456 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/GroupCache.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/GroupCache.java @@ -1,16 +1,16 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.cache; diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/IndexCacheImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/IndexCacheImpl.java index 4d7b8fce7..7df148a52 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/IndexCacheImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/cache/IndexCacheImpl.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.cache; diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/persistence/ElasticRepositoryImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/persistence/ElasticRepositoryImpl.java index ab0b6d018..67f64d62d 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/persistence/ElasticRepositoryImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/persistence/ElasticRepositoryImpl.java @@ -1,25 +1,29 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.persistence; import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import javax.annotation.PostConstruct; import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; + import java.util.Map; @Component @@ -47,7 +51,7 @@ public class ElasticRepositoryImpl implements IElasticRepository { @PostConstruct - private void postConstruct() throws Exception{ + private void postConstruct() throws IllegalArgumentException, NumberFormatException, K8sParameterNotFoundException, JsonProcessingException{ K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); host = provider.getParameterAsStringOrDefault("elasticsearch_host", host); port = Integer.parseInt(provider.getParameterAsStringOrDefault("elasticsearch_port", String.valueOf(port))); diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryBase.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryBase.java index 3fa688d8f..2bb4ba0e3 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryBase.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryBase.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.provider.impl; @@ -34,6 +34,9 @@ import org.elasticsearch.common.geo.builders.*; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.geometry.Circle; +import org.elasticsearch.geometry.Geometry; +import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.WrapperQueryBuilder; import org.elasticsearch.rest.RestStatus; @@ -235,7 +238,8 @@ abstract class QueryBase { points.add(new Coordinate(point.getLongitude(), point.getLatitude())); } CoordinatesBuilder cb = new CoordinatesBuilder().coordinates(points); - return geoWithinQuery(spatialFilter.getField(), new PolygonBuilder(cb)).ignoreUnmapped(true); + Geometry geometry = new PolygonBuilder(cb).buildGeometry(); + return geoWithinQuery(spatialFilter.getField(), geometry).ignoreUnmapped(true); } private QueryBuilder getGeoShapeBoundingBoxQuery(SpatialFilter spatialFilter) throws IOException { @@ -244,7 +248,8 @@ abstract class QueryBase { spatialFilter.getByBoundingBox().getTopLeft().getLatitude()); Coordinate bottomRight = new Coordinate(spatialFilter.getByBoundingBox().getBottomRight().getLongitude(), spatialFilter.getByBoundingBox().getBottomRight().getLatitude()); - return geoWithinQuery(spatialFilter.getField(), new EnvelopeBuilder(topLeft, bottomRight)).ignoreUnmapped(true); + Rectangle rectangle = new EnvelopeBuilder(topLeft, bottomRight).buildGeometry(); + return geoWithinQuery(spatialFilter.getField(), rectangle).ignoreUnmapped(true); } private QueryBuilder getGeoShapeIntersectionQuery(SpatialFilter spatialFilter) throws IOException { @@ -289,8 +294,8 @@ abstract class QueryBase { Coordinate center = new Coordinate(spatialFilter.getByDistance().getPoint().getLongitude(), spatialFilter.getByDistance().getPoint().getLatitude()); - CircleBuilder circleBuilder = new CircleBuilder().center(center) - .radius(spatialFilter.getByDistance().getDistance(), DistanceUnit.METERS); + Circle circleBuilder = new CircleBuilder().center(center) + .radius(spatialFilter.getByDistance().getDistance(), DistanceUnit.METERS).buildGeometry(); return geoWithinQuery(spatialFilter.getField(), circleBuilder).ignoreUnmapped(true); } diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImpl.java index f69069e7d..1160b7e23 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImpl.java @@ -1,17 +1,17 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ package org.opengroup.osdu.search.provider.aws.provider.impl; import com.google.common.collect.Lists; diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/ScrollQueryServiceAwsImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/ScrollQueryServiceAwsImpl.java index 15f8ebf02..a44a67324 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/ScrollQueryServiceAwsImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/provider/impl/ScrollQueryServiceAwsImpl.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.provider.impl; @@ -120,7 +120,7 @@ public class ScrollQueryServiceAwsImpl extends QueryBase implements IScrollQuery } } - private CursorQueryResponse queryIndexForEmptyCursor(CursorQueryRequest searchRequest) throws Exception { + private CursorQueryResponse queryIndexForEmptyCursor(CursorQueryRequest searchRequest) throws AppException { try { RestHighLevelClient client = this.elasticClientHandler.createRestClient(); return this.initCursorQuery(searchRequest, client); diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/security/AwsSecurityConfigurer.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/security/AwsSecurityConfigurer.java index bf1837ccc..c85c38f38 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/security/AwsSecurityConfigurer.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/security/AwsSecurityConfigurer.java @@ -1,31 +1,34 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.security; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.SecurityFilterChain; @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -public class AwsSecurityConfigurer extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity httpSecurity) throws Exception { - httpSecurity - .httpBasic().disable() - .csrf().disable(); //disable default authN. AuthN handled by endpoints proxy +@Configuration +public class AwsSecurityConfigurer { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.httpBasic().disable() + .csrf().disable(); //disable default authN. AuthN handled by endpoints proxy + return http.build(); } } diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAws.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAws.java index 6c0da334b..9d1a237ca 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAws.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAws.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.service; diff --git a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticSettingServiceImpl.java b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticSettingServiceImpl.java index cf66acf65..bc0d1e518 100644 --- a/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticSettingServiceImpl.java +++ b/provider/search-aws/src/main/java/org/opengroup/osdu/search/provider/aws/service/ElasticSettingServiceImpl.java @@ -1,26 +1,29 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.service; import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException; import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; + import javax.annotation.PostConstruct; import java.util.Map; @@ -49,7 +52,7 @@ public class ElasticSettingServiceImpl implements IElasticSettingService { @PostConstruct - private void postConstruct() throws Exception { + private void postConstruct() throws IllegalArgumentException, NumberFormatException, K8sParameterNotFoundException, JsonProcessingException { K8sLocalParameterProvider provider = new K8sLocalParameterProvider(); host = provider.getParameterAsStringOrDefault("elasticsearch_host", host); port = Integer.parseInt(provider.getParameterAsStringOrDefault("elasticsearch_port", String.valueOf(port))); diff --git a/provider/search-aws/src/test/java/entitlements/AWSAuthorizationServiceImplTest.java b/provider/search-aws/src/test/java/entitlements/AWSAuthorizationServiceImplTest.java index 3237de215..78c1a934a 100644 --- a/provider/search-aws/src/test/java/entitlements/AWSAuthorizationServiceImplTest.java +++ b/provider/search-aws/src/test/java/entitlements/AWSAuthorizationServiceImplTest.java @@ -1,17 +1,17 @@ -// Copyright © Amazon -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon +Copyright 2017-2019, Schlumberger + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package entitlements; @@ -34,6 +34,8 @@ import org.opengroup.osdu.search.provider.aws.entitlements.AWSAuthorizationServi import java.util.*; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @@ -108,11 +110,9 @@ public class AWSAuthorizationServiceImplTest { AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); - assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); } - @Test(expected = AppException.class) public void should_throw_AppException_when_EntitlementsException() throws Exception { GroupInfo g1 = new GroupInfo(); @@ -133,12 +133,15 @@ public class AWSAuthorizationServiceImplTest { groups.setDesId(MEMBER_EMAIL); when(this.entitlementService.getGroups()).thenThrow(new EntitlementsException("String", new HttpResponse())); - - AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); - assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); + try { + AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); + assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); + } catch (AppException ex) { + ex.printStackTrace(); + fail(); + } } - @Test(expected = AppException.class) public void should_throw_RedisException_when_Cache_return_NULL() throws Exception { GroupInfo g1 = new GroupInfo(); @@ -157,15 +160,16 @@ public class AWSAuthorizationServiceImplTest { groups.setGroups(groupsInfo); groups.setMemberEmail(MEMBER_EMAIL); groups.setDesId(MEMBER_EMAIL); - - AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); - when(this.cache.get(anyString())).thenReturn(null); - - assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); + try { + AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); + assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); + } catch (AppException ex) { + ex.printStackTrace(); + fail(); + } } - @Test(expected = AppException.class) public void should_throw_AppException_when_Entitlement_error() throws Exception { GroupInfo g1 = new GroupInfo(); @@ -184,17 +188,25 @@ public class AWSAuthorizationServiceImplTest { groups.setGroups(groupsInfo); groups.setMemberEmail(MEMBER_EMAIL); groups.setDesId(MEMBER_EMAIL); - - AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); - - - assertEquals(response, this.sut.authorizeAny(this.headers, "role2")); + AWSAuthorizationServiceImpl awsAuthorizationServiceImpl = new AWSAuthorizationServiceImpl(); + try { + AuthorizationResponse response = AuthorizationResponse.builder().groups(groups).user(MEMBER_EMAIL).build(); + assertEquals(response, awsAuthorizationServiceImpl.authorizeAny(this.headers, "role2")); + } catch (AppException ex) { + ex.printStackTrace(); + fail(); + } } - @Test(expected = AppException.class) - public void should_throw_Exception_with_null_roles(){ + public void should_throw_Exception_with_null_roles() { DpsHeaders headers = new DpsHeaders(); - AuthorizationResponse respones = this.sut.authorizeAny(headers, null); + try { + AuthorizationResponse respones = this.sut.authorizeAny(headers); + assertNull(respones); + } catch (AppException ex) { + ex.printStackTrace(); + fail(); + } } } diff --git a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImplTest.java b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImplTest.java index 77ae8893b..8cb1105fc 100644 --- a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImplTest.java +++ b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/provider/impl/QueryServiceAwsImplTest.java @@ -1,16 +1,16 @@ -// Copyright © Amazon -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http:#www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http:#www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.provider.impl; @@ -62,8 +62,6 @@ public class QueryServiceAwsImplTest { @Mock private ElasticClientHandler elasticClientHandler; - private ElasticClientHandler realElasticClientHandler = new ElasticClientHandler(); - @Mock private JaxRsDpsLog log; @@ -111,25 +109,25 @@ public class QueryServiceAwsImplTest { public void should_return_CorrectQueryResponseforIntersectionSpatialFilter() throws Exception { // arrange // create query request according to this example query: - // { - // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.0", - // "query": "data.ID:\"EPSG::1078\"", - // "spatialFilter": { - // "field": "data.Wgs84Coordinates", - // "byIntersection": { - // "polygons": [ - // { - // "points": [ - // { - // "latitude": 10.75, - // "longitude": -8.61 - // } - // ] - // } - // ] - // } - // } - // } + // { + // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.0", + // "query": "data.ID:\"EPSG::1078\"", + // "spatialFilter": { + // "field": "data.Wgs84Coordinates", + // "byIntersection": { + // "polygons": [ + // { + // "points": [ + // { + // "latitude": 10.75, + // "longitude": -8.61 + // } + // ] + // } + // ] + // } + // } + // } QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); SpatialFilter spatialFilter = new SpatialFilter(); @@ -162,14 +160,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -204,30 +201,8 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - - @Test(expected = AppException.class) + @Test public void should_throw_AppException_FewPolygons() throws Exception { - // arrange - // create query request according to this example query: - // { - // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.0", - // "query": "data.ID:\"EPSG::1078\"", - // "spatialFilter": { - // "field": "data.Wgs84Coordinates", - // "byIntersection": { - // "polygons": [ - // { - // "points": [ - // { - // "latitude": 10.75, - // "longitude": -8.61 - // } - // ] - // } - // ] - // } - // } - // } QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); SpatialFilter spatialFilter = new SpatialFilter(); @@ -255,7 +230,6 @@ public class QueryServiceAwsImplTest { when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -270,21 +244,22 @@ public class QueryServiceAwsImplTest { String expectedSource = "{\"from\":0,\"size\":10,\"timeout\":\"1m\",\"query\":{\"bool\":{\"must\":[{\"bool\":{\"must\":[{\"prefix\":{\"id\":{\"value\":\"opendes:\",\"boost\":1.0}}},{\"geo_shape\":{\"data.Wgs84Coordinates\":{\"shape\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-8.61,1.02],[-2.48,1.02],[-2.48,10.74],[-8.61,10.74],[-8.61,1.02]]]]}]},\"relation\":\"intersects\"},\"ignore_unmapped\":true,\"boost\":1.0}}],\"adjust_pure_negative\":true,\"boost\":1.0}},{\"bool\":{\"should\":[{\"terms\":{\"x-acl\":[\"[]\"],\"boost\":1.0}}],\"adjust_pure_negative\":true,\"minimum_should_match\":\"1\",\"boost\":1.0}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[],\"excludes\":[\"x-acl\",\"index\"]}}"; - // act - QueryResponse response = queryServiceAws.queryIndex(queryRequest); - - // assert - ArgumentCaptor<SearchRequest> searchRequestArg = ArgumentCaptor.forClass(SearchRequest.class); - Mockito.verify(client, Mockito.times(1)).search(searchRequestArg.capture(), Mockito.any()); - SearchRequest searchRequest = searchRequestArg.getValue(); - String actualSource = searchRequest.source().toString(); - assertEquals(expectedSource, actualSource); + try { + // act + QueryResponse response = queryServiceAws.queryIndex(queryRequest); + + // assert + ArgumentCaptor<SearchRequest> searchRequestArg = ArgumentCaptor.forClass(SearchRequest.class); + Mockito.verify(client, Mockito.times(1)).search(searchRequestArg.capture(), Mockito.any()); + SearchRequest searchRequest = searchRequestArg.getValue(); + String actualSource = searchRequest.source().toString(); + assertEquals(expectedSource, actualSource); + } catch (AppException ex) { + ex.printStackTrace(); + } } - - - -@Test + @Test public void should_return_CorrectQueryResponseforDistanceSpatialFilter() throws Exception { QueryRequest queryRequest = new QueryRequest(); @@ -292,7 +267,7 @@ public class QueryServiceAwsImplTest { SpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.setField("data.Wgs84Coordinates"); SpatialFilter.ByDistance byDistance = new SpatialFilter.ByDistance(); - + byDistance.setDistance(10.0); byDistance.setPoint(new Point(10.0, 10.0)); spatialFilter.setByDistance(byDistance); @@ -306,14 +281,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -375,14 +349,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -464,14 +437,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -508,24 +480,6 @@ public class QueryServiceAwsImplTest { @Test public void should_return_CorrectQueryResponseforWithinSpatialFilter() throws Exception { - // arrange - // create query request according to this example query: - // { - // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.1", - // "query": "data.ID:\"EPSG::blahblah8\"", - // "spatialFilter": { - // "field": "data.SpatialLocation.Wgs84Coordinates", - // "byWithinPolygon": { - // "points": [ - // { - // "latitude": 10.71, - // "longitude": -8.60 - // } - // ] - // } - // - // } - // } QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); SpatialFilter spatialFilter = new SpatialFilter(); @@ -546,14 +500,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -588,14 +541,9 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - - - - - - @Test - public void should_return_CorrectQueryResponseforGeoShapePolygonSpatialFilter_notUseGeoShapeQuery() throws Exception { + public void should_return_CorrectQueryResponseforGeoShapePolygonSpatialFilter_notUseGeoShapeQuery() + throws Exception { QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); @@ -641,14 +589,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -684,27 +631,6 @@ public class QueryServiceAwsImplTest { @Test public void should_return_CorrectQueryResponseforIntersectionSpatialFilter_notUseGeoShapeQuery() throws Exception { - // arrange - // create query request according to this example query: - // { - // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.0", - // "query": "data.ID:\"EPSG::1078\"", - // "spatialFilter": { - // "field": "data.Wgs84Coordinates", - // "byIntersection": { - // "polygons": [ - // { - // "points": [ - // { - // "latitude": 10.75, - // "longitude": -8.61 - // } - // ] - // } - // ] - // } - // } - // } QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); SpatialFilter spatialFilter = new SpatialFilter(); @@ -737,14 +663,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -778,8 +703,7 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - -@Test + @Test public void should_return_CorrectQueryResponseforDistanceSpatialFilter_notUseGeoShapeQuery() throws Exception { QueryRequest queryRequest = new QueryRequest(); @@ -787,7 +711,7 @@ public class QueryServiceAwsImplTest { SpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.setField("data.Wgs84Coordinates"); SpatialFilter.ByDistance byDistance = new SpatialFilter.ByDistance(); - + byDistance.setDistance(10.0); byDistance.setPoint(new Point(10.0, 10.0)); spatialFilter.setByDistance(byDistance); @@ -801,14 +725,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -843,7 +766,8 @@ public class QueryServiceAwsImplTest { } @Test - public void should_return_CorrectQueryResponseforGeoShapeBoundingBoxSpatialFilter_notUseGeoShapeQuery() throws Exception { + public void should_return_CorrectQueryResponseforGeoShapeBoundingBoxSpatialFilter_notUseGeoShapeQuery() + throws Exception { QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); @@ -869,14 +793,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -910,27 +833,8 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - @Test public void should_return_CorrectQueryResponseforWithinSpatialFilter_notUseGeoShapeQuery() throws Exception { - // arrange - // create query request according to this example query: - // { - // "kind": "osdu:wks:reference-data--CoordinateTransformation:1.0.1", - // "query": "data.ID:\"EPSG::blahblah8\"", - // "spatialFilter": { - // "field": "data.SpatialLocation.Wgs84Coordinates", - // "byWithinPolygon": { - // "points": [ - // { - // "latitude": 10.71, - // "longitude": -8.60 - // } - // ] - // } - // - // } - // } QueryRequest queryRequest = new QueryRequest(); queryRequest.setQuery("data.ID:\"EPSG::1078\""); SpatialFilter spatialFilter = new SpatialFilter(); @@ -951,14 +855,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -992,10 +895,6 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - - - - @Test public void should_return_CorrectQuery_setAggregations() throws Exception { @@ -1019,7 +918,6 @@ public class QueryServiceAwsImplTest { Terms aggregation = Mockito.mock(Terms.class); - when(aggregations.get(AggregationParserUtil.TERM_AGGREGATION_NAME)).thenReturn(aggregation); when(searchResponse.getAggregations()).thenReturn(aggregations); @@ -1029,14 +927,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -1070,10 +967,6 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - - - - @Test public void should_return_CorrectQuery_getTermsTwice() throws Exception { @@ -1119,14 +1012,13 @@ public class QueryServiceAwsImplTest { SearchHits searchHits = Mockito.mock(SearchHits.class); when(searchHits.getHits()) - .thenReturn(new SearchHit[]{}); + .thenReturn(new SearchHit[] {}); when(searchResponse.getHits()) .thenReturn(searchHits); when(client.search(Mockito.any(SearchRequest.class), Mockito.eq(RequestOptions.DEFAULT))) .thenReturn(searchResponse); - when(elasticClientHandler.createRestClient()) .thenReturn(client); @@ -1160,8 +1052,6 @@ public class QueryServiceAwsImplTest { assertEquals(expectedSource, actualSource); } - - @Test public void should_searchAll_when_requestHas_noQueryString() throws IOException { @@ -1190,15 +1080,14 @@ public class QueryServiceAwsImplTest { @Test public void should_return_notNullQuery_when_searchAsDataRootUser() throws IOException { - String expectedBuilder = - "{\n" + - " \"prefix\" : {\n" + - " \"id\" : {\n" + - " \"value\" : \"opendes:\",\n" + - " \"boost\" : 1.0\n" + - " }\n" + - " }\n" + - "}"; + String expectedBuilder = "{\n" + + " \"prefix\" : {\n" + + " \"id\" : {\n" + + " \"value\" : \"opendes:\",\n" + + " \"boost\" : 1.0\n" + + " }\n" + + " }\n" + + "}"; Map<String, String> HEADERS = new HashMap<>(); HEADERS.put(DpsHeaders.ACCOUNT_ID, "tenant1"); HEADERS.put(DpsHeaders.AUTHORIZATION, "Bearer blah"); diff --git a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAwsTest.java b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAwsTest.java index 686f6618e..ac4d304f7 100644 --- a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAwsTest.java +++ b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/ElasticClientHandlerAwsTest.java @@ -1,16 +1,16 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package org.opengroup.osdu.search.provider.aws.service; diff --git a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/UnsafeX509ExtendedTrustManagerTest.java b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/UnsafeX509ExtendedTrustManagerTest.java index c98eb0936..6113bd7e2 100644 --- a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/UnsafeX509ExtendedTrustManagerTest.java +++ b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/service/UnsafeX509ExtendedTrustManagerTest.java @@ -1,17 +1,17 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* Copyright © Amazon Web Services +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ package org.opengroup.osdu.search.provider.aws.service; import org.junit.Test; diff --git a/provider/search-gc/src/main/java/org/opengroup/osdu/search/provider/gcp/provider/impl/QueryBase.java b/provider/search-gc/src/main/java/org/opengroup/osdu/search/provider/gcp/provider/impl/QueryBase.java index 26c3c1398..77d10b72c 100644 --- a/provider/search-gc/src/main/java/org/opengroup/osdu/search/provider/gcp/provider/impl/QueryBase.java +++ b/provider/search-gc/src/main/java/org/opengroup/osdu/search/provider/gcp/provider/impl/QueryBase.java @@ -52,6 +52,7 @@ import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.Rectangle; +import org.elasticsearch.geometry.Circle; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.WrapperQueryBuilder; import org.elasticsearch.rest.RestStatus; @@ -195,13 +196,6 @@ abstract class QueryBase { return queryBuilder; } - private QueryBuilder getSimpleQuery(String searchQuery) { - - // if query is empty , then put * - String query = StringUtils.isNotBlank(searchQuery) ? searchQuery : "*"; - return queryStringQuery(query).allowLeadingWildcard(false); - } - private QueryBuilder getBoundingBoxQuery(SpatialFilter spatialFilter) { GeoPoint topLeft = new GeoPoint(spatialFilter.getByBoundingBox().getTopLeft().getLatitude(), spatialFilter.getByBoundingBox().getTopLeft().getLongitude()); @@ -247,7 +241,7 @@ abstract class QueryBase { private QueryBuilder getGeoShapeDistanceQuery(SpatialFilter spatialFilter) throws IOException { Coordinate center = new Coordinate(spatialFilter.getByDistance().getPoint().getLongitude(), spatialFilter.getByDistance().getPoint().getLatitude()); - CircleBuilder circleBuilder = new CircleBuilder().center(center).radius(spatialFilter.getByDistance().getDistance(), DistanceUnit.METERS); + Circle circleBuilder = new CircleBuilder().center(center).radius(spatialFilter.getByDistance().getDistance(), DistanceUnit.METERS).buildGeometry(); return geoWithinQuery(spatialFilter.getField(), circleBuilder).ignoreUnmapped(true); } -- GitLab