/portal-impl/src/com/liferay/portlet/asset/model/adapter/impl/StagedAssetLinkImpl.java

http://github.com/liferay/liferay-portal · Java · 443 lines · 331 code · 96 blank · 16 comment · 13 complexity · 552de941d9b78b9aeff0ac9d27c57c87 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.portlet.asset.model.adapter.impl;
  15. import com.liferay.asset.kernel.model.AssetEntry;
  16. import com.liferay.asset.kernel.model.AssetLink;
  17. import com.liferay.asset.kernel.model.adapter.StagedAssetLink;
  18. import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
  19. import com.liferay.expando.kernel.model.ExpandoBridge;
  20. import com.liferay.exportimport.kernel.lar.StagedModelType;
  21. import com.liferay.petra.string.StringPool;
  22. import com.liferay.portal.kernel.model.BaseModel;
  23. import com.liferay.portal.kernel.model.CacheModel;
  24. import com.liferay.portal.kernel.service.ServiceContext;
  25. import com.liferay.portal.kernel.util.Validator;
  26. import java.io.Serializable;
  27. import java.util.Date;
  28. import java.util.Map;
  29. /**
  30. * @author Máté Thurzó
  31. */
  32. public class StagedAssetLinkImpl implements StagedAssetLink {
  33. public StagedAssetLinkImpl() {
  34. }
  35. public StagedAssetLinkImpl(AssetLink assetLink) {
  36. _assetLink = assetLink;
  37. populateEntry1Attributes();
  38. populateEntry2Attributes();
  39. populateUuid();
  40. }
  41. @Override
  42. public Object clone() {
  43. return new StagedAssetLinkImpl(_assetLink);
  44. }
  45. @Override
  46. public int compareTo(AssetLink assetLink) {
  47. return _assetLink.compareTo(assetLink);
  48. }
  49. @Override
  50. public long getCompanyId() {
  51. return _assetLink.getCompanyId();
  52. }
  53. @Override
  54. public Date getCreateDate() {
  55. return _assetLink.getCreateDate();
  56. }
  57. @Override
  58. public long getCtCollectionId() {
  59. return _assetLink.getCtCollectionId();
  60. }
  61. @Override
  62. public String getEntry1ClassName() {
  63. if (Validator.isNotNull(_entry1ClassName)) {
  64. return _entry1ClassName;
  65. }
  66. populateEntry1Attributes();
  67. return _entry1ClassName;
  68. }
  69. @Override
  70. public String getEntry1Uuid() {
  71. if (Validator.isNotNull(_entry1Uuid)) {
  72. return _entry1Uuid;
  73. }
  74. populateEntry1Attributes();
  75. return _entry1Uuid;
  76. }
  77. @Override
  78. public String getEntry2ClassName() {
  79. if (Validator.isNotNull(_entry2ClassName)) {
  80. return _entry2ClassName;
  81. }
  82. populateEntry2Attributes();
  83. return _entry2ClassName;
  84. }
  85. @Override
  86. public String getEntry2Uuid() {
  87. if (Validator.isNotNull(_entry2Uuid)) {
  88. return _entry2Uuid;
  89. }
  90. populateEntry2Attributes();
  91. return _entry2Uuid;
  92. }
  93. @Override
  94. public long getEntryId1() {
  95. return _assetLink.getEntryId1();
  96. }
  97. @Override
  98. public long getEntryId2() {
  99. return _assetLink.getEntryId2();
  100. }
  101. @Override
  102. public ExpandoBridge getExpandoBridge() {
  103. return _assetLink.getExpandoBridge();
  104. }
  105. @Override
  106. public long getLinkId() {
  107. return _assetLink.getLinkId();
  108. }
  109. @Override
  110. public Map<String, Object> getModelAttributes() {
  111. return _assetLink.getModelAttributes();
  112. }
  113. @Override
  114. public Class<?> getModelClass() {
  115. return _assetLink.getModelClass();
  116. }
  117. @Override
  118. public String getModelClassName() {
  119. return _assetLink.getModelClassName();
  120. }
  121. @Override
  122. public Date getModifiedDate() {
  123. return _assetLink.getCreateDate();
  124. }
  125. @Override
  126. public long getMvccVersion() {
  127. return _assetLink.getMvccVersion();
  128. }
  129. @Override
  130. public long getPrimaryKey() {
  131. return _assetLink.getPrimaryKey();
  132. }
  133. @Override
  134. public Serializable getPrimaryKeyObj() {
  135. return _assetLink.getPrimaryKeyObj();
  136. }
  137. @Override
  138. public StagedModelType getStagedModelType() {
  139. return new StagedModelType(StagedAssetLink.class);
  140. }
  141. @Override
  142. public int getType() {
  143. return _assetLink.getType();
  144. }
  145. @Override
  146. public long getUserId() {
  147. return _assetLink.getUserId();
  148. }
  149. @Override
  150. public String getUserName() {
  151. return _assetLink.getUserName();
  152. }
  153. @Override
  154. public String getUserUuid() {
  155. return _assetLink.getUserUuid();
  156. }
  157. @Override
  158. public String getUuid() {
  159. if (Validator.isNotNull(_uuid)) {
  160. return _uuid;
  161. }
  162. populateUuid();
  163. return _uuid;
  164. }
  165. @Override
  166. public int getWeight() {
  167. return _assetLink.getWeight();
  168. }
  169. @Override
  170. public boolean isCachedModel() {
  171. return false;
  172. }
  173. @Override
  174. public boolean isEntityCacheEnabled() {
  175. return false;
  176. }
  177. @Override
  178. public boolean isEscapedModel() {
  179. return false;
  180. }
  181. @Override
  182. public boolean isFinderCacheEnabled() {
  183. return false;
  184. }
  185. @Override
  186. public boolean isNew() {
  187. return false;
  188. }
  189. @Override
  190. public void persist() {
  191. throw new UnsupportedOperationException();
  192. }
  193. @Override
  194. public void resetOriginalValues() {
  195. throw new UnsupportedOperationException();
  196. }
  197. public void setAssetLink(AssetLink assetLink) {
  198. _assetLink = assetLink;
  199. }
  200. @Override
  201. public void setCachedModel(boolean cachedModel) {
  202. throw new UnsupportedOperationException();
  203. }
  204. @Override
  205. public void setCompanyId(long companyId) {
  206. throw new UnsupportedOperationException();
  207. }
  208. @Override
  209. public void setCreateDate(Date createDate) {
  210. throw new UnsupportedOperationException();
  211. }
  212. @Override
  213. public void setCtCollectionId(long ctCollectionId) {
  214. throw new UnsupportedOperationException();
  215. }
  216. @Override
  217. public void setEntryId1(long entryId1) {
  218. throw new UnsupportedOperationException();
  219. }
  220. @Override
  221. public void setEntryId2(long entryId2) {
  222. throw new UnsupportedOperationException();
  223. }
  224. @Override
  225. public void setExpandoBridgeAttributes(BaseModel<?> baseModel) {
  226. throw new UnsupportedOperationException();
  227. }
  228. @Override
  229. public void setExpandoBridgeAttributes(ExpandoBridge expandoBridge) {
  230. throw new UnsupportedOperationException();
  231. }
  232. @Override
  233. public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
  234. throw new UnsupportedOperationException();
  235. }
  236. @Override
  237. public void setLinkId(long linkId) {
  238. throw new UnsupportedOperationException();
  239. }
  240. @Override
  241. public void setModelAttributes(Map<String, Object> attributes) {
  242. throw new UnsupportedOperationException();
  243. }
  244. @Override
  245. public void setModifiedDate(Date date) {
  246. throw new UnsupportedOperationException();
  247. }
  248. @Override
  249. public void setMvccVersion(long mvccVersion) {
  250. throw new UnsupportedOperationException();
  251. }
  252. @Override
  253. public void setNew(boolean n) {
  254. throw new UnsupportedOperationException();
  255. }
  256. @Override
  257. public void setPrimaryKey(long primaryKey) {
  258. throw new UnsupportedOperationException();
  259. }
  260. @Override
  261. public void setPrimaryKeyObj(Serializable primaryKeyObj) {
  262. throw new UnsupportedOperationException();
  263. }
  264. @Override
  265. public void setType(int type) {
  266. throw new UnsupportedOperationException();
  267. }
  268. @Override
  269. public void setUserId(long userId) {
  270. throw new UnsupportedOperationException();
  271. }
  272. @Override
  273. public void setUserName(String userName) {
  274. throw new UnsupportedOperationException();
  275. }
  276. @Override
  277. public void setUserUuid(String userUuid) {
  278. throw new UnsupportedOperationException();
  279. }
  280. @Override
  281. public void setUuid(String uuid) {
  282. throw new UnsupportedOperationException();
  283. }
  284. @Override
  285. public void setWeight(int weight) {
  286. throw new UnsupportedOperationException();
  287. }
  288. @Override
  289. public CacheModel<AssetLink> toCacheModel() {
  290. return null;
  291. }
  292. @Override
  293. public AssetLink toEscapedModel() {
  294. return null;
  295. }
  296. @Override
  297. public AssetLink toUnescapedModel() {
  298. return null;
  299. }
  300. @Override
  301. public String toXmlString() {
  302. return null;
  303. }
  304. protected void populateEntry1Attributes() {
  305. if (Validator.isNotNull(_entry1ClassName) &&
  306. Validator.isNotNull(_entry1Uuid)) {
  307. return;
  308. }
  309. AssetEntry entry1 = AssetEntryLocalServiceUtil.fetchAssetEntry(
  310. _assetLink.getEntryId1());
  311. if (entry1 == null) {
  312. return;
  313. }
  314. _entry1ClassName = entry1.getClassName();
  315. _entry1Uuid = entry1.getClassUuid();
  316. }
  317. protected void populateEntry2Attributes() {
  318. if (Validator.isNotNull(_entry2ClassName) &&
  319. Validator.isNotNull(_entry2Uuid)) {
  320. return;
  321. }
  322. AssetEntry entry2 = AssetEntryLocalServiceUtil.fetchAssetEntry(
  323. _assetLink.getEntryId2());
  324. if (entry2 == null) {
  325. return;
  326. }
  327. _entry2ClassName = entry2.getClassName();
  328. _entry2Uuid = entry2.getClassUuid();
  329. }
  330. protected void populateUuid() {
  331. if (Validator.isNotNull(_uuid)) {
  332. return;
  333. }
  334. String entry1Uuid = getEntry1Uuid();
  335. String entry2Uuid = getEntry2Uuid();
  336. if (Validator.isNotNull(entry1Uuid) &&
  337. Validator.isNotNull(entry2Uuid)) {
  338. _uuid = entry1Uuid + StringPool.POUND + entry2Uuid;
  339. }
  340. }
  341. private AssetLink _assetLink;
  342. private String _entry1ClassName;
  343. private String _entry1Uuid;
  344. private String _entry2ClassName;
  345. private String _entry2Uuid;
  346. private String _uuid;
  347. }