001/* 002 * (C) Copyright 2017-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Kevin Leturc 018 */ 019package org.nuxeo.runtime.mongodb; 020 021import static org.apache.commons.lang3.StringUtils.defaultString; 022 023import java.time.Duration; 024import java.util.HashMap; 025import java.util.Map; 026 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeMap; 029import org.nuxeo.common.xmap.annotation.XObject; 030import org.nuxeo.runtime.model.Descriptor; 031 032/** 033 * Descriptor to retrieve connection information to MongoDB. 034 * 035 * @since 9.1 036 */ 037@XObject("connection") 038public class MongoDBConnectionConfig implements Descriptor { 039 040 @XNode("@id") 041 public String id; 042 043 @XNode("server") 044 public String server; 045 046 /** @since 10.3 */ 047 @XNode("ssl") 048 public Boolean ssl; 049 050 /** @since 10.3 */ 051 @XNode("trustStorePath") 052 public String trustStorePath; 053 054 /** @since 10.3 */ 055 @XNode("trustStorePassword") 056 public String trustStorePassword; 057 058 /** @since 10.3 */ 059 @XNode("trustStoreType") 060 public String trustStoreType; 061 062 /** @since 10.3 */ 063 @XNode("keyStorePath") 064 public String keyStorePath; 065 066 /** @since 10.3 */ 067 @XNode("keyStorePassword") 068 public String keyStorePassword; 069 070 /** @since 10.3 */ 071 @XNode("keyStoreType") 072 public String keyStoreType; 073 074 @XNode("dbname") 075 public String dbname; 076 077 /** @since 11.1 */ 078 @XNode("maxTime") 079 public Duration maxTime; 080 081 @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class) 082 public Map<String, String> properties = new HashMap<>(); 083 084 @Override 085 public String getId() { 086 return id; 087 } 088 089 @Override 090 public MongoDBConnectionConfig merge(Descriptor o) { 091 MongoDBConnectionConfig other = (MongoDBConnectionConfig) o; 092 MongoDBConnectionConfig merged = new MongoDBConnectionConfig(); 093 merged.id = id; 094 merged.server = defaultString(other.server, server); 095 merged.ssl = other.ssl != null ? other.ssl : ssl; 096 merged.trustStorePath = defaultString(other.trustStorePath, trustStorePath); 097 merged.trustStorePassword = defaultString(other.trustStorePassword, trustStorePassword); 098 merged.trustStoreType = defaultString(other.trustStoreType, trustStoreType); 099 merged.keyStorePath = defaultString(other.keyStorePath, keyStorePath); 100 merged.keyStorePassword = defaultString(other.keyStorePassword, keyStorePassword); 101 merged.keyStoreType = defaultString(other.keyStoreType, keyStoreType); 102 merged.dbname = defaultString(other.dbname, dbname); 103 merged.maxTime = other.maxTime != null ? other.maxTime : maxTime; 104 merged.properties.putAll(properties); 105 merged.properties.putAll(other.properties); 106 return merged; 107 } 108 109}