1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0.util;
16  
17  import com.liferay.documentlibrary.service.DLLocalServiceUtil;
18  import com.liferay.documentlibrary.service.DLServiceUtil;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
22  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
23  import com.liferay.portal.model.CompanyConstants;
24  
25  /**
26   * <a href="MBMessageAttachmentsUpgradeColumnImpl.java.html"><b><i>View Source
27   * </i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class MBMessageAttachmentsUpgradeColumnImpl
32      extends BaseUpgradeColumnImpl {
33  
34      public MBMessageAttachmentsUpgradeColumnImpl(
35          UpgradeColumn messageIdColumn, UpgradeColumn companyIdColumn,
36          UpgradeColumn threadIdColumn) {
37  
38          super("attachments");
39  
40          _messageIdColumn = messageIdColumn;
41          _companyIdColumn = companyIdColumn;
42          _threadIdColumn = threadIdColumn;
43      }
44  
45      public Object getNewValue(Object oldValue) throws Exception {
46          Boolean attachments = (Boolean)oldValue;
47  
48          if (attachments.booleanValue()) {
49              Long oldMessageId = (Long)_messageIdColumn.getOldValue();
50              String oldCompanyId = (String)_companyIdColumn.getOldValue();
51              Long oldThreadId = (Long)_threadIdColumn.getOldValue();
52  
53              Long newMessageId = (Long)_messageIdColumn.getNewValue();
54              Long newCompanyId = (Long)_companyIdColumn.getNewValue();
55              Long newThreadId = (Long)_threadIdColumn.getNewValue();
56  
57              try {
58                  DLServiceUtil.addDirectory(
59                      newCompanyId.longValue(), CompanyConstants.SYSTEM,
60                      "messageboards/" + newThreadId);
61  
62                  DLLocalServiceUtil.move(
63                      "/" + oldCompanyId +
64                          "/documentlibrary/system/messageboards/" + oldThreadId +
65                              "/" + oldMessageId,
66                      "/" + newCompanyId + "/documentlibrary/0/messageboards/" +
67                          newThreadId + "/" + newMessageId);
68              }
69              catch (Exception e) {
70                  _log.error(e.getMessage());
71              }
72          }
73  
74          return attachments;
75      }
76  
77      private static Log _log = LogFactoryUtil.getLog(
78          MBMessageAttachmentsUpgradeColumnImpl.class);
79  
80      private UpgradeColumn _messageIdColumn;
81      private UpgradeColumn _companyIdColumn;
82      private UpgradeColumn _threadIdColumn;
83  
84  }