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_3_0.util;
21  
22  import com.liferay.documentlibrary.service.DLLocalServiceUtil;
23  import com.liferay.documentlibrary.service.DLServiceUtil;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.model.CompanyConstants;
27  import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
28  import com.liferay.portal.upgrade.util.UpgradeColumn;
29  
30  /**
31   * <a href="MBMessageAttachmentsUpgradeColumnImpl.java.html"><b><i>View Source
32   * </i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class MBMessageAttachmentsUpgradeColumnImpl
38      extends BaseUpgradeColumnImpl {
39  
40      public MBMessageAttachmentsUpgradeColumnImpl(
41          UpgradeColumn messageIdColumn, UpgradeColumn companyIdColumn,
42          UpgradeColumn threadIdColumn) {
43  
44          super("attachments");
45  
46          _messageIdColumn = messageIdColumn;
47          _companyIdColumn = companyIdColumn;
48          _threadIdColumn = threadIdColumn;
49      }
50  
51      public Object getNewValue(Object oldValue) throws Exception {
52          Boolean attachments = (Boolean)oldValue;
53  
54          if (attachments.booleanValue()) {
55              Long oldMessageId = (Long)_messageIdColumn.getOldValue();
56              String oldCompanyId = (String)_companyIdColumn.getOldValue();
57              Long oldThreadId = (Long)_threadIdColumn.getOldValue();
58  
59              Long newMessageId = (Long)_messageIdColumn.getNewValue();
60              Long newCompanyId = (Long)_companyIdColumn.getNewValue();
61              Long newThreadId = (Long)_threadIdColumn.getNewValue();
62  
63              try {
64                  DLServiceUtil.addDirectory(
65                      newCompanyId.longValue(), CompanyConstants.SYSTEM,
66                      "messageboards/" + newThreadId);
67  
68                  DLLocalServiceUtil.move(
69                      "/" + oldCompanyId +
70                          "/documentlibrary/system/messageboards/" + oldThreadId +
71                              "/" + oldMessageId,
72                      "/" + newCompanyId + "/documentlibrary/0/messageboards/" +
73                          newThreadId + "/" + newMessageId);
74              }
75              catch (Exception e) {
76                  _log.error(e.getMessage());
77              }
78          }
79  
80          return attachments;
81      }
82  
83      private static Log _log =
84          LogFactoryUtil.getLog(MBMessageAttachmentsUpgradeColumnImpl.class);
85  
86      private UpgradeColumn _messageIdColumn;
87      private UpgradeColumn _companyIdColumn;
88      private UpgradeColumn _threadIdColumn;
89  
90  }