001/*
002 * (C) Copyright 2016 Nuxeo SA (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.ecm.core.storage.marklogic;
020
021import java.util.ArrayList;
022import java.util.List;
023import java.util.stream.Collectors;
024
025import org.nuxeo.common.xmap.annotation.XNode;
026import org.nuxeo.common.xmap.annotation.XNodeList;
027import org.nuxeo.common.xmap.annotation.XObject;
028import org.nuxeo.ecm.core.storage.dbs.DBSRepositoryDescriptor;
029
030/**
031 * MarkLogic Repository Descriptor.
032 *
033 * @since 8.3
034 */
035@XObject(value = "repository")
036public class MarkLogicRepositoryDescriptor extends DBSRepositoryDescriptor {
037
038    public MarkLogicRepositoryDescriptor() {
039    }
040
041    @XNode("host")
042    public String host;
043
044    @XNode("port")
045    public Integer port;
046
047    @XNode("user")
048    public String user;
049
050    @XNode("password")
051    public String password;
052
053    @XNode("dbname")
054    public String dbname;
055
056    @XNodeList(value = "range-element-indexes/range-element-index", type = ArrayList.class, componentType = MarkLogicRangeElementIndexDescriptor.class)
057    public List<MarkLogicRangeElementIndexDescriptor> rangeElementIndexes = new ArrayList<>(0);
058
059    @Override
060    public MarkLogicRepositoryDescriptor clone() {
061        MarkLogicRepositoryDescriptor clone = (MarkLogicRepositoryDescriptor) super.clone();
062        clone.rangeElementIndexes = rangeElementIndexes.stream().map(MarkLogicRangeElementIndexDescriptor::new).collect(
063                Collectors.toList());
064        return clone;
065    }
066
067    public void merge(MarkLogicRepositoryDescriptor other) {
068        super.merge(other);
069        if (other.host != null) {
070            host = other.host;
071        }
072        if (other.port != null) {
073            port = other.port;
074        }
075        if (other.password != null) {
076            password = other.password;
077        }
078        if (other.dbname != null) {
079            dbname = other.dbname;
080        }
081        for (MarkLogicRangeElementIndexDescriptor regi : other.rangeElementIndexes) {
082            rangeElementIndexes.add(new MarkLogicRangeElementIndexDescriptor(regi));
083        }
084    }
085
086}