001package org.nuxeo.box.api.marshalling.dao;
002
003import org.nuxeo.box.api.marshalling.interfaces.IBoxType;
004
005import java.util.HashMap;
006import java.util.Locale;
007import java.util.Map;
008
009/**
010 * Type of resources that can be requested by API's.
011 */
012public enum BoxResourceType implements IBoxType {
013    /**
014     * An item, which could be a file, a folder, a weblink...
015     */
016    ITEM,
017    /**
018     * A plural format of {@link #ITEM}.
019     */
020    ITEMS,
021    /**
022     * A box file.
023     */
024    FILE,
025    /**
026     * A plural format of {@link #FILE}.
027     */
028    FILES,
029    /**
030     * A box weblink.
031     */
032    WEB_LINK,
033    /**
034     * A plural format of {@link #WEB_LINK}.
035     */
036    WEB_LINKS,
037    /**
038     * Preview of a file.
039     */
040    PREVIEW,
041    /**
042     * A box folder.
043     */
044    FOLDER,
045    /**
046     * A box user.
047     */
048    USER,
049    /**
050     * A plural format of {@link #USER}.
051     */
052    USERS,
053    /**
054     * A group of {@link #GROUP}.
055     */
056    GROUP,
057    /**
058     * A comment.
059     */
060    COMMENT,
061    /**
062     * A plural format of {@link #COMMENT}.
063     */
064    COMMENTS,
065    /**
066     * A version of a file.
067     */
068    FILE_VERSION,
069    /**
070     * A plural format of {@link #FILE_VERSION}.
071     */
072    FILE_VERSIONS,
073    /**
074     * Box's equivalent of access control lists. They can be used to set and apply permissions for users to folders.
075     */
076    COLLABORATION,
077    /**
078     * A plural format of {@link org.nuxeo.box.api.marshalling.dao .BoxResourceType .COLLABORATIONS}.
079     */
080    COLLABORATIONS,
081    /**
082     * An email alias.
083     */
084    EMAIL_ALIAS,
085    /**
086     * A plural format of {@link #EMAIL_ALIAS}.
087     */
088    EMAIL_ALIASES,
089    /**
090     * OAuth data.
091     */
092    OAUTH_DATA,
093    /**
094     * Error.
095     */
096    ERROR,
097    /**
098     * Event.
099     */
100    EVENT,
101    /**
102     * A plural format of {@link #EVENT}.
103     */
104    EVENTS,
105    /**
106     * Updates
107     */
108    UPDATES,
109    /**
110     * Realtime server.
111     */
112    REALTIME_SERVER,
113    /**
114     * File lock (shows up in event stream).
115     */
116    LOCK,
117    /**
118     * Service action is a subtype of file lock.
119     */
120    SERVICE_ACTION,
121    /**
122     * Administrator settings
123     */
124    ADMIN_SETTINGS,
125    /**
126     * Login token
127     */
128    LOGIN_TOKEN;
129
130    // As a performance optimization, set up string values for all types.
131    private static final Map<BoxResourceType, String> typeToLowercaseString = new HashMap<BoxResourceType, String>();
132
133    static {
134        for (BoxResourceType type : values()) {
135            String str = type.name().toLowerCase(Locale.US);
136            typeToLowercaseString.put(type, str);
137        }
138    }
139
140    /**
141     * Get the BoxResourceType from a lower case string value. For example "file" would return BoxResourceType.FILE
142     * Deprecated, use getTypeFromLowercaseString method in IBoxResourceHub instead.
143     *
144     * @param string
145     * @return
146     */
147    @Deprecated
148    public static BoxResourceType getTypeFromLowercaseString(final String string) {
149        return Enum.valueOf(BoxResourceType.class, string.toUpperCase(Locale.US));
150    }
151
152    @Override
153    public String toString() {
154        return typeToLowercaseString.get(this);
155    }
156
157    /**
158     * Get the String representing plural format of a resource.
159     *
160     * @return the String representing plural format of a resource
161     */
162    public String toPluralString() {
163        return toString() + "s";
164    }
165}