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 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.core.storage.dbs;
020
021import java.util.ArrayList;
022import java.util.HashSet;
023import java.util.List;
024import java.util.Set;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeList;
028import org.nuxeo.ecm.core.storage.FulltextDescriptor;
029import org.nuxeo.ecm.core.storage.FulltextDescriptor.FulltextIndexDescriptor;
030
031/**
032 * DBS Repository Descriptor.
033 *
034 * @since 7.10-HF04, 8.1
035 */
036public class DBSRepositoryDescriptor implements Cloneable {
037
038    public DBSRepositoryDescriptor() {
039    }
040
041    @XNode("@name")
042    public String name;
043
044    @XNode("@label")
045    public String label;
046
047    @XNode("@isDefault")
048    protected Boolean isDefault;
049
050    public Boolean isDefault() {
051        return isDefault;
052    }
053
054    @XNode("idType")
055    public String idType; // "varchar", "uuid", "sequence"
056
057    protected FulltextDescriptor fulltextDescriptor = new FulltextDescriptor();
058
059    public FulltextDescriptor getFulltextDescriptor() {
060        return fulltextDescriptor;
061    }
062
063    @XNode("fulltext@disabled")
064    public void setFulltextDisabled(boolean disabled) {
065        fulltextDescriptor.setFulltextDisabled(disabled);
066    }
067
068    @XNode("fulltext@searchDisabled")
069    public void setFulltextSearchDisabled(boolean disabled) {
070        fulltextDescriptor.setFulltextSearchDisabled(disabled);
071    }
072
073    @XNode("fulltext@parser")
074    public void setFulltextParser(String fulltextParser) {
075        fulltextDescriptor.setFulltextParser(fulltextParser);
076    }
077
078    @XNodeList(value = "fulltext/index", type = ArrayList.class, componentType = FulltextIndexDescriptor.class)
079    public void setFulltextIndexes(List<FulltextIndexDescriptor> fulltextIndexes) {
080        fulltextDescriptor.setFulltextIndexes(fulltextIndexes);
081    }
082
083    @XNodeList(value = "fulltext/excludedTypes/type", type = HashSet.class, componentType = String.class)
084    public void setFulltextExcludedTypes(Set<String> fulltextExcludedTypes) {
085        fulltextDescriptor.setFulltextExcludedTypes(fulltextExcludedTypes);
086    }
087
088    @XNodeList(value = "fulltext/includedTypes/type", type = HashSet.class, componentType = String.class)
089    public void setFulltextIncludedTypes(Set<String> fulltextIncludedTypes) {
090        fulltextDescriptor.setFulltextIncludedTypes(fulltextIncludedTypes);
091    }
092
093    @Override
094    public DBSRepositoryDescriptor clone() {
095        try {
096            DBSRepositoryDescriptor clone = (DBSRepositoryDescriptor) super.clone();
097            clone.fulltextDescriptor = new FulltextDescriptor(fulltextDescriptor);
098            return clone;
099        } catch (CloneNotSupportedException e) { // cannot happen
100            throw new RuntimeException(e);
101        }
102    }
103
104    public void merge(DBSRepositoryDescriptor other) {
105        if (other.name != null) {
106            name = other.name;
107        }
108        if (other.label != null) {
109            label = other.label;
110        }
111        if (other.isDefault != null) {
112            isDefault = other.isDefault;
113        }
114        if (other.idType != null) {
115            idType = other.idType;
116        }
117        fulltextDescriptor.merge(other.fulltextDescriptor);
118    }
119
120}