001    /**
002     * Copyright (c) 2000-2010 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.portal.upgrade.v4_3_0.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
018    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
019    import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
020    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
021    import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
022    
023    import java.sql.Types;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class JournalArticlePKUpgradeColumnImpl extends PKUpgradeColumnImpl {
029    
030            public JournalArticlePKUpgradeColumnImpl(
031                    UpgradeColumn companyIdColumn, UpgradeColumn groupIdColumn) {
032    
033                    super("id_", new Integer(Types.VARCHAR), false);
034    
035                    _companyIdColumn = companyIdColumn;
036                    _groupIdColumn = groupIdColumn;
037                    _journalArticleIdMapper = ValueMapperFactoryUtil.getValueMapper();
038            }
039    
040            public Object getNewValue(Object oldValue) throws Exception {
041                    _resourcePrimKey = null;
042    
043                    Object newValue = super.getNewValue(oldValue);
044    
045                    String companyId = (String)_companyIdColumn.getOldValue();
046                    Long oldGroupId = (Long)_groupIdColumn.getOldValue();
047                    Long newGroupId = (Long)_groupIdColumn.getNewValue();
048                    String articleId = (String)oldValue;
049    
050                    String oldIdValue =
051                            "{companyId=" + companyId + ", groupId=" + oldGroupId +
052                                    ", articleId=" + articleId + ", version=1.0}";
053    
054                    _resourcePrimKey = new Long(JournalArticleResourceLocalServiceUtil.
055                            getArticleResourcePrimKey(newGroupId.longValue(), articleId));
056    
057                    _journalArticleIdMapper.mapValue(oldIdValue, _resourcePrimKey);
058    
059                    return newValue;
060            }
061    
062            public ValueMapper getValueMapper() {
063                    return _journalArticleIdMapper;
064            }
065    
066            public Long getResourcePrimKey() {
067                    return _resourcePrimKey;
068            }
069    
070            private UpgradeColumn _companyIdColumn;
071            private UpgradeColumn _groupIdColumn;
072            private ValueMapper _journalArticleIdMapper;
073            private Long _resourcePrimKey;
074    
075    }