001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.model;
016    
017    /**
018     * <p>
019     * This contains several utility methods for the purpose of determining folder
020     * IDs and data repository IDs as used by back-end data systems like search and
021     * Document Library stores. These repository IDs should not be confused with the
022     * repository ID used by {@link
023     * com.liferay.portal.service.impl.RepositoryServiceImpl}.
024     * </p>
025     *
026     * @author Samuel Kong
027     * @author Alexander Chow
028     */
029    public class DLFolderConstants {
030    
031            public static final long DEFAULT_PARENT_FOLDER_ID = 0;
032    
033            public static String getClassName() {
034                    return DLFolder.class.getName();
035            }
036    
037            /**
038             * Determine the data repository ID from the group ID and folder ID. The
039             * folder ID may be zero, implying that it is the root folder for the given
040             * group.
041             */
042            public static long getDataRepositoryId(long groupId, long folderId) {
043                    if (folderId != DEFAULT_PARENT_FOLDER_ID) {
044                            return folderId;
045                    }
046                    else {
047                            return groupId;
048                    }
049            }
050    
051            /**
052             * Determine the folder ID when no knowledge of it currently exists.
053             */
054            public static long getFolderId(long groupId, long dataRepositoryId) {
055                    if (groupId != dataRepositoryId) {
056                            return dataRepositoryId;
057                    }
058                    else {
059                            return DEFAULT_PARENT_FOLDER_ID;
060                    }
061            }
062    
063    }