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