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.portlet.asset.model.AssetEntry;
020    import com.liferay.portlet.asset.model.AssetLink;
021    import com.liferay.portlet.asset.model.adapter.StagedAssetLink;
022    import com.liferay.portlet.asset.model.impl.AssetLinkImpl;
023    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
024    import com.liferay.portlet.exportimport.lar.StagedModelType;
025    
026    import java.util.Date;
027    
028    /**
029     * @author Mate Thurzo
030     */
031    public class StagedAssetLinkImpl extends AssetLinkImpl
032            implements StagedAssetLink {
033    
034            public StagedAssetLinkImpl() {
035            }
036    
037            public StagedAssetLinkImpl(AssetLink assetLink) {
038                    _assetLink = assetLink;
039    
040                    populateEntry1Attributes();
041                    populateEntry2Attributes();
042    
043                    populateUuid();
044            }
045    
046            @Override
047            public String getEntry1ClassName() {
048                    if (Validator.isNotNull(_entry1ClassName)) {
049                            return _entry1ClassName;
050                    }
051    
052                    populateEntry1Attributes();
053    
054                    return _entry1ClassName;
055            }
056    
057            @Override
058            public String getEntry1Uuid() {
059                    if (Validator.isNotNull(_entry1Uuid)) {
060                            return _entry1Uuid;
061                    }
062    
063                    populateEntry1Attributes();
064    
065                    return _entry1Uuid;
066            }
067    
068            @Override
069            public String getEntry2ClassName() {
070                    if (Validator.isNotNull(_entry2ClassName)) {
071                            return _entry2ClassName;
072                    }
073    
074                    populateEntry2Attributes();
075    
076                    return _entry2ClassName;
077            }
078    
079            @Override
080            public String getEntry2Uuid() {
081                    if (Validator.isNotNull(_entry2Uuid)) {
082                            return _entry2Uuid;
083                    }
084    
085                    populateEntry2Attributes();
086    
087                    return _entry2Uuid;
088            }
089    
090            @Override
091            public Date getModifiedDate() {
092                    return _assetLink.getCreateDate();
093            }
094    
095            @Override
096            public StagedModelType getStagedModelType() {
097                    return new StagedModelType(StagedAssetLink.class);
098            }
099    
100            @Override
101            public String getUuid() {
102                    if (Validator.isNotNull(_uuid)) {
103                            return _uuid;
104                    }
105    
106                    populateUuid();
107    
108                    return _uuid;
109            }
110    
111            public void setAssetLink(AssetLink assetLink) {
112                    _assetLink = assetLink;
113            }
114    
115            @Override
116            public void setModifiedDate(Date date) {
117                    throw new UnsupportedOperationException();
118            }
119    
120            @Override
121            public void setUuid(String uuid) {
122                    throw new UnsupportedOperationException();
123            }
124    
125            protected void populateEntry1Attributes() {
126                    if (Validator.isNotNull(_entry1ClassName) &&
127                            Validator.isNotNull(_entry1Uuid)) {
128    
129                            return;
130                    }
131    
132                    AssetEntry entry1 = AssetEntryLocalServiceUtil.fetchAssetEntry(
133                            _assetLink.getEntryId1());
134    
135                    if (entry1 == null) {
136                            return;
137                    }
138    
139                    _entry1ClassName = entry1.getClassName();
140                    _entry1Uuid = entry1.getClassUuid();
141            }
142    
143            protected void populateEntry2Attributes() {
144                    if (Validator.isNotNull(_entry2ClassName) &&
145                            Validator.isNotNull(_entry2Uuid)) {
146    
147                            return;
148                    }
149    
150                    AssetEntry entry2 = AssetEntryLocalServiceUtil.fetchAssetEntry(
151                            _assetLink.getEntryId2());
152    
153                    if (entry2 == null) {
154                            return;
155                    }
156    
157                    _entry2ClassName = entry2.getClassName();
158                    _entry2Uuid = entry2.getClassUuid();
159            }
160    
161            protected void populateUuid() {
162                    if (Validator.isNotNull(_uuid)) {
163                            return;
164                    }
165    
166                    String entry1Uuid = getEntry1Uuid();
167                    String entry2Uuid = getEntry2Uuid();
168    
169                    if (Validator.isNotNull(entry1Uuid) &&
170                            Validator.isNotNull(entry2Uuid)) {
171    
172                            _uuid = entry1Uuid + StringPool.POUND + entry2Uuid;
173                    }
174            }
175    
176            private AssetLink _assetLink;
177            private String _entry1ClassName;
178            private String _entry1Uuid;
179            private String _entry2ClassName;
180            private String _entry2Uuid;
181            private String _uuid;
182    
183    }