diff --git a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/RegisterApplication.java b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/RegisterApplication.java index 2045d5be47f2ffd7f98d3d89a0c9f0a378eed6bc..33f5bf96add1d1b32094f2dc0cfe795e471a5bf3 100644 --- a/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/RegisterApplication.java +++ b/provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/RegisterApplication.java @@ -18,15 +18,9 @@ import org.opengroup.osdu.azure.dependencies.AzureOSDUConfig; import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig; import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication(exclude = { - MongoAutoConfiguration.class, - MongoDataAutoConfiguration.class -}) + @ComponentScan(value = { "org.opengroup.osdu.register", "org.opengroup.osdu.core", diff --git a/provider/register-gcp/src/main/java/org/opengroup/osdu/register/provider/gcp/RegisterApplication.java b/provider/register-gcp/src/main/java/org/opengroup/osdu/register/provider/gcp/RegisterApplication.java index 49188cfb688175d7ca6cc0de937ab4ac0218155d..c6002429d2d44158c6c5d621b469705998292f40 100644 --- a/provider/register-gcp/src/main/java/org/opengroup/osdu/register/provider/gcp/RegisterApplication.java +++ b/provider/register-gcp/src/main/java/org/opengroup/osdu/register/provider/gcp/RegisterApplication.java @@ -1,17 +1,10 @@ package org.opengroup.osdu.register.provider.gcp; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import javax.annotation.PostConstruct; -@SpringBootApplication(exclude = { - MongoAutoConfiguration.class, - MongoDataAutoConfiguration.class -}) @ComponentScan({"org.opengroup.osdu"}) public class RegisterApplication { @PostConstruct diff --git a/register-core/pom.xml b/register-core/pom.xml index 41ebb643cb2c8edbccd392e3739590ba1582665b..f960cc6ef190503c78bce62eaca48ebc330ce5d7 100644 --- a/register-core/pom.xml +++ b/register-core/pom.xml @@ -177,11 +177,6 @@ <artifactId>commons-beanutils</artifactId> <version>1.9.4</version> </dependency> - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - <version>3.12.5</version> - </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> diff --git a/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsClient.java b/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsClient.java deleted file mode 100644 index ea2be86e438197cb4244489478a63951f76db5f6..0000000000000000000000000000000000000000 --- a/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsClient.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2017-2020, 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 org.opengroup.osdu.register.ddms.persistence.mongo; - -import com.mongodb.client.MongoCollection; -import org.opengroup.osdu.register.utils.AppServiceConfig; -import org.opengroup.osdu.register.utils.MongoClientHandler; -import org.bson.Document; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; - -@Component -@ConditionalOnProperty(name = "PERSISTENCE", havingValue = "MONGODB") -public class MongoDdmsClient { - - @Autowired - private AppServiceConfig config; - @Autowired - private MongoClientHandler mongoClientHandler; - @Autowired - private TenantInfo tenantInfo; - - public MongoCollection<Document> getTenantRegisterMongoCollection() { - return mongoClientHandler.getMongoClient().getDatabase(config.getMongoDatabaseName()).getCollection(getMongoCollectionName("register")); - } - - private String getMongoCollectionName(String serviceId) { - return String.format("collection-%s-%s", tenantInfo.getName(), serviceId).toLowerCase(); - } -} diff --git a/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsRepository.java b/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsRepository.java deleted file mode 100644 index ddaa59e7f64b03036486ca0203aa5cdcab199f98..0000000000000000000000000000000000000000 --- a/register-core/src/main/java/org/opengroup/osdu/register/ddms/persistence/mongo/MongoDdmsRepository.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2017-2020, 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 org.opengroup.osdu.register.ddms.persistence.mongo; - -import com.google.gson.Gson; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.result.DeleteResult; -import org.bson.Document; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.register.ddms.model.Ddms; -import org.opengroup.osdu.register.ddms.model.RegisteredInterface; -import org.opengroup.osdu.register.provider.interfaces.ddms.IDdmsRepository; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Repository; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static com.mongodb.client.model.Filters.eq; - -@Repository -@ConditionalOnProperty(name="PERSISTENCE", havingValue = "MONGODB") -public class MongoDdmsRepository implements IDdmsRepository { - - private static final String ID = "id"; - private static final String NAME = "name"; - private static final String CREATED_ON_SECONDS = "createdDateTimeEpoch.seconds"; - private static final String CREATED_ON_NANOS = "createdDateTimeEpoch.nanos"; - private static final String CONTACT_EMAIL = "contactEmail"; - private static final String DESCRIPTION = "description"; - private static final String INTERFACES = "interfaces"; - private static final String TYPE = "entityType"; - private static final String SCHEMA = "schema"; - - @Autowired - private MongoDdmsClient mongoClient; - @Autowired - private JaxRsDpsLog log; - - @Override - public Ddms create(Ddms spec) { - MongoCollection collection = this.mongoClient.getTenantRegisterMongoCollection(); - FindIterable<Document> results = collection.find(eq("id", spec.getId())); - if (results != null && results.first() != null) { - throw new AppException(409, "Conflict", "A DDMS already exists with the same id"); - } - collection.insertOne(Document.parse(new Gson().toJson(spec))); - return spec; - } - - @Override - public Ddms get(String id) { - MongoCollection collection = this.mongoClient.getTenantRegisterMongoCollection(); - Document record = (Document) collection.find(eq("id", id)).first(); - if (record == null) { - throw new AppException(404, "Not found", String.format("DDMS with id %s does not exist.", id)); - } - return new Gson().fromJson(record.toJson(), Ddms.class); - } - - @Override - public List<Ddms> query(String type) { - List<Ddms> output = new ArrayList<>(); - MongoCollection collection = this.mongoClient.getTenantRegisterMongoCollection(); - FindIterable<Document> queryResults = collection.find(eq("interfaces.entityType", type), Document.class); - for (Document doc : queryResults) { - output.add(convertEntityToDocument(doc)); - } - return output; - } - - @Override - public boolean delete(String id) { - MongoCollection collection = this.mongoClient.getTenantRegisterMongoCollection(); - DeleteResult deleteResult = collection.deleteOne(eq("id", id)); - return deleteResult.wasAcknowledged() && deleteResult.getDeletedCount() == 1; - } - - private Ddms convertEntityToDocument(Document doc) { - Ddms ddms = new Ddms(); - try { - ddms.setId(doc.getString(ID)); - ddms.setName(doc.getString(NAME)); - ddms.setDescription(doc.getString(DESCRIPTION)); - ddms.setContactEmail(doc.getString(CONTACT_EMAIL)); - List<Document> dsInterfaces = doc.getList(INTERFACES, Document.class); - for (Document typeInterface : dsInterfaces) { - RegisteredInterface ri = new RegisteredInterface(); - ri.setEntityType(typeInterface.getString(TYPE)); - Map<String, Object> map = typeInterface.get((SCHEMA), Map.class); - ri.setSchema(map); - ddms.getInterfaces().add(ri); - } - } catch (ClassCastException e) { - this.log.error(String.format("error casting property, message: %s", e.getMessage())); - } - return ddms; - } -} diff --git a/register-core/src/main/java/org/opengroup/osdu/register/utils/MongoClientHandler.java b/register-core/src/main/java/org/opengroup/osdu/register/utils/MongoClientHandler.java deleted file mode 100644 index 5a08e2a34678b2f08e9049b2cedf19bab00ad478..0000000000000000000000000000000000000000 --- a/register-core/src/main/java/org/opengroup/osdu/register/utils/MongoClientHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2017-2020, 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 org.opengroup.osdu.register.utils; - -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; - -@Component -@ConditionalOnProperty(name = "PERSISTENCE", havingValue = "MONGODB") -public class MongoClientHandler { - - private static final String MONGO_PREFIX = "mongodb+srv://"; - private static final String MONGO_OPTIONS = "retryWrites=true&w=majority"; - - private com.mongodb.client.MongoClient mongoClient = null; - - @Autowired - private JaxRsDpsLog log; - @Value("${MONGO_SERVER}") - private String MONGO_SERVER; - @Value("${MONGO_USERNAME}") - private String MONGO_USERNAME; - @Value("${MONGO_PASSWORD}") - private String MONGO_PASSWORD; - - private MongoClient getOrInitMongoClient() throws RuntimeException { - if (mongoClient != null) { - return mongoClient; - } - - final String connectionString = String.format("%s%s:%s@%s?%s", - MONGO_PREFIX, - MONGO_USERNAME, - MONGO_PASSWORD, - MONGO_SERVER, - MONGO_OPTIONS); - ConnectionString connString = new ConnectionString(connectionString); - MongoClientSettings settings = MongoClientSettings.builder() - .applyConnectionString(connString) - .retryWrites(true) - .build(); - try { - mongoClient = MongoClients.create(settings); - } catch (Exception ex) { - this.log.error("Error connecting MongoDB", ex); - throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error connecting MongoDB", ex.getMessage(), ex); - } - return mongoClient; - } - - public MongoClient getMongoClient() { - if (mongoClient == null) { - getOrInitMongoClient(); - } - return mongoClient; - } -} \ No newline at end of file