1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.lar;
16  
17  import com.liferay.portal.NoSuchResourceException;
18  import com.liferay.portal.NoSuchRoleException;
19  import com.liferay.portal.PortalException;
20  import com.liferay.portal.SystemException;
21  import com.liferay.portal.kernel.log.Log;
22  import com.liferay.portal.kernel.log.LogFactoryUtil;
23  import com.liferay.portal.kernel.util.KeyValuePair;
24  import com.liferay.portal.kernel.util.MapUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.StringUtil;
27  import com.liferay.portal.kernel.zip.ZipReader;
28  import com.liferay.portal.kernel.zip.ZipWriter;
29  import com.liferay.portal.model.Group;
30  import com.liferay.portal.model.Resource;
31  import com.liferay.portal.model.ResourceConstants;
32  import com.liferay.portal.model.Role;
33  import com.liferay.portal.model.RoleConstants;
34  import com.liferay.portal.security.permission.ResourceActionsUtil;
35  import com.liferay.portal.service.GroupLocalServiceUtil;
36  import com.liferay.portal.service.PermissionLocalServiceUtil;
37  import com.liferay.portal.service.ResourceLocalServiceUtil;
38  import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
39  import com.liferay.portal.service.RoleLocalServiceUtil;
40  import com.liferay.portal.service.ServiceContext;
41  import com.liferay.portal.util.PropsValues;
42  import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
43  import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryImpl;
44  import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderImpl;
45  import com.liferay.portlet.calendar.model.impl.CalEventImpl;
46  import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
47  import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
48  import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
49  import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
50  import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
51  import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
52  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
53  import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
54  import com.liferay.portlet.journal.model.impl.JournalStructureImpl;
55  import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
56  import com.liferay.portlet.messageboards.NoSuchDiscussionException;
57  import com.liferay.portlet.messageboards.model.MBDiscussion;
58  import com.liferay.portlet.messageboards.model.MBMessage;
59  import com.liferay.portlet.messageboards.model.MBThread;
60  import com.liferay.portlet.messageboards.model.impl.MBBanImpl;
61  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
62  import com.liferay.portlet.messageboards.model.impl.MBMessageFlagImpl;
63  import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
64  import com.liferay.portlet.messageboards.service.MBDiscussionLocalServiceUtil;
65  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
66  import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
67  import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
68  import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
69  import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
70  import com.liferay.portlet.ratings.model.RatingsEntry;
71  import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
72  import com.liferay.portlet.ratings.service.RatingsEntryLocalServiceUtil;
73  import com.liferay.portlet.tags.model.TagsEntryConstants;
74  import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
75  import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
76  import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
77  
78  import com.thoughtworks.xstream.XStream;
79  
80  import java.io.IOException;
81  import java.io.InputStream;
82  
83  import java.util.ArrayList;
84  import java.util.Date;
85  import java.util.HashMap;
86  import java.util.HashSet;
87  import java.util.Iterator;
88  import java.util.List;
89  import java.util.Map;
90  import java.util.Set;
91  
92  /**
93   * <a href="PortletDataContextImpl.java.html"><b><i>View Source</i></b></a>
94   *
95   * <p>
96   * Holds context information that is used during exporting and importing portlet
97   * data.
98   * </p>
99   *
100  * @author Brian Wing Shun Chan
101  * @author Raymond Augé
102  * @author Bruno Farache
103  * @author Alex Chow
104  */
105 public class PortletDataContextImpl implements PortletDataContext {
106 
107     public PortletDataContextImpl(
108             long companyId, long groupId, Map<String, String[]> parameterMap,
109             Set<String> primaryKeys, Date startDate, Date endDate,
110             ZipWriter zipWriter)
111         throws PortletDataException {
112 
113         validateDateRange(startDate, endDate);
114 
115         _companyId = companyId;
116         _groupId = groupId;
117         _scopeGroupId = groupId;
118         _parameterMap = parameterMap;
119         _primaryKeys = primaryKeys;
120         _dataStrategy =  null;
121         _userIdStrategy = null;
122         _startDate = startDate;
123         _endDate = endDate;
124         _zipReader = null;
125         _zipWriter = zipWriter;
126 
127         initXStream();
128     }
129 
130     public PortletDataContextImpl(
131         long companyId, long groupId, Map<String, String[]> parameterMap,
132         Set<String> primaryKeys, UserIdStrategy userIdStrategy,
133         ZipReader zipReader) {
134 
135         _companyId = companyId;
136         _groupId = groupId;
137         _scopeGroupId = groupId;
138         _parameterMap = parameterMap;
139         _primaryKeys = primaryKeys;
140         _dataStrategy =  MapUtil.getString(
141             parameterMap, PortletDataHandlerKeys.DATA_STRATEGY,
142             PortletDataHandlerKeys.DATA_STRATEGY_MIRROR);
143         _userIdStrategy = userIdStrategy;
144         _zipReader = zipReader;
145         _zipWriter = null;
146 
147         initXStream();
148     }
149 
150     public void addComments(Class<?> classObj, long classPK)
151         throws SystemException {
152 
153         List<MBMessage> messages = MBMessageLocalServiceUtil.getMessages(
154             classObj.getName(), classPK);
155 
156         if (messages.size() == 0) {
157             return;
158         }
159 
160         Iterator<MBMessage> itr = messages.iterator();
161 
162         while (itr.hasNext()) {
163             MBMessage message = itr.next();
164 
165             message.setUserUuid(message.getUserUuid());
166 
167             addRatingsEntries(MBMessage.class, message.getPrimaryKey());
168         }
169 
170         _commentsMap.put(getPrimaryKeyString(classObj, classPK), messages);
171     }
172 
173     public void addComments(
174         String className, long classPK, List<MBMessage> messages) {
175 
176         _commentsMap.put(getPrimaryKeyString(className, classPK), messages);
177     }
178 
179     public void addPermissions(Class<?> classObj, long classPK)
180         throws PortalException, SystemException {
181 
182         addPermissions(classObj.getName(), classPK);
183     }
184 
185     public void addPermissions(String resourceName, long resourcePK)
186         throws PortalException, SystemException {
187 
188         if (((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
189              (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) ||
190             (!MapUtil.getBoolean(
191                 _parameterMap, PortletDataHandlerKeys.PERMISSIONS))) {
192 
193             return;
194         }
195 
196         List<KeyValuePair> permissions = new ArrayList<KeyValuePair>();
197 
198         Group group = GroupLocalServiceUtil.getGroup(_groupId);
199 
200         List<Role> roles = RoleLocalServiceUtil.getRoles(_companyId);
201 
202         for (Role role : roles) {
203             int type = role.getType();
204 
205             if ((type == RoleConstants.TYPE_REGULAR) ||
206                 ((type == RoleConstants.TYPE_COMMUNITY) &&
207                  (group.isCommunity())) ||
208                 ((type == RoleConstants.TYPE_ORGANIZATION) &&
209                  (group.isOrganization()))) {
210 
211                 String name = role.getName();
212                 String actionIds = getActionIds(
213                     role, resourceName, String.valueOf(resourcePK));
214 
215                 KeyValuePair permission = new KeyValuePair(name, actionIds);
216 
217                 permissions.add(permission);
218             }
219         }
220 
221         _permissionsMap.put(
222             getPrimaryKeyString(resourceName, resourcePK), permissions);
223     }
224 
225     public void addPermissions(
226         String resourceName, long resourcePK, List<KeyValuePair> permissions) {
227 
228         if ((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
229             (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) {
230 
231             return;
232         }
233 
234         _permissionsMap.put(
235             getPrimaryKeyString(resourceName, resourcePK), permissions);
236     }
237 
238     public boolean addPrimaryKey(Class<?> classObj, String primaryKey) {
239         boolean value = hasPrimaryKey(classObj, primaryKey);
240 
241         if (!value) {
242             _primaryKeys.add(getPrimaryKeyString(classObj, primaryKey));
243         }
244 
245         return value;
246     }
247 
248     public void addRatingsEntries(Class<?> classObj, long classPK)
249         throws SystemException {
250 
251         List<RatingsEntry> ratingsEntries =
252             RatingsEntryLocalServiceUtil.getEntries(
253                 classObj.getName(), classPK);
254 
255         if (ratingsEntries.size() == 0) {
256             return;
257         }
258 
259         Iterator<RatingsEntry> itr = ratingsEntries.iterator();
260 
261         while (itr.hasNext()) {
262             RatingsEntry entry = itr.next();
263 
264             entry.setUserUuid(entry.getUserUuid());
265         }
266 
267         _ratingsEntriesMap.put(
268             getPrimaryKeyString(classObj, classPK), ratingsEntries);
269     }
270 
271     public void addRatingsEntries(
272         String className, long classPK, List<RatingsEntry> ratingsEntries) {
273 
274         _ratingsEntriesMap.put(
275             getPrimaryKeyString(className, classPK), ratingsEntries);
276     }
277 
278     public void addTagsCategories(Class<?> classObj, long classPK)
279         throws SystemException {
280 
281         String[] tagsCategories = TagsEntryLocalServiceUtil.getEntryNames(
282             classObj.getName(), classPK,
283             TagsEntryConstants.FOLKSONOMY_CATEGORY);
284 
285         if (tagsCategories.length == 0) {
286             return;
287         }
288 
289         _tagsCategoriesMap.put(
290             getPrimaryKeyString(classObj, classPK), tagsCategories);
291     }
292 
293     public void addTagsCategories(
294         String className, long classPK, String[] tagsCategories) {
295 
296         _tagsCategoriesMap.put(
297             getPrimaryKeyString(className, classPK), tagsCategories);
298     }
299 
300     public void addTagsEntries(Class<?> classObj, long classPK)
301         throws SystemException {
302 
303         String[] tagsEntries = TagsEntryLocalServiceUtil.getEntryNames(
304             classObj.getName(), classPK, TagsEntryConstants.FOLKSONOMY_TAG);
305 
306         if (tagsEntries.length == 0) {
307             return;
308         }
309 
310         _tagsEntriesMap.put(
311             getPrimaryKeyString(classObj, classPK), tagsEntries);
312     }
313 
314     public void addTagsEntries(
315         String className, long classPK, String[] tagsEntries) {
316 
317         _tagsEntriesMap.put(
318             getPrimaryKeyString(className, classPK), tagsEntries);
319     }
320 
321     public void addZipEntry(String path, byte[] bytes) throws SystemException {
322         try {
323             getZipWriter().addEntry(path, bytes);
324         }
325         catch (IOException ioe) {
326             throw new SystemException(ioe);
327         }
328     }
329 
330     public void addZipEntry(String path, InputStream is)
331         throws SystemException {
332 
333         try {
334             getZipWriter().addEntry(path, is);
335         }
336         catch (IOException ioe) {
337             throw new SystemException(ioe);
338         }
339     }
340 
341     public void addZipEntry(String path, Object object) throws SystemException {
342         addZipEntry(path, toXML(object));
343     }
344 
345     public void addZipEntry(String path, String s) throws SystemException {
346         try {
347             getZipWriter().addEntry(path, s);
348         }
349         catch (IOException ioe) {
350             throw new SystemException(ioe);
351         }
352     }
353 
354     public void addZipEntry(String path, StringBuilder sb)
355         throws SystemException {
356 
357         try {
358             getZipWriter().addEntry(path, sb);
359         }
360         catch (IOException ioe) {
361             throw new SystemException(ioe);
362         }
363     }
364 
365     public Object fromXML(byte[] bytes) {
366         return _xStream.fromXML(new String(bytes));
367     }
368 
369     public Object fromXML(String xml) {
370         return _xStream.fromXML(xml);
371     }
372 
373     public boolean getBooleanParameter(String namespace, String name) {
374         boolean defaultValue = MapUtil.getBoolean(
375             getParameterMap(),
376             PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT, true);
377 
378         return MapUtil.getBoolean(
379             getParameterMap(),
380             PortletDataHandlerControl.getNamespacedControlName(namespace, name),
381             defaultValue);
382     }
383 
384     public ClassLoader getClassLoader() {
385         return _xStream.getClassLoader();
386     }
387 
388     public Map<String, List<MBMessage>> getComments() {
389         return _commentsMap;
390     }
391 
392     public long getCompanyId() {
393         return _companyId;
394     }
395 
396     public String getDataStrategy() {
397         return _dataStrategy;
398     }
399 
400     public Date getEndDate() {
401         return _endDate;
402     }
403 
404     public long getGroupId() {
405         return _groupId;
406     }
407 
408     public String getLayoutPath(long layoutId) {
409         return getRootPath() + ROOT_PATH_LAYOUTS + layoutId;
410     }
411 
412     public Map<?, ?> getNewPrimaryKeysMap(Class<?> classObj) {
413         Map<?, ?> map = _newPrimaryKeysMaps.get(classObj.getName());
414 
415         if (map == null) {
416             map = new HashMap<Object, Object>();
417 
418             _newPrimaryKeysMaps.put(classObj.getName(), map);
419         }
420 
421         return map;
422     }
423 
424     public long getOldPlid() {
425         return _oldPlid;
426     }
427 
428     public Map<String, String[]> getParameterMap() {
429         return _parameterMap;
430     }
431 
432     public Map<String, List<KeyValuePair>> getPermissions() {
433         return _permissionsMap;
434     }
435 
436     public long getPlid() {
437         return _plid;
438     }
439 
440     public String getPortletPath(String portletId) {
441         return getRootPath() + ROOT_PATH_PORTLETS + portletId;
442     }
443 
444     public Set<String> getPrimaryKeys() {
445         return _primaryKeys;
446     }
447 
448     public Map<String, List<RatingsEntry>> getRatingsEntries() {
449         return _ratingsEntriesMap;
450     }
451 
452     public String getRootPath() {
453         return ROOT_PATH_GROUPS + getScopeGroupId();
454     }
455 
456     public long getScopeGroupId() {
457         return _scopeGroupId;
458     }
459 
460     public long getScopeLayoutId() {
461         return _scopeLayoutId;
462     }
463 
464     public long getSourceGroupId() {
465         return _sourceGroupId;
466     }
467 
468     public String getSourceLayoutPath(long layoutId) {
469         return getSourceRootPath() + ROOT_PATH_LAYOUTS + layoutId;
470     }
471 
472     public String getSourcePortletPath(String portletId) {
473         return getSourceRootPath() + ROOT_PATH_PORTLETS + portletId;
474     }
475 
476     public String getSourceRootPath() {
477         return ROOT_PATH_GROUPS + getSourceGroupId();
478     }
479 
480     public Date getStartDate() {
481         return _startDate;
482     }
483 
484     public Map<String, String[]> getTagsCategories() {
485         return _tagsCategoriesMap;
486     }
487 
488     public String[] getTagsCategories(Class<?> classObj, long classPK) {
489         return _tagsCategoriesMap.get(
490             getPrimaryKeyString(classObj, classPK));
491     }
492 
493     public Map<String, String[]> getTagsEntries() {
494         return _tagsEntriesMap;
495     }
496 
497     public String[] getTagsEntries(Class<?> classObj, long classPK) {
498         return _tagsEntriesMap.get(getPrimaryKeyString(classObj, classPK));
499     }
500 
501     public String[] getTagsEntries(String className, long classPK) {
502         return _tagsEntriesMap.get(getPrimaryKeyString(className, classPK));
503     }
504 
505     public long getUserId(String userUuid) throws SystemException {
506         return _userIdStrategy.getUserId(userUuid);
507     }
508 
509     public UserIdStrategy getUserIdStrategy() {
510         return _userIdStrategy;
511     }
512 
513     public List<String> getZipEntries() {
514         return getZipReader().getEntries();
515     }
516 
517     public byte[] getZipEntryAsByteArray(String path) {
518         return getZipReader().getEntryAsByteArray(path);
519     }
520 
521     public InputStream getZipEntryAsInputStream(String path) {
522         return getZipReader().getEntryAsInputStream(path);
523     }
524 
525     public Object getZipEntryAsObject(String path) {
526         return fromXML(getZipEntryAsString(path));
527     }
528 
529     public String getZipEntryAsString(String path) {
530         return getZipReader().getEntryAsString(path);
531     }
532 
533     public List<String> getZipFolderEntries() {
534         return getZipFolderEntries(StringPool.SLASH);
535     }
536 
537     public List<String> getZipFolderEntries(String path) {
538         return getZipReader().getFolderEntries(path);
539     }
540 
541     public ZipReader getZipReader() {
542         return _zipReader;
543     }
544 
545     public ZipWriter getZipWriter() {
546         return _zipWriter;
547     }
548 
549     public boolean hasDateRange() {
550         if (_startDate != null) {
551             return true;
552         }
553         else {
554             return false;
555         }
556     }
557 
558     public boolean hasNotUniquePerLayout(String dataKey) {
559         return _notUniquePerLayout.contains(dataKey);
560     }
561 
562     public boolean hasPrimaryKey(Class<?> classObj, String primaryKey) {
563         return _primaryKeys.contains(getPrimaryKeyString(classObj, primaryKey));
564     }
565 
566     public void importComments(
567             Class<?> classObj, long classPK, long newClassPK, long groupId)
568         throws PortalException, SystemException {
569 
570         Map<Long, Long> messagePKs = new HashMap<Long, Long>();
571         Map<Long, Long> threadPKs = new HashMap<Long, Long>();
572 
573         List<MBMessage> messages = _commentsMap.get(
574             getPrimaryKeyString(classObj, classPK));
575 
576         if (messages == null) {
577             return;
578         }
579 
580         MBDiscussion discussion = null;
581 
582         try {
583             discussion = MBDiscussionLocalServiceUtil.getDiscussion(
584                 classObj.getName(), newClassPK);
585         }
586         catch (NoSuchDiscussionException nsde) {
587         }
588 
589         for (MBMessage message : messages) {
590             long userId = getUserId(message.getUserUuid());
591             long parentMessageId = MapUtil.getLong(
592                 messagePKs, message.getParentMessageId(),
593                 message.getParentMessageId());
594             long threadId = MapUtil.getLong(
595                 threadPKs, message.getThreadId(), message.getThreadId());
596 
597             if ((message.getParentMessageId() ==
598                     MBMessageImpl.DEFAULT_PARENT_MESSAGE_ID) &&
599                 (discussion != null)) {
600 
601                 MBThread thread = MBThreadLocalServiceUtil.getThread(
602                     discussion.getThreadId());
603 
604                 long rootMessageId = thread.getRootMessageId();
605 
606                 messagePKs.put(message.getMessageId(), rootMessageId);
607                 threadPKs.put(message.getThreadId(), thread.getThreadId());
608             }
609             else {
610                 ServiceContext serviceContext = new ServiceContext();
611 
612                 serviceContext.setScopeGroupId(groupId);
613 
614                 MBMessage newMessage =
615                     MBMessageLocalServiceUtil.addDiscussionMessage(
616                         userId, message.getUserName(), classObj.getName(),
617                         newClassPK, threadId, parentMessageId,
618                         message.getSubject(), message.getBody(),
619                         serviceContext);
620 
621                 messagePKs.put(
622                     message.getMessageId(), newMessage.getMessageId());
623                 threadPKs.put(message.getThreadId(), newMessage.getThreadId());
624             }
625 
626             importRatingsEntries(
627                 MBMessage.class, message.getPrimaryKey(),
628                 messagePKs.get(message.getPrimaryKey()));
629         }
630     }
631 
632     public void importPermissions(
633             Class<?> classObj, long classPK, long newClassPK)
634         throws PortalException, SystemException {
635 
636         importPermissions(classObj.getName(), classPK, newClassPK);
637     }
638 
639     public void importPermissions(
640             String resourceName, long resourcePK, long newResourcePK)
641         throws PortalException, SystemException {
642 
643         if (((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
644              (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) ||
645             (!MapUtil.getBoolean(
646                 _parameterMap, PortletDataHandlerKeys.PERMISSIONS))) {
647 
648             return;
649         }
650 
651         List<KeyValuePair> permissions = _permissionsMap.get(
652             getPrimaryKeyString(resourceName, resourcePK));
653 
654         if (permissions == null) {
655             return;
656         }
657 
658         for (KeyValuePair permission : permissions) {
659             String roleName = permission.getKey();
660 
661             Role role = null;
662 
663             try {
664                 role = RoleLocalServiceUtil.getRole(_companyId, roleName);
665             }
666             catch (NoSuchRoleException nsre) {
667                 if (_log.isWarnEnabled()) {
668                     _log.warn("Role " + roleName + " does not exist");
669                 }
670 
671                 continue;
672             }
673 
674             String[] actionIds = StringUtil.split(permission.getValue());
675 
676             if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
677                 Resource resource = null;
678 
679                 try {
680                     resource = ResourceLocalServiceUtil.getResource(
681                         _companyId, resourceName,
682                         ResourceConstants.SCOPE_INDIVIDUAL,
683                         String.valueOf(newResourcePK));
684                 }
685                 catch (NoSuchResourceException nsre) {
686                     resource = ResourceLocalServiceUtil.addResource(
687                         _companyId, resourceName,
688                         ResourceConstants.SCOPE_INDIVIDUAL,
689                         String.valueOf(newResourcePK));
690                 }
691 
692                 PermissionLocalServiceUtil.setRolePermissions(
693                     role.getRoleId(), actionIds, resource.getResourceId());
694             }
695             else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
696                 ResourcePermissionLocalServiceUtil.setResourcePermissions(
697                     _companyId, resourceName,
698                     ResourceConstants.SCOPE_INDIVIDUAL,
699                     String.valueOf(newResourcePK), role.getRoleId(), actionIds);
700             }
701         }
702     }
703 
704     public void importRatingsEntries(
705             Class<?> classObj, long classPK, long newClassPK)
706         throws PortalException, SystemException {
707 
708         List<RatingsEntry> ratingsEntries = _ratingsEntriesMap.get(
709             getPrimaryKeyString(classObj, classPK));
710 
711         if (ratingsEntries == null) {
712             return;
713         }
714 
715         ServiceContext serviceContext = new ServiceContext();
716 
717         for (RatingsEntry ratingsEntry : ratingsEntries) {
718             long userId = getUserId(ratingsEntry.getUserUuid());
719 
720             serviceContext.setCreateDate(ratingsEntry.getCreateDate());
721             serviceContext.setModifiedDate(ratingsEntry.getModifiedDate());
722 
723             RatingsEntryLocalServiceUtil.updateEntry(
724                 userId, classObj.getName(), ((Long)newClassPK).longValue(),
725                 ratingsEntry.getScore(), serviceContext);
726         }
727     }
728 
729     public boolean isPathNotProcessed(String path) {
730         return !addPrimaryKey(String.class, path);
731     }
732 
733     public boolean isPrivateLayout() {
734         return _privateLayout;
735     }
736 
737     public boolean isWithinDateRange(Date modifiedDate) {
738         if (!hasDateRange()) {
739             return true;
740         }
741         else if ((_startDate.compareTo(modifiedDate) <= 0) &&
742                  (_endDate.after(modifiedDate))) {
743 
744             return true;
745         }
746         else {
747             return false;
748         }
749     }
750 
751     public void putNotUniquePerLayout(String dataKey) {
752         _notUniquePerLayout.add(dataKey);
753     }
754 
755     public void setClassLoader(ClassLoader classLoader) {
756         _xStream.setClassLoader(classLoader);
757     }
758 
759     public void setGroupId(long groupId) {
760         _groupId = groupId;
761     }
762 
763     public void setOldPlid(long oldPlid) {
764         _oldPlid = oldPlid;
765     }
766 
767     public void setPlid(long plid) {
768         _plid = plid;
769     }
770 
771     public void setPrivateLayout(boolean privateLayout) {
772         _privateLayout = privateLayout;
773     }
774 
775     public void setScopeGroupId(long scopeGroupId) {
776         _scopeGroupId = scopeGroupId;
777     }
778 
779     public void setScopeLayoutId(long scopeLayoutId) {
780         _scopeLayoutId = scopeLayoutId;
781     }
782 
783     public void setSourceGroupId(long sourceGroupId) {
784         _sourceGroupId = sourceGroupId;
785     }
786 
787     public String toXML(Object object) {
788         return _xStream.toXML(object);
789     }
790 
791     protected String getActionIds(
792             Role role, String className, String primKey)
793         throws PortalException, SystemException {
794 
795         List<String> allActionIds = ResourceActionsUtil.getModelResourceActions(
796             className);
797 
798         List<String> actionIds = new ArrayList<String>(allActionIds.size());
799 
800         for (String actionId : allActionIds) {
801             if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
802                 if (PermissionLocalServiceUtil.hasRolePermission(
803                         role.getRoleId(), role.getCompanyId(), className,
804                         ResourceConstants.SCOPE_INDIVIDUAL, primKey,
805                         actionId)) {
806 
807                     actionIds.add(actionId);
808                 }
809             }
810             else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
811                 if (ResourcePermissionLocalServiceUtil.hasResourcePermission(
812                         role.getCompanyId(), className,
813                         ResourceConstants.SCOPE_INDIVIDUAL, primKey,
814                         role.getRoleId(), actionId)) {
815 
816                     actionIds.add(actionId);
817                 }
818             }
819         }
820 
821         return StringUtil.merge(actionIds);
822     }
823 
824     protected String getPrimaryKeyString(Class<?> classObj, long classPK) {
825         return getPrimaryKeyString(classObj.getName(), String.valueOf(classPK));
826     }
827 
828     protected String getPrimaryKeyString(Class<?> classObj, String primaryKey) {
829         return getPrimaryKeyString(classObj.getName(), primaryKey);
830     }
831 
832     protected String getPrimaryKeyString(String className, long classPK) {
833         return getPrimaryKeyString(className, String.valueOf(classPK));
834     }
835 
836     protected String getPrimaryKeyString(String className, String primaryKey) {
837         return className.concat(StringPool.POUND).concat(primaryKey);
838     }
839 
840     protected void initXStream() {
841         _xStream = new XStream();
842 
843         _xStream.alias("BlogsEntry", BlogsEntryImpl.class);
844         _xStream.alias("BookmarksFolder", BookmarksFolderImpl.class);
845         _xStream.alias("BookmarksEntry", BookmarksEntryImpl.class);
846         _xStream.alias("CalEvent", CalEventImpl.class);
847         _xStream.alias("DLFolder", DLFolderImpl.class);
848         _xStream.alias("DLFileEntry", DLFileEntryImpl.class);
849         _xStream.alias("DLFileShortcut", DLFileShortcutImpl.class);
850         _xStream.alias("DLFileRank", DLFileRankImpl.class);
851         _xStream.alias("IGFolder", IGFolderImpl.class);
852         _xStream.alias("IGImage", IGImageImpl.class);
853         _xStream.alias("JournalArticle", JournalArticleImpl.class);
854         _xStream.alias("JournalFeed", JournalFeedImpl.class);
855         _xStream.alias("JournalStructure", JournalStructureImpl.class);
856         _xStream.alias("JournalTemplate", JournalTemplateImpl.class);
857         _xStream.alias("MBCategory", MBCategoryImpl.class);
858         _xStream.alias("MBMessage", MBMessageImpl.class);
859         _xStream.alias("MBMessageFlag", MBMessageFlagImpl.class);
860         _xStream.alias("MBBan", MBBanImpl.class);
861         _xStream.alias("PollsQuestion", PollsQuestionImpl.class);
862         _xStream.alias("PollsChoice", PollsChoiceImpl.class);
863         _xStream.alias("PollsVote", PollsVoteImpl.class);
864         _xStream.alias("RatingsEntry", RatingsEntryImpl.class);
865         _xStream.alias("WikiNode", WikiNodeImpl.class);
866         _xStream.alias("WikiPage", WikiPageImpl.class);
867     }
868 
869     protected void validateDateRange(Date startDate, Date endDate)
870         throws PortletDataException {
871 
872         if ((startDate == null) ^ (endDate == null)) {
873             throw new PortletDataException(
874                 "Both start and end dates must have valid values or be null");
875         }
876 
877         if (startDate != null) {
878             if (startDate.after(endDate) || startDate.equals(endDate)) {
879                 throw new PortletDataException(
880                     "The start date cannot be after the end date");
881             }
882 
883             Date now = new Date();
884 
885             if (startDate.after(now) || endDate.after(now)) {
886                 throw new PortletDataException(
887                     "Dates must not be in the future");
888             }
889         }
890     }
891 
892     private static Log _log = LogFactoryUtil.getLog(
893         PortletDataContextImpl.class);
894 
895     private Map<String, List<MBMessage>> _commentsMap =
896         new HashMap<String, List<MBMessage>>();
897     private long _companyId;
898     private String _dataStrategy;
899     private Date _endDate;
900     private long _groupId;
901     private Map<String, Map<?, ?>> _newPrimaryKeysMaps =
902         new HashMap<String, Map<?, ?>>();
903     private Set<String> _notUniquePerLayout = new HashSet<String>();
904     private long _oldPlid;
905     private Map<String, String[]> _parameterMap;
906     private Map<String, List<KeyValuePair>> _permissionsMap =
907         new HashMap<String, List<KeyValuePair>>();
908     private long _plid;
909     private Set<String> _primaryKeys;
910     private boolean _privateLayout;
911     private Map<String, List<RatingsEntry>> _ratingsEntriesMap =
912         new HashMap<String, List<RatingsEntry>>();
913     private long _scopeGroupId;
914     private long _scopeLayoutId;
915     private long _sourceGroupId;
916     private Date _startDate;
917     private Map<String, String[]> _tagsCategoriesMap =
918         new HashMap<String, String[]>();
919     private Map<String, String[]> _tagsEntriesMap =
920         new HashMap<String, String[]>();
921     private UserIdStrategy _userIdStrategy;
922     private XStream _xStream;
923     private ZipReader _zipReader;
924     private ZipWriter _zipWriter;
925 
926 }