added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / spring / configuration / OTFMongoConfiguration.java
diff --git a/otf-camunda/src/main/java/org/oran/otf/spring/configuration/OTFMongoConfiguration.java b/otf-camunda/src/main/java/org/oran/otf/spring/configuration/OTFMongoConfiguration.java
new file mode 100644 (file)
index 0000000..665823f
--- /dev/null
@@ -0,0 +1,78 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.spring.configuration;\r
+\r
+import com.mongodb.MongoClient;\r
+import com.mongodb.MongoClientOptions;\r
+import com.mongodb.MongoCredential;\r
+import com.mongodb.ServerAddress;\r
+import java.util.ArrayList;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.data.mongodb.config.AbstractMongoConfiguration;\r
+import org.springframework.data.mongodb.core.MongoTemplate;\r
+import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;\r
+\r
+@Configuration\r
+@EnableMongoRepositories(basePackages = "org.oran.otf.common.repository")\r
+public class OTFMongoConfiguration extends AbstractMongoConfiguration {\r
+  @Value("${otf.mongo.hosts}")\r
+  private String hosts;\r
+\r
+  @Value("${otf.mongo.username}")\r
+  private String username;\r
+\r
+  @Value("${otf.mongo.password}")\r
+  private String password;\r
+\r
+  @Value("${otf.mongo.replica-set}")\r
+  private String replicaSet;\r
+\r
+  @Value("${otf.mongo.database}")\r
+  private String database;\r
+\r
+  @Override\r
+  protected String getDatabaseName() {\r
+    return database;\r
+  }\r
+\r
+  @Override\r
+  public MongoClient mongoClient() {\r
+    MongoCredential credential =\r
+        MongoCredential.createScramSha1Credential(username, database, password.toCharArray());\r
+\r
+    MongoClientOptions options =\r
+        MongoClientOptions.builder().sslEnabled(false).requiredReplicaSetName(replicaSet).build();\r
+\r
+    String[] hostArray = hosts.split(",");\r
+    ArrayList<ServerAddress> hosts = new ArrayList<>();\r
+\r
+    for (String host : hostArray) {\r
+      String[] hostSplit = host.split(":");\r
+      hosts.add(new ServerAddress(hostSplit[0], Integer.parseInt(hostSplit[1])));\r
+    }\r
+\r
+    return new MongoClient(hosts, credential, options);\r
+  }\r
+\r
+  @Override\r
+  public @Bean\r
+  MongoTemplate mongoTemplate() {\r
+    return new MongoTemplate(mongoClient(), database);\r
+  }\r
+}\r