001
014
015 package com.liferay.portlet.asset.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.ListUtil;
020 import com.liferay.portal.kernel.util.StringUtil;
021 import com.liferay.portlet.asset.model.AssetCategory;
022 import com.liferay.portlet.asset.model.AssetEntry;
023 import com.liferay.portlet.asset.model.AssetTag;
024 import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
025 import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
026 import com.liferay.portlet.social.model.SocialEquityAssetEntry;
027 import com.liferay.portlet.social.model.SocialEquityValue;
028 import com.liferay.portlet.social.service.persistence.SocialEquityAssetEntryUtil;
029
030 import java.util.List;
031 import java.util.concurrent.atomic.AtomicReference;
032
033
036 public class AssetEntryImpl extends AssetEntryModelImpl implements AssetEntry {
037
038 public AssetEntryImpl() {
039 }
040
041 public List<AssetCategory> getCategories() throws SystemException {
042 return AssetCategoryLocalServiceUtil.getEntryCategories(getEntryId());
043 }
044
045 public long[] getCategoryIds() throws SystemException {
046 return StringUtil.split(
047 ListUtil.toString(getCategories(), "categoryId"), 0L);
048 }
049
050 public double getSocialInformationEquity() {
051 if (_socialInformationEquity == null) {
052 try {
053 SocialEquityAssetEntry equityAssetEntry =
054 SocialEquityAssetEntryUtil.findByAssetEntryId(
055 getEntryId());
056
057 SocialEquityValue socialEquityValue = new SocialEquityValue(
058 equityAssetEntry.getInformationK(),
059 equityAssetEntry.getInformationB());
060
061 _socialInformationEquity = new AtomicReference<Double>(
062 socialEquityValue.getValue());
063 }
064 catch (PortalException pe) {
065 return 0;
066 }
067 catch (SystemException se) {
068 return 0;
069 }
070 }
071
072 return _socialInformationEquity.get();
073 }
074
075 public String[] getTagNames() throws SystemException {
076 return StringUtil.split(ListUtil.toString(getTags(), "name"));
077 }
078
079 public List<AssetTag> getTags() throws SystemException {
080 return AssetTagLocalServiceUtil.getEntryTags(getEntryId());
081 }
082
083 public void updateSocialInformationEquity(double value) {
084 if (_socialInformationEquity != null) {
085 double currentValue = 0;
086 double newValue = 0;
087
088 do {
089 currentValue = _socialInformationEquity.get();
090
091 newValue = currentValue + value;
092
093 }
094 while (!_socialInformationEquity.compareAndSet(
095 currentValue, newValue));
096 }
097 }
098
099 private AtomicReference<Double> _socialInformationEquity = null;
100
101 }