001
014
015 package com.liferay.portal.lar;
016
017 import com.liferay.portal.NoSuchRoleException;
018 import com.liferay.portal.NoSuchTeamException;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.lar.PortletDataContext;
022 import com.liferay.portal.kernel.lar.PortletDataContextListener;
023 import com.liferay.portal.kernel.lar.PortletDataException;
024 import com.liferay.portal.kernel.lar.PortletDataHandlerControl;
025 import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
026 import com.liferay.portal.kernel.lar.UserIdStrategy;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.KeyValuePair;
030 import com.liferay.portal.kernel.util.ListUtil;
031 import com.liferay.portal.kernel.util.MapUtil;
032 import com.liferay.portal.kernel.util.PrimitiveLongList;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.kernel.workflow.WorkflowConstants;
037 import com.liferay.portal.kernel.xml.Element;
038 import com.liferay.portal.kernel.zip.ZipReader;
039 import com.liferay.portal.kernel.zip.ZipWriter;
040 import com.liferay.portal.model.AuditedModel;
041 import com.liferay.portal.model.ClassedModel;
042 import com.liferay.portal.model.Group;
043 import com.liferay.portal.model.Lock;
044 import com.liferay.portal.model.ResourceConstants;
045 import com.liferay.portal.model.ResourcedModel;
046 import com.liferay.portal.model.Role;
047 import com.liferay.portal.model.RoleConstants;
048 import com.liferay.portal.model.Team;
049 import com.liferay.portal.model.impl.LockImpl;
050 import com.liferay.portal.security.permission.ResourceActionsUtil;
051 import com.liferay.portal.service.GroupLocalServiceUtil;
052 import com.liferay.portal.service.LockLocalServiceUtil;
053 import com.liferay.portal.service.PermissionLocalServiceUtil;
054 import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
055 import com.liferay.portal.service.RoleLocalServiceUtil;
056 import com.liferay.portal.service.ServiceContext;
057 import com.liferay.portal.service.TeamLocalServiceUtil;
058 import com.liferay.portal.util.PortalUtil;
059 import com.liferay.portal.util.PropsValues;
060 import com.liferay.portlet.asset.NoSuchEntryException;
061 import com.liferay.portlet.asset.model.AssetCategory;
062 import com.liferay.portlet.asset.model.AssetEntry;
063 import com.liferay.portlet.asset.model.AssetLink;
064 import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
065 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
066 import com.liferay.portlet.asset.service.AssetLinkLocalServiceUtil;
067 import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
068 import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
069 import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryImpl;
070 import com.liferay.portlet.bookmarks.model.impl.BookmarksFolderImpl;
071 import com.liferay.portlet.calendar.model.impl.CalEventImpl;
072 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
073 import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
074 import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
075 import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
076 import com.liferay.portlet.expando.model.ExpandoBridge;
077 import com.liferay.portlet.expando.model.ExpandoColumn;
078 import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil;
079 import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
080 import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
081 import com.liferay.portlet.journal.model.impl.JournalStructureImpl;
082 import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
083 import com.liferay.portlet.messageboards.NoSuchDiscussionException;
084 import com.liferay.portlet.messageboards.model.MBDiscussion;
085 import com.liferay.portlet.messageboards.model.MBMessage;
086 import com.liferay.portlet.messageboards.model.MBMessageConstants;
087 import com.liferay.portlet.messageboards.model.MBThread;
088 import com.liferay.portlet.messageboards.model.impl.MBBanImpl;
089 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
090 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
091 import com.liferay.portlet.messageboards.model.impl.MBThreadFlagImpl;
092 import com.liferay.portlet.messageboards.service.MBDiscussionLocalServiceUtil;
093 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
094 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
095 import com.liferay.portlet.messageboards.service.persistence.MBDiscussionUtil;
096 import com.liferay.portlet.messageboards.service.persistence.MBMessageUtil;
097 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
098 import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
099 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
100 import com.liferay.portlet.ratings.model.RatingsEntry;
101 import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
102 import com.liferay.portlet.ratings.service.RatingsEntryLocalServiceUtil;
103 import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
104 import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
105
106 import com.thoughtworks.xstream.XStream;
107
108 import java.io.IOException;
109 import java.io.InputStream;
110 import java.io.Serializable;
111
112 import java.util.ArrayList;
113 import java.util.Date;
114 import java.util.HashMap;
115 import java.util.HashSet;
116 import java.util.Iterator;
117 import java.util.List;
118 import java.util.Map;
119 import java.util.Set;
120
121
132 public class PortletDataContextImpl implements PortletDataContext {
133
134 public PortletDataContextImpl(
135 long companyId, long groupId, Map<String, String[]> parameterMap,
136 Set<String> primaryKeys, Date startDate, Date endDate,
137 ZipWriter zipWriter)
138 throws PortletDataException {
139
140 validateDateRange(startDate, endDate);
141
142 _companyId = companyId;
143 _groupId = groupId;
144 _scopeGroupId = groupId;
145 _parameterMap = parameterMap;
146 _primaryKeys = primaryKeys;
147 _dataStrategy = null;
148 _userIdStrategy = null;
149 _startDate = startDate;
150 _endDate = endDate;
151 _zipReader = null;
152 _zipWriter = zipWriter;
153
154 initXStream();
155 }
156
157 public PortletDataContextImpl(
158 long companyId, long groupId, Map<String, String[]> parameterMap,
159 Set<String> primaryKeys, UserIdStrategy userIdStrategy,
160 ZipReader zipReader) {
161
162 _companyId = companyId;
163 _groupId = groupId;
164 _scopeGroupId = groupId;
165 _parameterMap = parameterMap;
166 _primaryKeys = primaryKeys;
167 _dataStrategy = MapUtil.getString(
168 parameterMap, PortletDataHandlerKeys.DATA_STRATEGY,
169 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR);
170 _userIdStrategy = userIdStrategy;
171 _zipReader = zipReader;
172 _zipWriter = null;
173
174 initXStream();
175 }
176
177 public void addAssetCategories(Class<?> clazz, long classPK)
178 throws SystemException {
179
180 List<AssetCategory> assetCategories =
181 AssetCategoryLocalServiceUtil.getCategories(
182 clazz.getName(), classPK);
183
184 if (assetCategories.isEmpty()) {
185 return;
186 }
187
188 _assetCategoryUuidsMap.put(
189 getPrimaryKeyString(clazz, classPK),
190 StringUtil.split(
191 ListUtil.toString(
192 assetCategories, AssetCategory.UUID_ACCESSOR)));
193 _assetCategoryIdsMap.put(
194 getPrimaryKeyString(clazz, classPK),
195 StringUtil.split(
196 ListUtil.toString(
197 assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L));
198 }
199
200 public void addAssetCategories(
201 String className, long classPK, long[] assetCategoryIds) {
202
203 _assetCategoryIdsMap.put(
204 getPrimaryKeyString(className, classPK), assetCategoryIds);
205 }
206
207 public void addAssetLinks(Class<?> clazz, long classPK)
208 throws PortalException, SystemException {
209
210 AssetEntry assetEntry = null;
211
212 try {
213 assetEntry = AssetEntryLocalServiceUtil.getEntry(
214 clazz.getName(), classPK);
215 }
216 catch (NoSuchEntryException nsee) {
217 return;
218 }
219
220 List<AssetLink> directAssetLinks =
221 AssetLinkLocalServiceUtil.getDirectLinks(assetEntry.getEntryId());
222
223 if (directAssetLinks.isEmpty()) {
224 return;
225 }
226
227 Map<Integer, List<AssetLink>> assetLinksMap =
228 new HashMap<Integer, List<AssetLink>>();
229
230 for (AssetLink assetLink : directAssetLinks) {
231 List<AssetLink> assetLinks = assetLinksMap.get(assetLink.getType());
232
233 if (assetLinks == null) {
234 assetLinks = new ArrayList<AssetLink>();
235
236 assetLinksMap.put(assetLink.getType(), assetLinks);
237 }
238
239 assetLinks.add(assetLink);
240 }
241
242 for (Map.Entry<Integer, List<AssetLink>> entry :
243 assetLinksMap.entrySet()) {
244
245 int assetLinkType = entry.getKey();
246 List<AssetLink> assetLinks = entry.getValue();
247
248 List<String> assetLinkUuids = new ArrayList<String>(
249 directAssetLinks.size());
250
251 for (AssetLink assetLink : assetLinks) {
252 try {
253 AssetEntry assetLinkEntry =
254 AssetEntryLocalServiceUtil.getEntry(
255 assetLink.getEntryId2());
256
257 assetLinkUuids.add(assetLinkEntry.getClassUuid());
258 }
259 catch (NoSuchEntryException nsee) {
260 }
261 }
262
263 _assetLinkUuidsMap.put(
264 getPrimaryKeyString(
265 assetEntry.getClassUuid(), String.valueOf(assetLinkType)),
266 assetLinkUuids.toArray(new String[assetLinkUuids.size()]));
267 }
268 }
269
270 public void addAssetTags(Class<?> clazz, long classPK)
271 throws SystemException {
272
273 String[] tagNames = AssetTagLocalServiceUtil.getTagNames(
274 clazz.getName(), classPK);
275
276 if (tagNames.length == 0) {
277 return;
278 }
279
280 _assetTagNamesMap.put(getPrimaryKeyString(clazz, classPK), tagNames);
281 }
282
283 public void addAssetTags(
284 String className, long classPK, String[] assetTagNames) {
285
286 _assetTagNamesMap.put(
287 getPrimaryKeyString(className, classPK), assetTagNames);
288 }
289
290 public void addClassedModel(
291 Element element, String path, ClassedModel classedModel,
292 String namespace)
293 throws PortalException, SystemException {
294
295 element.addAttribute("path", path);
296
297 if (classedModel instanceof AuditedModel) {
298 AuditedModel auditedModel = (AuditedModel)classedModel;
299
300 auditedModel.setUserUuid(auditedModel.getUserUuid());
301 }
302
303 if (isResourceMain(classedModel)) {
304 Class<?> clazz = classedModel.getModelClass();
305 long classPK = getClassPK(classedModel);
306
307 addAssetLinks(clazz, classPK);
308 addExpando(element, path, classedModel);
309 addLocks(clazz, String.valueOf(classPK));
310 addPermissions(clazz, classPK);
311
312 if (getBooleanParameter(namespace, "categories")) {
313 addAssetCategories(clazz, classPK);
314 }
315
316 if (getBooleanParameter(namespace, "comments")) {
317 addComments(clazz, classPK);
318 }
319
320 if (getBooleanParameter(namespace, "ratings")) {
321 addRatingsEntries(clazz, classPK);
322 }
323
324 if (getBooleanParameter(namespace, "tags")) {
325 addAssetTags(clazz, classPK);
326 }
327 }
328
329 addZipEntry(path, classedModel);
330 }
331
332 public void addComments(Class<?> clazz, long classPK)
333 throws SystemException {
334
335 long classNameId = PortalUtil.getClassNameId(clazz);
336
337 MBDiscussion discussion = MBDiscussionUtil.fetchByC_C(
338 classNameId, classPK);
339
340 if (discussion == null) {
341 return;
342 }
343
344 List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages(
345 discussion.getThreadId(), WorkflowConstants.STATUS_APPROVED);
346
347 if (messages.size() == 0) {
348 return;
349 }
350
351 Iterator<MBMessage> itr = messages.iterator();
352
353 while (itr.hasNext()) {
354 MBMessage message = itr.next();
355
356 message.setUserUuid(message.getUserUuid());
357
358 addRatingsEntries(MBDiscussion.class, message.getPrimaryKey());
359 }
360
361 _commentsMap.put(getPrimaryKeyString(clazz, classPK), messages);
362 }
363
364 public void addComments(
365 String className, long classPK, List<MBMessage> messages) {
366
367 _commentsMap.put(getPrimaryKeyString(className, classPK), messages);
368 }
369
370 public void addExpando(
371 Element element, String path, ClassedModel classedModel)
372 throws PortalException, SystemException {
373
374 Class<?> clazz = classedModel.getModelClass();
375
376 String className = clazz.getName();
377
378 if (!_expandoColumnsMap.containsKey(className)) {
379 List<ExpandoColumn> expandoColumns =
380 ExpandoColumnLocalServiceUtil.getDefaultTableColumns(
381 _companyId, className);
382
383 for (ExpandoColumn expandoColumn : expandoColumns) {
384 addPermissions(
385 ExpandoColumn.class, expandoColumn.getColumnId());
386 }
387
388 _expandoColumnsMap.put(className, expandoColumns);
389 }
390
391 ExpandoBridge expandoBridge = classedModel.getExpandoBridge();
392
393 Map<String, Serializable> expandoBridgeAttributes =
394 expandoBridge.getAttributes();
395
396 if (!expandoBridgeAttributes.isEmpty()) {
397 String expandoPath = getExpandoPath(path);
398
399 element.addAttribute("expando-path", expandoPath);
400
401 addZipEntry(expandoPath, expandoBridgeAttributes);
402 }
403 }
404
405 public void addLocks(Class<?> clazz, String key)
406 throws PortalException, SystemException {
407
408 if (!_locksMap.containsKey(getPrimaryKeyString(clazz, key)) &&
409 LockLocalServiceUtil.isLocked(clazz.getName(), key)) {
410
411 Lock lock = LockLocalServiceUtil.getLock(clazz.getName(), key);
412
413 addLocks(clazz.getName(), key, lock);
414 }
415 }
416
417 public void addLocks(String className, String key, Lock lock) {
418 _locksMap.put(getPrimaryKeyString(className, key), lock);
419 }
420
421 public void addPermissions(Class<?> clazz, long classPK)
422 throws PortalException, SystemException {
423
424 addPermissions(clazz.getName(), classPK);
425 }
426
427 public void addPermissions(String resourceName, long resourcePK)
428 throws PortalException, SystemException {
429
430 if (((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
431 (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) ||
432 (!MapUtil.getBoolean(
433 _parameterMap, PortletDataHandlerKeys.PERMISSIONS))) {
434
435 return;
436 }
437
438 List<KeyValuePair> permissions = new ArrayList<KeyValuePair>();
439
440 Group group = GroupLocalServiceUtil.getGroup(_groupId);
441
442 List<Role> roles = RoleLocalServiceUtil.getRoles(_companyId);
443
444 PrimitiveLongList roleIds = new PrimitiveLongList(roles.size());
445 Map<Long, String> roleIdsToNames = new HashMap<Long, String>();
446
447 for (Role role : roles) {
448 int type = role.getType();
449
450 if ((type == RoleConstants.TYPE_REGULAR) ||
451 ((type == RoleConstants.TYPE_ORGANIZATION) &&
452 group.isOrganization()) ||
453 ((type == RoleConstants.TYPE_SITE) &&
454 (group.isLayoutSetPrototype() || group.isSite()))) {
455
456 String name = role.getName();
457
458 roleIds.add(role.getRoleId());
459 roleIdsToNames.put(role.getRoleId(), name);
460 }
461 else if ((type == RoleConstants.TYPE_PROVIDER) && role.isTeam()) {
462 Team team = TeamLocalServiceUtil.getTeam(role.getClassPK());
463
464 if (team.getGroupId() == _groupId) {
465 String name =
466 PermissionExporter.ROLE_TEAM_PREFIX + team.getName();
467
468 roleIds.add(role.getRoleId());
469 roleIdsToNames.put(role.getRoleId(), name);
470 }
471 }
472 }
473
474 List<String> actionIds = ResourceActionsUtil.getModelResourceActions(
475 resourceName);
476
477 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
478 for (Map.Entry<Long, String> entry : roleIdsToNames.entrySet()) {
479 long roleId = entry.getKey();
480 String name = entry.getValue();
481
482 String availableActionIds = getActionIds_5(
483 _companyId, roleId, resourceName,
484 String.valueOf(resourcePK), actionIds);
485
486 KeyValuePair permission = new KeyValuePair(
487 name, availableActionIds);
488
489 permissions.add(permission);
490 }
491
492 }
493 else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
494
495 Map<Long, Set<String>> roleIdsToActionIds = getActionIds_6(
496 _companyId, roleIds.getArray(), resourceName,
497 String.valueOf(resourcePK), actionIds);
498
499 for (Map.Entry<Long, String> entry : roleIdsToNames.entrySet()) {
500 long roleId = entry.getKey();
501 String name = entry.getValue();
502
503 Set<String> availableActionIds = roleIdsToActionIds.get(roleId);
504
505 if ((availableActionIds == null) ||
506 availableActionIds.isEmpty()) {
507
508 continue;
509 }
510
511 KeyValuePair permission = new KeyValuePair(
512 name, StringUtil.merge(availableActionIds));
513
514 permissions.add(permission);
515 }
516 }
517
518 _permissionsMap.put(
519 getPrimaryKeyString(resourceName, resourcePK), permissions);
520 }
521
522 public void addPermissions(
523 String resourceName, long resourcePK, List<KeyValuePair> permissions) {
524
525 if ((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
526 (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) {
527
528 return;
529 }
530
531 _permissionsMap.put(
532 getPrimaryKeyString(resourceName, resourcePK), permissions);
533 }
534
535 public boolean addPrimaryKey(Class<?> clazz, String primaryKey) {
536 boolean value = hasPrimaryKey(clazz, primaryKey);
537
538 if (!value) {
539 _primaryKeys.add(getPrimaryKeyString(clazz, primaryKey));
540 }
541
542 return value;
543 }
544
545 public void addRatingsEntries(Class<?> clazz, long classPK)
546 throws SystemException {
547
548 List<RatingsEntry> ratingsEntries =
549 RatingsEntryLocalServiceUtil.getEntries(clazz.getName(), classPK);
550
551 if (ratingsEntries.size() == 0) {
552 return;
553 }
554
555 Iterator<RatingsEntry> itr = ratingsEntries.iterator();
556
557 while (itr.hasNext()) {
558 RatingsEntry entry = itr.next();
559
560 entry.setUserUuid(entry.getUserUuid());
561 }
562
563 _ratingsEntriesMap.put(
564 getPrimaryKeyString(clazz, classPK), ratingsEntries);
565 }
566
567 public void addRatingsEntries(
568 String className, long classPK, List<RatingsEntry> ratingsEntries) {
569
570 _ratingsEntriesMap.put(
571 getPrimaryKeyString(className, classPK), ratingsEntries);
572 }
573
574 public void addZipEntry(String path, byte[] bytes) throws SystemException {
575 if (_portletDataContextListener != null) {
576 _portletDataContextListener.onAddZipEntry(path);
577 }
578
579 try {
580 ZipWriter zipWriter = getZipWriter();
581
582 zipWriter.addEntry(path, bytes);
583 }
584 catch (IOException ioe) {
585 throw new SystemException(ioe);
586 }
587 }
588
589 public void addZipEntry(String path, InputStream is)
590 throws SystemException {
591
592 if (_portletDataContextListener != null) {
593 _portletDataContextListener.onAddZipEntry(path);
594 }
595
596 try {
597 ZipWriter zipWriter = getZipWriter();
598
599 zipWriter.addEntry(path, is);
600 }
601 catch (IOException ioe) {
602 throw new SystemException(ioe);
603 }
604 }
605
606 public void addZipEntry(String path, Object object) throws SystemException {
607 addZipEntry(path, toXML(object));
608 }
609
610 public void addZipEntry(String path, String s) throws SystemException {
611 if (_portletDataContextListener != null) {
612 _portletDataContextListener.onAddZipEntry(path);
613 }
614
615 try {
616 ZipWriter zipWriter = getZipWriter();
617
618 zipWriter.addEntry(path, s);
619 }
620 catch (IOException ioe) {
621 throw new SystemException(ioe);
622 }
623 }
624
625 public void addZipEntry(String path, StringBuilder sb)
626 throws SystemException {
627
628 if (_portletDataContextListener != null) {
629 _portletDataContextListener.onAddZipEntry(path);
630 }
631
632 try {
633 ZipWriter zipWriter = getZipWriter();
634
635 zipWriter.addEntry(path, sb);
636 }
637 catch (IOException ioe) {
638 throw new SystemException(ioe);
639 }
640 }
641
642 public ServiceContext createServiceContext(
643 Element element, ClassedModel classedModel, String namespace) {
644
645 return createServiceContext(element, null, classedModel, namespace);
646 }
647
648 public ServiceContext createServiceContext(
649 String path, ClassedModel classedModel, String namespace) {
650
651 return createServiceContext(null, path, classedModel, namespace);
652 }
653
654 public Object fromXML(byte[] bytes) {
655 if ((bytes == null) || (bytes.length == 0)) {
656 return null;
657 }
658
659 return _xStream.fromXML(new String(bytes));
660 }
661
662 public Object fromXML(String xml) {
663 if (Validator.isNull(xml)) {
664 return null;
665 }
666
667 return _xStream.fromXML(xml);
668 }
669
670 public long[] getAssetCategoryIds(Class<?> clazz, long classPK) {
671 return _assetCategoryIdsMap.get(getPrimaryKeyString(clazz, classPK));
672 }
673
674 public Map<String, long[]> getAssetCategoryIdsMap() {
675 return _assetCategoryIdsMap;
676 }
677
678 public Map<String, String[]> getAssetCategoryUuidsMap() {
679 return _assetCategoryUuidsMap;
680 }
681
682 public Map<String, String[]> getAssetLinkUuidsMap() {
683 return _assetLinkUuidsMap;
684 }
685
686 public String[] getAssetTagNames(Class<?> clazz, long classPK) {
687 return _assetTagNamesMap.get(getPrimaryKeyString(clazz, classPK));
688 }
689
690 public String[] getAssetTagNames(String className, long classPK) {
691 return _assetTagNamesMap.get(getPrimaryKeyString(className, classPK));
692 }
693
694 public Map<String, String[]> getAssetTagNamesMap() {
695 return _assetTagNamesMap;
696 }
697
698 public boolean getBooleanParameter(String namespace, String name) {
699 boolean defaultValue = MapUtil.getBoolean(
700 getParameterMap(),
701 PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT, true);
702
703 return MapUtil.getBoolean(
704 getParameterMap(),
705 PortletDataHandlerControl.getNamespacedControlName(namespace, name),
706 defaultValue);
707 }
708
709 public ClassLoader getClassLoader() {
710 return _xStream.getClassLoader();
711 }
712
713 public Map<String, List<MBMessage>> getComments() {
714 return _commentsMap;
715 }
716
717 public long getCompanyId() {
718 return _companyId;
719 }
720
721 public String getDataStrategy() {
722 return _dataStrategy;
723 }
724
725 public Date getEndDate() {
726 return _endDate;
727 }
728
729 public Map<String, List<ExpandoColumn>> getExpandoColumns() {
730 return _expandoColumnsMap;
731 }
732
733 public long getGroupId() {
734 return _groupId;
735 }
736
737 public String getLayoutPath(long layoutId) {
738 return getRootPath() + ROOT_PATH_LAYOUTS + layoutId;
739 }
740
741 public Map<String, Lock> getLocks() {
742 return _locksMap;
743 }
744
745 public Map<?, ?> getNewPrimaryKeysMap(Class<?> clazz) {
746 return getNewPrimaryKeysMap(clazz.getName());
747 }
748
749 public Map<?, ?> getNewPrimaryKeysMap(String className) {
750 Map<?, ?> map = _newPrimaryKeysMaps.get(className);
751
752 if (map == null) {
753 map = new HashMap<Object, Object>();
754
755 _newPrimaryKeysMaps.put(className, map);
756 }
757
758 return map;
759 }
760
761 public long getOldPlid() {
762 return _oldPlid;
763 }
764
765 public Map<String, String[]> getParameterMap() {
766 return _parameterMap;
767 }
768
769 public Map<String, List<KeyValuePair>> getPermissions() {
770 return _permissionsMap;
771 }
772
773 public long getPlid() {
774 return _plid;
775 }
776
777 public String getPortletPath(String portletId) {
778 return getRootPath() + ROOT_PATH_PORTLETS + portletId;
779 }
780
781 public Set<String> getPrimaryKeys() {
782 return _primaryKeys;
783 }
784
785 public Map<String, List<RatingsEntry>> getRatingsEntries() {
786 return _ratingsEntriesMap;
787 }
788
789 public String getRootPath() {
790 return ROOT_PATH_GROUPS + getScopeGroupId();
791 }
792
793 public long getScopeGroupId() {
794 return _scopeGroupId;
795 }
796
797 public String getScopeLayoutUuid() {
798 return _scopeLayoutUuid;
799 }
800
801 public String getScopeType() {
802 return _scopeType;
803 }
804
805 public long getSourceGroupId() {
806 return _sourceGroupId;
807 }
808
809 public String getSourceLayoutPath(long layoutId) {
810 return getSourceRootPath() + ROOT_PATH_LAYOUTS + layoutId;
811 }
812
813 public String getSourcePortletPath(String portletId) {
814 return getSourceRootPath() + ROOT_PATH_PORTLETS + portletId;
815 }
816
817 public String getSourceRootPath() {
818 return ROOT_PATH_GROUPS + getSourceGroupId();
819 }
820
821 public Date getStartDate() {
822 return _startDate;
823 }
824
825 public long getUserId(String userUuid) throws SystemException {
826 return _userIdStrategy.getUserId(userUuid);
827 }
828
829 public UserIdStrategy getUserIdStrategy() {
830 return _userIdStrategy;
831 }
832
833 public List<String> getZipEntries() {
834 return getZipReader().getEntries();
835 }
836
837 public byte[] getZipEntryAsByteArray(String path) {
838 if (_portletDataContextListener != null) {
839 _portletDataContextListener.onGetZipEntry(path);
840 }
841
842 return getZipReader().getEntryAsByteArray(path);
843 }
844
845 public InputStream getZipEntryAsInputStream(String path) {
846 if (_portletDataContextListener != null) {
847 _portletDataContextListener.onGetZipEntry(path);
848 }
849
850 return getZipReader().getEntryAsInputStream(path);
851 }
852
853 public Object getZipEntryAsObject(String path) {
854 return fromXML(getZipEntryAsString(path));
855 }
856
857 public String getZipEntryAsString(String path) {
858 if (_portletDataContextListener != null) {
859 _portletDataContextListener.onGetZipEntry(path);
860 }
861
862 return getZipReader().getEntryAsString(path);
863 }
864
865 public List<String> getZipFolderEntries() {
866 return getZipFolderEntries(StringPool.SLASH);
867 }
868
869 public List<String> getZipFolderEntries(String path) {
870 return getZipReader().getFolderEntries(path);
871 }
872
873 public ZipReader getZipReader() {
874 return _zipReader;
875 }
876
877 public ZipWriter getZipWriter() {
878 return _zipWriter;
879 }
880
881 public boolean hasDateRange() {
882 if (_startDate != null) {
883 return true;
884 }
885 else {
886 return false;
887 }
888 }
889
890 public boolean hasNotUniquePerLayout(String dataKey) {
891 return _notUniquePerLayout.contains(dataKey);
892 }
893
894 public boolean hasPrimaryKey(Class<?> clazz, String primaryKey) {
895 return _primaryKeys.contains(getPrimaryKeyString(clazz, primaryKey));
896 }
897
898 public void importClassedModel(
899 ClassedModel classedModel, ClassedModel newClassedModel,
900 String namespace)
901 throws PortalException, SystemException {
902
903 if (!isResourceMain(classedModel)) {
904 return;
905 }
906
907 Class<?> clazz = classedModel.getModelClass();
908 long classPK = getClassPK(classedModel);
909
910 long newClassPK = getClassPK(newClassedModel);
911
912 Map<Long, Long> newPrimaryKeysMap =
913 (Map<Long, Long>)getNewPrimaryKeysMap(clazz);
914
915 newPrimaryKeysMap.put(classPK, newClassPK);
916
917 importLocks(clazz, String.valueOf(classPK), String.valueOf(newClassPK));
918 importPermissions(clazz, classPK, newClassPK);
919
920 if (getBooleanParameter(namespace, "comments")) {
921 importComments(clazz, classPK, newClassPK, getScopeGroupId());
922 }
923
924 if (getBooleanParameter(namespace, "ratings")) {
925 importRatingsEntries(clazz, classPK, newClassPK);
926 }
927 }
928
929 public void importComments(
930 Class<?> clazz, long classPK, long newClassPK, long groupId)
931 throws PortalException, SystemException {
932
933 Map<Long, Long> messagePKs = new HashMap<Long, Long>();
934 Map<Long, Long> threadPKs = new HashMap<Long, Long>();
935
936 List<MBMessage> messages = _commentsMap.get(
937 getPrimaryKeyString(clazz, classPK));
938
939 if (messages == null) {
940 return;
941 }
942
943 MBDiscussion discussion = null;
944
945 try {
946 discussion = MBDiscussionLocalServiceUtil.getDiscussion(
947 clazz.getName(), newClassPK);
948 }
949 catch (NoSuchDiscussionException nsde) {
950 }
951
952 for (MBMessage message : messages) {
953 long userId = getUserId(message.getUserUuid());
954 long parentMessageId = MapUtil.getLong(
955 messagePKs, message.getParentMessageId(),
956 message.getParentMessageId());
957 long threadId = MapUtil.getLong(
958 threadPKs, message.getThreadId(), message.getThreadId());
959
960 if ((message.getParentMessageId() ==
961 MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) &&
962 (discussion != null)) {
963
964 MBThread thread = MBThreadLocalServiceUtil.getThread(
965 discussion.getThreadId());
966
967 long rootMessageId = thread.getRootMessageId();
968
969 messagePKs.put(message.getMessageId(), rootMessageId);
970 threadPKs.put(message.getThreadId(), thread.getThreadId());
971 }
972 else {
973 ServiceContext serviceContext = new ServiceContext();
974
975 serviceContext.setCreateDate(message.getCreateDate());
976 serviceContext.setModifiedDate(message.getModifiedDate());
977 serviceContext.setScopeGroupId(groupId);
978
979 MBMessage importedMessage = null;
980
981 if (_dataStrategy.equals(
982 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR) ||
983 _dataStrategy.equals(
984 PortletDataHandlerKeys.
985 DATA_STRATEGY_MIRROR_OVERWRITE)) {
986
987 MBMessage existingMessage = MBMessageUtil.fetchByUUID_G(
988 message.getUuid(), groupId);
989
990 if (existingMessage == null) {
991 serviceContext.setUuid(message.getUuid());
992
993 importedMessage =
994 MBMessageLocalServiceUtil.addDiscussionMessage(
995 userId, message.getUserName(), groupId,
996 clazz.getName(), newClassPK, threadId,
997 parentMessageId, message.getSubject(),
998 message.getBody(), serviceContext);
999 }
1000 else {
1001 serviceContext.setWorkflowAction(
1002 WorkflowConstants.ACTION_PUBLISH);
1003
1004 importedMessage =
1005 MBMessageLocalServiceUtil.updateDiscussionMessage(
1006 userId, existingMessage.getMessageId(),
1007 clazz.getName(), newClassPK,
1008 message.getSubject(), message.getBody(),
1009 serviceContext);
1010 }
1011 }
1012 else {
1013 importedMessage =
1014 MBMessageLocalServiceUtil.addDiscussionMessage(
1015 userId, message.getUserName(), groupId,
1016 clazz.getName(), newClassPK, threadId,
1017 parentMessageId, message.getSubject(),
1018 message.getBody(), serviceContext);
1019 }
1020
1021 messagePKs.put(
1022 message.getMessageId(), importedMessage.getMessageId());
1023 threadPKs.put(
1024 message.getThreadId(), importedMessage.getThreadId());
1025 }
1026
1027 importRatingsEntries(
1028 MBDiscussion.class, message.getPrimaryKey(),
1029 messagePKs.get(message.getPrimaryKey()));
1030 }
1031 }
1032
1033 public void importLocks(Class<?> clazz, String key, String newKey)
1034 throws PortalException, SystemException {
1035
1036 Lock lock = _locksMap.get(getPrimaryKeyString(clazz, key));
1037
1038 if (lock == null) {
1039 return;
1040 }
1041
1042 long userId = getUserId(lock.getUserUuid());
1043
1044 long expirationTime = 0;
1045
1046 if (lock.getExpirationDate() != null) {
1047 Date expirationDate = lock.getExpirationDate();
1048
1049 expirationTime = expirationDate.getTime();
1050 }
1051
1052 LockLocalServiceUtil.lock(
1053 userId, clazz.getName(), newKey, lock.getOwner(),
1054 lock.isInheritable(), expirationTime);
1055 }
1056
1057 public void importPermissions(Class<?> clazz, long classPK, long newClassPK)
1058 throws PortalException, SystemException {
1059
1060 importPermissions(clazz.getName(), classPK, newClassPK);
1061 }
1062
1063 public void importPermissions(
1064 String resourceName, long resourcePK, long newResourcePK)
1065 throws PortalException, SystemException {
1066
1067 if (((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 5) &&
1068 (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM != 6)) ||
1069 (!MapUtil.getBoolean(
1070 _parameterMap, PortletDataHandlerKeys.PERMISSIONS))) {
1071
1072 return;
1073 }
1074
1075 List<KeyValuePair> permissions = _permissionsMap.get(
1076 getPrimaryKeyString(resourceName, resourcePK));
1077
1078 if (permissions == null) {
1079 return;
1080 }
1081
1082 Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>();
1083
1084 for (KeyValuePair permission : permissions) {
1085 String roleName = permission.getKey();
1086
1087 Role role = null;
1088
1089 Team team = null;
1090
1091 if (roleName.startsWith(PermissionExporter.ROLE_TEAM_PREFIX)) {
1092 roleName = roleName.substring(
1093 PermissionExporter.ROLE_TEAM_PREFIX.length());
1094
1095 try {
1096 team = TeamLocalServiceUtil.getTeam(_groupId, roleName);
1097 }
1098 catch (NoSuchTeamException nste) {
1099 if (_log.isWarnEnabled()) {
1100 _log.warn("Team " + roleName + " does not exist");
1101 }
1102
1103 continue;
1104 }
1105 }
1106
1107 try {
1108 if (team != null) {
1109 role = RoleLocalServiceUtil.getTeamRole(
1110 _companyId, team.getTeamId());
1111 }
1112 else {
1113 role = RoleLocalServiceUtil.getRole(_companyId, roleName);
1114 }
1115 }
1116 catch (NoSuchRoleException nsre) {
1117 if (_log.isWarnEnabled()) {
1118 _log.warn("Role " + roleName + " does not exist");
1119 }
1120
1121 continue;
1122 }
1123
1124 String[] actionIds = StringUtil.split(permission.getValue());
1125
1126 roleIdsToActionIds.put(role.getRoleId(), actionIds);
1127 }
1128
1129 if (roleIdsToActionIds.isEmpty()) {
1130 return;
1131 }
1132
1133 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
1134 PermissionLocalServiceUtil.setRolesPermissions(
1135 _companyId, roleIdsToActionIds, resourceName,
1136 ResourceConstants.SCOPE_INDIVIDUAL,
1137 String.valueOf(newResourcePK));
1138 }
1139 else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
1140 ResourcePermissionLocalServiceUtil.setResourcePermissions(
1141 _companyId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL,
1142 String.valueOf(newResourcePK), roleIdsToActionIds);
1143 }
1144 }
1145
1146 public void importRatingsEntries(
1147 Class<?> clazz, long classPK, long newClassPK)
1148 throws PortalException, SystemException {
1149
1150 List<RatingsEntry> ratingsEntries = _ratingsEntriesMap.get(
1151 getPrimaryKeyString(clazz, classPK));
1152
1153 if (ratingsEntries == null) {
1154 return;
1155 }
1156
1157 ServiceContext serviceContext = new ServiceContext();
1158
1159 for (RatingsEntry ratingsEntry : ratingsEntries) {
1160 long userId = getUserId(ratingsEntry.getUserUuid());
1161
1162 serviceContext.setCreateDate(ratingsEntry.getCreateDate());
1163 serviceContext.setModifiedDate(ratingsEntry.getModifiedDate());
1164
1165 RatingsEntryLocalServiceUtil.updateEntry(
1166 userId, clazz.getName(), newClassPK, ratingsEntry.getScore(),
1167 serviceContext);
1168 }
1169 }
1170
1171 public boolean isDataStrategyMirror() {
1172 if (_dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR) ||
1173 _dataStrategy.equals(
1174 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) {
1175
1176 return true;
1177 }
1178 else {
1179 return false;
1180 }
1181 }
1182
1183 public boolean isDataStrategyMirrorWithOverwritting() {
1184 if (_dataStrategy.equals(
1185 PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) {
1186
1187 return true;
1188 }
1189 else {
1190 return false;
1191 }
1192 }
1193
1194 public boolean isPathNotProcessed(String path) {
1195 return !addPrimaryKey(String.class, path);
1196 }
1197
1198 public boolean isPerformDirectBinaryImport() {
1199 return MapUtil.getBoolean(
1200 _parameterMap, PortletDataHandlerKeys.PERFORM_DIRECT_BINARY_IMPORT);
1201 }
1202
1203 public boolean isPrivateLayout() {
1204 return _privateLayout;
1205 }
1206
1207 public boolean isWithinDateRange(Date modifiedDate) {
1208 if (!hasDateRange()) {
1209 return true;
1210 }
1211 else if ((_startDate.compareTo(modifiedDate) <= 0) &&
1212 (_endDate.after(modifiedDate))) {
1213
1214 return true;
1215 }
1216 else {
1217 return false;
1218 }
1219 }
1220
1221 public void putNotUniquePerLayout(String dataKey) {
1222 _notUniquePerLayout.add(dataKey);
1223 }
1224
1225 public void setClassLoader(ClassLoader classLoader) {
1226 _xStream.setClassLoader(classLoader);
1227 }
1228
1229 public void setGroupId(long groupId) {
1230 _groupId = groupId;
1231 }
1232
1233 public void setOldPlid(long oldPlid) {
1234 _oldPlid = oldPlid;
1235 }
1236
1237 public void setPlid(long plid) {
1238 _plid = plid;
1239 }
1240
1241 public void setPortetDataContextListener(
1242 PortletDataContextListener portletDataContextListener) {
1243
1244 _portletDataContextListener = portletDataContextListener;
1245 }
1246
1247 public void setPrivateLayout(boolean privateLayout) {
1248 _privateLayout = privateLayout;
1249 }
1250
1251 public void setScopeGroupId(long scopeGroupId) {
1252 _scopeGroupId = scopeGroupId;
1253 }
1254
1255 public void setScopeLayoutUuid(String scopeLayoutUuid) {
1256 _scopeLayoutUuid = scopeLayoutUuid;
1257 }
1258
1259 public void setScopeType(String scopeType) {
1260 _scopeType = scopeType;
1261 }
1262
1263 public void setSourceGroupId(long sourceGroupId) {
1264 _sourceGroupId = sourceGroupId;
1265 }
1266
1267 public String toXML(Object object) {
1268 return _xStream.toXML(object);
1269 }
1270
1271 public void setStartDate(Date startDate) {
1272 _startDate = startDate;
1273 }
1274
1275 protected ServiceContext createServiceContext(
1276 Element element, String path, ClassedModel classedModel,
1277 String namespace) {
1278
1279 Class<?> clazz = classedModel.getModelClass();
1280 long classPK = getClassPK(classedModel);
1281
1282 ServiceContext serviceContext = new ServiceContext();
1283
1284
1285
1286 serviceContext.setCompanyId(getCompanyId());
1287 serviceContext.setScopeGroupId(getScopeGroupId());
1288
1289
1290
1291 if (classedModel instanceof AuditedModel) {
1292 AuditedModel auditedModel = (AuditedModel)classedModel;
1293
1294 serviceContext.setCreateDate(auditedModel.getCreateDate());
1295 serviceContext.setModifiedDate(auditedModel.getModifiedDate());
1296 }
1297
1298
1299
1300 serviceContext.setAddGroupPermissions(true);
1301 serviceContext.setAddGuestPermissions(true);
1302
1303
1304
1305 if (isResourceMain(classedModel)) {
1306 if (getBooleanParameter(namespace, "categories")) {
1307 long[] assetCategoryIds = getAssetCategoryIds(clazz, classPK);
1308
1309 serviceContext.setAssetCategoryIds(assetCategoryIds);
1310 }
1311
1312 if (getBooleanParameter(namespace, "tags")) {
1313 String[] assetTagNames = getAssetTagNames(clazz, classPK);
1314
1315 serviceContext.setAssetTagNames(assetTagNames);
1316 }
1317 }
1318
1319
1320
1321 String expandoPath = null;
1322
1323 if (element != null) {
1324 expandoPath = element.attributeValue("expando-path");
1325 }
1326 else {
1327 expandoPath = getExpandoPath(path);
1328 }
1329
1330 if (Validator.isNotNull(expandoPath)) {
1331 try {
1332 Map<String, Serializable> expandoBridgeAttributes =
1333 (Map<String, Serializable>)getZipEntryAsObject(expandoPath);
1334
1335 serviceContext.setExpandoBridgeAttributes(
1336 expandoBridgeAttributes);
1337 }
1338 catch (Exception e) {
1339 if (_log.isDebugEnabled()) {
1340 _log.debug(e, e);
1341 }
1342 }
1343 }
1344
1345 return serviceContext;
1346 }
1347
1348 protected String getActionIds_5(
1349 long companyId, long roleId, String className, String primKey,
1350 List<String> actionIds)
1351 throws SystemException {
1352
1353 List<String> availableActionIds = new ArrayList<String>(
1354 actionIds.size());
1355
1356 for (String actionId : actionIds) {
1357 if (PermissionLocalServiceUtil.hasRolePermission(
1358 roleId, companyId, className,
1359 ResourceConstants.SCOPE_INDIVIDUAL, primKey, actionId)) {
1360
1361 availableActionIds.add(actionId);
1362 }
1363 }
1364
1365 return StringUtil.merge(availableActionIds);
1366 }
1367
1368 protected Map<Long, Set<String>> getActionIds_6(
1369 long companyId, long[] roleIds, String className, String primKey,
1370 List<String> actionIds)
1371 throws PortalException, SystemException {
1372
1373 return ResourcePermissionLocalServiceUtil.
1374 getAvailableResourcePermissionActionIds(
1375 companyId, className, ResourceConstants.SCOPE_INDIVIDUAL,
1376 primKey, roleIds, actionIds);
1377 }
1378
1379 protected long getClassPK(ClassedModel classedModel) {
1380 if (classedModel instanceof ResourcedModel) {
1381 ResourcedModel resourcedModel = (ResourcedModel)classedModel;
1382
1383 return resourcedModel.getResourcePrimKey();
1384 }
1385 else {
1386 return (Long)classedModel.getPrimaryKeyObj();
1387 }
1388 }
1389
1390 protected String getExpandoPath(String path) {
1391 int pos = path.lastIndexOf(".xml");
1392
1393 if (pos == -1) {
1394 throw new IllegalArgumentException(
1395 path + " does not end with .xml");
1396 }
1397
1398 return path.substring(0, pos).concat("-expando").concat(
1399 path.substring(pos, path.length()));
1400 }
1401
1402 protected String getPrimaryKeyString(Class<?> clazz, long classPK) {
1403 return getPrimaryKeyString(clazz.getName(), String.valueOf(classPK));
1404 }
1405
1406 protected String getPrimaryKeyString(Class<?> clazz, String primaryKey) {
1407 return getPrimaryKeyString(clazz.getName(), primaryKey);
1408 }
1409
1410 protected String getPrimaryKeyString(String className, long classPK) {
1411 return getPrimaryKeyString(className, String.valueOf(classPK));
1412 }
1413
1414 protected String getPrimaryKeyString(String className, String primaryKey) {
1415 return className.concat(StringPool.POUND).concat(primaryKey);
1416 }
1417
1418 protected void initXStream() {
1419 _xStream = new XStream();
1420
1421 _xStream.alias("BlogsEntry", BlogsEntryImpl.class);
1422 _xStream.alias("BookmarksFolder", BookmarksFolderImpl.class);
1423 _xStream.alias("BookmarksEntry", BookmarksEntryImpl.class);
1424 _xStream.alias("CalEvent", CalEventImpl.class);
1425 _xStream.alias("DLFolder", DLFolderImpl.class);
1426 _xStream.alias("DLFileEntry", DLFileEntryImpl.class);
1427 _xStream.alias("DLFileShortcut", DLFileShortcutImpl.class);
1428 _xStream.alias("DLFileRank", DLFileRankImpl.class);
1429 _xStream.alias("JournalArticle", JournalArticleImpl.class);
1430 _xStream.alias("JournalFeed", JournalFeedImpl.class);
1431 _xStream.alias("JournalStructure", JournalStructureImpl.class);
1432 _xStream.alias("JournalTemplate", JournalTemplateImpl.class);
1433 _xStream.alias("Lock", LockImpl.class);
1434 _xStream.alias("MBBan", MBBanImpl.class);
1435 _xStream.alias("MBCategory", MBCategoryImpl.class);
1436 _xStream.alias("MBMessage", MBMessageImpl.class);
1437 _xStream.alias("MBThreadFlag", MBThreadFlagImpl.class);
1438 _xStream.alias("PollsQuestion", PollsQuestionImpl.class);
1439 _xStream.alias("PollsChoice", PollsChoiceImpl.class);
1440 _xStream.alias("PollsVote", PollsVoteImpl.class);
1441 _xStream.alias("RatingsEntry", RatingsEntryImpl.class);
1442 _xStream.alias("WikiNode", WikiNodeImpl.class);
1443 _xStream.alias("WikiPage", WikiPageImpl.class);
1444 }
1445
1446 protected boolean isResourceMain(ClassedModel classedModel) {
1447 if (classedModel instanceof ResourcedModel) {
1448 ResourcedModel resourcedModel = (ResourcedModel)classedModel;
1449
1450 return resourcedModel.isResourceMain();
1451 }
1452
1453 return true;
1454 }
1455
1456 protected void validateDateRange(Date startDate, Date endDate)
1457 throws PortletDataException {
1458
1459 if ((startDate == null) && (endDate != null)) {
1460 throw new PortletDataException(
1461 PortletDataException.END_DATE_IS_MISSING_START_DATE);
1462 }
1463 else if ((startDate != null) && (endDate == null)) {
1464 throw new PortletDataException(
1465 PortletDataException.START_DATE_IS_MISSING_END_DATE);
1466 }
1467
1468 if (startDate != null) {
1469 if (startDate.after(endDate) || startDate.equals(endDate)) {
1470 throw new PortletDataException(
1471 PortletDataException.START_DATE_AFTER_END_DATE);
1472 }
1473
1474 Date now = new Date();
1475
1476 if (startDate.after(now)) {
1477 throw new PortletDataException(
1478 PortletDataException.FUTURE_START_DATE);
1479 }
1480
1481 if (endDate.after(now)) {
1482 throw new PortletDataException(
1483 PortletDataException.FUTURE_END_DATE);
1484 }
1485 }
1486 }
1487
1488 private static Log _log = LogFactoryUtil.getLog(
1489 PortletDataContextImpl.class);
1490
1491 private Map<String, long[]> _assetCategoryIdsMap =
1492 new HashMap<String, long[]>();
1493 private Map<String, String[]> _assetCategoryUuidsMap =
1494 new HashMap<String, String[]>();
1495 private Map<String, String[]> _assetLinkUuidsMap =
1496 new HashMap<String, String[]>();
1497 private Map<String, String[]> _assetTagNamesMap =
1498 new HashMap<String, String[]>();
1499 private Map<String, List<MBMessage>> _commentsMap =
1500 new HashMap<String, List<MBMessage>>();
1501 private long _companyId;
1502 private String _dataStrategy;
1503 private Date _endDate;
1504 private Map<String, List<ExpandoColumn>> _expandoColumnsMap =
1505 new HashMap<String, List<ExpandoColumn>>();
1506 private long _groupId;
1507 private Map<String, Lock> _locksMap = new HashMap<String, Lock>();
1508 private Map<String, Map<?, ?>> _newPrimaryKeysMaps =
1509 new HashMap<String, Map<?, ?>>();
1510 private Set<String> _notUniquePerLayout = new HashSet<String>();
1511 private long _oldPlid;
1512 private Map<String, String[]> _parameterMap;
1513 private Map<String, List<KeyValuePair>> _permissionsMap =
1514 new HashMap<String, List<KeyValuePair>>();
1515 private long _plid;
1516 private PortletDataContextListener _portletDataContextListener;
1517 private Set<String> _primaryKeys;
1518 private boolean _privateLayout;
1519 private Map<String, List<RatingsEntry>> _ratingsEntriesMap =
1520 new HashMap<String, List<RatingsEntry>>();
1521 private long _scopeGroupId;
1522 private String _scopeLayoutUuid;
1523 private String _scopeType;
1524 private long _sourceGroupId;
1525 private Date _startDate;
1526 private UserIdStrategy _userIdStrategy;
1527 private XStream _xStream;
1528 private ZipReader _zipReader;
1529 private ZipWriter _zipWriter;
1530
1531 }