Commit ac8d1908 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Changed properties to properties from SearchConfigurationProperties.

Added Copyright.
Added several new properties to SearchConfigurationProperties.
parent 90d20505
......@@ -88,6 +88,11 @@
<artifactId>jts-io-common</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
</dependencies>
<build>
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference;
import org.springframework.boot.SpringApplication;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.cache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.model.search.CursorSettings;
import org.opengroup.osdu.search.cache.CursorCache;
import org.springframework.beans.factory.annotation.Value;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class CursorCacheImpl extends RedisCache<String, CursorSettings> implements CursorCache {
public CursorCacheImpl(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, @Value("${REDIS_SEARCH_PORT}") final int REDIS_SEARCH_PORT, @Value("${CURSOR_CACHE_EXPIRATION}") final int CURSOR_CACHE_EXPIRATION) {
super(REDIS_SEARCH_HOST, REDIS_SEARCH_PORT, CURSOR_CACHE_EXPIRATION, String.class, CursorSettings.class);
}
@Autowired
public CursorCacheImpl(SearchConfigurationProperties searchConfigurationProperties) {
super(searchConfigurationProperties.getSearchHost(),
Integer.parseInt(searchConfigurationProperties.getRedisSearchPort()),
searchConfigurationProperties.getCursorCacheExpiration(), String.class,
CursorSettings.class);
}
}
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.cache;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.springframework.beans.factory.annotation.Value;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ElasticCredentialsCache extends RedisCache<String, ClusterSettings> {
public ElasticCredentialsCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST,
@Value("${REDIS_SEARCH_PORT}") final int REDIS_SEARCH_PORT,
@Value("${ELASTIC_CACHE_EXPIRATION}") final int ELASTIC_CACHE_EXPIRATION) {
super(REDIS_SEARCH_HOST, REDIS_SEARCH_PORT, ELASTIC_CACHE_EXPIRATION * 60, String.class, ClusterSettings.class);
@Autowired
public ElasticCredentialsCache(final SearchConfigurationProperties configurationProperties) {
super(configurationProperties.getRedisSearchHost(),
Integer.parseInt(configurationProperties.getRedisSearchPort()),
configurationProperties.getElasticCacheExpiration() * 60,
String.class,
ClusterSettings.class);
}
}
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.cache;
import java.util.HashSet;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.springframework.beans.factory.annotation.Value;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class FieldTypeMappingCache extends RedisCache<String, HashSet> {
public FieldTypeMappingCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST,
@Value("${REDIS_SEARCH_PORT}") final int REDIS_SEARCH_PORT) {
super(REDIS_SEARCH_HOST, REDIS_SEARCH_PORT, 1440 * 60, String.class, HashSet.class);
@Autowired
public FieldTypeMappingCache(final SearchConfigurationProperties configurationProperties) {
super(configurationProperties.getRedisSearchHost(),
Integer.parseInt(configurationProperties.getRedisSearchPort()),
1440 * 60,
String.class, HashSet.class);
}
}
package org.opengroup.osdu.search.provider.reference.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties
@Getter
@Setter
public class MongoDBConfig {
private String mongoDbUrl;
private String mongoDbUser;
private String mongoDbPassword;
}
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.di;
import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig;
import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.search.provider.reference.security.EntitlementsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
......@@ -12,19 +31,15 @@ import org.springframework.web.context.annotation.RequestScope;
@RequestScope
public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlementsFactory> {
@Value("${AUTHORIZE_API}")
private String AUTHORIZE_API;
@Value("${AUTHORIZE_API_KEY:}")
private String AUTHORIZE_API_KEY;
@Autowired
private EntitlementsConfig entitlementsConfig;
@Override
protected IEntitlementsFactory createInstance() throws Exception {
return new EntitlementsFactory(EntitlementsAPIConfig
.builder()
.rootUrl(AUTHORIZE_API)
.apiKey(AUTHORIZE_API_KEY)
.rootUrl(entitlementsConfig.getAuthorizeApi())
.build());
}
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.di;
import com.google.gson.Gson;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.model;
import javax.validation.constraints.NotEmpty;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.model;
import java.util.List;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import java.util.ArrayList;
......@@ -18,7 +35,7 @@ import org.opengroup.osdu.core.common.model.search.QueryResponse;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.opengroup.osdu.search.provider.interfaces.ICcsQueryService;
import org.opengroup.osdu.search.provider.interfaces.IQueryService;
import org.springframework.stereotype.Service;
......@@ -27,6 +44,9 @@ import org.springframework.stereotype.Service;
@Service
public class CcsQueryServiceImpl implements ICcsQueryService {
@Inject
private SearchConfigurationProperties searchConfigurationProperties;
@Inject
private DpsHeaders dpsHeaders;
......@@ -48,7 +68,7 @@ public class CcsQueryServiceImpl implements ICcsQueryService {
private List<QueryResponse> getTenantResponses(final List<String> accounts, final CcsQueryRequest ccsQueryRequest) throws Exception {
List<QueryResponse> tenantResponses = new ArrayList<>();
if (Config.isSmartSearchCcsDisabled() || accounts.size() == 1) {
if (searchConfigurationProperties.isSmartSearchCcsDisabled() || accounts.size() == 1) {
TenantInfo tenant = tenantStorageFactory.getTenantInfo(this.dpsHeaders.getPartitionIdWithFallbackToAccountId());
tenantResponses.add(queryService.queryIndex(convertCcsQueryRequestToQueryRequest(ccsQueryRequest),
elasticRepository.getElasticClusterSettings(tenant)));
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import java.util.LinkedList;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import org.opengroup.osdu.search.provider.interfaces.IProviderHeaderService;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import java.io.IOException;
......@@ -16,23 +33,30 @@ import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.model.search.Query;
import org.opengroup.osdu.core.common.model.search.QueryRequest;
import org.opengroup.osdu.core.common.model.search.QueryResponse;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.opengroup.osdu.search.logging.AuditLogger;
import org.opengroup.osdu.search.provider.interfaces.IQueryService;
import org.opengroup.osdu.search.util.ElasticClientHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class QueryServiceImpl extends QueryBase implements IQueryService {
private final String environment;
private final SearchConfigurationProperties searchConfigurationProperties;
@Inject
private ElasticClientHandler elasticClientHandler;
@Inject
private AuditLogger auditLogger;
@Value("${ENVIRONMENT}")
private String ENVIRONMENT;
@Autowired
public QueryServiceImpl(SearchConfigurationProperties searchConfigurationProperties){
this.environment = searchConfigurationProperties.getEnvironment();
this.searchConfigurationProperties = searchConfigurationProperties;
}
@Override
public QueryResponse queryIndex(QueryRequest searchRequest) throws IOException {
......@@ -80,7 +104,7 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
if (isEnvironmentPreDemo() && !(searchRequest.getAggregateBy() == null || searchRequest.getAggregateBy().isEmpty())) {
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME, ValueType.STRING);
termsAggregationBuilder.field(searchRequest.getAggregateBy());
termsAggregationBuilder.size(Config.getAggregationSize());
termsAggregationBuilder.size(searchConfigurationProperties.getAggregationSize());
sourceBuilder.aggregation(termsAggregationBuilder);
}
......@@ -100,14 +124,15 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
}
private boolean isEnvironmentLocal() {
return "local".equalsIgnoreCase(ENVIRONMENT);
return "local".equalsIgnoreCase(environment);
}
private boolean isEnvironmentPreP4d() {
return isEnvironmentLocal() || "dev".equalsIgnoreCase(ENVIRONMENT) || "evt".equalsIgnoreCase(ENVIRONMENT);
return isEnvironmentLocal() || "dev".equalsIgnoreCase(environment) || "evt".equalsIgnoreCase(
environment);
}
protected boolean isEnvironmentPreDemo() {
return isEnvironmentPreP4d() || "p4d".equalsIgnoreCase(ENVIRONMENT);
return isEnvironmentPreP4d() || "p4d".equalsIgnoreCase(environment);
}
}
\ No newline at end of file
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.impl;
import java.io.IOException;
......
/*
* Copyright 2021 Google LLC
* Copyright 2021 EPAM Systems, Inc
*
* 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
*
* https://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.reference.provider.persistence;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.util.JSON.serialize;
import com.google.gson.Gson;
import com.mongodb.client.MongoCollection;
import java.util.Objects;
......@@ -13,67 +30,66 @@ import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.core.common.search.Preconditions;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;