1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade.v4_3_0.util;
24  
25  import com.liferay.documentlibrary.service.DLLocalServiceUtil;
26  import com.liferay.documentlibrary.service.DLServiceUtil;
27  import com.liferay.portal.kernel.log.Log;
28  import com.liferay.portal.kernel.log.LogFactoryUtil;
29  import com.liferay.portal.model.CompanyConstants;
30  import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
31  import com.liferay.portal.upgrade.util.UpgradeColumn;
32  
33  /**
34   * <a href="MBMessageAttachmentsUpgradeColumnImpl.java.html"><b><i>View Source
35   * </i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   */
39  public class MBMessageAttachmentsUpgradeColumnImpl
40      extends BaseUpgradeColumnImpl {
41  
42      public MBMessageAttachmentsUpgradeColumnImpl(
43          UpgradeColumn messageIdColumn, UpgradeColumn companyIdColumn,
44          UpgradeColumn threadIdColumn) {
45  
46          super("attachments");
47  
48          _messageIdColumn = messageIdColumn;
49          _companyIdColumn = companyIdColumn;
50          _threadIdColumn = threadIdColumn;
51      }
52  
53      public Object getNewValue(Object oldValue) throws Exception {
54          Boolean attachments = (Boolean)oldValue;
55  
56          if (attachments.booleanValue()) {
57              Long oldMessageId = (Long)_messageIdColumn.getOldValue();
58              String oldCompanyId = (String)_companyIdColumn.getOldValue();
59              Long oldThreadId = (Long)_threadIdColumn.getOldValue();
60  
61              Long newMessageId = (Long)_messageIdColumn.getNewValue();
62              Long newCompanyId = (Long)_companyIdColumn.getNewValue();
63              Long newThreadId = (Long)_threadIdColumn.getNewValue();
64  
65              try {
66                  DLServiceUtil.addDirectory(
67                      newCompanyId.longValue(), CompanyConstants.SYSTEM,
68                      "messageboards/" + newThreadId);
69  
70                  DLLocalServiceUtil.move(
71                      "/" + oldCompanyId +
72                          "/documentlibrary/system/messageboards/" + oldThreadId +
73                              "/" + oldMessageId,
74                      "/" + newCompanyId + "/documentlibrary/0/messageboards/" +
75                          newThreadId + "/" + newMessageId);
76              }
77              catch (Exception e) {
78                  _log.error(e.getMessage());
79              }
80          }
81  
82          return attachments;
83      }
84  
85      private static Log _log =
86          LogFactoryUtil.getLog(MBMessageAttachmentsUpgradeColumnImpl.class);
87  
88      private UpgradeColumn _messageIdColumn;
89      private UpgradeColumn _companyIdColumn;
90      private UpgradeColumn _threadIdColumn;
91  
92  }