001
014
015 package com.liferay.portal.tools.samplesqlbuilder;
016
017 import com.liferay.counter.model.Counter;
018 import com.liferay.counter.model.impl.CounterImpl;
019 import com.liferay.portal.kernel.util.CharPool;
020 import com.liferay.portal.kernel.util.ContentTypes;
021 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
022 import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
023 import com.liferay.portal.kernel.util.IntegerWrapper;
024 import com.liferay.portal.kernel.util.ListUtil;
025 import com.liferay.portal.kernel.util.StringBundler;
026 import com.liferay.portal.kernel.util.StringPool;
027 import com.liferay.portal.kernel.util.StringUtil;
028 import com.liferay.portal.kernel.util.Time;
029 import com.liferay.portal.kernel.util.UnicodeProperties;
030 import com.liferay.portal.kernel.util.Validator;
031 import com.liferay.portal.kernel.workflow.WorkflowConstants;
032 import com.liferay.portal.model.Account;
033 import com.liferay.portal.model.ClassName;
034 import com.liferay.portal.model.Company;
035 import com.liferay.portal.model.Contact;
036 import com.liferay.portal.model.ContactConstants;
037 import com.liferay.portal.model.Group;
038 import com.liferay.portal.model.GroupConstants;
039 import com.liferay.portal.model.Layout;
040 import com.liferay.portal.model.LayoutConstants;
041 import com.liferay.portal.model.LayoutSet;
042 import com.liferay.portal.model.LayoutTypePortletConstants;
043 import com.liferay.portal.model.ModelHintsUtil;
044 import com.liferay.portal.model.PortletConstants;
045 import com.liferay.portal.model.PortletPreferences;
046 import com.liferay.portal.model.ResourceConstants;
047 import com.liferay.portal.model.ResourcePermission;
048 import com.liferay.portal.model.Role;
049 import com.liferay.portal.model.RoleConstants;
050 import com.liferay.portal.model.User;
051 import com.liferay.portal.model.VirtualHost;
052 import com.liferay.portal.model.impl.AccountImpl;
053 import com.liferay.portal.model.impl.ClassNameImpl;
054 import com.liferay.portal.model.impl.CompanyImpl;
055 import com.liferay.portal.model.impl.ContactImpl;
056 import com.liferay.portal.model.impl.GroupImpl;
057 import com.liferay.portal.model.impl.LayoutImpl;
058 import com.liferay.portal.model.impl.LayoutSetImpl;
059 import com.liferay.portal.model.impl.PortletPreferencesImpl;
060 import com.liferay.portal.model.impl.ResourcePermissionImpl;
061 import com.liferay.portal.model.impl.RoleImpl;
062 import com.liferay.portal.model.impl.UserImpl;
063 import com.liferay.portal.model.impl.VirtualHostImpl;
064 import com.liferay.portal.service.permission.PortletPermissionUtil;
065 import com.liferay.portal.util.PortletKeys;
066 import com.liferay.portal.util.PropsValues;
067 import com.liferay.portlet.PortletPreferencesFactoryUtil;
068 import com.liferay.portlet.asset.model.AssetCategory;
069 import com.liferay.portlet.asset.model.AssetCategoryConstants;
070 import com.liferay.portlet.asset.model.AssetEntry;
071 import com.liferay.portlet.asset.model.AssetVocabulary;
072 import com.liferay.portlet.asset.model.impl.AssetCategoryImpl;
073 import com.liferay.portlet.asset.model.impl.AssetEntryImpl;
074 import com.liferay.portlet.asset.model.impl.AssetVocabularyImpl;
075 import com.liferay.portlet.blogs.model.BlogsEntry;
076 import com.liferay.portlet.blogs.model.BlogsStatsUser;
077 import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
078 import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
079 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
080 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
081 import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
082 import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
083 import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
084 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
085 import com.liferay.portlet.documentlibrary.model.DLFolder;
086 import com.liferay.portlet.documentlibrary.model.DLSync;
087 import com.liferay.portlet.documentlibrary.model.DLSyncConstants;
088 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
089 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl;
090 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeImpl;
091 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
092 import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
093 import com.liferay.portlet.documentlibrary.model.impl.DLSyncImpl;
094 import com.liferay.portlet.documentlibrary.social.DLActivityKeys;
095 import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
096 import com.liferay.portlet.dynamicdatalists.model.DDLRecordConstants;
097 import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
098 import com.liferay.portlet.dynamicdatalists.model.DDLRecordSetConstants;
099 import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
100 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordImpl;
101 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordSetImpl;
102 import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionImpl;
103 import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
104 import com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink;
105 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
106 import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink;
107 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentImpl;
108 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStorageLinkImpl;
109 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl;
110 import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLinkImpl;
111 import com.liferay.portlet.journal.model.JournalArticle;
112 import com.liferay.portlet.journal.model.JournalArticleConstants;
113 import com.liferay.portlet.journal.model.JournalArticleResource;
114 import com.liferay.portlet.journal.model.JournalContentSearch;
115 import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
116 import com.liferay.portlet.journal.model.impl.JournalArticleResourceImpl;
117 import com.liferay.portlet.journal.model.impl.JournalContentSearchImpl;
118 import com.liferay.portlet.journal.social.JournalActivityKeys;
119 import com.liferay.portlet.messageboards.model.MBCategory;
120 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
121 import com.liferay.portlet.messageboards.model.MBDiscussion;
122 import com.liferay.portlet.messageboards.model.MBMailingList;
123 import com.liferay.portlet.messageboards.model.MBMessage;
124 import com.liferay.portlet.messageboards.model.MBMessageConstants;
125 import com.liferay.portlet.messageboards.model.MBStatsUser;
126 import com.liferay.portlet.messageboards.model.MBThread;
127 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
128 import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
129 import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
130 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
131 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
132 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
133 import com.liferay.portlet.social.model.SocialActivity;
134 import com.liferay.portlet.social.model.impl.SocialActivityImpl;
135 import com.liferay.portlet.wiki.model.WikiNode;
136 import com.liferay.portlet.wiki.model.WikiPage;
137 import com.liferay.portlet.wiki.model.WikiPageConstants;
138 import com.liferay.portlet.wiki.model.WikiPageResource;
139 import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
140 import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
141 import com.liferay.portlet.wiki.model.impl.WikiPageResourceImpl;
142 import com.liferay.util.SimpleCounter;
143
144 import java.io.File;
145 import java.io.FileInputStream;
146 import java.io.IOException;
147
148 import java.text.Format;
149
150 import java.util.ArrayList;
151 import java.util.Date;
152 import java.util.HashMap;
153 import java.util.List;
154 import java.util.Map;
155
156
159 public class DataFactory {
160
161 public DataFactory(
162 String baseDir, int maxAssetCategoryCount, int maxBlogsEntryCount,
163 int maxGroupsCount, int maxJournalArticleCount,
164 int maxJournalArticleSize, int maxMBCategoryCount,
165 int maxMBThreadCount, int maxMBMessageCount,
166 int maxUserToGroupCount)
167 throws Exception {
168
169 _baseDir = baseDir;
170 _maxAssetCategoryCount = maxAssetCategoryCount;
171 _maxBlogsEntryCount = maxBlogsEntryCount;
172 _maxGroupsCount = maxGroupsCount;
173 _maxJournalArticleCount = maxJournalArticleCount;
174 _maxMBCategoryCount = maxMBCategoryCount;
175 _maxMBThreadCount = maxMBThreadCount;
176 _maxMBMessageCount = maxMBMessageCount;
177 _maxUserToGroupCount = maxUserToGroupCount;
178
179 _counter = new SimpleCounter(_maxGroupsCount + 1);
180 _futureDateCounter = new SimpleCounter();
181 _resourcePermissionCounter = new SimpleCounter();
182 _socialActivityCounter = new SimpleCounter();
183 _userScreenNameCounter = new SimpleCounter();
184
185 _classNames = new ArrayList<ClassName>();
186
187 List<String> models = ModelHintsUtil.getModels();
188
189 for (String model : models) {
190 ClassName className = new ClassNameImpl();
191
192 long classNameId = _counter.get();
193
194 className.setClassNameId(classNameId);
195
196 className.setValue(model);
197
198 _classNames.add(className);
199
200 _classNamesMap.put(model, classNameId);
201 }
202
203 _accountId = _counter.get();
204 _companyId = _counter.get();
205 _defaultUserId = _counter.get();
206 _globalGroupId = _counter.get();
207 _guestGroupId = _counter.get();
208 _sampleUserId = _counter.get();
209
210 _dlDDMStructureContent = StringUtil.read(
211 new FileInputStream(
212 new File(
213 _baseDir,
214 _DEPENDENCIES_DIR + "ddm_structure_basic_document.xml")));
215 _ddlDDMStructureContent = StringUtil.read(
216 new FileInputStream(
217 new File(
218 _baseDir, _DEPENDENCIES_DIR + "ddm_structure_ddl.xml")));
219
220 initAssetCateogries();
221 initCompany();
222 initDLFileEntryType();
223 initGroups();
224 initJournalArticle(maxJournalArticleSize);
225 initRoles();
226 initUserNames();
227 initUsers();
228 initVirtualHost();
229 }
230
231 public Account getAccount() {
232 return _account;
233 }
234
235 public Role getAdministratorRole() {
236 return _administratorRole;
237 }
238
239 public List<AssetCategory> getAssetCategories() {
240 return _assetCategories;
241 }
242
243 public long getAssetCategoryId(long groupId, int currentIndex) {
244 int index = (currentIndex - 1) % _maxAssetCategoryCount;
245
246 index = _maxAssetCategoryCount * ((int)groupId - 1) + index;
247
248 AssetCategory assetCategory = _assetCategories.get(index);
249
250 return assetCategory.getCategoryId();
251 }
252
253 public List<AssetVocabulary> getAssetVocabularies() {
254 return _assetVocabularies;
255 }
256
257 public long getBlogsEntryClassNameId() {
258 return _classNamesMap.get(BlogsEntry.class.getName());
259 }
260
261 public List<ClassName> getClassNames() {
262 return _classNames;
263 }
264
265 public Company getCompany() {
266 return _company;
267 }
268
269 public SimpleCounter getCounter() {
270 return _counter;
271 }
272
273 public String getDateLong(Date date) {
274 return String.valueOf(date.getTime());
275 }
276
277 public String getDateString(Date date) {
278 if (date == null) {
279 return null;
280 }
281
282 return _simpleDateFormat.format(date);
283 }
284
285 public long getDDLRecordSetClassNameId() {
286 return _classNamesMap.get(DDLRecordSet.class.getName());
287 }
288
289 public DDMStructure getDefaultDLDDMStructure() {
290 return _defaultDLDDMStructure;
291 }
292
293 public long getDefaultDLDDMStructureId() {
294 return _defaultDLDDMStructure.getStructureId();
295 }
296
297 public DLFileEntryType getDefaultDLFileEntryType() {
298 return _defaultDLFileEntryType;
299 }
300
301 public User getDefaultUser() {
302 return _defaultUser;
303 }
304
305 public long getDLFileEntryClassNameId() {
306 return _classNamesMap.get(DLFileEntry.class.getName());
307 }
308
309 public Group getGlobalGroup() {
310 return _globalGroup;
311 }
312
313 public long getGroupClassNameId() {
314 return _classNamesMap.get(Group.class.getName());
315 }
316
317 public List<Group> getGroups() {
318 return _groups;
319 }
320
321 public Group getGuestGroup() {
322 return _guestGroup;
323 }
324
325 public User getGuestUser() {
326 return _guestUser;
327 }
328
329 public long getJournalArticleClassNameId() {
330 return _classNamesMap.get(JournalArticle.class.getName());
331 }
332
333 public String getJournalArticleLayoutColumn(String portletPrefix) {
334 StringBundler sb = new StringBundler(3 * _maxJournalArticleCount);
335
336 for (int i = 1; i <= _maxJournalArticleCount; i++) {
337 sb.append(portletPrefix);
338 sb.append(i);
339 sb.append(StringPool.COMMA);
340 }
341
342 return sb.toString();
343 }
344
345 public long getLayoutClassNameId() {
346 return _classNamesMap.get(Layout.class.getName());
347 }
348
349 public List<Long> getNewUserGroupIds(long groupId) {
350 List<Long> groupIds = new ArrayList<Long>(_maxUserToGroupCount + 1);
351
352 groupIds.add(_guestGroup.getGroupId());
353
354 if ((groupId + _maxUserToGroupCount) > _maxGroupsCount) {
355 groupId = groupId - _maxUserToGroupCount + 1;
356 }
357
358 for (int i = 0; i < _maxUserToGroupCount; i++) {
359 groupIds.add(groupId + i);
360 }
361
362 return groupIds;
363 }
364
365 public Role getPowerUserRole() {
366 return _powerUserRole;
367 }
368
369 public List<Role> getRoles() {
370 return _roles;
371 }
372
373 public User getSampleUser() {
374 return _sampleUser;
375 }
376
377 public Role getUserRole() {
378 return _userRole;
379 }
380
381 public VirtualHost getVirtualHost() {
382 return _virtualHost;
383 }
384
385 public long getWikiPageClassNameId() {
386 return _classNamesMap.get(WikiPage.class.getName());
387 }
388
389 public void initAssetCateogries() {
390 _assetVocabularies = new ArrayList<AssetVocabulary>();
391 _assetCategories = new ArrayList<AssetCategory>();
392
393 StringBundler sb = new StringBundler(5);
394
395 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
396 sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
397 sb.append("<Title language-id=\"en_US\">");
398 sb.append(PropsValues.ASSET_VOCABULARY_DEFAULT);
399 sb.append("</Title></root>");
400
401 String defaultTitle = sb.toString();
402
403 _assetVocabularies.add(
404 newAssetVocabulary(
405 _globalGroupId, _defaultUserId, null,
406 PropsValues.ASSET_VOCABULARY_DEFAULT, defaultTitle));
407
408 for (int i = 1; i <= _maxGroupsCount; i++) {
409 long lastRightCategoryId = 2;
410
411 for (int j = 0; j < _maxAssetCategoryCount; j++) {
412 sb = new StringBundler(4);
413
414 sb.append("Test_");
415 sb.append(i);
416 sb.append(StringPool.UNDERLINE);
417 sb.append(j);
418
419 String name = sb.toString();
420
421 sb = new StringBundler(5);
422
423 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
424 sb.append(
425 "available-locales=\"en_US\" default-locale=\"en_US\">");
426 sb.append("<Title language-id=\"en_US\">");
427 sb.append(name);
428 sb.append("</Title></root>");
429
430 String title = sb.toString();
431
432 AssetVocabulary assetVocabulary = newAssetVocabulary(
433 i, _sampleUserId, _SAMPLE_USER_NAME, name, title);
434
435 _assetVocabularies.add(assetVocabulary);
436
437 AssetCategory assetCategory = new AssetCategoryImpl();
438
439 assetCategory.setUuid(SequentialUUID.generate());
440 assetCategory.setCategoryId(_counter.get());
441 assetCategory.setGroupId(i);
442 assetCategory.setCompanyId(_companyId);
443 assetCategory.setUserId(_sampleUserId);
444 assetCategory.setUserName(_SAMPLE_USER_NAME);
445 assetCategory.setCreateDate(new Date());
446 assetCategory.setModifiedDate(new Date());
447 assetCategory.setParentCategoryId(
448 AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
449 assetCategory.setLeftCategoryId(lastRightCategoryId++);
450 assetCategory.setRightCategoryId(lastRightCategoryId++);
451 assetCategory.setName(name);
452 assetCategory.setTitle(title);
453 assetCategory.setVocabularyId(
454 assetVocabulary.getVocabularyId());
455
456 _assetCategories.add(assetCategory);
457 }
458 }
459 }
460
461 public void initCompany() {
462 _company = new CompanyImpl();
463
464 _company.setCompanyId(_companyId);
465 _company.setAccountId(_accountId);
466 _company.setWebId("liferay.com");
467 _company.setMx("liferay.com");
468 _company.setActive(true);
469
470 _account = new AccountImpl();
471
472 _account.setAccountId(_accountId);
473 _account.setCompanyId(_companyId);
474 _account.setCreateDate(new Date());
475 _account.setModifiedDate(new Date());
476 _account.setName("Liferay");
477 _account.setLegalName("Liferay, Inc.");
478 }
479
480 public void initDLFileEntryType() {
481 _defaultDLFileEntryType = new DLFileEntryTypeImpl();
482
483 _defaultDLFileEntryType.setUuid(SequentialUUID.generate());
484 _defaultDLFileEntryType.setFileEntryTypeId(
485 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);
486 _defaultDLFileEntryType.setCreateDate(nextFutureDate());
487 _defaultDLFileEntryType.setModifiedDate(nextFutureDate());
488 _defaultDLFileEntryType.setName(
489 DLFileEntryTypeConstants.NAME_BASIC_DOCUMENT);
490
491 _defaultDLDDMStructure = newDDMStructure(
492 _guestGroupId, getDLFileEntryClassNameId(), "TIKARAWMETADATA",
493 _dlDDMStructureContent);
494 }
495
496 public void initGroups() throws Exception {
497 long groupClassNameId = getGroupClassNameId();
498
499 _globalGroup = newGroup(
500 _globalGroupId, _classNamesMap.get(Company.class.getName()),
501 _companyId, GroupConstants.GLOBAL, false);
502
503 _guestGroup = newGroup(
504 _guestGroupId, groupClassNameId, _guestGroupId,
505 GroupConstants.GUEST, true);
506
507 _groups = new ArrayList<Group>(_maxGroupsCount);
508
509 for (int i = 1; i <= _maxGroupsCount; i++) {
510 Group group = newGroup(i, groupClassNameId, i, "Site " + i, true);
511
512 _groups.add(group);
513 }
514 }
515
516 public void initJournalArticle(int maxJournalArticleSize) {
517 StringBundler sb = new StringBundler(5);
518
519 sb.append("<?xml version=\"1.0\"?><root available-locales=\"en_US\" ");
520 sb.append("default-locale=\"en_US\"><static-content language-id=");
521 sb.append("\"en_US\"><![CDATA[<p>");
522
523 if (maxJournalArticleSize <= 0) {
524 maxJournalArticleSize = 1;
525 }
526
527 char[] chars = new char[maxJournalArticleSize];
528
529 for (int i = 0; i < maxJournalArticleSize; i++) {
530 chars[i] = (char)(CharPool.LOWER_CASE_A + (i % 26));
531 }
532
533 sb.append(new String(chars));
534
535 sb.append("</p>]]></static-content></root>");
536
537 _journalArticleContent = sb.toString();
538 }
539
540 public void initRoles() {
541 _roles = new ArrayList<Role>();
542
543
544
545 _administratorRole = newRole(
546 RoleConstants.ADMINISTRATOR, RoleConstants.TYPE_REGULAR);
547
548 _roles.add(_administratorRole);
549
550
551
552 _guestRole = newRole(RoleConstants.GUEST, RoleConstants.TYPE_REGULAR);
553
554 _roles.add(_guestRole);
555
556
557
558 Role organizationAdministratorRole = newRole(
559 RoleConstants.ORGANIZATION_ADMINISTRATOR,
560 RoleConstants.TYPE_ORGANIZATION);
561
562 _roles.add(organizationAdministratorRole);
563
564
565
566 Role organizationOwnerRole = newRole(
567 RoleConstants.ORGANIZATION_OWNER, RoleConstants.TYPE_ORGANIZATION);
568
569 _roles.add(organizationOwnerRole);
570
571
572
573 Role organizationUserRole = newRole(
574 RoleConstants.ORGANIZATION_USER, RoleConstants.TYPE_ORGANIZATION);
575
576 _roles.add(organizationUserRole);
577
578
579
580 _ownerRole = newRole(RoleConstants.OWNER, RoleConstants.TYPE_REGULAR);
581
582 _roles.add(_ownerRole);
583
584
585
586 _powerUserRole = newRole(
587 RoleConstants.POWER_USER, RoleConstants.TYPE_REGULAR);
588
589 _roles.add(_powerUserRole);
590
591
592
593 Role siteAdministratorRole = newRole(
594 RoleConstants.SITE_ADMINISTRATOR, RoleConstants.TYPE_SITE);
595
596 _roles.add(siteAdministratorRole);
597
598
599
600 _siteMemberRole = newRole(
601 RoleConstants.SITE_MEMBER, RoleConstants.TYPE_SITE);
602
603 _roles.add(_siteMemberRole);
604
605
606
607 Role siteOwnerRole = newRole(
608 RoleConstants.SITE_OWNER, RoleConstants.TYPE_SITE);
609
610 _roles.add(siteOwnerRole);
611
612
613
614 _userRole = newRole(RoleConstants.USER, RoleConstants.TYPE_REGULAR);
615
616 _roles.add(_userRole);
617 }
618
619 public void initUserNames() throws IOException {
620 _firstNames = ListUtil.fromFile(
621 new File(_baseDir, _DEPENDENCIES_DIR + "first_names.txt"));
622 _lastNames = ListUtil.fromFile(
623 new File(_baseDir, _DEPENDENCIES_DIR + "last_names.txt"));
624 }
625
626 public void initUsers() {
627 _defaultUser = newUser(
628 _defaultUserId, StringPool.BLANK, StringPool.BLANK,
629 StringPool.BLANK, true);
630 _guestUser = newUser(_counter.get(), "Test", "Test", "Test", false);
631 _sampleUser = newUser(
632 _sampleUserId, _SAMPLE_USER_NAME, _SAMPLE_USER_NAME,
633 _SAMPLE_USER_NAME, false);
634 }
635
636 public void initVirtualHost() {
637 _virtualHost = new VirtualHostImpl();
638
639 _virtualHost.setVirtualHostId(_counter.get());
640 _virtualHost.setCompanyId(_companyId);
641 _virtualHost.setHostname("localhost");
642 }
643
644 public AssetEntry newAssetEntry(BlogsEntry blogsEntry) {
645 return newAssetEntry(
646 blogsEntry.getGroupId(), blogsEntry.getCreateDate(),
647 blogsEntry.getModifiedDate(), getBlogsEntryClassNameId(),
648 blogsEntry.getEntryId(), blogsEntry.getUuid(), 0, true,
649 ContentTypes.TEXT_HTML, blogsEntry.getTitle());
650 }
651
652 public AssetEntry newAssetEntry(DLFileEntry dlFileEntry) {
653 return newAssetEntry(
654 dlFileEntry.getGroupId(), dlFileEntry.getCreateDate(),
655 dlFileEntry.getModifiedDate(), getDLFileEntryClassNameId(),
656 dlFileEntry.getFileEntryId(), dlFileEntry.getUuid(),
657 dlFileEntry.getFileEntryTypeId(), true, dlFileEntry.getMimeType(),
658 dlFileEntry.getTitle());
659 }
660
661 public AssetEntry newAssetEntry(JournalArticle journalArticle) {
662 return newAssetEntry(
663 journalArticle.getGroupId(), journalArticle.getCreateDate(),
664 journalArticle.getModifiedDate(), getJournalArticleClassNameId(),
665 journalArticle.getResourcePrimKey(), journalArticle.getUuid(), 0,
666 true, ContentTypes.TEXT_HTML, journalArticle.getTitle());
667 }
668
669 public AssetEntry newAssetEntry(MBMessage mbMessage) {
670 long classNameId = 0;
671 boolean visible = false;
672
673 if (mbMessage.isDiscussion()) {
674 classNameId = _classNamesMap.get(MBDiscussion.class.getName());
675 }
676 else {
677 classNameId = _classNamesMap.get(MBMessage.class.getName());
678 visible = true;
679 }
680
681 return newAssetEntry(
682 mbMessage.getGroupId(), mbMessage.getCreateDate(),
683 mbMessage.getModifiedDate(), classNameId, mbMessage.getMessageId(),
684 mbMessage.getUuid(), 0, visible, ContentTypes.TEXT_HTML,
685 mbMessage.getSubject());
686 }
687
688 public AssetEntry newAssetEntry(WikiPage wikiPage) {
689 return newAssetEntry(
690 wikiPage.getGroupId(), wikiPage.getCreateDate(),
691 wikiPage.getModifiedDate(), getWikiPageClassNameId(),
692 wikiPage.getResourcePrimKey(), wikiPage.getUuid(), 0, true,
693 ContentTypes.TEXT_HTML, wikiPage.getTitle());
694 }
695
696 public BlogsEntry newBlogsEntry(long groupId, int index) {
697 BlogsEntry blogsEntry = new BlogsEntryImpl();
698
699 blogsEntry.setUuid(SequentialUUID.generate());
700 blogsEntry.setEntryId(_counter.get());
701 blogsEntry.setGroupId(groupId);
702 blogsEntry.setCompanyId(_companyId);
703 blogsEntry.setUserId(_sampleUserId);
704 blogsEntry.setUserName(_SAMPLE_USER_NAME);
705 blogsEntry.setCreateDate(new Date());
706 blogsEntry.setModifiedDate(new Date());
707 blogsEntry.setTitle("Test Blog " + index);
708 blogsEntry.setUrlTitle("testblog" + index);
709 blogsEntry.setContent("This is test blog " + index + ".");
710 blogsEntry.setDisplayDate(new Date());
711 blogsEntry.setStatusDate(new Date());
712
713 return blogsEntry;
714 }
715
716 public BlogsStatsUser newBlogsStatsUser(long groupId) {
717 BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
718
719 blogsStatsUser.setStatsUserId(_counter.get());
720 blogsStatsUser.setGroupId(groupId);
721 blogsStatsUser.setCompanyId(_companyId);
722 blogsStatsUser.setUserId(_sampleUserId);
723 blogsStatsUser.setEntryCount(_maxBlogsEntryCount);
724 blogsStatsUser.setLastPostDate(new Date());
725
726 return blogsStatsUser;
727 }
728
729 public Contact newContact(User user) {
730 Contact contact = new ContactImpl();
731
732 contact.setContactId(user.getContactId());
733 contact.setCompanyId(user.getCompanyId());
734 contact.setUserId(user.getUserId());
735 contact.setUserName(user.getFullName());
736 contact.setCreateDate(new Date());
737 contact.setModifiedDate(new Date());
738 contact.setClassNameId(_classNamesMap.get(User.class.getName()));
739 contact.setClassPK(user.getUserId());
740 contact.setAccountId(_accountId);
741 contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
742 contact.setEmailAddress(user.getEmailAddress());
743 contact.setFirstName(user.getFirstName());
744 contact.setLastName(user.getLastName());
745 contact.setMale(true);
746 contact.setBirthday(new Date());
747
748 return contact;
749 }
750
751 public List<Counter> newCounters() {
752 List<Counter> counters = new ArrayList<Counter>();
753
754
755
756 Counter counter = new CounterImpl();
757
758 counter.setName(Counter.class.getName());
759 counter.setCurrentId(_counter.get());
760
761 counters.add(counter);
762
763
764
765 counter = new CounterImpl();
766
767 counter.setName(ResourcePermission.class.getName());
768 counter.setCurrentId(_resourcePermissionCounter.get());
769
770 counters.add(counter);
771
772
773
774 counter = new CounterImpl();
775
776 counter.setName(SocialActivity.class.getName());
777 counter.setCurrentId(_socialActivityCounter.get());
778
779 counters.add(counter);
780
781 return counters;
782 }
783
784 public DDMStructure newDDLDDMStructure(long groupId) {
785 return newDDMStructure(
786 groupId, _classNamesMap.get(DDLRecordSet.class.getName()),
787 "Test DDM Structure", _ddlDDMStructureContent);
788 }
789
790 public DDLRecord newDDLRecord(DDLRecordSet ddlRecordSet) {
791 DDLRecord ddlRecord = new DDLRecordImpl();
792
793 ddlRecord.setUuid(SequentialUUID.generate());
794 ddlRecord.setRecordId(_counter.get());
795 ddlRecord.setGroupId(ddlRecordSet.getGroupId());
796 ddlRecord.setCompanyId(_companyId);
797 ddlRecord.setUserId(_sampleUserId);
798 ddlRecord.setUserName(_SAMPLE_USER_NAME);
799 ddlRecord.setVersionUserId(_sampleUserId);
800 ddlRecord.setVersionUserName(_SAMPLE_USER_NAME);
801 ddlRecord.setCreateDate(new Date());
802 ddlRecord.setModifiedDate(new Date());
803 ddlRecord.setDDMStorageId(_counter.get());
804 ddlRecord.setRecordSetId(ddlRecordSet.getRecordSetId());
805 ddlRecord.setVersion(DDLRecordConstants.VERSION_DEFAULT);
806 ddlRecord.setDisplayIndex(DDLRecordConstants.DISPLAY_INDEX_DEFAULT);
807
808 return ddlRecord;
809 }
810
811 public DDLRecordSet newDDLRecordSet(
812 DDMStructure ddmStructure, int currentIndex) {
813
814 DDLRecordSet ddlRecordSet = new DDLRecordSetImpl();
815
816 ddlRecordSet.setUuid(SequentialUUID.generate());
817 ddlRecordSet.setRecordSetId(_counter.get());
818 ddlRecordSet.setGroupId(ddmStructure.getGroupId());
819 ddlRecordSet.setCompanyId(_companyId);
820 ddlRecordSet.setUserId(_sampleUserId);
821 ddlRecordSet.setUserName(_SAMPLE_USER_NAME);
822 ddlRecordSet.setCreateDate(new Date());
823 ddlRecordSet.setModifiedDate(new Date());
824 ddlRecordSet.setDDMStructureId(ddmStructure.getStructureId());
825 ddlRecordSet.setRecordSetKey(String.valueOf(_counter.get()));
826
827 StringBundler sb = new StringBundler(5);
828
829 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
830 sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
831 sb.append("<Name language-id=\"en_US\">Test DDL Record Set ");
832 sb.append(currentIndex);
833 sb.append("</Name></root>");
834
835 ddlRecordSet.setName(sb.toString());
836
837 ddlRecordSet.setMinDisplayRows(
838 DDLRecordSetConstants.MIN_DISPLAY_ROWS_DEFAULT);
839 ddlRecordSet.setScope(DDLRecordSetConstants.SCOPE_DYNAMIC_DATA_LISTS);
840
841 return ddlRecordSet;
842 }
843
844 public DDLRecordVersion newDDLRecordVersion(DDLRecord ddlRecord) {
845 DDLRecordVersion ddlRecordVersion = new DDLRecordVersionImpl();
846
847 ddlRecordVersion.setRecordVersionId(_counter.get());
848 ddlRecordVersion.setGroupId(ddlRecord.getGroupId());
849 ddlRecordVersion.setCompanyId(_companyId);
850 ddlRecordVersion.setUserId(_sampleUserId);
851 ddlRecordVersion.setUserName(_SAMPLE_USER_NAME);
852 ddlRecordVersion.setCreateDate(ddlRecord.getModifiedDate());
853 ddlRecordVersion.setDDMStorageId(ddlRecord.getDDMStorageId());
854 ddlRecordVersion.setRecordSetId(ddlRecord.getRecordSetId());
855 ddlRecordVersion.setRecordId(ddlRecord.getRecordId());
856 ddlRecordVersion.setVersion(ddlRecord.getVersion());
857 ddlRecordVersion.setDisplayIndex(ddlRecord.getDisplayIndex());
858 ddlRecordVersion.setStatus(WorkflowConstants.STATUS_DRAFT);
859 ddlRecordVersion.setStatusDate(ddlRecord.getModifiedDate());
860
861 return ddlRecordVersion;
862 }
863
864 public DDMContent newDDMContent(DDLRecord ddlRecord, int currentIndex) {
865 StringBundler sb = new StringBundler(4);
866
867 sb.append("<?xml version=\"1.0\"?><root><dynamic-element ");
868 sb.append("name=\"text2102\"><dynamic-content><![CDATA[Test Record ");
869 sb.append(currentIndex);
870 sb.append("]]></dynamic-content></dynamic-element></root>");
871
872 return newDDMContent(
873 ddlRecord.getDDMStorageId(), ddlRecord.getGroupId(), sb.toString());
874 }
875
876 public DDMContent newDDMContent(DLFileEntry dlFileEntry) {
877 StringBundler sb = new StringBundler(5);
878
879 sb.append("<?xml version=\"1.0\"?><root><dynamic-element ");
880 sb.append("name=\"CONTENT_TYPE\"><dynamic-content>");
881 sb.append("<![CDATA[text/plain]]></dynamic-content></dynamic-element>");
882 sb.append("<dynamic-element <![CDATA[ISO-8859-1]]></dynamic-content>");
883 sb.append("</dynamic-element></root>");
884
885 return newDDMContent(
886 _counter.get(), dlFileEntry.getGroupId(), sb.toString());
887 }
888
889 public DDMStorageLink newDDMStorageLink(
890 long ddmStorageLinkId, DDMContent ddmContent, long structureId) {
891
892 DDMStorageLink ddmStorageLink = new DDMStorageLinkImpl();
893
894 ddmStorageLink.setUuid(SequentialUUID.generate());
895 ddmStorageLink.setStorageLinkId(ddmStorageLinkId);
896 ddmStorageLink.setClassNameId(
897 _classNamesMap.get(DDMContent.class.getName()));
898 ddmStorageLink.setClassPK(ddmContent.getContentId());
899 ddmStorageLink.setStructureId(structureId);
900
901 return ddmStorageLink;
902 }
903
904 public DDMStructureLink newDDMStructureLink(DDLRecordSet ddlRecordSet) {
905 return newDDMStructureLink(
906 _classNamesMap.get(DDLRecordSet.class.getName()),
907 ddlRecordSet.getRecordSetId(), ddlRecordSet.getDDMStructureId());
908 }
909
910 public DDMStructureLink newDDMStructureLink(
911 DLFileEntryMetadata dLFileEntryMetadata) {
912
913 return newDDMStructureLink(
914 _classNamesMap.get(DLFileEntryMetadata.class.getName()),
915 dLFileEntryMetadata.getFileEntryMetadataId(),
916 dLFileEntryMetadata.getDDMStructureId());
917 }
918
919 public DLFileEntry newDlFileEntry(DLFolder dlFoler, int index) {
920 DLFileEntry dlFileEntry = new DLFileEntryImpl();
921
922 dlFileEntry.setUuid(SequentialUUID.generate());
923 dlFileEntry.setFileEntryId(_counter.get());
924 dlFileEntry.setGroupId(dlFoler.getGroupId());
925 dlFileEntry.setCompanyId(_companyId);
926 dlFileEntry.setUserId(_sampleUserId);
927 dlFileEntry.setUserName(_SAMPLE_USER_NAME);
928 dlFileEntry.setVersionUserId(_sampleUserId);
929 dlFileEntry.setVersionUserName(_SAMPLE_USER_NAME);
930 dlFileEntry.setCreateDate(nextFutureDate());
931 dlFileEntry.setModifiedDate(nextFutureDate());
932 dlFileEntry.setRepositoryId(dlFoler.getRepositoryId());
933 dlFileEntry.setFolderId(dlFoler.getFolderId());
934 dlFileEntry.setName("TestFile" + index);
935 dlFileEntry.setExtension("txt");
936 dlFileEntry.setMimeType(ContentTypes.TEXT_PLAIN);
937 dlFileEntry.setTitle("TestFile" + index + ".txt");
938 dlFileEntry.setFileEntryTypeId(
939 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);
940 dlFileEntry.setVersion(DLFileEntryConstants.VERSION_DEFAULT);
941 dlFileEntry.setSize(_maxDLFileEntrySize);
942
943 return dlFileEntry;
944 }
945
946 public DLFileEntryMetadata newDLFileEntryMetadata(
947 long ddmStorageLinkId, long ddmStructureId,
948 DLFileVersion dlFileVersion) {
949
950 DLFileEntryMetadata dlFileEntryMetadata = new DLFileEntryMetadataImpl();
951
952 dlFileEntryMetadata.setUuid(SequentialUUID.generate());
953 dlFileEntryMetadata.setFileEntryMetadataId(_counter.get());
954 dlFileEntryMetadata.setDDMStorageId(ddmStorageLinkId);
955 dlFileEntryMetadata.setDDMStructureId(ddmStructureId);
956 dlFileEntryMetadata.setFileEntryTypeId(
957 dlFileVersion.getFileEntryTypeId());
958 dlFileEntryMetadata.setFileEntryId(dlFileVersion.getFileEntryId());
959 dlFileEntryMetadata.setFileVersionId(dlFileVersion.getFileVersionId());
960
961 return dlFileEntryMetadata;
962 }
963
964 public DLFileVersion newDLFileVersion(DLFileEntry dlFileEntry) {
965 DLFileVersion dlFileVersion = new DLFileVersionImpl();
966
967 dlFileVersion.setUuid(SequentialUUID.generate());
968 dlFileVersion.setFileVersionId(_counter.get());
969 dlFileVersion.setGroupId(dlFileEntry.getGroupId());
970 dlFileVersion.setCompanyId(_companyId);
971 dlFileVersion.setUserId(_sampleUserId);
972 dlFileVersion.setUserName(_SAMPLE_USER_NAME);
973 dlFileVersion.setCreateDate(nextFutureDate());
974 dlFileVersion.setModifiedDate(nextFutureDate());
975 dlFileVersion.setRepositoryId(dlFileEntry.getRepositoryId());
976 dlFileVersion.setFolderId(dlFileEntry.getFolderId());
977 dlFileVersion.setFileEntryId(dlFileEntry.getFileEntryId());
978 dlFileVersion.setExtension(dlFileEntry.getExtension());
979 dlFileVersion.setMimeType(dlFileEntry.getMimeType());
980 dlFileVersion.setTitle(dlFileEntry.getTitle());
981 dlFileVersion.setFileEntryTypeId(dlFileEntry.getFileEntryTypeId());
982 dlFileVersion.setVersion(dlFileEntry.getVersion());
983 dlFileVersion.setSize(dlFileEntry.getSize());
984
985 return dlFileVersion;
986 }
987
988 public DLFolder newDLFolder(long groupId, long parentFolderId, int index) {
989 DLFolder dlFolder = new DLFolderImpl();
990
991 dlFolder.setUuid(SequentialUUID.generate());
992 dlFolder.setFolderId(_counter.get());
993 dlFolder.setGroupId(groupId);
994 dlFolder.setCompanyId(_companyId);
995 dlFolder.setUserId(_sampleUserId);
996 dlFolder.setUserName(_SAMPLE_USER_NAME);
997 dlFolder.setCreateDate(nextFutureDate());
998 dlFolder.setModifiedDate(nextFutureDate());
999 dlFolder.setRepositoryId(groupId);
1000 dlFolder.setParentFolderId(parentFolderId);
1001 dlFolder.setName("Test Folder " + index);
1002 dlFolder.setLastPostDate(nextFutureDate());
1003 dlFolder.setDefaultFileEntryTypeId(
1004 _defaultDLFileEntryType.getFileEntryTypeId());
1005 dlFolder.setStatusDate(nextFutureDate());
1006
1007 return dlFolder;
1008 }
1009
1010 public DLSync newDLSync(DLFileEntry dlFileEntry) {
1011 return newDLSync(
1012 dlFileEntry.getFileEntryId(), dlFileEntry.getUuid(),
1013 dlFileEntry.getRepositoryId(), dlFileEntry.getFolderId(),
1014 dlFileEntry.getName(), DLSyncConstants.TYPE_FILE);
1015 }
1016
1017 public DLSync newDLSync(DLFolder dLFolder) {
1018 return newDLSync(
1019 dLFolder.getFolderId(), dLFolder.getUuid(),
1020 dLFolder.getRepositoryId(), dLFolder.getParentFolderId(),
1021 dLFolder.getName(), DLSyncConstants.TYPE_FOLDER);
1022 }
1023
1024 public Group newGroup(User user) throws Exception {
1025 return newGroup(
1026 _counter.get(), _classNamesMap.get(User.class.getName()),
1027 user.getUserId(), user.getScreenName(), false);
1028 }
1029
1030 public IntegerWrapper newInteger() {
1031 return new IntegerWrapper();
1032 }
1033
1034 public JournalArticle newJournalArticle(
1035 JournalArticleResource journalArticleResource, int articleIndex,
1036 int versionIndex) {
1037
1038 JournalArticle journalArticle = new JournalArticleImpl();
1039
1040 journalArticle.setUuid(SequentialUUID.generate());
1041 journalArticle.setId(_counter.get());
1042 journalArticle.setResourcePrimKey(
1043 journalArticleResource.getResourcePrimKey());
1044 journalArticle.setGroupId(journalArticleResource.getGroupId());
1045 journalArticle.setCompanyId(_companyId);
1046 journalArticle.setUserId(_sampleUserId);
1047 journalArticle.setUserName(_SAMPLE_USER_NAME);
1048 journalArticle.setCreateDate(new Date());
1049 journalArticle.setModifiedDate(new Date());
1050 journalArticle.setClassNameId(
1051 JournalArticleConstants.CLASSNAME_ID_DEFAULT);
1052 journalArticle.setArticleId(journalArticleResource.getArticleId());
1053 journalArticle.setVersion(versionIndex);
1054
1055 StringBundler sb = new StringBundler(4);
1056
1057 sb.append("TestJournalArticle_");
1058 sb.append(articleIndex);
1059 sb.append(StringPool.UNDERLINE);
1060 sb.append(versionIndex);
1061
1062 String urlTitle = sb.toString();
1063
1064 sb = new StringBundler(5);
1065
1066 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
1067 sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
1068 sb.append("<Title language-id=\"en_US\">");
1069 sb.append(urlTitle);
1070 sb.append("</Title></root>");
1071
1072 String title = sb.toString();
1073
1074 journalArticle.setTitle(title);
1075 journalArticle.setUrlTitle(urlTitle);
1076
1077 journalArticle.setContent(_journalArticleContent);
1078 journalArticle.setType("general");
1079 journalArticle.setDisplayDate(new Date());
1080 journalArticle.setExpirationDate(nextFutureDate());
1081 journalArticle.setReviewDate(new Date());
1082 journalArticle.setIndexable(true);
1083 journalArticle.setStatusDate(new Date());
1084
1085 return journalArticle;
1086 }
1087
1088 public JournalArticleResource newJournalArticleResource(long groupId) {
1089 JournalArticleResource journalArticleResource =
1090 new JournalArticleResourceImpl();
1091
1092 journalArticleResource.setUuid(SequentialUUID.generate());
1093 journalArticleResource.setResourcePrimKey(_counter.get());
1094 journalArticleResource.setGroupId(groupId);
1095 journalArticleResource.setArticleId(String.valueOf(_counter.get()));
1096
1097 return journalArticleResource;
1098 }
1099
1100 public JournalContentSearch newJournalContentSearch(
1101 JournalArticle journalArticle, long layoutId) {
1102
1103 JournalContentSearch journalContentSearch =
1104 new JournalContentSearchImpl();
1105
1106 journalContentSearch.setContentSearchId(_counter.get());
1107 journalContentSearch.setGroupId(journalArticle.getGroupId());
1108 journalContentSearch.setCompanyId(_companyId);
1109 journalContentSearch.setLayoutId(layoutId);
1110 journalContentSearch.setPortletId(PortletKeys.JOURNAL_CONTENT);
1111 journalContentSearch.setArticleId(journalArticle.getArticleId());
1112
1113 return journalContentSearch;
1114 }
1115
1116 public Layout newLayout(
1117 long groupId, String name, String column1, String column2) {
1118
1119 SimpleCounter simpleCounter = _layoutCounters.get(groupId);
1120
1121 if (simpleCounter == null) {
1122 simpleCounter = new SimpleCounter();
1123
1124 _layoutCounters.put(groupId, simpleCounter);
1125 }
1126
1127 Layout layout = new LayoutImpl();
1128
1129 layout.setUuid(SequentialUUID.generate());
1130 layout.setPlid(_counter.get());
1131 layout.setGroupId(groupId);
1132 layout.setCompanyId(_companyId);
1133 layout.setCreateDate(new Date());
1134 layout.setModifiedDate(new Date());
1135 layout.setLayoutId(simpleCounter.get());
1136 layout.setName(
1137 "<?xml version=\"1.0\"?><root><name>" + name + "</name></root>");
1138 layout.setType(LayoutConstants.TYPE_PORTLET);
1139 layout.setFriendlyURL(StringPool.FORWARD_SLASH + name);
1140
1141 UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);
1142
1143 typeSettingsProperties.setProperty(
1144 LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, "2_columns_ii");
1145 typeSettingsProperties.setProperty("column-1", column1);
1146 typeSettingsProperties.setProperty("column-2", column2);
1147
1148 String typeSettings = StringUtil.replace(
1149 typeSettingsProperties.toString(), "\n", "\\n");
1150
1151 layout.setTypeSettings(typeSettings);
1152
1153 return layout;
1154 }
1155
1156 public List<LayoutSet> newLayoutSets(
1157 long groupId, int publicLayoutSetPageCount) {
1158
1159 List<LayoutSet> layoutSets = new ArrayList<LayoutSet>(2);
1160
1161 layoutSets.add(newLayoutSet(groupId, true, 0));
1162 layoutSets.add(newLayoutSet(groupId, false, publicLayoutSetPageCount));
1163
1164 return layoutSets;
1165 }
1166
1167 public MBCategory newMBCategory(long groupId, int index) {
1168 MBCategory mbCategory = new MBCategoryImpl();
1169
1170 mbCategory.setUuid(SequentialUUID.generate());
1171 mbCategory.setCategoryId(_counter.get());
1172 mbCategory.setGroupId(groupId);
1173 mbCategory.setCompanyId(_companyId);
1174 mbCategory.setUserId(_sampleUserId);
1175 mbCategory.setUserName(_SAMPLE_USER_NAME);
1176 mbCategory.setCreateDate(new Date());
1177 mbCategory.setModifiedDate(new Date());
1178 mbCategory.setParentCategoryId(
1179 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
1180 mbCategory.setName("Test Category " + index);
1181 mbCategory.setDisplayStyle(MBCategoryConstants.DEFAULT_DISPLAY_STYLE);
1182 mbCategory.setThreadCount(_maxMBThreadCount);
1183 mbCategory.setMessageCount(_maxMBThreadCount * _maxMBMessageCount);
1184 mbCategory.setLastPostDate(new Date());
1185 mbCategory.setStatusDate(new Date());
1186
1187 return mbCategory;
1188 }
1189
1190 public MBDiscussion newMBDiscussion(
1191 long groupId, long classNameId, long classPK, long threadId) {
1192
1193 MBDiscussion mbDiscussion = new MBDiscussionImpl();
1194
1195 mbDiscussion.setUuid(SequentialUUID.generate());
1196 mbDiscussion.setDiscussionId(_counter.get());
1197 mbDiscussion.setGroupId(groupId);
1198 mbDiscussion.setCompanyId(_companyId);
1199 mbDiscussion.setUserId(_sampleUserId);
1200 mbDiscussion.setUserName(_SAMPLE_USER_NAME);
1201 mbDiscussion.setCreateDate(new Date());
1202 mbDiscussion.setModifiedDate(new Date());
1203 mbDiscussion.setClassNameId(classNameId);
1204 mbDiscussion.setClassPK(classPK);
1205 mbDiscussion.setThreadId(threadId);
1206
1207 return mbDiscussion;
1208 }
1209
1210 public MBMailingList newMBMailingList(MBCategory mbCategory) {
1211 MBMailingList mbMailingList = new MBMailingListImpl();
1212
1213 mbMailingList.setUuid(SequentialUUID.generate());
1214 mbMailingList.setMailingListId(_counter.get());
1215 mbMailingList.setGroupId(mbCategory.getGroupId());
1216 mbMailingList.setCompanyId(_companyId);
1217 mbMailingList.setUserId(_sampleUserId);
1218 mbMailingList.setUserName(_SAMPLE_USER_NAME);
1219 mbMailingList.setCreateDate(new Date());
1220 mbMailingList.setModifiedDate(new Date());
1221 mbMailingList.setCategoryId(mbCategory.getCategoryId());
1222 mbMailingList.setInProtocol("pop3");
1223 mbMailingList.setInServerPort(110);
1224 mbMailingList.setInUserName(_sampleUser.getEmailAddress());
1225 mbMailingList.setInPassword(_sampleUser.getPassword());
1226 mbMailingList.setInReadInterval(5);
1227 mbMailingList.setOutServerPort(25);
1228
1229 return mbMailingList;
1230 }
1231
1232 public MBMessage newMBMessage(MBThread mbThread, int index) {
1233 long messageId = 0;
1234 long parentMessageId = 0;
1235
1236 if (index == 1) {
1237 messageId = mbThread.getRootMessageId();
1238 parentMessageId = MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID;
1239 }
1240 else {
1241 messageId = _counter.get();
1242 parentMessageId = mbThread.getRootMessageId();
1243 }
1244
1245 return newMBMessage(
1246 mbThread.getGroupId(), 0, 0, mbThread.getCategoryId(),
1247 mbThread.getThreadId(), messageId, mbThread.getRootMessageId(),
1248 parentMessageId, "Test Message " + index,
1249 "This is test message " + index + ".");
1250 }
1251
1252 public MBMessage newMBMessage(
1253 MBThread mbThread, long classNameId, long classPK, int index) {
1254
1255 long messageId = 0;
1256 long parentMessageId = 0;
1257 String subject = null;
1258 String body = null;
1259
1260 if (index == 0) {
1261 messageId = mbThread.getRootMessageId();
1262 parentMessageId = MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID;
1263 subject = StringUtil.valueOf(classPK);
1264 body = StringUtil.valueOf(classPK);
1265 }
1266 else {
1267 messageId = _counter.get();
1268 parentMessageId = mbThread.getRootMessageId();
1269 subject = "N/A";
1270 body = "This is test comment " + index + ".";
1271 }
1272
1273 return newMBMessage(
1274 mbThread.getGroupId(), classNameId, classPK,
1275 MBCategoryConstants.DISCUSSION_CATEGORY_ID, mbThread.getThreadId(),
1276 messageId, mbThread.getRootMessageId(), parentMessageId, subject,
1277 body);
1278 }
1279
1280 public MBStatsUser newMBStatsUser(long groupId) {
1281 MBStatsUser mbStatsUser = new MBStatsUserImpl();
1282
1283 mbStatsUser.setStatsUserId(_counter.get());
1284 mbStatsUser.setGroupId(groupId);
1285 mbStatsUser.setUserId(_sampleUserId);
1286 mbStatsUser.setMessageCount(
1287 _maxMBCategoryCount * _maxMBThreadCount * _maxMBMessageCount);
1288 mbStatsUser.setLastPostDate(new Date());
1289
1290 return mbStatsUser;
1291 }
1292
1293 public MBThread newMBThread(
1294 long threadId, long groupId, long rootMessageId, int messageCount) {
1295
1296 if (messageCount == 0) {
1297 messageCount = 1;
1298 }
1299
1300 return newMBThread(
1301 threadId, groupId, MBCategoryConstants.DISCUSSION_CATEGORY_ID,
1302 rootMessageId, messageCount);
1303 }
1304
1305 public MBThread newMBThread(MBCategory mbCategory) {
1306 return newMBThread(
1307 _counter.get(), mbCategory.getGroupId(), mbCategory.getCategoryId(),
1308 _counter.get(), _maxMBMessageCount);
1309 }
1310
1311 public List<PortletPreferences> newPortletPreferences(long plid) {
1312 List<PortletPreferences> portletPreferencesList =
1313 new ArrayList<PortletPreferences>(2);
1314
1315 portletPreferencesList.add(
1316 newPortletPreferences(
1317 plid, PortletKeys.DOCKBAR,
1318 PortletConstants.DEFAULT_PREFERENCES));
1319
1320 portletPreferencesList.add(
1321 newPortletPreferences(
1322 plid, PortletKeys.PORTLET_CONFIGURATION,
1323 PortletConstants.DEFAULT_PREFERENCES));
1324
1325 return portletPreferencesList;
1326 }
1327
1328 public PortletPreferences newPortletPreferences(
1329 long plid, String portletId, DDLRecordSet ddlRecordSet)
1330 throws Exception {
1331
1332 javax.portlet.PortletPreferences jxPreferences =
1333 new com.liferay.portlet.PortletPreferencesImpl();
1334
1335 jxPreferences.setValue("editable", "true");
1336 jxPreferences.setValue(
1337 "recordSetId", String.valueOf(ddlRecordSet.getRecordSetId()));
1338 jxPreferences.setValue("spreadsheet", "false");
1339
1340 return newPortletPreferences(
1341 plid, portletId,
1342 PortletPreferencesFactoryUtil.toXML(jxPreferences));
1343 }
1344
1345 public PortletPreferences newPortletPreferences(
1346 long plid, String portletId,
1347 JournalArticleResource journalArticleResource)
1348 throws Exception {
1349
1350 javax.portlet.PortletPreferences jxPreferences =
1351 new com.liferay.portlet.PortletPreferencesImpl();
1352
1353 jxPreferences.setValue(
1354 "articleId", journalArticleResource.getArticleId());
1355 jxPreferences.setValue("enableCommentRatings", "false");
1356 jxPreferences.setValue("enableComments", "false");
1357 jxPreferences.setValue("enablePrint", "false");
1358 jxPreferences.setValue("enableRatings", "false");
1359 jxPreferences.setValue("enableRelatedAssets", "true");
1360 jxPreferences.setValue("enableViewCountIncrement", "false");
1361 jxPreferences.setValue(
1362 "groupId", String.valueOf(journalArticleResource.getGroupId()));
1363 jxPreferences.setValue("showAvailableLocales", "false");
1364
1365 return newPortletPreferences(
1366 plid, portletId,
1367 PortletPreferencesFactoryUtil.toXML(jxPreferences));
1368 }
1369
1370 public List<Layout> newPublicLayouts(long groupId) {
1371 List<Layout> layouts = new ArrayList<Layout>();
1372
1373 layouts.add(newLayout(groupId, "welcome", "58,", "47,"));
1374 layouts.add(newLayout(groupId, "blogs", "", "33,"));
1375 layouts.add(newLayout(groupId, "document_library", "", "20,"));
1376 layouts.add(newLayout(groupId, "forums", "", "19,"));
1377 layouts.add(newLayout(groupId, "wiki", "", "36,"));
1378
1379 return layouts;
1380 }
1381
1382 public List<ResourcePermission> newResourcePermissions(
1383 AssetCategory assetCategory) {
1384
1385 return newResourcePermissions(
1386 AssetCategory.class.getName(),
1387 StringUtil.valueOf(assetCategory.getCategoryId()), _sampleUserId);
1388 }
1389
1390 public List<ResourcePermission> newResourcePermissions(
1391 AssetVocabulary assetVocabulary) {
1392
1393 if (assetVocabulary.getUserId() == _defaultUserId) {
1394 List<ResourcePermission> resourcePermissions =
1395 new ArrayList<ResourcePermission>(1);
1396
1397 resourcePermissions.add(
1398 newResourcePermission(
1399 AssetVocabulary.class.getName(),
1400 StringUtil.valueOf(assetVocabulary.getVocabularyId()),
1401 _ownerRole.getRoleId(), _defaultUserId));
1402
1403 return resourcePermissions;
1404 }
1405
1406 return newResourcePermissions(
1407 AssetVocabulary.class.getName(),
1408 StringUtil.valueOf(assetVocabulary.getVocabularyId()),
1409 _sampleUserId);
1410 }
1411
1412 public List<ResourcePermission> newResourcePermissions(
1413 JournalArticleResource journalArticleResource) {
1414
1415 return newResourcePermissions(
1416 JournalArticle.class.getName(),
1417 StringUtil.valueOf(journalArticleResource.getResourcePrimKey()),
1418 _sampleUserId);
1419 }
1420
1421 public List<ResourcePermission> newResourcePermissions(Layout layout) {
1422 return newResourcePermissions(
1423 Layout.class.getName(), StringUtil.valueOf(layout.getPlid()),
1424 _sampleUserId);
1425 }
1426
1427 public List<ResourcePermission> newResourcePermissions(
1428 PortletPreferences portletPreferences) {
1429
1430 String portletId = portletPreferences.getPortletId();
1431
1432 String name = portletId;
1433
1434 int index = portletId.indexOf(StringPool.UNDERLINE);
1435
1436 if (index > 0) {
1437 name = portletId.substring(0, index);
1438 }
1439
1440 String primKey = PortletPermissionUtil.getPrimaryKey(
1441 portletPreferences.getPlid(), portletId);
1442
1443 return newResourcePermissions(name, primKey, 0);
1444 }
1445
1446 public SocialActivity newSocialActivity(DLFileEntry dlFileEntry) {
1447 return newSocialActivity(
1448 dlFileEntry.getGroupId(), getDLFileEntryClassNameId(),
1449 dlFileEntry.getFileEntryId(), DLActivityKeys.ADD_FILE_ENTRY,
1450 dlFileEntry.getTitle());
1451 }
1452
1453 public SocialActivity newSocialActivity(JournalArticle journalArticle) {
1454 int type = JournalActivityKeys.UPDATE_ARTICLE;
1455
1456 if (journalArticle.getVersion() ==
1457 JournalArticleConstants.VERSION_DEFAULT) {
1458
1459 type = JournalActivityKeys.ADD_ARTICLE;
1460 }
1461
1462 return newSocialActivity(
1463 journalArticle.getGroupId(), getJournalArticleClassNameId(),
1464 journalArticle.getResourcePrimKey(), type,
1465 journalArticle.getUrlTitle());
1466 }
1467
1468 public User newUser(int index) {
1469 String[] userName = nextUserName(index - 1);
1470
1471 return newUser(
1472 _counter.get(), userName[0], userName[1],
1473 "test" + _userScreenNameCounter.get(), false);
1474 }
1475
1476 public WikiNode newWikiNode(long groupId, int index) {
1477 WikiNode wikiNode = new WikiNodeImpl();
1478
1479 wikiNode.setUuid(SequentialUUID.generate());
1480 wikiNode.setNodeId(_counter.get());
1481 wikiNode.setGroupId(groupId);
1482 wikiNode.setCompanyId(_companyId);
1483 wikiNode.setUserId(_sampleUserId);
1484 wikiNode.setUserName(_SAMPLE_USER_NAME);
1485 wikiNode.setCreateDate(new Date());
1486 wikiNode.setModifiedDate(new Date());
1487 wikiNode.setName("Test Node " + index);
1488 wikiNode.setLastPostDate(new Date());
1489 wikiNode.setStatusDate(new Date());
1490
1491 return wikiNode;
1492 }
1493
1494 public WikiPage newWikiPage(WikiNode wikiNode, int index) {
1495 WikiPage wikiPage = new WikiPageImpl();
1496
1497 wikiPage.setUuid(SequentialUUID.generate());
1498 wikiPage.setPageId(_counter.get());
1499 wikiPage.setResourcePrimKey(_counter.get());
1500 wikiPage.setGroupId(wikiNode.getGroupId());
1501 wikiPage.setCompanyId(_companyId);
1502 wikiPage.setUserId(_sampleUserId);
1503 wikiPage.setUserName(_SAMPLE_USER_NAME);
1504 wikiPage.setCreateDate(new Date());
1505 wikiPage.setModifiedDate(new Date());
1506 wikiPage.setNodeId(wikiNode.getNodeId());
1507 wikiPage.setTitle("Test Page " + index);
1508 wikiPage.setVersion(WikiPageConstants.VERSION_DEFAULT);
1509 wikiPage.setContent("This is test page " + index + ".");
1510 wikiPage.setFormat(WikiPageConstants.DEFAULT_FORMAT);
1511 wikiPage.setHead(true);
1512
1513 return wikiPage;
1514 }
1515
1516 public WikiPageResource newWikiPageResource(WikiPage wikiPage) {
1517 WikiPageResource wikiPageResource = new WikiPageResourceImpl();
1518
1519 wikiPageResource.setUuid(SequentialUUID.generate());
1520 wikiPageResource.setResourcePrimKey(wikiPage.getResourcePrimKey());
1521 wikiPageResource.setNodeId(wikiPage.getNodeId());
1522 wikiPageResource.setTitle(wikiPage.getTitle());
1523
1524 return wikiPageResource;
1525 }
1526
1527 public String[] nextUserName(long index) {
1528 String[] userName = new String[2];
1529
1530 userName[0] = _firstNames.get(
1531 (int)(index / _lastNames.size()) % _firstNames.size());
1532 userName[1] = _lastNames.get((int)(index % _lastNames.size()));
1533
1534 return userName;
1535 }
1536
1537 protected AssetEntry newAssetEntry(
1538 long groupId, Date createDate, Date modifiedDate, long classNameId,
1539 long classPK, String uuid, long classTypeId, boolean visible,
1540 String mimeType, String title) {
1541
1542 AssetEntry assetEntry = new AssetEntryImpl();
1543
1544 assetEntry.setEntryId(_counter.get());
1545 assetEntry.setGroupId(groupId);
1546 assetEntry.setCompanyId(_companyId);
1547 assetEntry.setUserId(_sampleUserId);
1548 assetEntry.setUserName(_SAMPLE_USER_NAME);
1549 assetEntry.setCreateDate(createDate);
1550 assetEntry.setModifiedDate(modifiedDate);
1551 assetEntry.setClassNameId(classNameId);
1552 assetEntry.setClassPK(classPK);
1553 assetEntry.setClassUuid(uuid);
1554 assetEntry.setClassTypeId(classTypeId);
1555 assetEntry.setVisible(visible);
1556 assetEntry.setStartDate(createDate);
1557 assetEntry.setEndDate(nextFutureDate());
1558 assetEntry.setPublishDate(createDate);
1559 assetEntry.setExpirationDate(nextFutureDate());
1560 assetEntry.setMimeType(mimeType);
1561 assetEntry.setTitle(title);
1562
1563 return assetEntry;
1564 }
1565
1566 protected AssetVocabulary newAssetVocabulary(
1567 long grouId, long userId, String userName, String name, String title) {
1568
1569 AssetVocabulary assetVocabulary = new AssetVocabularyImpl();
1570
1571 assetVocabulary.setUuid(SequentialUUID.generate());
1572 assetVocabulary.setVocabularyId(_counter.get());
1573 assetVocabulary.setGroupId(grouId);
1574 assetVocabulary.setCompanyId(_companyId);
1575 assetVocabulary.setUserId(userId);
1576 assetVocabulary.setUserName(userName);
1577 assetVocabulary.setCreateDate(new Date());
1578 assetVocabulary.setModifiedDate(new Date());
1579 assetVocabulary.setName(name);
1580 assetVocabulary.setTitle(title);
1581 assetVocabulary.setSettings(
1582 "multiValued=true\\nselectedClassNameIds=0");
1583
1584 return assetVocabulary;
1585 }
1586
1587 protected DDMContent newDDMContent(
1588 long contentId, long groupId, String xml) {
1589
1590 DDMContent ddmContent = new DDMContentImpl();
1591
1592 ddmContent.setUuid(SequentialUUID.generate());
1593 ddmContent.setContentId(contentId);
1594 ddmContent.setGroupId(groupId);
1595 ddmContent.setCompanyId(_companyId);
1596 ddmContent.setUserId(_sampleUserId);
1597 ddmContent.setUserName(_SAMPLE_USER_NAME);
1598 ddmContent.setCreateDate(nextFutureDate());
1599 ddmContent.setModifiedDate(nextFutureDate());
1600 ddmContent.setName(DDMStorageLink.class.getName());
1601 ddmContent.setXml(xml);
1602
1603 return ddmContent;
1604 }
1605
1606 protected DDMStructure newDDMStructure(
1607 long groupId, long classNameId, String structureKey, String xsd) {
1608
1609 DDMStructure ddmStructure = new DDMStructureImpl();
1610
1611 ddmStructure.setUuid(SequentialUUID.generate());
1612 ddmStructure.setStructureId(_counter.get());
1613 ddmStructure.setGroupId(groupId);
1614 ddmStructure.setCompanyId(_companyId);
1615 ddmStructure.setUserId(_sampleUserId);
1616 ddmStructure.setUserName(_SAMPLE_USER_NAME);
1617 ddmStructure.setCreateDate(nextFutureDate());
1618 ddmStructure.setModifiedDate(nextFutureDate());
1619 ddmStructure.setClassNameId(classNameId);
1620 ddmStructure.setStructureKey(structureKey);
1621
1622 StringBundler sb = new StringBundler(5);
1623
1624 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
1625 sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
1626 sb.append("<Name language-id=\"en_US\">");
1627 sb.append(structureKey);
1628 sb.append("</Name></root>");
1629
1630 ddmStructure.setName(sb.toString());
1631
1632 ddmStructure.setXsd(xsd);
1633 ddmStructure.setStorageType("xml");
1634
1635 return ddmStructure;
1636 }
1637
1638 protected DDMStructureLink newDDMStructureLink(
1639 long classNameId, long classPK, long structureId) {
1640
1641 DDMStructureLink ddmStructureLink = new DDMStructureLinkImpl();
1642
1643 ddmStructureLink.setStructureLinkId(_counter.get());
1644 ddmStructureLink.setClassNameId(classNameId);
1645 ddmStructureLink.setClassPK(classPK);
1646 ddmStructureLink.setStructureId(structureId);
1647
1648 return ddmStructureLink;
1649 }
1650
1651 protected DLSync newDLSync(
1652 long fileId, String fileUuid, long repositoryId, long parentFolderId,
1653 String name, String type) {
1654
1655 DLSync dlSync = new DLSyncImpl();
1656
1657 dlSync.setSyncId(_counter.get());
1658 dlSync.setCompanyId(_companyId);
1659 dlSync.setCreateDate(nextFutureDate().getTime());
1660 dlSync.setModifiedDate(nextFutureDate().getTime());
1661 dlSync.setFileId(fileId);
1662 dlSync.setFileUuid(fileUuid);
1663 dlSync.setRepositoryId(repositoryId);
1664 dlSync.setParentFolderId(parentFolderId);
1665 dlSync.setName(name);
1666 dlSync.setEvent(DLSyncConstants.EVENT_ADD);
1667 dlSync.setType(type);
1668
1669 return dlSync;
1670 }
1671
1672 protected Group newGroup(
1673 long groupId, long classNameId, long classPK, String name,
1674 boolean site)
1675 throws Exception {
1676
1677 Group group = new GroupImpl();
1678
1679 group.setUuid(SequentialUUID.generate());
1680 group.setGroupId(groupId);
1681 group.setCompanyId(_companyId);
1682 group.setCreatorUserId(_sampleUserId);
1683 group.setClassNameId(classNameId);
1684 group.setClassPK(classPK);
1685 group.setTreePath(group.buildTreePath());
1686 group.setName(name);
1687 group.setFriendlyURL(
1688 StringPool.FORWARD_SLASH +
1689 FriendlyURLNormalizerUtil.normalize(name));
1690 group.setSite(site);
1691 group.setActive(true);
1692
1693 return group;
1694 }
1695
1696 protected LayoutSet newLayoutSet(
1697 long groupId, boolean privateLayout, int pageCount) {
1698
1699 LayoutSet layoutSet = new LayoutSetImpl();
1700
1701 layoutSet.setLayoutSetId(_counter.get());
1702 layoutSet.setGroupId(groupId);
1703 layoutSet.setCompanyId(_companyId);
1704 layoutSet.setCreateDate(new Date());
1705 layoutSet.setModifiedDate(new Date());
1706 layoutSet.setPrivateLayout(privateLayout);
1707 layoutSet.setThemeId("classic");
1708 layoutSet.setColorSchemeId("01");
1709 layoutSet.setWapThemeId("mobile");
1710 layoutSet.setWapColorSchemeId("01");
1711 layoutSet.setPageCount(pageCount);
1712
1713 return layoutSet;
1714 }
1715
1716 protected MBMessage newMBMessage(
1717 long groupId, long classNameId, long classPK, long categoryId,
1718 long threadId, long messageId, long rootMessageId, long parentMessageId,
1719 String subject, String body) {
1720
1721 MBMessage mbMessage = new MBMessageImpl();
1722
1723 mbMessage.setUuid(SequentialUUID.generate());
1724 mbMessage.setMessageId(messageId);
1725 mbMessage.setGroupId(groupId);
1726 mbMessage.setCompanyId(_companyId);
1727 mbMessage.setUserId(_sampleUserId);
1728 mbMessage.setUserName(_SAMPLE_USER_NAME);
1729 mbMessage.setCreateDate(new Date());
1730 mbMessage.setModifiedDate(new Date());
1731 mbMessage.setClassNameId(classNameId);
1732 mbMessage.setClassPK(classPK);
1733 mbMessage.setCategoryId(categoryId);
1734 mbMessage.setThreadId(threadId);
1735 mbMessage.setRootMessageId(rootMessageId);
1736 mbMessage.setParentMessageId(parentMessageId);
1737 mbMessage.setSubject(subject);
1738 mbMessage.setBody(body);
1739 mbMessage.setFormat(MBMessageConstants.DEFAULT_FORMAT);
1740 mbMessage.setStatusDate(new Date());
1741
1742 return mbMessage;
1743 }
1744
1745 protected MBThread newMBThread(
1746 long threadId, long groupId, long categoryId, long rootMessageId,
1747 int messageCount) {
1748
1749 MBThread mbThread = new MBThreadImpl();
1750
1751 mbThread.setUuid(SequentialUUID.generate());
1752 mbThread.setThreadId(threadId);
1753 mbThread.setGroupId(groupId);
1754 mbThread.setCompanyId(_companyId);
1755 mbThread.setUserId(_sampleUserId);
1756 mbThread.setUserName(_SAMPLE_USER_NAME);
1757 mbThread.setCreateDate(new Date());
1758 mbThread.setModifiedDate(new Date());
1759 mbThread.setCategoryId(categoryId);
1760 mbThread.setRootMessageId(rootMessageId);
1761 mbThread.setRootMessageUserId(_sampleUserId);
1762 mbThread.setMessageCount(messageCount);
1763 mbThread.setLastPostByUserId(_sampleUserId);
1764 mbThread.setLastPostDate(new Date());
1765 mbThread.setStatusDate(new Date());
1766
1767 return mbThread;
1768 }
1769
1770 protected PortletPreferences newPortletPreferences(
1771 long plid, String portletId, String preferences) {
1772
1773 PortletPreferences portletPreferences = new PortletPreferencesImpl();
1774
1775 portletPreferences.setPortletPreferencesId(_counter.get());
1776 portletPreferences.setOwnerId(PortletKeys.PREFS_OWNER_ID_DEFAULT);
1777 portletPreferences.setOwnerType(PortletKeys.PREFS_OWNER_TYPE_LAYOUT);
1778 portletPreferences.setPlid(plid);
1779 portletPreferences.setPortletId(portletId);
1780 portletPreferences.setPreferences(preferences);
1781
1782 return portletPreferences;
1783 }
1784
1785 protected ResourcePermission newResourcePermission(
1786 String name, String primKey, long roleId, long ownerId) {
1787
1788 ResourcePermission resourcePermission = new ResourcePermissionImpl();
1789
1790 resourcePermission.setResourcePermissionId(
1791 _resourcePermissionCounter.get());
1792 resourcePermission.setCompanyId(_companyId);
1793 resourcePermission.setName(name);
1794 resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
1795 resourcePermission.setPrimKey(primKey);
1796 resourcePermission.setRoleId(roleId);
1797 resourcePermission.setOwnerId(ownerId);
1798 resourcePermission.setActionIds(1);
1799
1800 return resourcePermission;
1801 }
1802
1803 protected List<ResourcePermission> newResourcePermissions(
1804 String name, String primKey, long ownerId) {
1805
1806 List<ResourcePermission> resourcePermissions =
1807 new ArrayList<ResourcePermission>(3);
1808
1809 resourcePermissions.add(
1810 newResourcePermission(name, primKey, _guestRole.getRoleId(), 0));
1811 resourcePermissions.add(
1812 newResourcePermission(
1813 name, primKey, _ownerRole.getRoleId(), ownerId));
1814 resourcePermissions.add(
1815 newResourcePermission(
1816 name, primKey, _siteMemberRole.getRoleId(), 0));
1817
1818 return resourcePermissions;
1819 }
1820
1821 protected Role newRole(String name, int type) {
1822 Role role = new RoleImpl();
1823
1824 role.setUuid(SequentialUUID.generate());
1825 role.setRoleId(_counter.get());
1826 role.setCompanyId(_companyId);
1827 role.setUserId(_sampleUserId);
1828 role.setUserName(_SAMPLE_USER_NAME);
1829 role.setCreateDate(new Date());
1830 role.setModifiedDate(new Date());
1831 role.setClassNameId(_classNamesMap.get(Role.class.getName()));
1832 role.setClassPK(role.getRoleId());
1833 role.setName(name);
1834 role.setType(type);
1835
1836 return role;
1837 }
1838
1839 protected SocialActivity newSocialActivity(
1840 long groupId, long classNameId, long classPK, int type, String title) {
1841
1842 SocialActivity socialActivity = new SocialActivityImpl();
1843
1844 socialActivity.setActivityId(_socialActivityCounter.get());
1845 socialActivity.setGroupId(groupId);
1846 socialActivity.setCompanyId(_companyId);
1847 socialActivity.setUserId(_sampleUserId);
1848 socialActivity.setCreateDate(System.currentTimeMillis());
1849 socialActivity.setClassNameId(classNameId);
1850 socialActivity.setClassPK(classPK);
1851 socialActivity.setType(type);
1852 socialActivity.setExtraData("{\"title\":\""+ title +"\"}");
1853
1854 return socialActivity;
1855 }
1856
1857 protected User newUser(
1858 long userId, String firstName, String lastName, String screenName,
1859 boolean defaultUser) {
1860
1861 if (Validator.isNull(screenName)) {
1862 screenName = String.valueOf(userId);
1863 }
1864
1865 User user = new UserImpl();
1866
1867 user.setUuid(SequentialUUID.generate());
1868 user.setUserId(userId);
1869 user.setCompanyId(_companyId);
1870 user.setCreateDate(new Date());
1871 user.setModifiedDate(new Date());
1872 user.setDefaultUser(defaultUser);
1873 user.setContactId(_counter.get());
1874 user.setPassword("test");
1875 user.setPasswordModifiedDate(new Date());
1876 user.setReminderQueryQuestion("What is your screen name?");
1877 user.setReminderQueryAnswer(screenName);
1878 user.setEmailAddress(screenName + "@liferay.com");
1879 user.setScreenName(screenName);
1880 user.setLanguageId("en_US");
1881 user.setGreeting("Welcome " + screenName + StringPool.EXCLAMATION);
1882 user.setFirstName(firstName);
1883 user.setLastName(lastName);
1884 user.setLoginDate(new Date());
1885 user.setLastLoginDate(new Date());
1886 user.setLastFailedLoginDate(new Date());
1887 user.setLockoutDate(new Date());
1888 user.setAgreedToTermsOfUse(true);
1889 user.setEmailAddressVerified(true);
1890
1891 return user;
1892 }
1893
1894 protected Date nextFutureDate() {
1895 return new Date(
1896 _FUTURE_TIME + (_futureDateCounter.get() * Time.SECOND));
1897 }
1898
1899 private static final String _DEPENDENCIES_DIR=
1900 "../portal-impl/src/com/liferay/portal/tools/samplesqlbuilder/" +
1901 "dependencies/";
1902
1903 private static final long _FUTURE_TIME =
1904 System.currentTimeMillis() + Time.YEAR;
1905
1906 private static final String _SAMPLE_USER_NAME = "Sample";
1907
1908 private Account _account;
1909 private long _accountId;
1910 private Role _administratorRole;
1911 private List<AssetCategory> _assetCategories;
1912 private List<AssetVocabulary> _assetVocabularies;
1913 private String _baseDir;
1914 private List<ClassName> _classNames;
1915 private Map<String, Long> _classNamesMap = new HashMap<String, Long>();
1916 private Company _company;
1917 private long _companyId;
1918 private SimpleCounter _counter;
1919 private String _ddlDDMStructureContent;
1920 private DDMStructure _defaultDLDDMStructure;
1921 private DLFileEntryType _defaultDLFileEntryType;
1922 private User _defaultUser;
1923 private long _defaultUserId;
1924 private String _dlDDMStructureContent;
1925 private List<String> _firstNames;
1926 private SimpleCounter _futureDateCounter;
1927 private Group _globalGroup;
1928 private long _globalGroupId;
1929 private List<Group> _groups;
1930 private Group _guestGroup;
1931 private long _guestGroupId;
1932 private Role _guestRole;
1933 private User _guestUser;
1934 private String _journalArticleContent;
1935 private List<String> _lastNames;
1936 private Map<Long, SimpleCounter> _layoutCounters =
1937 new HashMap<Long, SimpleCounter>();
1938 private int _maxAssetCategoryCount;
1939 private int _maxBlogsEntryCount;
1940 private int _maxDLFileEntrySize;
1941 private int _maxGroupsCount;
1942 private int _maxJournalArticleCount;
1943 private int _maxMBCategoryCount;
1944 private int _maxMBMessageCount;
1945 private int _maxMBThreadCount;
1946 private int _maxUserToGroupCount;
1947 private Role _ownerRole;
1948 private Role _powerUserRole;
1949 private SimpleCounter _resourcePermissionCounter;
1950 private List<Role> _roles;
1951 private User _sampleUser;
1952 private long _sampleUserId;
1953 private Format _simpleDateFormat =
1954 FastDateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1955 private Role _siteMemberRole;
1956 private SimpleCounter _socialActivityCounter;
1957 private Role _userRole;
1958 private SimpleCounter _userScreenNameCounter;
1959 private VirtualHost _virtualHost;
1960
1961 }