001/*
002 * (C) Copyright 2015 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.blob;
020
021import java.util.HashMap;
022import java.util.Map;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeMap;
026import org.nuxeo.common.xmap.annotation.XObject;
027
028/**
029 * Descriptor for a {@link BlobProvider}.
030 */
031@XObject(value = "blobprovider")
032public class BlobProviderDescriptor {
033
034    public static final String PREVENT_USER_UPDATE = "preventUserUpdate";
035
036    /**
037     * An optional namespace that may be used to disambiguate otherwise similar descriptors (in particular, copies).
038     *
039     * @since 10.10
040     */
041    public static final String NAMESPACE = "namespace";
042
043    /**
044     * Flags this blob provider as transient: blobs may disappear after a while, so a caller should not rely on them
045     * being available forever.
046     *
047     * @since 10.1
048     */
049    public static final String TRANSIENT = "transient";
050
051    /**
052     * Flags this blob provider as using "record mode".
053     * <p>
054     * Record mode has the following characteristics:
055     * <ul>
056     * <li>transactional (blobs aren't actually written/deleted until the transaction commits, and transaction rollback
057     * is possible),
058     * <li>can replace or delete a document's blob.
059     * </ul>
060     *
061     * @since 11.1
062     */
063    public static final String RECORD = "record";
064
065    /**
066     * Flags this blob provider as transactional.
067     * <p>
068     * A transactional blob provider only writes blobs to final storage at commit time.
069     *
070     * @since 11.1
071     */
072    public static final String TRANSACTIONAL = "transactional";
073
074    /**
075     * Flags this blob provider as allowing internal queries with keys containing a byte range.
076     *
077     * @since 11.1
078     */
079    public static final String ALLOW_BYTE_RANGE = "allowByteRange";
080
081    /**
082     * A comma-separated list of users that can create blobs in this blob provider based only on a key.
083     *
084     * @since 10.2
085     */
086    public static final String CREATE_FROM_KEY_USERS = "createFromKey.users";
087
088    /**
089     * A comma-separated list of groups that can create blobs in this blob provider based only on a key.
090     *
091     * @since 10.2
092     */
093    public static final String CREATE_FROM_KEY_GROUPS = "createFromKey.groups";
094
095    @XNode("@name")
096    public String name = "";
097
098    @XNode("class")
099    public Class<?> klass;
100
101    @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class)
102    public Map<String, String> properties = new HashMap<>();
103
104    public BlobProviderDescriptor() {
105    }
106
107    /** Copy constructor. */
108    public BlobProviderDescriptor(BlobProviderDescriptor other) {
109        name = other.name;
110        klass = other.klass;
111        properties = new HashMap<>(other.properties);
112    }
113
114    public void merge(BlobProviderDescriptor other) {
115        if (other.name != null) {
116            name = other.name;
117        }
118        if (other.klass != null) {
119            klass = other.klass;
120        }
121        properties.putAll(other.properties);
122    }
123
124}