001    /**
002     * Copyright (c) 2000-present 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.asset.model.adapter.impl;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.model.BaseModel;
020    import com.liferay.portal.model.CacheModel;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.asset.model.AssetEntry;
023    import com.liferay.portlet.asset.model.AssetLink;
024    import com.liferay.portlet.asset.model.adapter.StagedAssetLink;
025    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
026    import com.liferay.portlet.expando.model.ExpandoBridge;
027    import com.liferay.portlet.exportimport.lar.StagedModelType;
028    
029    import java.io.Serializable;
030    
031    import java.util.Date;
032    import java.util.Map;
033    
034    /**
035     * @author Mate Thurzo
036     */
037    public class StagedAssetLinkImpl implements StagedAssetLink {
038    
039            public StagedAssetLinkImpl() {
040            }
041    
042            public StagedAssetLinkImpl(AssetLink assetLink) {
043                    _assetLink = assetLink;
044    
045                    populateEntry1Attributes();
046                    populateEntry2Attributes();
047    
048                    populateUuid();
049            }
050    
051            @Override
052            public Object clone() {
053                    return new StagedAssetLinkImpl(_assetLink);
054            }
055    
056            @Override
057            public int compareTo(AssetLink assetLink) {
058                    return _assetLink.compareTo(assetLink);
059            }
060    
061            @Override
062            public long getCompanyId() {
063                    return _assetLink.getCompanyId();
064            }
065    
066            @Override
067            public Date getCreateDate() {
068                    return _assetLink.getCreateDate();
069            }
070    
071            @Override
072            public String getEntry1ClassName() {
073                    if (Validator.isNotNull(_entry1ClassName)) {
074                            return _entry1ClassName;
075                    }
076    
077                    populateEntry1Attributes();
078    
079                    return _entry1ClassName;
080            }
081    
082            @Override
083            public String getEntry1Uuid() {
084                    if (Validator.isNotNull(_entry1Uuid)) {
085                            return _entry1Uuid;
086                    }
087    
088                    populateEntry1Attributes();
089    
090                    return _entry1Uuid;
091            }
092    
093            @Override
094            public String getEntry2ClassName() {
095                    if (Validator.isNotNull(_entry2ClassName)) {
096                            return _entry2ClassName;
097                    }
098    
099                    populateEntry2Attributes();
100    
101                    return _entry2ClassName;
102            }
103    
104            @Override
105            public String getEntry2Uuid() {
106                    if (Validator.isNotNull(_entry2Uuid)) {
107                            return _entry2Uuid;
108                    }
109    
110                    populateEntry2Attributes();
111    
112                    return _entry2Uuid;
113            }
114    
115            @Override
116            public long getEntryId1() {
117                    return _assetLink.getEntryId1();
118            }
119    
120            @Override
121            public long getEntryId2() {
122                    return _assetLink.getEntryId2();
123            }
124    
125            @Override
126            public ExpandoBridge getExpandoBridge() {
127                    return _assetLink.getExpandoBridge();
128            }
129    
130            @Override
131            public long getLinkId() {
132                    return _assetLink.getLinkId();
133            }
134    
135            @Override
136            public Map<String, Object> getModelAttributes() {
137                    return _assetLink.getModelAttributes();
138            }
139    
140            @Override
141            public Class<?> getModelClass() {
142                    return StagedAssetLink.class;
143            }
144    
145            @Override
146            public String getModelClassName() {
147                    return StagedAssetLink.class.getName();
148            }
149    
150            @Override
151            public Date getModifiedDate() {
152                    return _assetLink.getCreateDate();
153            }
154    
155            @Override
156            public long getPrimaryKey() {
157                    return _assetLink.getPrimaryKey();
158            }
159    
160            @Override
161            public Serializable getPrimaryKeyObj() {
162                    return _assetLink.getPrimaryKeyObj();
163            }
164    
165            @Override
166            public StagedModelType getStagedModelType() {
167                    return new StagedModelType(StagedAssetLink.class);
168            }
169    
170            @Override
171            public int getType() {
172                    return _assetLink.getType();
173            }
174    
175            @Override
176            public long getUserId() {
177                    return _assetLink.getUserId();
178            }
179    
180            @Override
181            public String getUserName() {
182                    return _assetLink.getUserName();
183            }
184    
185            @Override
186            public String getUserUuid() {
187                    return _assetLink.getUserUuid();
188            }
189    
190            @Override
191            public String getUuid() {
192                    if (Validator.isNotNull(_uuid)) {
193                            return _uuid;
194                    }
195    
196                    populateUuid();
197    
198                    return _uuid;
199            }
200    
201            @Override
202            public int getWeight() {
203                    return _assetLink.getWeight();
204            }
205    
206            @Override
207            public boolean isCachedModel() {
208                    return false;
209            }
210    
211            @Override
212            public boolean isEntityCacheEnabled() {
213                    return false;
214            }
215    
216            @Override
217            public boolean isEscapedModel() {
218                    return false;
219            }
220    
221            @Override
222            public boolean isFinderCacheEnabled() {
223                    return false;
224            }
225    
226            @Override
227            public boolean isNew() {
228                    return false;
229            }
230    
231            @Override
232            public void persist() {
233                    throw new UnsupportedOperationException();
234            }
235    
236            @Override
237            public void resetOriginalValues() {
238                    throw new UnsupportedOperationException();
239            }
240    
241            public void setAssetLink(AssetLink assetLink) {
242                    _assetLink = assetLink;
243            }
244    
245            @Override
246            public void setCachedModel(boolean cachedModel) {
247                    throw new UnsupportedOperationException();
248            }
249    
250            @Override
251            public void setCompanyId(long companyId) {
252                    throw new UnsupportedOperationException();
253            }
254    
255            @Override
256            public void setCreateDate(Date createDate) {
257                    throw new UnsupportedOperationException();
258            }
259    
260            @Override
261            public void setEntryId1(long entryId1) {
262                    throw new UnsupportedOperationException();
263            }
264    
265            @Override
266            public void setEntryId2(long entryId2) {
267                    throw new UnsupportedOperationException();
268            }
269    
270            @Override
271            public void setExpandoBridgeAttributes(BaseModel<?> baseModel) {
272                    throw new UnsupportedOperationException();
273            }
274    
275            @Override
276            public void setExpandoBridgeAttributes(ExpandoBridge expandoBridge) {
277                    throw new UnsupportedOperationException();
278            }
279    
280            @Override
281            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
282                    throw new UnsupportedOperationException();
283            }
284    
285            @Override
286            public void setLinkId(long linkId) {
287                    throw new UnsupportedOperationException();
288            }
289    
290            @Override
291            public void setModelAttributes(Map<String, Object> attributes) {
292                    throw new UnsupportedOperationException();
293            }
294    
295            @Override
296            public void setModifiedDate(Date date) {
297                    throw new UnsupportedOperationException();
298            }
299    
300            @Override
301            public void setNew(boolean n) {
302                    throw new UnsupportedOperationException();
303            }
304    
305            @Override
306            public void setPrimaryKey(long primaryKey) {
307                    throw new UnsupportedOperationException();
308            }
309    
310            @Override
311            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
312                    throw new UnsupportedOperationException();
313            }
314    
315            @Override
316            public void setType(int type) {
317                    throw new UnsupportedOperationException();
318            }
319    
320            @Override
321            public void setUserId(long userId) {
322                    throw new UnsupportedOperationException();
323            }
324    
325            @Override
326            public void setUserName(String userName) {
327                    throw new UnsupportedOperationException();
328            }
329    
330            @Override
331            public void setUserUuid(String userUuid) {
332                    throw new UnsupportedOperationException();
333            }
334    
335            @Override
336            public void setUuid(String uuid) {
337                    throw new UnsupportedOperationException();
338            }
339    
340            @Override
341            public void setWeight(int weight) {
342                    throw new UnsupportedOperationException();
343            }
344    
345            @Override
346            public CacheModel<AssetLink> toCacheModel() {
347                    return null;
348            }
349    
350            @Override
351            public AssetLink toEscapedModel() {
352                    return null;
353            }
354    
355            @Override
356            public AssetLink toUnescapedModel() {
357                    return null;
358            }
359    
360            @Override
361            public String toXmlString() {
362                    return null;
363            }
364    
365            protected void populateEntry1Attributes() {
366                    if (Validator.isNotNull(_entry1ClassName) &&
367                            Validator.isNotNull(_entry1Uuid)) {
368    
369                            return;
370                    }
371    
372                    AssetEntry entry1 = AssetEntryLocalServiceUtil.fetchAssetEntry(
373                            _assetLink.getEntryId1());
374    
375                    if (entry1 == null) {
376                            return;
377                    }
378    
379                    _entry1ClassName = entry1.getClassName();
380                    _entry1Uuid = entry1.getClassUuid();
381            }
382    
383            protected void populateEntry2Attributes() {
384                    if (Validator.isNotNull(_entry2ClassName) &&
385                            Validator.isNotNull(_entry2Uuid)) {
386    
387                            return;
388                    }
389    
390                    AssetEntry entry2 = AssetEntryLocalServiceUtil.fetchAssetEntry(
391                            _assetLink.getEntryId2());
392    
393                    if (entry2 == null) {
394                            return;
395                    }
396    
397                    _entry2ClassName = entry2.getClassName();
398                    _entry2Uuid = entry2.getClassUuid();
399            }
400    
401            protected void populateUuid() {
402                    if (Validator.isNotNull(_uuid)) {
403                            return;
404                    }
405    
406                    String entry1Uuid = getEntry1Uuid();
407                    String entry2Uuid = getEntry2Uuid();
408    
409                    if (Validator.isNotNull(entry1Uuid) &&
410                            Validator.isNotNull(entry2Uuid)) {
411    
412                            _uuid = entry1Uuid + StringPool.POUND + entry2Uuid;
413                    }
414            }
415    
416            private AssetLink _assetLink;
417            private String _entry1ClassName;
418            private String _entry1Uuid;
419            private String _entry2ClassName;
420            private String _entry2Uuid;
421            private String _uuid;
422    
423    }