1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.upgrade.v4_4_0;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.upgrade.UpgradeException;
25  import com.liferay.portal.upgrade.UpgradeProcess;
26  import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
27  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
28  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
29  import com.liferay.portal.upgrade.util.UpgradeColumn;
30  import com.liferay.portal.upgrade.util.UpgradeTable;
31  import com.liferay.portal.upgrade.v4_4_0.util.DLFileEntryTitleColumnImpl;
32  import com.liferay.portal.upgrade.v4_4_0.util.DLFolderNameColumnImpl;
33  import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryModelImpl;
34  import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
35  
36  import java.util.Set;
37  
38  /**
39   * <a href="UpgradeDocumentLibrary.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Alexander Chow
42   *
43   */
44  public class UpgradeDocumentLibrary extends UpgradeProcess {
45  
46      public void upgrade() throws UpgradeException {
47          _log.info("Upgrading");
48  
49          try {
50              doUpgrade();
51          }
52          catch (Exception e) {
53              throw new UpgradeException(e);
54          }
55      }
56  
57      protected void doUpgrade() throws Exception {
58  
59          // DLFolder
60  
61          UpgradeColumn groupIdColumn = new TempUpgradeColumnImpl("groupId");
62  
63          UpgradeColumn parentFolderIdColumn = new TempUpgradeColumnImpl(
64              "parentFolderId");
65  
66          DLFolderNameColumnImpl dlFolderNameColumn = new DLFolderNameColumnImpl(
67              groupIdColumn, parentFolderIdColumn);
68  
69          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
70              DLFolderModelImpl.TABLE_NAME, DLFolderModelImpl.TABLE_COLUMNS,
71              groupIdColumn, parentFolderIdColumn, dlFolderNameColumn);
72  
73          upgradeTable.updateTable();
74  
75          Set<String> distinctNames = dlFolderNameColumn.getDistintNames();
76  
77          // DLFileEntry
78  
79          UpgradeColumn folderIdColumn = new TempUpgradeColumnImpl("folderId");
80  
81          UpgradeColumn nameColumn = new TempUpgradeColumnImpl("name");
82  
83          BaseUpgradeColumnImpl dlFileEntryTitleColumn =
84              new DLFileEntryTitleColumnImpl(
85                  groupIdColumn, folderIdColumn, nameColumn, distinctNames);
86  
87          upgradeTable = new DefaultUpgradeTableImpl(
88              DLFileEntryModelImpl.TABLE_NAME, DLFileEntryModelImpl.TABLE_COLUMNS,
89              folderIdColumn, nameColumn, dlFileEntryTitleColumn);
90  
91          upgradeTable.updateTable();
92      }
93  
94      private static Log _log =
95          LogFactoryUtil.getLog(UpgradeDocumentLibrary.class);
96  
97  }