001    /**
002     * Copyright (c) 2000-2013 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.portlet.social.model.impl;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.json.JSONException;
019    import com.liferay.portal.kernel.json.JSONFactoryUtil;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portlet.asset.model.AssetEntry;
023    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Zsolt Berentey
028     */
029    public class SocialActivityImpl extends SocialActivityBaseImpl {
030    
031            public AssetEntry getAssetEntry() throws SystemException {
032                    if ((_assetEntry == null) && Validator.isNotNull(getClassName()) &&
033                            (getClassPK() > 0)) {
034    
035                            _assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
036                                    getClassName(), getClassPK());
037                    }
038    
039                    return _assetEntry;
040            }
041    
042            public String getExtraDataValue(String key) throws JSONException {
043                    if (_extraDataJSONObject == null) {
044                            _extraDataJSONObject = JSONFactoryUtil.createJSONObject(
045                                    getExtraData());
046                    }
047    
048                    return _extraDataJSONObject.getString(key);
049            }
050    
051            public boolean isClassName(String className) {
052                    if (className == null) {
053                            return false;
054                    }
055    
056                    return className.equals(getClassName());
057            }
058    
059            public void setAssetEntry(AssetEntry assetEntry) {
060                    _assetEntry = assetEntry;
061            }
062    
063            @Override
064            public void setExtraData(String extraData) {
065                    _extraDataJSONObject = null;
066    
067                    super.setExtraData(extraData);
068            }
069    
070            private AssetEntry _assetEntry;
071            private JSONObject _extraDataJSONObject;
072    
073    }