001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.tools.samplesqlbuilder;
016    
017    import com.liferay.counter.model.Counter;
018    import com.liferay.counter.model.CounterModel;
019    import com.liferay.counter.model.impl.CounterModelImpl;
020    import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
021    import com.liferay.portal.kernel.metadata.RawMetadataProcessor;
022    import com.liferay.portal.kernel.template.TemplateConstants;
023    import com.liferay.portal.kernel.util.CharPool;
024    import com.liferay.portal.kernel.util.ContentTypes;
025    import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
026    import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
027    import com.liferay.portal.kernel.util.GetterUtil;
028    import com.liferay.portal.kernel.util.IntegerWrapper;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.kernel.util.StringUtil;
032    import com.liferay.portal.kernel.util.Time;
033    import com.liferay.portal.kernel.util.UnicodeProperties;
034    import com.liferay.portal.kernel.util.Validator;
035    import com.liferay.portal.kernel.workflow.WorkflowConstants;
036    import com.liferay.portal.model.AccountModel;
037    import com.liferay.portal.model.ClassNameModel;
038    import com.liferay.portal.model.Company;
039    import com.liferay.portal.model.CompanyModel;
040    import com.liferay.portal.model.ContactConstants;
041    import com.liferay.portal.model.ContactModel;
042    import com.liferay.portal.model.Group;
043    import com.liferay.portal.model.GroupConstants;
044    import com.liferay.portal.model.GroupModel;
045    import com.liferay.portal.model.Layout;
046    import com.liferay.portal.model.LayoutConstants;
047    import com.liferay.portal.model.LayoutFriendlyURLModel;
048    import com.liferay.portal.model.LayoutModel;
049    import com.liferay.portal.model.LayoutSetModel;
050    import com.liferay.portal.model.LayoutTypePortletConstants;
051    import com.liferay.portal.model.ModelHintsUtil;
052    import com.liferay.portal.model.PortletConstants;
053    import com.liferay.portal.model.PortletPreferencesModel;
054    import com.liferay.portal.model.ResourceConstants;
055    import com.liferay.portal.model.ResourcePermission;
056    import com.liferay.portal.model.ResourcePermissionModel;
057    import com.liferay.portal.model.Role;
058    import com.liferay.portal.model.RoleConstants;
059    import com.liferay.portal.model.RoleModel;
060    import com.liferay.portal.model.SubscriptionConstants;
061    import com.liferay.portal.model.SubscriptionModel;
062    import com.liferay.portal.model.User;
063    import com.liferay.portal.model.UserModel;
064    import com.liferay.portal.model.VirtualHostModel;
065    import com.liferay.portal.model.impl.AccountModelImpl;
066    import com.liferay.portal.model.impl.ClassNameModelImpl;
067    import com.liferay.portal.model.impl.CompanyModelImpl;
068    import com.liferay.portal.model.impl.ContactModelImpl;
069    import com.liferay.portal.model.impl.GroupModelImpl;
070    import com.liferay.portal.model.impl.LayoutFriendlyURLModelImpl;
071    import com.liferay.portal.model.impl.LayoutModelImpl;
072    import com.liferay.portal.model.impl.LayoutSetModelImpl;
073    import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
074    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
075    import com.liferay.portal.model.impl.RoleModelImpl;
076    import com.liferay.portal.model.impl.SubscriptionModelImpl;
077    import com.liferay.portal.model.impl.UserModelImpl;
078    import com.liferay.portal.model.impl.VirtualHostModelImpl;
079    import com.liferay.portal.security.auth.FullNameGenerator;
080    import com.liferay.portal.security.auth.FullNameGeneratorFactory;
081    import com.liferay.portal.service.permission.PortletPermissionUtil;
082    import com.liferay.portal.util.PortletKeys;
083    import com.liferay.portal.util.PropsValues;
084    import com.liferay.portlet.PortletPreferencesFactory;
085    import com.liferay.portlet.PortletPreferencesFactoryImpl;
086    import com.liferay.portlet.PortletPreferencesImpl;
087    import com.liferay.portlet.asset.model.AssetCategory;
088    import com.liferay.portlet.asset.model.AssetCategoryConstants;
089    import com.liferay.portlet.asset.model.AssetCategoryModel;
090    import com.liferay.portlet.asset.model.AssetEntryModel;
091    import com.liferay.portlet.asset.model.AssetTag;
092    import com.liferay.portlet.asset.model.AssetTagModel;
093    import com.liferay.portlet.asset.model.AssetTagStatsModel;
094    import com.liferay.portlet.asset.model.AssetVocabulary;
095    import com.liferay.portlet.asset.model.AssetVocabularyModel;
096    import com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl;
097    import com.liferay.portlet.asset.model.impl.AssetEntryModelImpl;
098    import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
099    import com.liferay.portlet.asset.model.impl.AssetTagStatsModelImpl;
100    import com.liferay.portlet.asset.model.impl.AssetVocabularyModelImpl;
101    import com.liferay.portlet.blogs.model.BlogsEntry;
102    import com.liferay.portlet.blogs.model.BlogsEntryModel;
103    import com.liferay.portlet.blogs.model.BlogsStatsUserModel;
104    import com.liferay.portlet.blogs.model.impl.BlogsEntryModelImpl;
105    import com.liferay.portlet.blogs.model.impl.BlogsStatsUserModelImpl;
106    import com.liferay.portlet.blogs.social.BlogsActivityKeys;
107    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
108    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
109    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
110    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadataModel;
111    import com.liferay.portlet.documentlibrary.model.DLFileEntryModel;
112    import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
113    import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeModel;
114    import com.liferay.portlet.documentlibrary.model.DLFileVersionModel;
115    import com.liferay.portlet.documentlibrary.model.DLFolder;
116    import com.liferay.portlet.documentlibrary.model.DLFolderModel;
117    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl;
118    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryModelImpl;
119    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryTypeModelImpl;
120    import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
121    import com.liferay.portlet.documentlibrary.model.impl.DLFolderModelImpl;
122    import com.liferay.portlet.documentlibrary.social.DLActivityKeys;
123    import com.liferay.portlet.dynamicdatalists.model.DDLRecordConstants;
124    import com.liferay.portlet.dynamicdatalists.model.DDLRecordModel;
125    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
126    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSetConstants;
127    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSetModel;
128    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersionModel;
129    import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordModelImpl;
130    import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordSetModelImpl;
131    import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordVersionModelImpl;
132    import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
133    import com.liferay.portlet.dynamicdatamapping.model.DDMContentModel;
134    import com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink;
135    import com.liferay.portlet.dynamicdatamapping.model.DDMStorageLinkModel;
136    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
137    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants;
138    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLinkModel;
139    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureModel;
140    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants;
141    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateModel;
142    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentModelImpl;
143    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStorageLinkModelImpl;
144    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLinkModelImpl;
145    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl;
146    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl;
147    import com.liferay.portlet.dynamicdatamapping.util.DDMImpl;
148    import com.liferay.portlet.journal.model.JournalArticle;
149    import com.liferay.portlet.journal.model.JournalArticleConstants;
150    import com.liferay.portlet.journal.model.JournalArticleModel;
151    import com.liferay.portlet.journal.model.JournalArticleResourceModel;
152    import com.liferay.portlet.journal.model.JournalContentSearchModel;
153    import com.liferay.portlet.journal.model.impl.JournalArticleModelImpl;
154    import com.liferay.portlet.journal.model.impl.JournalArticleResourceModelImpl;
155    import com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl;
156    import com.liferay.portlet.journal.social.JournalActivityKeys;
157    import com.liferay.portlet.messageboards.model.MBCategory;
158    import com.liferay.portlet.messageboards.model.MBCategoryConstants;
159    import com.liferay.portlet.messageboards.model.MBCategoryModel;
160    import com.liferay.portlet.messageboards.model.MBDiscussion;
161    import com.liferay.portlet.messageboards.model.MBDiscussionModel;
162    import com.liferay.portlet.messageboards.model.MBMailingListModel;
163    import com.liferay.portlet.messageboards.model.MBMessage;
164    import com.liferay.portlet.messageboards.model.MBMessageConstants;
165    import com.liferay.portlet.messageboards.model.MBMessageModel;
166    import com.liferay.portlet.messageboards.model.MBStatsUserModel;
167    import com.liferay.portlet.messageboards.model.MBThread;
168    import com.liferay.portlet.messageboards.model.MBThreadFlagModel;
169    import com.liferay.portlet.messageboards.model.MBThreadModel;
170    import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
171    import com.liferay.portlet.messageboards.model.impl.MBDiscussionModelImpl;
172    import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
173    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
174    import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
175    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl;
176    import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
177    import com.liferay.portlet.messageboards.social.MBActivityKeys;
178    import com.liferay.portlet.social.model.SocialActivity;
179    import com.liferay.portlet.social.model.SocialActivityConstants;
180    import com.liferay.portlet.social.model.SocialActivityModel;
181    import com.liferay.portlet.social.model.impl.SocialActivityModelImpl;
182    import com.liferay.portlet.wiki.model.WikiNode;
183    import com.liferay.portlet.wiki.model.WikiNodeModel;
184    import com.liferay.portlet.wiki.model.WikiPage;
185    import com.liferay.portlet.wiki.model.WikiPageConstants;
186    import com.liferay.portlet.wiki.model.WikiPageModel;
187    import com.liferay.portlet.wiki.model.WikiPageResourceModel;
188    import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
189    import com.liferay.portlet.wiki.model.impl.WikiPageModelImpl;
190    import com.liferay.portlet.wiki.model.impl.WikiPageResourceModelImpl;
191    import com.liferay.portlet.wiki.social.WikiActivityKeys;
192    import com.liferay.util.SimpleCounter;
193    
194    import java.io.IOException;
195    import java.io.InputStream;
196    import java.io.InputStreamReader;
197    
198    import java.text.Format;
199    
200    import java.util.ArrayList;
201    import java.util.Collections;
202    import java.util.Date;
203    import java.util.HashMap;
204    import java.util.List;
205    import java.util.Map;
206    import java.util.Properties;
207    import java.util.TimeZone;
208    
209    import javax.portlet.PortletPreferences;
210    
211    /**
212     * @author Brian Wing Shun Chan
213     */
214    public class DataFactory {
215    
216            public DataFactory(Properties properties) throws Exception {
217                    initContext(properties);
218    
219                    _counter = new SimpleCounter(_maxGroupsCount + 1);
220                    _timeCounter = new SimpleCounter();
221                    _futureDateCounter = new SimpleCounter();
222                    _resourcePermissionCounter = new SimpleCounter();
223                    _socialActivityCounter = new SimpleCounter();
224                    _userScreenNameCounter = new SimpleCounter();
225    
226                    _classNameModels = new ArrayList<ClassNameModel>();
227    
228                    List<String> models = ModelHintsUtil.getModels();
229    
230                    for (String model : models) {
231                            ClassNameModel classNameModel = new ClassNameModelImpl();
232    
233                            long classNameId = _counter.get();
234    
235                            classNameModel.setClassNameId(classNameId);
236    
237                            classNameModel.setValue(model);
238    
239                            _classNameModels.add(classNameModel);
240    
241                            _classNameModelsMap.put(model, classNameId);
242                    }
243    
244                    _accountId = _counter.get();
245                    _companyId = _counter.get();
246                    _defaultUserId = _counter.get();
247                    _globalGroupId = _counter.get();
248                    _guestGroupId = _counter.get();
249                    _sampleUserId = _counter.get();
250    
251                    _dlDDMStructureContent = StringUtil.read(
252                            getResourceInputStream("ddm_structure_basic_document.xml"));
253                    _journalDDMStructureContent = StringUtil.read(
254                            getResourceInputStream("ddm_structure_basic_web_content.xml"));
255    
256                    String defaultAssetPublisherPreference = StringUtil.read(
257                            getResourceInputStream("default_asset_publisher_preference.xml"));
258    
259                    _defaultAssetPublisherPortletPreference =
260                            (PortletPreferencesImpl)_portletPreferencesFactory.fromDefaultXML(
261                                    defaultAssetPublisherPreference);
262    
263                    initAssetCategoryModels();
264                    initAssetTagModels();
265                    initCompanyModel();
266                    initDLFileEntryTypeModel();
267                    initGroupModels();
268    
269                    int maxJournalArticleSize = GetterUtil.getInteger(
270                            properties.getProperty("sample.sql.max.journal.article.size"));
271    
272                    initJournalArticleContent(maxJournalArticleSize);
273    
274                    initRoleModels();
275                    initUserNames();
276                    initUserModels();
277                    initVirtualHostModel(
278                            properties.getProperty("sample.sql.virtual.hostname"));
279            }
280    
281            public AccountModel getAccountModel() {
282                    return _accountModel;
283            }
284    
285            public RoleModel getAdministratorRoleModel() {
286                    return _administratorRoleModel;
287            }
288    
289            public List<Long> getAssetCategoryIds(long groupId) {
290                    SimpleCounter counter = _assetCategoryCounters.get(groupId);
291    
292                    if (counter == null) {
293                            counter = new SimpleCounter(0);
294    
295                            _assetCategoryCounters.put(groupId, counter);
296                    }
297    
298                    List<AssetCategoryModel> assetCategoryModels =
299                            _assetCategoryModelsArray[(int)groupId - 1];
300    
301                    if ((assetCategoryModels == null) || assetCategoryModels.isEmpty()) {
302                            return Collections.emptyList();
303                    }
304    
305                    List<Long> assetCategoryIds = new ArrayList<Long>(
306                            _maxAssetEntryToAssetCategoryCount);
307    
308                    for (int i = 0; i < _maxAssetEntryToAssetCategoryCount; i++) {
309                            int index = (int)counter.get() % assetCategoryModels.size();
310    
311                            AssetCategoryModel assetCategoryModel = assetCategoryModels.get(
312                                    index);
313    
314                            assetCategoryIds.add(assetCategoryModel.getCategoryId());
315                    }
316    
317                    return assetCategoryIds;
318            }
319    
320            public List<AssetCategoryModel> getAssetCategoryModels() {
321                    List<AssetCategoryModel> allAssetCategoryModels =
322                            new ArrayList<AssetCategoryModel>();
323    
324                    for (List<AssetCategoryModel> assetCategoryModels :
325                                    _assetCategoryModelsArray) {
326    
327                            allAssetCategoryModels.addAll(assetCategoryModels);
328                    }
329    
330                    return allAssetCategoryModels;
331            }
332    
333            public List<Long> getAssetTagIds(long groupId) {
334                    SimpleCounter counter = _assetTagCounters.get(groupId);
335    
336                    if (counter == null) {
337                            counter = new SimpleCounter(0);
338    
339                            _assetTagCounters.put(groupId, counter);
340                    }
341    
342                    List<AssetTagModel> assetTagModels =
343                            _assetTagModelsArray[(int)groupId - 1];
344    
345                    if ((assetTagModels == null) || assetTagModels.isEmpty()) {
346                            return Collections.emptyList();
347                    }
348    
349                    List<Long> assetTagIds = new ArrayList<Long>(
350                            _maxAssetEntryToAssetTagCount);
351    
352                    for (int i = 0; i < _maxAssetEntryToAssetTagCount; i++) {
353                            int index = (int)counter.get() % assetTagModels.size();
354    
355                            AssetTagModel assetTagModel = assetTagModels.get(index);
356    
357                            assetTagIds.add(assetTagModel.getTagId());
358                    }
359    
360                    return assetTagIds;
361            }
362    
363            public List<AssetTagModel> getAssetTagModels() {
364                    List<AssetTagModel> allAssetTagModels = new ArrayList<AssetTagModel>();
365    
366                    for (List<AssetTagModel> assetTagModels : _assetTagModelsArray) {
367                            allAssetTagModels.addAll(assetTagModels);
368                    }
369    
370                    return allAssetTagModels;
371            }
372    
373            public List<AssetTagStatsModel> getAssetTagStatsModels() {
374                    List<AssetTagStatsModel> allAssetTagStatsModels =
375                            new ArrayList<AssetTagStatsModel>();
376    
377                    for (List<AssetTagStatsModel> assetTagStatsModels :
378                                    _assetTagStatsModelsArray) {
379    
380                            allAssetTagStatsModels.addAll(assetTagStatsModels);
381                    }
382    
383                    return allAssetTagStatsModels;
384            }
385    
386            public List<AssetVocabularyModel> getAssetVocabularyModels() {
387                    List<AssetVocabularyModel> allAssetVocabularyModels =
388                            new ArrayList<AssetVocabularyModel>();
389    
390                    allAssetVocabularyModels.add(_defaultAssetVocabularyModel);
391    
392                    for (List<AssetVocabularyModel> assetVocabularyModels :
393                                    _assetVocabularyModelsArray) {
394    
395                            allAssetVocabularyModels.addAll(assetVocabularyModels);
396                    }
397    
398                    return allAssetVocabularyModels;
399            }
400    
401            public long getBlogsEntryClassNameId() {
402                    return _classNameModelsMap.get(BlogsEntry.class.getName());
403            }
404    
405            public long getClassNameId(String className) {
406                    return _classNameModelsMap.get(className);
407            }
408    
409            public List<ClassNameModel> getClassNameModels() {
410                    return _classNameModels;
411            }
412    
413            public CompanyModel getCompanyModel() {
414                    return _companyModel;
415            }
416    
417            public SimpleCounter getCounter() {
418                    return _counter;
419            }
420    
421            public long getCounterNext() {
422                    return _counter.get();
423            }
424    
425            public String getDateLong(Date date) {
426                    return String.valueOf(date.getTime());
427            }
428    
429            public String getDateString(Date date) {
430                    if (date == null) {
431                            return null;
432                    }
433    
434                    return _simpleDateFormat.format(date);
435            }
436    
437            public long getDDLRecordSetClassNameId() {
438                    return _classNameModelsMap.get(DDLRecordSet.class.getName());
439            }
440    
441            public long getDefaultDLDDMStructureId() {
442                    return _defaultDLDDMStructureModel.getStructureId();
443            }
444    
445            public DDMStructureModel getDefaultDLDDMStructureModel() {
446                    return _defaultDLDDMStructureModel;
447            }
448    
449            public DLFileEntryTypeModel getDefaultDLFileEntryTypeModel() {
450                    return _defaultDLFileEntryTypeModel;
451            }
452    
453            public DDMStructureModel getDefaultJournalDDMStructureModel() {
454                    return _defaultJournalDDMStructureModel;
455            }
456    
457            public DDMTemplateModel getDefaultJournalDDMTemplateModel() {
458                    return _defaultJournalDDMTemplateModel;
459            }
460    
461            public UserModel getDefaultUserModel() {
462                    return _defaultUserModel;
463            }
464    
465            public long getDLFileEntryClassNameId() {
466                    return _classNameModelsMap.get(DLFileEntry.class.getName());
467            }
468    
469            public GroupModel getGlobalGroupModel() {
470                    return _globalGroupModel;
471            }
472    
473            public long getGroupClassNameId() {
474                    return _classNameModelsMap.get(Group.class.getName());
475            }
476    
477            public List<GroupModel> getGroupModels() {
478                    return _groupModels;
479            }
480    
481            public GroupModel getGuestGroupModel() {
482                    return _guestGroupModel;
483            }
484    
485            public UserModel getGuestUserModel() {
486                    return _guestUserModel;
487            }
488    
489            public long getJournalArticleClassNameId() {
490                    return _classNameModelsMap.get(JournalArticle.class.getName());
491            }
492    
493            public String getJournalArticleLayoutColumn(String portletPrefix) {
494                    StringBundler sb = new StringBundler(3 * _maxJournalArticleCount);
495    
496                    for (int i = 1; i <= _maxJournalArticleCount; i++) {
497                            sb.append(portletPrefix);
498                            sb.append(i);
499                            sb.append(StringPool.COMMA);
500                    }
501    
502                    return sb.toString();
503            }
504    
505            public long getLayoutClassNameId() {
506                    return _classNameModelsMap.get(Layout.class.getName());
507            }
508    
509            public int getMaxAssetPublisherPageCount() {
510                    return _maxAssetPublisherPageCount;
511            }
512    
513            public int getMaxBlogsEntryCommentCount() {
514                    return _maxBlogsEntryCommentCount;
515            }
516    
517            public int getMaxDDLRecordCount() {
518                    return _maxDDLRecordCount;
519            }
520    
521            public int getMaxDDLRecordSetCount() {
522                    return _maxDDLRecordSetCount;
523            }
524    
525            public int getMaxDLFolderDepth() {
526                    return _maxDLFolderDepth;
527            }
528    
529            public int getMaxGroupCount() {
530                    return _maxGroupsCount;
531            }
532    
533            public int getMaxJournalArticleCount() {
534                    return _maxJournalArticleCount;
535            }
536    
537            public int getMaxJournalArticlePageCount() {
538                    return _maxJournalArticlePageCount;
539            }
540    
541            public int getMaxJournalArticleVersionCount() {
542                    return _maxJournalArticleVersionCount;
543            }
544    
545            public int getMaxWikiPageCommentCount() {
546                    return _maxWikiPageCommentCount;
547            }
548    
549            public List<Long> getNewUserGroupIds(long groupId) {
550                    List<Long> groupIds = new ArrayList<Long>(_maxUserToGroupCount + 1);
551    
552                    groupIds.add(_guestGroupModel.getGroupId());
553    
554                    if ((groupId + _maxUserToGroupCount) > _maxGroupsCount) {
555                            groupId = groupId - _maxUserToGroupCount + 1;
556                    }
557    
558                    for (int i = 0; i < _maxUserToGroupCount; i++) {
559                            groupIds.add(groupId + i);
560                    }
561    
562                    return groupIds;
563            }
564    
565            public RoleModel getPowerUserRoleModel() {
566                    return _powerUserRoleModel;
567            }
568    
569            public List<RoleModel> getRoleModels() {
570                    return _roleModels;
571            }
572    
573            public UserModel getSampleUserModel() {
574                    return _sampleUserModel;
575            }
576    
577            public List<Integer> getSequence(int size) {
578                    List<Integer> sequence = new ArrayList<Integer>(size);
579    
580                    for (int i = 1; i <= size; i++) {
581                            sequence.add(i);
582                    }
583    
584                    return sequence;
585            }
586    
587            public RoleModel getUserRoleModel() {
588                    return _userRoleModel;
589            }
590    
591            public VirtualHostModel getVirtualHostModel() {
592                    return _virtualHostModel;
593            }
594    
595            public long getWikiPageClassNameId() {
596                    return _classNameModelsMap.get(WikiPage.class.getName());
597            }
598    
599            public void initAssetCategoryModels() {
600                    _assetCategoryModelsArray =
601                            (List<AssetCategoryModel>[])new List<?>[_maxGroupsCount];
602                    _assetVocabularyModelsArray =
603                            (List<AssetVocabularyModel>[])new List<?>[_maxGroupsCount];
604                    _defaultAssetVocabularyModel = newAssetVocabularyModel(
605                            _globalGroupId, _defaultUserId, null,
606                            PropsValues.ASSET_VOCABULARY_DEFAULT);
607    
608                    StringBundler sb = new StringBundler(4);
609    
610                    for (int i = 1; i <= _maxGroupsCount; i++) {
611                            List<AssetVocabularyModel> assetVocabularyModels =
612                                    new ArrayList<AssetVocabularyModel>(_maxAssetVocabularyCount);
613                            List<AssetCategoryModel> assetCategoryModels =
614                                    new ArrayList<AssetCategoryModel>(
615                                            _maxAssetVocabularyCount * _maxAssetCategoryCount);
616    
617                            long lastRightCategoryId = 2;
618    
619                            for (int j = 0; j < _maxAssetVocabularyCount; j++) {
620                                    sb.setIndex(0);
621    
622                                    sb.append("TestVocabulary_");
623                                    sb.append(i);
624                                    sb.append(StringPool.UNDERLINE);
625                                    sb.append(j);
626    
627                                    AssetVocabularyModel assetVocabularyModel =
628                                            newAssetVocabularyModel(
629                                                    i, _sampleUserId, _SAMPLE_USER_NAME, sb.toString());
630    
631                                    assetVocabularyModels.add(assetVocabularyModel);
632    
633                                    for (int k = 0; k < _maxAssetCategoryCount; k++) {
634                                            sb.setIndex(0);
635    
636                                            sb.append("TestCategory_");
637                                            sb.append(assetVocabularyModel.getVocabularyId());
638                                            sb.append(StringPool.UNDERLINE);
639                                            sb.append(k);
640    
641                                            AssetCategoryModel assetCategoryModel =
642                                                    newAssetCategoryModel(
643                                                            i, lastRightCategoryId, sb.toString(),
644                                                            assetVocabularyModel.getVocabularyId());
645    
646                                            lastRightCategoryId += 2;
647    
648                                            assetCategoryModels.add(assetCategoryModel);
649                                    }
650                            }
651    
652                            _assetCategoryModelsArray[i - 1] = assetCategoryModels;
653                            _assetVocabularyModelsArray[i - 1] = assetVocabularyModels;
654                    }
655            }
656    
657            public void initAssetTagModels() {
658                    _assetTagModelsArray =
659                            (List<AssetTagModel>[])new List<?>[_maxGroupsCount];
660                    _assetTagStatsModelsArray =
661                            (List<AssetTagStatsModel>[])new List<?>[_maxGroupsCount];
662    
663                    for (int i = 1; i <= _maxGroupsCount; i++) {
664                            List<AssetTagModel> assetTagModels = new ArrayList<AssetTagModel>(
665                                    _maxAssetTagCount);
666                            List<AssetTagStatsModel> assetTagStatsModels =
667                                    new ArrayList<AssetTagStatsModel>(_maxAssetTagCount * 3);
668    
669                            for (int j = 0; j < _maxAssetTagCount; j++) {
670                                    AssetTagModel assetTagModel = new AssetTagModelImpl();
671    
672                                    assetTagModel.setTagId(_counter.get());
673                                    assetTagModel.setGroupId(i);
674                                    assetTagModel.setCompanyId(_companyId);
675                                    assetTagModel.setUserId(_sampleUserId);
676                                    assetTagModel.setUserName(_SAMPLE_USER_NAME);
677                                    assetTagModel.setCreateDate(new Date());
678                                    assetTagModel.setModifiedDate(new Date());
679                                    assetTagModel.setName("TestTag_" + i + "_" + j);
680    
681                                    assetTagModels.add(assetTagModel);
682    
683                                    AssetTagStatsModel assetTagStatsModel = newAssetTagStatsModel(
684                                            assetTagModel.getTagId(),
685                                            _classNameModelsMap.get(BlogsEntry.class.getName()));
686    
687                                    assetTagStatsModels.add(assetTagStatsModel);
688    
689                                    assetTagStatsModel = newAssetTagStatsModel(
690                                            assetTagModel.getTagId(),
691                                            _classNameModelsMap.get(JournalArticle.class.getName()));
692    
693                                    assetTagStatsModels.add(assetTagStatsModel);
694    
695                                    assetTagStatsModel = newAssetTagStatsModel(
696                                            assetTagModel.getTagId(),
697                                            _classNameModelsMap.get(WikiPage.class.getName()));
698    
699                                    assetTagStatsModels.add(assetTagStatsModel);
700                            }
701    
702                            _assetTagModelsArray[i - 1] = assetTagModels;
703                            _assetTagStatsModelsArray[i - 1] = assetTagStatsModels;
704                    }
705            }
706    
707            public void initCompanyModel() {
708                    _companyModel = new CompanyModelImpl();
709    
710                    _companyModel.setCompanyId(_companyId);
711                    _companyModel.setAccountId(_accountId);
712                    _companyModel.setWebId("liferay.com");
713                    _companyModel.setMx("liferay.com");
714                    _companyModel.setActive(true);
715    
716                    _accountModel = new AccountModelImpl();
717    
718                    _accountModel.setAccountId(_accountId);
719                    _accountModel.setCompanyId(_companyId);
720                    _accountModel.setCreateDate(new Date());
721                    _accountModel.setModifiedDate(new Date());
722                    _accountModel.setName("Liferay");
723                    _accountModel.setLegalName("Liferay, Inc.");
724            }
725    
726            public void initContext(Properties properties) {
727                    String timeZoneId = properties.getProperty("sample.sql.db.time.zone");
728    
729                    if (Validator.isNotNull(timeZoneId)) {
730                            TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
731    
732                            if (timeZone != null) {
733                                    TimeZone.setDefault(timeZone);
734    
735                                    _simpleDateFormat =
736                                            FastDateFormatFactoryUtil.getSimpleDateFormat(
737                                                    "yyyy-MM-dd HH:mm:ss", timeZone);
738                            }
739                    }
740    
741                    _assetPublisherQueryName = GetterUtil.getString(
742                            properties.getProperty("sample.sql.asset.publisher.query.name"));
743    
744                    if (!_assetPublisherQueryName.equals("assetCategories")) {
745                            _assetPublisherQueryName = "assetTags";
746                    }
747    
748                    _maxAssetCategoryCount = GetterUtil.getInteger(
749                            properties.getProperty("sample.sql.max.asset.category.count"));
750                    _maxAssetEntryToAssetCategoryCount = GetterUtil.getInteger(
751                            properties.getProperty(
752                                    "sample.sql.max.asset.entry.to.asset.category.count"));
753                    _maxAssetEntryToAssetTagCount = GetterUtil.getInteger(
754                            properties.getProperty(
755                                    "sample.sql.max.asset.entry.to.asset.tag.count"));
756                    _maxAssetPublisherPageCount = GetterUtil.getInteger(
757                            properties.getProperty(
758                                    "sample.sql.max.asset.publisher.page.count"));
759                    _maxAssetTagCount = GetterUtil.getInteger(
760                            properties.getProperty("sample.sql.max.asset.tag.count"));
761                    _maxAssetVocabularyCount = GetterUtil.getInteger(
762                            properties.getProperty("sample.sql.max.asset.vocabulary.count"));
763                    _maxBlogsEntryCommentCount = GetterUtil.getInteger(
764                            properties.getProperty("sample.sql.max.blogs.entry.comment.count"));
765                    _maxBlogsEntryCount = GetterUtil.getInteger(
766                            properties.getProperty("sample.sql.max.blogs.entry.count"));
767                    _maxDDLCustomFieldCount = GetterUtil.getInteger(
768                            properties.getProperty("sample.sql.max.ddl.custom.field.count"));
769                    _maxDDLRecordCount = GetterUtil.getInteger(
770                            properties.getProperty("sample.sql.max.ddl.record.count"));
771                    _maxDDLRecordSetCount = GetterUtil.getInteger(
772                            properties.getProperty("sample.sql.max.ddl.record.set.count"));
773                    _maxDLFileEntryCount = GetterUtil.getInteger(
774                            properties.getProperty("sample.sql.max.dl.file.entry.count"));
775                    _maxDLFileEntrySize = GetterUtil.getInteger(
776                            properties.getProperty("sample.sql.max.dl.file.entry.size"));
777                    _maxDLFolderCount = GetterUtil.getInteger(
778                            properties.getProperty("sample.sql.max.dl.folder.count"));
779                    _maxDLFolderDepth = GetterUtil.getInteger(
780                            properties.getProperty("sample.sql.max.dl.folder.depth"));
781                    _maxGroupsCount = GetterUtil.getInteger(
782                            properties.getProperty("sample.sql.max.group.count"));
783                    _maxJournalArticleCount = GetterUtil.getInteger(
784                            properties.getProperty("sample.sql.max.journal.article.count"));
785                    _maxJournalArticlePageCount = GetterUtil.getInteger(
786                            properties.getProperty(
787                                    "sample.sql.max.journal.article.page.count"));
788                    _maxJournalArticleVersionCount = GetterUtil.getInteger(
789                            properties.getProperty(
790                                    "sample.sql.max.journal.article.version.count"));
791                    _maxMBCategoryCount = GetterUtil.getInteger(
792                            properties.getProperty("sample.sql.max.mb.category.count"));
793                    _maxMBMessageCount = GetterUtil.getInteger(
794                            properties.getProperty("sample.sql.max.mb.message.count"));
795                    _maxMBThreadCount = GetterUtil.getInteger(
796                            properties.getProperty("sample.sql.max.mb.thread.count"));
797                    _maxUserCount = GetterUtil.getInteger(
798                            properties.getProperty("sample.sql.max.user.count"));
799                    _maxUserToGroupCount = GetterUtil.getInteger(
800                            properties.getProperty("sample.sql.max.user.to.group.count"));
801                    _maxWikiNodeCount = GetterUtil.getInteger(
802                            properties.getProperty("sample.sql.max.wiki.node.count"));
803                    _maxWikiPageCommentCount = GetterUtil.getInteger(
804                            properties.getProperty("sample.sql.max.wiki.page.comment.count"));
805                    _maxWikiPageCount = GetterUtil.getInteger(
806                            properties.getProperty("sample.sql.max.wiki.page.count"));
807            }
808    
809            public void initDLFileEntryTypeModel() {
810                    _defaultDLFileEntryTypeModel = new DLFileEntryTypeModelImpl();
811    
812                    _defaultDLFileEntryTypeModel.setUuid(SequentialUUID.generate());
813                    _defaultDLFileEntryTypeModel.setFileEntryTypeId(
814                            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);
815                    _defaultDLFileEntryTypeModel.setCreateDate(nextFutureDate());
816                    _defaultDLFileEntryTypeModel.setModifiedDate(nextFutureDate());
817                    _defaultDLFileEntryTypeModel.setFileEntryTypeKey(
818                            StringUtil.toUpperCase(
819                                    DLFileEntryTypeConstants.NAME_BASIC_DOCUMENT));
820    
821                    StringBundler sb = new StringBundler(5);
822    
823                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
824                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
825                    sb.append("<name language-id=\"en_US\">");
826                    sb.append(DLFileEntryTypeConstants.NAME_BASIC_DOCUMENT);
827                    sb.append("</name></root>");
828    
829                    _defaultDLFileEntryTypeModel.setName(sb.toString());
830    
831                    _defaultDLDDMStructureModel = newDDMStructureModel(
832                            _globalGroupId, _defaultUserId, getDLFileEntryClassNameId(),
833                            RawMetadataProcessor.TIKA_RAW_METADATA, _dlDDMStructureContent);
834                    _defaultJournalDDMStructureModel = newDDMStructureModel(
835                            _globalGroupId, _defaultUserId, getJournalArticleClassNameId(),
836                            "BASIC-WEB-CONTENT", _journalDDMStructureContent);
837                    _defaultJournalDDMTemplateModel = newDDMTemplateModel(
838                            _globalGroupId, _defaultUserId,
839                            _defaultJournalDDMStructureModel.getStructureId());
840            }
841    
842            public void initGroupModels() throws Exception {
843                    long groupClassNameId = getGroupClassNameId();
844    
845                    _globalGroupModel = newGroupModel(
846                            _globalGroupId, _classNameModelsMap.get(Company.class.getName()),
847                            _companyId, GroupConstants.GLOBAL, false);
848    
849                    _guestGroupModel = newGroupModel(
850                            _guestGroupId, groupClassNameId, _guestGroupId,
851                            GroupConstants.GUEST, true);
852    
853                    _groupModels = new ArrayList<GroupModel>(_maxGroupsCount);
854    
855                    for (int i = 1; i <= _maxGroupsCount; i++) {
856                            GroupModel groupModel = newGroupModel(
857                                    i, groupClassNameId, i, "Site " + i, true);
858    
859                            _groupModels.add(groupModel);
860                    }
861            }
862    
863            public void initJournalArticleContent(int maxJournalArticleSize) {
864                    StringBundler sb = new StringBundler(5);
865    
866                    sb.append("<?xml version=\"1.0\"?><root available-locales=\"en_US\" ");
867                    sb.append("default-locale=\"en_US\"><dynamic-element name=\"content");
868                    sb.append("\" type=\"text_area\" index-type=\"keyword\" index=\"0\">");
869                    sb.append("<dynamic-content language-id=\"en_US\"><![CDATA[");
870    
871                    if (maxJournalArticleSize <= 0) {
872                            maxJournalArticleSize = 1;
873                    }
874    
875                    char[] chars = new char[maxJournalArticleSize];
876    
877                    for (int i = 0; i < maxJournalArticleSize; i++) {
878                            chars[i] = (char)(CharPool.LOWER_CASE_A + (i % 26));
879                    }
880    
881                    sb.append(new String(chars));
882    
883                    sb.append("]]></dynamic-content></dynamic-element></root>");
884    
885                    _journalArticleContent = sb.toString();
886            }
887    
888            public void initRoleModels() {
889                    _roleModels = new ArrayList<RoleModel>();
890    
891                    // Administrator
892    
893                    _administratorRoleModel = newRoleModel(
894                            RoleConstants.ADMINISTRATOR, RoleConstants.TYPE_REGULAR);
895    
896                    _roleModels.add(_administratorRoleModel);
897    
898                    // Guest
899    
900                    _guestRoleModel = newRoleModel(
901                            RoleConstants.GUEST, RoleConstants.TYPE_REGULAR);
902    
903                    _roleModels.add(_guestRoleModel);
904    
905                    // Organization Administrator
906    
907                    RoleModel organizationAdministratorRoleModel = newRoleModel(
908                            RoleConstants.ORGANIZATION_ADMINISTRATOR,
909                            RoleConstants.TYPE_ORGANIZATION);
910    
911                    _roleModels.add(organizationAdministratorRoleModel);
912    
913                    // Organization Owner
914    
915                    RoleModel organizationOwnerRoleModel = newRoleModel(
916                            RoleConstants.ORGANIZATION_OWNER, RoleConstants.TYPE_ORGANIZATION);
917    
918                    _roleModels.add(organizationOwnerRoleModel);
919    
920                    // Organization User
921    
922                    RoleModel organizationUserRoleModel = newRoleModel(
923                            RoleConstants.ORGANIZATION_USER, RoleConstants.TYPE_ORGANIZATION);
924    
925                    _roleModels.add(organizationUserRoleModel);
926    
927                    // Owner
928    
929                    _ownerRoleModel = newRoleModel(
930                            RoleConstants.OWNER, RoleConstants.TYPE_REGULAR);
931    
932                    _roleModels.add(_ownerRoleModel);
933    
934                    // Power User
935    
936                    _powerUserRoleModel = newRoleModel(
937                            RoleConstants.POWER_USER, RoleConstants.TYPE_REGULAR);
938    
939                    _roleModels.add(_powerUserRoleModel);
940    
941                    // Site Administrator
942    
943                    RoleModel siteAdministratorRoleModel = newRoleModel(
944                            RoleConstants.SITE_ADMINISTRATOR, RoleConstants.TYPE_SITE);
945    
946                    _roleModels.add(siteAdministratorRoleModel);
947    
948                    // Site Member
949    
950                    _siteMemberRoleModel = newRoleModel(
951                            RoleConstants.SITE_MEMBER, RoleConstants.TYPE_SITE);
952    
953                    _roleModels.add(_siteMemberRoleModel);
954    
955                    // Site Owner
956    
957                    RoleModel siteOwnerRoleModel = newRoleModel(
958                            RoleConstants.SITE_OWNER, RoleConstants.TYPE_SITE);
959    
960                    _roleModels.add(siteOwnerRoleModel);
961    
962                    // User
963    
964                    _userRoleModel = newRoleModel(
965                            RoleConstants.USER, RoleConstants.TYPE_REGULAR);
966    
967                    _roleModels.add(_userRoleModel);
968            }
969    
970            public void initUserModels() {
971                    _defaultUserModel = newUserModel(
972                            _defaultUserId, StringPool.BLANK, StringPool.BLANK,
973                            StringPool.BLANK, true);
974                    _guestUserModel = newUserModel(
975                            _counter.get(), "Test", "Test", "Test", false);
976                    _sampleUserModel = newUserModel(
977                            _sampleUserId, _SAMPLE_USER_NAME, _SAMPLE_USER_NAME,
978                            _SAMPLE_USER_NAME, false);
979            }
980    
981            public void initUserNames() throws IOException {
982                    _firstNames = new ArrayList<String>();
983    
984                    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
985                            new InputStreamReader(getResourceInputStream("first_names.txt")));
986    
987                    String line = null;
988    
989                    while ((line = unsyncBufferedReader.readLine()) != null) {
990                            _firstNames.add(line);
991                    }
992    
993                    unsyncBufferedReader.close();
994    
995                    _lastNames = new ArrayList<String>();
996    
997                    unsyncBufferedReader = new UnsyncBufferedReader(
998                            new InputStreamReader(getResourceInputStream("last_names.txt")));
999    
1000                    while ((line = unsyncBufferedReader.readLine()) != null) {
1001                            _lastNames.add(line);
1002                    }
1003    
1004                    unsyncBufferedReader.close();
1005            }
1006    
1007            public void initVirtualHostModel(String hostname) {
1008                    _virtualHostModel = new VirtualHostModelImpl();
1009    
1010                    _virtualHostModel.setVirtualHostId(_counter.get());
1011                    _virtualHostModel.setCompanyId(_companyId);
1012                    _virtualHostModel.setHostname(hostname);
1013            }
1014    
1015            public AssetEntryModel newAssetEntryModel(BlogsEntryModel blogsEntryModel) {
1016                    return newAssetEntryModel(
1017                            blogsEntryModel.getGroupId(), blogsEntryModel.getCreateDate(),
1018                            blogsEntryModel.getModifiedDate(), getBlogsEntryClassNameId(),
1019                            blogsEntryModel.getEntryId(), blogsEntryModel.getUuid(), 0, true,
1020                            true, ContentTypes.TEXT_HTML, blogsEntryModel.getTitle());
1021            }
1022    
1023            public AssetEntryModel newAssetEntryModel(
1024                    DLFileEntryModel dLFileEntryModel) {
1025    
1026                    return newAssetEntryModel(
1027                            dLFileEntryModel.getGroupId(), dLFileEntryModel.getCreateDate(),
1028                            dLFileEntryModel.getModifiedDate(), getDLFileEntryClassNameId(),
1029                            dLFileEntryModel.getFileEntryId(), dLFileEntryModel.getUuid(),
1030                            dLFileEntryModel.getFileEntryTypeId(), true, true,
1031                            dLFileEntryModel.getMimeType(), dLFileEntryModel.getTitle());
1032            }
1033    
1034            public AssetEntryModel newAssetEntryModel(DLFolderModel dLFolderModel) {
1035                    return newAssetEntryModel(
1036                            dLFolderModel.getGroupId(), dLFolderModel.getCreateDate(),
1037                            dLFolderModel.getModifiedDate(),
1038                            _classNameModelsMap.get(DLFolder.class.getName()),
1039                            dLFolderModel.getFolderId(), dLFolderModel.getUuid(), 0, true, true,
1040                            null, dLFolderModel.getName());
1041            }
1042    
1043            public AssetEntryModel newAssetEntryModel(
1044                    JournalArticleModel journalArticleModel) {
1045    
1046                    long resourcePrimKey = journalArticleModel.getResourcePrimKey();
1047    
1048                    String resourceUuid = _journalArticleResourceUUIDs.get(resourcePrimKey);
1049    
1050                    return newAssetEntryModel(
1051                            journalArticleModel.getGroupId(),
1052                            journalArticleModel.getCreateDate(),
1053                            journalArticleModel.getModifiedDate(),
1054                            getJournalArticleClassNameId(), resourcePrimKey, resourceUuid,
1055                            _defaultJournalDDMStructureModel.getStructureId(),
1056                            journalArticleModel.isIndexable(), true, ContentTypes.TEXT_HTML,
1057                            journalArticleModel.getTitle());
1058            }
1059    
1060            public AssetEntryModel newAssetEntryModel(MBMessageModel mbMessageModel) {
1061                    long classNameId = 0;
1062                    boolean visible = false;
1063    
1064                    if (mbMessageModel.getCategoryId() ==
1065                                    MBCategoryConstants.DISCUSSION_CATEGORY_ID) {
1066    
1067                            classNameId = _classNameModelsMap.get(MBDiscussion.class.getName());
1068                    }
1069                    else {
1070                            classNameId = _classNameModelsMap.get(MBMessage.class.getName());
1071                            visible = true;
1072                    }
1073    
1074                    return newAssetEntryModel(
1075                            mbMessageModel.getGroupId(), mbMessageModel.getCreateDate(),
1076                            mbMessageModel.getModifiedDate(), classNameId,
1077                            mbMessageModel.getMessageId(), mbMessageModel.getUuid(), 0, true,
1078                            visible, ContentTypes.TEXT_HTML, mbMessageModel.getSubject());
1079            }
1080    
1081            public AssetEntryModel newAssetEntryModel(MBThreadModel mbThreadModel) {
1082                    return newAssetEntryModel(
1083                            mbThreadModel.getGroupId(), mbThreadModel.getCreateDate(),
1084                            mbThreadModel.getModifiedDate(),
1085                            _classNameModelsMap.get(MBThread.class.getName()),
1086                            mbThreadModel.getThreadId(), mbThreadModel.getUuid(), 0, true,
1087                            false, StringPool.BLANK,
1088                            String.valueOf(mbThreadModel.getRootMessageId()));
1089            }
1090    
1091            public AssetEntryModel newAssetEntryModel(WikiPageModel wikiPageModel) {
1092                    return newAssetEntryModel(
1093                            wikiPageModel.getGroupId(), wikiPageModel.getCreateDate(),
1094                            wikiPageModel.getModifiedDate(), getWikiPageClassNameId(),
1095                            wikiPageModel.getResourcePrimKey(), wikiPageModel.getUuid(), 0,
1096                            true, true, ContentTypes.TEXT_HTML, wikiPageModel.getTitle());
1097            }
1098    
1099            public List<PortletPreferencesModel>
1100                    newAssetPublisherPortletPreferencesModels(long plid) {
1101    
1102                    List<PortletPreferencesModel> portletPreferencesModels =
1103                            new ArrayList<PortletPreferencesModel>(4);
1104    
1105                    portletPreferencesModels.add(
1106                            newPortletPreferencesModel(
1107                                    plid, PortletKeys.BLOGS, PortletConstants.DEFAULT_PREFERENCES));
1108                    portletPreferencesModels.add(
1109                            newPortletPreferencesModel(
1110                                    plid, PortletKeys.DOCKBAR,
1111                                    PortletConstants.DEFAULT_PREFERENCES));
1112                    portletPreferencesModels.add(
1113                            newPortletPreferencesModel(
1114                                    plid, PortletKeys.JOURNAL,
1115                                    PortletConstants.DEFAULT_PREFERENCES));
1116                    portletPreferencesModels.add(
1117                            newPortletPreferencesModel(
1118                                    plid, PortletKeys.WIKI, PortletConstants.DEFAULT_PREFERENCES));
1119    
1120                    return portletPreferencesModels;
1121            }
1122    
1123            public List<BlogsEntryModel> newBlogsEntryModels(long groupId) {
1124                    List<BlogsEntryModel> blogEntryModels = new ArrayList<BlogsEntryModel>(
1125                            _maxBlogsEntryCount);
1126    
1127                    for (int i = 1; i <= _maxBlogsEntryCount; i++) {
1128                            blogEntryModels.add(newBlogsEntryModel(groupId, i));
1129                    }
1130    
1131                    return blogEntryModels;
1132            }
1133    
1134            public BlogsStatsUserModel newBlogsStatsUserModel(long groupId) {
1135                    BlogsStatsUserModel blogsStatsUserModel = new BlogsStatsUserModelImpl();
1136    
1137                    blogsStatsUserModel.setStatsUserId(_counter.get());
1138                    blogsStatsUserModel.setGroupId(groupId);
1139                    blogsStatsUserModel.setCompanyId(_companyId);
1140                    blogsStatsUserModel.setUserId(_sampleUserId);
1141                    blogsStatsUserModel.setEntryCount(_maxBlogsEntryCount);
1142                    blogsStatsUserModel.setLastPostDate(new Date());
1143    
1144                    return blogsStatsUserModel;
1145            }
1146    
1147            public ContactModel newContactModel(UserModel userModel) {
1148                    ContactModel contactModel = new ContactModelImpl();
1149    
1150                    contactModel.setContactId(userModel.getContactId());
1151                    contactModel.setCompanyId(userModel.getCompanyId());
1152                    contactModel.setUserId(userModel.getUserId());
1153    
1154                    FullNameGenerator fullNameGenerator =
1155                            FullNameGeneratorFactory.getInstance();
1156    
1157                    String fullName = fullNameGenerator.getFullName(
1158                            userModel.getFirstName(), userModel.getMiddleName(),
1159                            userModel.getLastName());
1160    
1161                    contactModel.setUserName(fullName);
1162                    contactModel.setCreateDate(new Date());
1163                    contactModel.setModifiedDate(new Date());
1164                    contactModel.setClassNameId(
1165                            _classNameModelsMap.get(User.class.getName()));
1166                    contactModel.setClassPK(userModel.getUserId());
1167                    contactModel.setAccountId(_accountId);
1168                    contactModel.setParentContactId(
1169                            ContactConstants.DEFAULT_PARENT_CONTACT_ID);
1170                    contactModel.setEmailAddress(userModel.getEmailAddress());
1171                    contactModel.setFirstName(userModel.getFirstName());
1172                    contactModel.setLastName(userModel.getLastName());
1173                    contactModel.setMale(true);
1174                    contactModel.setBirthday(new Date());
1175    
1176                    return contactModel;
1177            }
1178    
1179            public List<CounterModel> newCounterModels() {
1180                    List<CounterModel> counterModels = new ArrayList<CounterModel>();
1181    
1182                    // Counter
1183    
1184                    CounterModel counterModel = new CounterModelImpl();
1185    
1186                    counterModel.setName(Counter.class.getName());
1187                    counterModel.setCurrentId(_counter.get());
1188    
1189                    counterModels.add(counterModel);
1190    
1191                    // ResourcePermission
1192    
1193                    counterModel = new CounterModelImpl();
1194    
1195                    counterModel.setName(ResourcePermission.class.getName());
1196                    counterModel.setCurrentId(_resourcePermissionCounter.get());
1197    
1198                    counterModels.add(counterModel);
1199    
1200                    // SocialActivity
1201    
1202                    counterModel = new CounterModelImpl();
1203    
1204                    counterModel.setName(SocialActivity.class.getName());
1205                    counterModel.setCurrentId(_socialActivityCounter.get());
1206    
1207                    counterModels.add(counterModel);
1208    
1209                    return counterModels;
1210            }
1211    
1212            public DDMStructureModel newDDLDDMStructureModel(long groupId) {
1213                    StringBundler sb = new StringBundler(3 + _maxDDLCustomFieldCount * 10);
1214    
1215                    sb.append("<?xml version=\"1.0\"?>");
1216                    sb.append(
1217                            "<root available-locales=\"en_US\" default-locale=\"en_US\">");
1218    
1219                    for (int i = 0; i < _maxDDLCustomFieldCount; i++) {
1220                            sb.append(
1221                                    "<dynamic-element dataType=\"string\" indexType=\"keyword\"");
1222                            sb.append(" name=\"");
1223                            sb.append(nextDDLCustomFieldName(groupId, i));
1224                            sb.append(
1225                                    "\" readOnly=\"false\" repeatable=\"false\" required=\"false");
1226                            sb.append(
1227                                    "\" showLabel=\"true\" type=\"text\" width=\"25\"><meta-data");
1228                            sb.append(" locale=\"en_US\"><entry name=\"label\"><![CDATA[Text");
1229                            sb.append(i);
1230                            sb.append(
1231                                    "]]></entry><entry name=\"predefinedValue\"><![CDATA[]]>");
1232                            sb.append("</entry><entry name=\"tip\"><![CDATA[]]></entry>");
1233                            sb.append("</meta-data></dynamic-element>");
1234                    }
1235    
1236                    sb.append("</root>");
1237    
1238                    return newDDMStructureModel(
1239                            groupId, _sampleUserId,
1240                            _classNameModelsMap.get(DDLRecordSet.class.getName()),
1241                            "Test DDM Structure", sb.toString());
1242            }
1243    
1244            public List<PortletPreferencesModel>
1245                    newDDLPortletPreferencesModels(long plid) {
1246    
1247                    List<PortletPreferencesModel> portletPreferencesModels =
1248                            new ArrayList<PortletPreferencesModel>(2);
1249    
1250                    portletPreferencesModels.add(
1251                            newPortletPreferencesModel(
1252                                    plid, PortletKeys.DOCKBAR,
1253                                    PortletConstants.DEFAULT_PREFERENCES));
1254                    portletPreferencesModels.add(
1255                            newPortletPreferencesModel(
1256                                    plid, PortletKeys.DYNAMIC_DATA_LIST_DISPLAY,
1257                                    PortletConstants.DEFAULT_PREFERENCES));
1258                    portletPreferencesModels.add(
1259                            newPortletPreferencesModel(
1260                                    plid, PortletKeys.DYNAMIC_DATA_LISTS,
1261                                    PortletConstants.DEFAULT_PREFERENCES));
1262                    portletPreferencesModels.add(
1263                            newPortletPreferencesModel(
1264                                    plid, PortletKeys.DYNAMIC_DATA_MAPPING,
1265                                    PortletConstants.DEFAULT_PREFERENCES));
1266    
1267                    return portletPreferencesModels;
1268            }
1269    
1270            public DDLRecordModel newDDLRecordModel(
1271                    DDLRecordSetModel dDLRecordSetModel) {
1272    
1273                    DDLRecordModel ddlRecordModel = new DDLRecordModelImpl();
1274    
1275                    ddlRecordModel.setUuid(SequentialUUID.generate());
1276                    ddlRecordModel.setRecordId(_counter.get());
1277                    ddlRecordModel.setGroupId(dDLRecordSetModel.getGroupId());
1278                    ddlRecordModel.setCompanyId(_companyId);
1279                    ddlRecordModel.setUserId(_sampleUserId);
1280                    ddlRecordModel.setUserName(_SAMPLE_USER_NAME);
1281                    ddlRecordModel.setVersionUserId(_sampleUserId);
1282                    ddlRecordModel.setVersionUserName(_SAMPLE_USER_NAME);
1283                    ddlRecordModel.setCreateDate(new Date());
1284                    ddlRecordModel.setModifiedDate(new Date());
1285                    ddlRecordModel.setDDMStorageId(_counter.get());
1286                    ddlRecordModel.setRecordSetId(dDLRecordSetModel.getRecordSetId());
1287                    ddlRecordModel.setVersion(DDLRecordConstants.VERSION_DEFAULT);
1288                    ddlRecordModel.setDisplayIndex(
1289                            DDLRecordConstants.DISPLAY_INDEX_DEFAULT);
1290    
1291                    return ddlRecordModel;
1292            }
1293    
1294            public DDLRecordSetModel newDDLRecordSetModel(
1295                    DDMStructureModel ddmStructureModel, int currentIndex) {
1296    
1297                    DDLRecordSetModel ddlRecordSetModel = new DDLRecordSetModelImpl();
1298    
1299                    ddlRecordSetModel.setUuid(SequentialUUID.generate());
1300                    ddlRecordSetModel.setRecordSetId(_counter.get());
1301                    ddlRecordSetModel.setGroupId(ddmStructureModel.getGroupId());
1302                    ddlRecordSetModel.setCompanyId(_companyId);
1303                    ddlRecordSetModel.setUserId(_sampleUserId);
1304                    ddlRecordSetModel.setUserName(_SAMPLE_USER_NAME);
1305                    ddlRecordSetModel.setCreateDate(new Date());
1306                    ddlRecordSetModel.setModifiedDate(new Date());
1307                    ddlRecordSetModel.setDDMStructureId(ddmStructureModel.getStructureId());
1308                    ddlRecordSetModel.setRecordSetKey(String.valueOf(_counter.get()));
1309    
1310                    StringBundler sb = new StringBundler(5);
1311    
1312                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
1313                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
1314                    sb.append("<name language-id=\"en_US\">Test DDL Record Set ");
1315                    sb.append(currentIndex);
1316                    sb.append("</name></root>");
1317    
1318                    ddlRecordSetModel.setName(sb.toString());
1319    
1320                    ddlRecordSetModel.setMinDisplayRows(
1321                            DDLRecordSetConstants.MIN_DISPLAY_ROWS_DEFAULT);
1322                    ddlRecordSetModel.setScope(
1323                            DDLRecordSetConstants.SCOPE_DYNAMIC_DATA_LISTS);
1324    
1325                    return ddlRecordSetModel;
1326            }
1327    
1328            public DDLRecordVersionModel newDDLRecordVersionModel(
1329                    DDLRecordModel dDLRecordModel) {
1330    
1331                    DDLRecordVersionModel ddlRecordVersionModel =
1332                            new DDLRecordVersionModelImpl();
1333    
1334                    ddlRecordVersionModel.setRecordVersionId(_counter.get());
1335                    ddlRecordVersionModel.setGroupId(dDLRecordModel.getGroupId());
1336                    ddlRecordVersionModel.setCompanyId(_companyId);
1337                    ddlRecordVersionModel.setUserId(_sampleUserId);
1338                    ddlRecordVersionModel.setUserName(_SAMPLE_USER_NAME);
1339                    ddlRecordVersionModel.setCreateDate(dDLRecordModel.getModifiedDate());
1340                    ddlRecordVersionModel.setDDMStorageId(dDLRecordModel.getDDMStorageId());
1341                    ddlRecordVersionModel.setRecordSetId(dDLRecordModel.getRecordSetId());
1342                    ddlRecordVersionModel.setRecordId(dDLRecordModel.getRecordId());
1343                    ddlRecordVersionModel.setVersion(dDLRecordModel.getVersion());
1344                    ddlRecordVersionModel.setDisplayIndex(dDLRecordModel.getDisplayIndex());
1345                    ddlRecordVersionModel.setStatus(WorkflowConstants.STATUS_APPROVED);
1346                    ddlRecordVersionModel.setStatusDate(dDLRecordModel.getModifiedDate());
1347    
1348                    return ddlRecordVersionModel;
1349            }
1350    
1351            public DDMContentModel newDDMContentModel(
1352                    DDLRecordModel ddlRecordModel, int currentIndex) {
1353    
1354                    StringBundler sb = new StringBundler(3 + _maxDDLCustomFieldCount * 10);
1355    
1356                    sb.append("<?xml version=\"1.0\"?><root>");
1357    
1358                    for (int i = 0; i < _maxDDLCustomFieldCount; i++) {
1359                            sb.append("<dynamic-element default-language-id=\"en_US\" name=\"");
1360                            sb.append(nextDDLCustomFieldName(ddlRecordModel.getGroupId(), i));
1361                            sb.append("\"><dynamic-content language-id=\"en_US\">");
1362                            sb.append("<![CDATA[Test Record ");
1363                            sb.append(currentIndex);
1364                            sb.append("]]></dynamic-content></dynamic-element>");
1365                    }
1366    
1367                    sb.append("<dynamic-element default-language-id=\"en_US\" name=\"_");
1368                    sb.append(
1369                            "fieldsDisplay\"><dynamic-content language-id=\"en_US\"><![CDATA[");
1370    
1371                    for (int i = 0; i < _maxDDLCustomFieldCount; i++) {
1372                            sb.append(nextDDLCustomFieldName(ddlRecordModel.getGroupId(), i));
1373                            sb.append(DDMImpl.INSTANCE_SEPARATOR);
1374                            sb.append(StringUtil.randomId());
1375                            sb.append(StringPool.COMMA);
1376                    }
1377    
1378                    sb.setStringAt(
1379                            "]]></dynamic-content></dynamic-element></root>", sb.index() - 1);
1380    
1381                    return newDDMContentModel(
1382                            ddlRecordModel.getDDMStorageId(), ddlRecordModel.getGroupId(),
1383                            sb.toString());
1384            }
1385    
1386            public DDMContentModel newDDMContentModel(
1387                    DLFileEntryModel dlFileEntryModel) {
1388    
1389                    StringBundler sb = new StringBundler(5);
1390    
1391                    sb.append("<?xml version=\"1.0\"?><root><dynamic-element ");
1392                    sb.append("name=\"CONTENT_TYPE\"><dynamic-content>");
1393                    sb.append("<![CDATA[text/plain]]></dynamic-content></dynamic-element>");
1394                    sb.append("<dynamic-element <![CDATA[ISO-8859-1]]></dynamic-content>");
1395                    sb.append("</dynamic-element></root>");
1396    
1397                    return newDDMContentModel(
1398                            _counter.get(), dlFileEntryModel.getGroupId(), sb.toString());
1399            }
1400    
1401            public DDMStorageLinkModel newDDMStorageLinkModel(
1402                    long ddmStorageLinkId, DDMContentModel ddmContentModel,
1403                    long structureId) {
1404    
1405                    DDMStorageLinkModel ddmStorageLinkModel = new DDMStorageLinkModelImpl();
1406    
1407                    ddmStorageLinkModel.setUuid(SequentialUUID.generate());
1408                    ddmStorageLinkModel.setStorageLinkId(ddmStorageLinkId);
1409                    ddmStorageLinkModel.setClassNameId(
1410                            _classNameModelsMap.get(DDMContent.class.getName()));
1411                    ddmStorageLinkModel.setClassPK(ddmContentModel.getContentId());
1412                    ddmStorageLinkModel.setStructureId(structureId);
1413    
1414                    return ddmStorageLinkModel;
1415            }
1416    
1417            public DDMStructureLinkModel newDDMStructureLinkModel(
1418                    DDLRecordSetModel ddlRecordSetModel) {
1419    
1420                    return newDDMStructureLinkModel(
1421                            _classNameModelsMap.get(DDLRecordSet.class.getName()),
1422                            ddlRecordSetModel.getRecordSetId(),
1423                            ddlRecordSetModel.getDDMStructureId());
1424            }
1425    
1426            public DDMStructureLinkModel newDDMStructureLinkModel(
1427                    DLFileEntryMetadataModel dLFileEntryMetadataModel) {
1428    
1429                    return newDDMStructureLinkModel(
1430                            _classNameModelsMap.get(DLFileEntryMetadata.class.getName()),
1431                            dLFileEntryMetadataModel.getFileEntryMetadataId(),
1432                            dLFileEntryMetadataModel.getDDMStructureId());
1433            }
1434    
1435            public DLFileEntryMetadataModel newDLFileEntryMetadataModel(
1436                    long ddmStorageLinkId, long ddmStructureId,
1437                    DLFileVersionModel dlFileVersionModel) {
1438    
1439                    DLFileEntryMetadataModel dlFileEntryMetadataModel =
1440                            new DLFileEntryMetadataModelImpl();
1441    
1442                    dlFileEntryMetadataModel.setUuid(SequentialUUID.generate());
1443                    dlFileEntryMetadataModel.setFileEntryMetadataId(_counter.get());
1444                    dlFileEntryMetadataModel.setDDMStorageId(ddmStorageLinkId);
1445                    dlFileEntryMetadataModel.setDDMStructureId(ddmStructureId);
1446                    dlFileEntryMetadataModel.setFileEntryTypeId(
1447                            dlFileVersionModel.getFileEntryTypeId());
1448                    dlFileEntryMetadataModel.setFileEntryId(
1449                            dlFileVersionModel.getFileEntryId());
1450                    dlFileEntryMetadataModel.setFileVersionId(
1451                            dlFileVersionModel.getFileVersionId());
1452    
1453                    return dlFileEntryMetadataModel;
1454            }
1455    
1456            public List<DLFileEntryModel> newDlFileEntryModels(
1457                    DLFolderModel dlFolerModel) {
1458    
1459                    List<DLFileEntryModel> dlFileEntryModels =
1460                            new ArrayList<DLFileEntryModel>(_maxDLFileEntryCount);
1461    
1462                    for (int i = 1; i <= _maxDLFileEntryCount; i++) {
1463                            dlFileEntryModels.add(newDlFileEntryModel(dlFolerModel, i));
1464                    }
1465    
1466                    return dlFileEntryModels;
1467            }
1468    
1469            public DLFileVersionModel newDLFileVersionModel(
1470                    DLFileEntryModel dlFileEntryModel) {
1471    
1472                    DLFileVersionModel dlFileVersionModel = new DLFileVersionModelImpl();
1473    
1474                    dlFileVersionModel.setUuid(SequentialUUID.generate());
1475                    dlFileVersionModel.setFileVersionId(_counter.get());
1476                    dlFileVersionModel.setGroupId(dlFileEntryModel.getGroupId());
1477                    dlFileVersionModel.setCompanyId(_companyId);
1478                    dlFileVersionModel.setUserId(_sampleUserId);
1479                    dlFileVersionModel.setUserName(_SAMPLE_USER_NAME);
1480                    dlFileVersionModel.setCreateDate(nextFutureDate());
1481                    dlFileVersionModel.setModifiedDate(nextFutureDate());
1482                    dlFileVersionModel.setRepositoryId(dlFileEntryModel.getRepositoryId());
1483                    dlFileVersionModel.setFolderId(dlFileEntryModel.getFolderId());
1484                    dlFileVersionModel.setFileEntryId(dlFileEntryModel.getFileEntryId());
1485                    dlFileVersionModel.setFileName(dlFileEntryModel.getFileName());
1486                    dlFileVersionModel.setExtension(dlFileEntryModel.getExtension());
1487                    dlFileVersionModel.setMimeType(dlFileEntryModel.getMimeType());
1488                    dlFileVersionModel.setTitle(dlFileEntryModel.getTitle());
1489                    dlFileVersionModel.setFileEntryTypeId(
1490                            dlFileEntryModel.getFileEntryTypeId());
1491                    dlFileVersionModel.setVersion(dlFileEntryModel.getVersion());
1492                    dlFileVersionModel.setSize(dlFileEntryModel.getSize());
1493    
1494                    return dlFileVersionModel;
1495            }
1496    
1497            public List<DLFolderModel> newDLFolderModels(
1498                    long groupId, long parentFolderId) {
1499    
1500                    List<DLFolderModel> dlFolderModels = new ArrayList<DLFolderModel>(
1501                            _maxDLFolderCount);
1502    
1503                    for (int i = 1; i <= _maxDLFolderCount; i++) {
1504                            dlFolderModels.add(newDLFolderModel(groupId, parentFolderId, i));
1505                    }
1506    
1507                    return dlFolderModels;
1508            }
1509    
1510            public GroupModel newGroupModel(UserModel userModel) throws Exception {
1511                    return newGroupModel(
1512                            _counter.get(), _classNameModelsMap.get(User.class.getName()),
1513                            userModel.getUserId(), userModel.getScreenName(), false);
1514            }
1515    
1516            public IntegerWrapper newInteger() {
1517                    return new IntegerWrapper();
1518            }
1519    
1520            public JournalArticleModel newJournalArticleModel(
1521                    JournalArticleResourceModel journalArticleResourceModel,
1522                    int articleIndex, int versionIndex) {
1523    
1524                    JournalArticleModel journalArticleModel = new JournalArticleModelImpl();
1525    
1526                    journalArticleModel.setUuid(SequentialUUID.generate());
1527                    journalArticleModel.setId(_counter.get());
1528                    journalArticleModel.setResourcePrimKey(
1529                            journalArticleResourceModel.getResourcePrimKey());
1530                    journalArticleModel.setGroupId(
1531                            journalArticleResourceModel.getGroupId());
1532                    journalArticleModel.setCompanyId(_companyId);
1533                    journalArticleModel.setUserId(_sampleUserId);
1534                    journalArticleModel.setUserName(_SAMPLE_USER_NAME);
1535                    journalArticleModel.setCreateDate(new Date());
1536                    journalArticleModel.setModifiedDate(new Date());
1537                    journalArticleModel.setClassNameId(
1538                            JournalArticleConstants.CLASSNAME_ID_DEFAULT);
1539                    journalArticleModel.setArticleId(
1540                            journalArticleResourceModel.getArticleId());
1541                    journalArticleModel.setVersion(versionIndex);
1542    
1543                    StringBundler sb = new StringBundler(4);
1544    
1545                    sb.append("TestJournalArticle_");
1546                    sb.append(articleIndex);
1547                    sb.append(StringPool.UNDERLINE);
1548                    sb.append(versionIndex);
1549    
1550                    String urlTitle = sb.toString();
1551    
1552                    sb = new StringBundler(5);
1553    
1554                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
1555                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
1556                    sb.append("<Title language-id=\"en_US\">");
1557                    sb.append(urlTitle);
1558                    sb.append("</Title></root>");
1559    
1560                    String title = sb.toString();
1561    
1562                    journalArticleModel.setTitle(title);
1563                    journalArticleModel.setUrlTitle(urlTitle);
1564    
1565                    journalArticleModel.setContent(_journalArticleContent);
1566                    journalArticleModel.setDDMStructureKey(
1567                            _defaultJournalDDMStructureModel.getStructureKey());
1568                    journalArticleModel.setDDMTemplateKey(
1569                            _defaultJournalDDMTemplateModel.getTemplateKey());
1570                    journalArticleModel.setDisplayDate(new Date());
1571                    journalArticleModel.setExpirationDate(nextFutureDate());
1572                    journalArticleModel.setReviewDate(new Date());
1573                    journalArticleModel.setIndexable(true);
1574                    journalArticleModel.setStatusDate(new Date());
1575    
1576                    return journalArticleModel;
1577            }
1578    
1579            public JournalArticleResourceModel newJournalArticleResourceModel(
1580                    long groupId) {
1581    
1582                    JournalArticleResourceModel journalArticleResourceModel =
1583                            new JournalArticleResourceModelImpl();
1584    
1585                    journalArticleResourceModel.setUuid(SequentialUUID.generate());
1586                    journalArticleResourceModel.setResourcePrimKey(_counter.get());
1587                    journalArticleResourceModel.setGroupId(groupId);
1588                    journalArticleResourceModel.setArticleId(
1589                            String.valueOf(_counter.get()));
1590    
1591                    _journalArticleResourceUUIDs.put(
1592                            journalArticleResourceModel.getPrimaryKey(),
1593                            journalArticleResourceModel.getUuid());
1594    
1595                    return journalArticleResourceModel;
1596            }
1597    
1598            public JournalContentSearchModel newJournalContentSearchModel(
1599                    JournalArticleModel journalArticleModel, long layoutId) {
1600    
1601                    JournalContentSearchModel journalContentSearchModel =
1602                            new JournalContentSearchModelImpl();
1603    
1604                    journalContentSearchModel.setContentSearchId(_counter.get());
1605                    journalContentSearchModel.setGroupId(journalArticleModel.getGroupId());
1606                    journalContentSearchModel.setCompanyId(_companyId);
1607                    journalContentSearchModel.setLayoutId(layoutId);
1608                    journalContentSearchModel.setPortletId(
1609                            "com_liferay_journal_content_web_portlet_JournalContentPortlet");
1610                    journalContentSearchModel.setArticleId(
1611                            journalArticleModel.getArticleId());
1612    
1613                    return journalContentSearchModel;
1614            }
1615    
1616            public List<PortletPreferencesModel>
1617                    newJournalPortletPreferencesModels(long plid) {
1618    
1619                    List<PortletPreferencesModel> portletPreferencesModels =
1620                            new ArrayList<PortletPreferencesModel>(2);
1621    
1622                    portletPreferencesModels.add(
1623                            newPortletPreferencesModel(
1624                                    plid, PortletKeys.DOCKBAR,
1625                                    PortletConstants.DEFAULT_PREFERENCES));
1626                    portletPreferencesModels.add(
1627                            newPortletPreferencesModel(
1628                                    plid, PortletKeys.JOURNAL,
1629                                    PortletConstants.DEFAULT_PREFERENCES));
1630    
1631                    return portletPreferencesModels;
1632            }
1633    
1634            public LayoutFriendlyURLModel newLayoutFriendlyURLModel(
1635                    LayoutModel layoutModel) {
1636    
1637                    LayoutFriendlyURLModel layoutFriendlyURLModel =
1638                            new LayoutFriendlyURLModelImpl();
1639    
1640                    layoutFriendlyURLModel.setUuid(SequentialUUID.generate());
1641                    layoutFriendlyURLModel.setLayoutFriendlyURLId(_counter.get());
1642                    layoutFriendlyURLModel.setGroupId(layoutModel.getGroupId());
1643                    layoutFriendlyURLModel.setCompanyId(_companyId);
1644                    layoutFriendlyURLModel.setUserId(_sampleUserId);
1645                    layoutFriendlyURLModel.setUserName(_SAMPLE_USER_NAME);
1646                    layoutFriendlyURLModel.setCreateDate(new Date());
1647                    layoutFriendlyURLModel.setModifiedDate(new Date());
1648                    layoutFriendlyURLModel.setPlid(layoutModel.getPlid());
1649                    layoutFriendlyURLModel.setFriendlyURL(layoutModel.getFriendlyURL());
1650                    layoutFriendlyURLModel.setLanguageId("en_US");
1651    
1652                    return layoutFriendlyURLModel;
1653            }
1654    
1655            public LayoutModel newLayoutModel(
1656                    long groupId, String name, String column1, String column2) {
1657    
1658                    SimpleCounter simpleCounter = _layoutCounters.get(groupId);
1659    
1660                    if (simpleCounter == null) {
1661                            simpleCounter = new SimpleCounter();
1662    
1663                            _layoutCounters.put(groupId, simpleCounter);
1664                    }
1665    
1666                    LayoutModel layoutModel = new LayoutModelImpl();
1667    
1668                    layoutModel.setUuid(SequentialUUID.generate());
1669                    layoutModel.setPlid(_counter.get());
1670                    layoutModel.setGroupId(groupId);
1671                    layoutModel.setCompanyId(_companyId);
1672                    layoutModel.setUserId(_sampleUserId);
1673                    layoutModel.setUserName(_SAMPLE_USER_NAME);
1674                    layoutModel.setCreateDate(new Date());
1675                    layoutModel.setModifiedDate(new Date());
1676                    layoutModel.setLayoutId(simpleCounter.get());
1677                    layoutModel.setName(
1678                            "<?xml version=\"1.0\"?><root><name>" + name + "</name></root>");
1679                    layoutModel.setType(LayoutConstants.TYPE_PORTLET);
1680                    layoutModel.setFriendlyURL(StringPool.FORWARD_SLASH + name);
1681    
1682                    UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);
1683    
1684                    typeSettingsProperties.setProperty(
1685                            LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, "2_columns_ii");
1686                    typeSettingsProperties.setProperty("column-1", column1);
1687                    typeSettingsProperties.setProperty("column-2", column2);
1688    
1689                    String typeSettings = StringUtil.replace(
1690                            typeSettingsProperties.toString(), "\n", "\\n");
1691    
1692                    layoutModel.setTypeSettings(typeSettings);
1693    
1694                    return layoutModel;
1695            }
1696    
1697            public List<LayoutSetModel> newLayoutSetModels(
1698                    long groupId, int publicLayoutSetPageCount) {
1699    
1700                    List<LayoutSetModel> layoutSetModels = new ArrayList<LayoutSetModel>(2);
1701    
1702                    layoutSetModels.add(newLayoutSetModel(groupId, true, 0));
1703                    layoutSetModels.add(
1704                            newLayoutSetModel(groupId, false, publicLayoutSetPageCount));
1705    
1706                    return layoutSetModels;
1707            }
1708    
1709            public List<MBCategoryModel> newMBCategoryModels(long groupId) {
1710                    List<MBCategoryModel> mbCategoryModels = new ArrayList<MBCategoryModel>(
1711                            _maxMBCategoryCount);
1712    
1713                    for (int i = 1; i <= _maxMBCategoryCount; i++) {
1714                            mbCategoryModels.add(newMBCategoryModel(groupId, i));
1715                    }
1716    
1717                    return mbCategoryModels;
1718            }
1719    
1720            public MBDiscussionModel newMBDiscussionModel(
1721                    long groupId, long classNameId, long classPK, long threadId) {
1722    
1723                    MBDiscussionModel mbDiscussionModel = new MBDiscussionModelImpl();
1724    
1725                    mbDiscussionModel.setUuid(SequentialUUID.generate());
1726                    mbDiscussionModel.setDiscussionId(_counter.get());
1727                    mbDiscussionModel.setGroupId(groupId);
1728                    mbDiscussionModel.setCompanyId(_companyId);
1729                    mbDiscussionModel.setUserId(_sampleUserId);
1730                    mbDiscussionModel.setUserName(_SAMPLE_USER_NAME);
1731                    mbDiscussionModel.setCreateDate(new Date());
1732                    mbDiscussionModel.setModifiedDate(new Date());
1733                    mbDiscussionModel.setClassNameId(classNameId);
1734                    mbDiscussionModel.setClassPK(classPK);
1735                    mbDiscussionModel.setThreadId(threadId);
1736    
1737                    return mbDiscussionModel;
1738            }
1739    
1740            public MBMailingListModel newMBMailingListModel(
1741                    MBCategoryModel mbCategoryModel) {
1742    
1743                    MBMailingListModel mbMailingListModel = new MBMailingListModelImpl();
1744    
1745                    mbMailingListModel.setUuid(SequentialUUID.generate());
1746                    mbMailingListModel.setMailingListId(_counter.get());
1747                    mbMailingListModel.setGroupId(mbCategoryModel.getGroupId());
1748                    mbMailingListModel.setCompanyId(_companyId);
1749                    mbMailingListModel.setUserId(_sampleUserId);
1750                    mbMailingListModel.setUserName(_SAMPLE_USER_NAME);
1751                    mbMailingListModel.setCreateDate(new Date());
1752                    mbMailingListModel.setModifiedDate(new Date());
1753                    mbMailingListModel.setCategoryId(mbCategoryModel.getCategoryId());
1754                    mbMailingListModel.setInProtocol("pop3");
1755                    mbMailingListModel.setInServerPort(110);
1756                    mbMailingListModel.setInUserName(_sampleUserModel.getEmailAddress());
1757                    mbMailingListModel.setInPassword(_sampleUserModel.getPassword());
1758                    mbMailingListModel.setInReadInterval(5);
1759                    mbMailingListModel.setOutServerPort(25);
1760    
1761                    return mbMailingListModel;
1762            }
1763    
1764            public MBMessageModel newMBMessageModel(
1765                    MBThreadModel mbThreadModel, long classNameId, long classPK,
1766                    int index) {
1767    
1768                    long messageId = 0;
1769                    long parentMessageId = 0;
1770                    String subject = null;
1771                    String body = null;
1772    
1773                    if (index == 0) {
1774                            messageId = mbThreadModel.getRootMessageId();
1775                            parentMessageId = MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID;
1776                            subject = String.valueOf(classPK);
1777                            body = String.valueOf(classPK);
1778                    }
1779                    else {
1780                            messageId = _counter.get();
1781                            parentMessageId = mbThreadModel.getRootMessageId();
1782                            subject = "N/A";
1783                            body = "This is test comment " + index + ".";
1784                    }
1785    
1786                    return newMBMessageModel(
1787                            mbThreadModel.getGroupId(), classNameId, classPK,
1788                            MBCategoryConstants.DISCUSSION_CATEGORY_ID,
1789                            mbThreadModel.getThreadId(), messageId,
1790                            mbThreadModel.getRootMessageId(), parentMessageId, subject, body);
1791            }
1792    
1793            public List<MBMessageModel> newMBMessageModels(
1794                    MBThreadModel mbThreadModel) {
1795    
1796                    List<MBMessageModel> mbMessageModels = new ArrayList<MBMessageModel>(
1797                            _maxMBMessageCount);
1798    
1799                    mbMessageModels.add(
1800                            newMBMessageModel(
1801                                    mbThreadModel.getGroupId(), 0, 0, mbThreadModel.getCategoryId(),
1802                                    mbThreadModel.getThreadId(), mbThreadModel.getRootMessageId(),
1803                                    mbThreadModel.getRootMessageId(),
1804                                    MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID, "Test Message 1",
1805                                    "This is test message 1."));
1806    
1807                    for (int i = 2; i <= _maxMBMessageCount; i++) {
1808                            mbMessageModels.add(
1809                                    newMBMessageModel(
1810                                            mbThreadModel.getGroupId(), 0, 0,
1811                                            mbThreadModel.getCategoryId(), mbThreadModel.getThreadId(),
1812                                            _counter.get(), mbThreadModel.getRootMessageId(),
1813                                            mbThreadModel.getRootMessageId(), "Test Message " + i,
1814                                            "This is test message " + i + "."));
1815                    }
1816    
1817                    return mbMessageModels;
1818            }
1819    
1820            public List<MBMessageModel> newMBMessageModels(
1821                    MBThreadModel mbThreadModel, long classNameId, long classPK,
1822                    int maxMessageCount) {
1823    
1824                    List<MBMessageModel> mbMessageModels = new ArrayList<MBMessageModel>(
1825                            maxMessageCount);
1826    
1827                    for (int i = 1; i <= maxMessageCount; i++) {
1828                            mbMessageModels.add(
1829                                    newMBMessageModel(mbThreadModel, classNameId, classPK, i));
1830                    }
1831    
1832                    return mbMessageModels;
1833            }
1834    
1835            public MBStatsUserModel newMBStatsUserModel(long groupId) {
1836                    MBStatsUserModel mbStatsUserModel = new MBStatsUserModelImpl();
1837    
1838                    mbStatsUserModel.setStatsUserId(_counter.get());
1839                    mbStatsUserModel.setGroupId(groupId);
1840                    mbStatsUserModel.setUserId(_sampleUserId);
1841                    mbStatsUserModel.setMessageCount(
1842                            _maxMBCategoryCount * _maxMBThreadCount * _maxMBMessageCount);
1843                    mbStatsUserModel.setLastPostDate(new Date());
1844    
1845                    return mbStatsUserModel;
1846            }
1847    
1848            public MBThreadFlagModel newMBThreadFlagModel(MBThreadModel mbThreadModel) {
1849                    MBThreadFlagModel mbThreadFlagModel = new MBThreadFlagModelImpl();
1850    
1851                    mbThreadFlagModel.setUuid(SequentialUUID.generate());
1852                    mbThreadFlagModel.setThreadFlagId(_counter.get());
1853                    mbThreadFlagModel.setGroupId(mbThreadModel.getGroupId());
1854                    mbThreadFlagModel.setCompanyId(_companyId);
1855                    mbThreadFlagModel.setUserId(_sampleUserId);
1856                    mbThreadFlagModel.setUserName(_SAMPLE_USER_NAME);
1857                    mbThreadFlagModel.setCreateDate(new Date());
1858                    mbThreadFlagModel.setModifiedDate(new Date());
1859                    mbThreadFlagModel.setThreadId(mbThreadModel.getThreadId());
1860    
1861                    return mbThreadFlagModel;
1862            }
1863    
1864            public MBThreadModel newMBThreadModel(
1865                    long threadId, long groupId, long rootMessageId, int messageCount) {
1866    
1867                    if (messageCount == 0) {
1868                            messageCount = 1;
1869                    }
1870    
1871                    return newMBThreadModel(
1872                            threadId, groupId, MBCategoryConstants.DISCUSSION_CATEGORY_ID,
1873                            rootMessageId, messageCount);
1874            }
1875    
1876            public List<MBThreadModel> newMBThreadModels(
1877                    MBCategoryModel mbCategoryModel) {
1878    
1879                    List<MBThreadModel> mbThreadModels = new ArrayList<MBThreadModel>(
1880                            _maxMBThreadCount);
1881    
1882                    for (int i = 0; i < _maxMBThreadCount; i++) {
1883                            mbThreadModels.add(
1884                                    newMBThreadModel(
1885                                            _counter.get(), mbCategoryModel.getGroupId(),
1886                                            mbCategoryModel.getCategoryId(), _counter.get(),
1887                                            _maxMBMessageCount));
1888                    }
1889    
1890                    return mbThreadModels;
1891            }
1892    
1893            public PortletPreferencesModel newPortletPreferencesModel(
1894                            long plid, long groupId, String portletId, int currentIndex)
1895                    throws Exception {
1896    
1897                    if (currentIndex == 1) {
1898                            return newPortletPreferencesModel(
1899                                    plid, portletId, PortletConstants.DEFAULT_PREFERENCES);
1900                    }
1901    
1902                    SimpleCounter counter = _assetPublisherQueryCounter.get(groupId);
1903    
1904                    if (counter == null) {
1905                            counter = new SimpleCounter(0);
1906    
1907                            _assetPublisherQueryCounter.put(groupId, counter);
1908                    }
1909    
1910                    String[] assetPublisherQueryValues = null;
1911    
1912                    if (_assetPublisherQueryName.equals("assetCategories")) {
1913                            List<AssetCategoryModel> assetCategoryModels =
1914                                    _assetCategoryModelsArray[(int)groupId - 1];
1915    
1916                            if ((assetCategoryModels == null) ||
1917                                    assetCategoryModels.isEmpty()) {
1918    
1919                                    return newPortletPreferencesModel(
1920                                            plid, portletId, PortletConstants.DEFAULT_PREFERENCES);
1921                            }
1922    
1923                            assetPublisherQueryValues =
1924                                    getAssetPublisherAssetCategoriesQueryValues(
1925                                            assetCategoryModels, (int)counter.get());
1926                    }
1927                    else {
1928                            List<AssetTagModel> assetTagModels =
1929                                    _assetTagModelsArray[(int)groupId - 1];
1930    
1931                            if ((assetTagModels == null) || assetTagModels.isEmpty()) {
1932                                    return newPortletPreferencesModel(
1933                                            plid, portletId, PortletConstants.DEFAULT_PREFERENCES);
1934                            }
1935    
1936                            assetPublisherQueryValues = getAssetPublisherAssetTagsQueryValues(
1937                                    assetTagModels, (int)counter.get());
1938                    }
1939    
1940                    PortletPreferences jxPortletPreferences =
1941                            (PortletPreferences)_defaultAssetPublisherPortletPreference.clone();
1942    
1943                    jxPortletPreferences.setValue("queryAndOperator0", "false");
1944                    jxPortletPreferences.setValue("queryContains0", "true");
1945                    jxPortletPreferences.setValue("queryName0", _assetPublisherQueryName);
1946                    jxPortletPreferences.setValues(
1947                            "queryValues0",
1948                            new String[] {
1949                                    assetPublisherQueryValues[0], assetPublisherQueryValues[1],
1950                                    assetPublisherQueryValues[2]
1951                            });
1952                    jxPortletPreferences.setValue("queryAndOperator1", "false");
1953                    jxPortletPreferences.setValue("queryContains1", "false");
1954                    jxPortletPreferences.setValue("queryName1", _assetPublisherQueryName);
1955                    jxPortletPreferences.setValue(
1956                            "queryValues1", assetPublisherQueryValues[3]);
1957    
1958                    return newPortletPreferencesModel(
1959                            plid, portletId,
1960                            _portletPreferencesFactory.toXML(jxPortletPreferences));
1961            }
1962    
1963            public PortletPreferencesModel newPortletPreferencesModel(
1964                            long plid, String portletId, DDLRecordSetModel ddlRecordSetModel)
1965                    throws Exception {
1966    
1967                    PortletPreferences jxPortletPreferences = new PortletPreferencesImpl();
1968    
1969                    jxPortletPreferences.setValue("editable", "true");
1970                    jxPortletPreferences.setValue(
1971                            "recordSetId", String.valueOf(ddlRecordSetModel.getRecordSetId()));
1972                    jxPortletPreferences.setValue("spreadsheet", "false");
1973    
1974                    return newPortletPreferencesModel(
1975                            plid, portletId,
1976                            _portletPreferencesFactory.toXML(jxPortletPreferences));
1977            }
1978    
1979            public PortletPreferencesModel newPortletPreferencesModel(
1980                            long plid, String portletId,
1981                            JournalArticleResourceModel journalArticleResourceModel)
1982                    throws Exception {
1983    
1984                    PortletPreferences jxPortletPreferences = new PortletPreferencesImpl();
1985    
1986                    jxPortletPreferences.setValue(
1987                            "articleId", journalArticleResourceModel.getArticleId());
1988                    jxPortletPreferences.setValue(
1989                            "groupId",
1990                            String.valueOf(journalArticleResourceModel.getGroupId()));
1991    
1992                    return newPortletPreferencesModel(
1993                            plid, portletId,
1994                            _portletPreferencesFactory.toXML(jxPortletPreferences));
1995            }
1996    
1997            public List<LayoutModel> newPublicLayoutModels(long groupId) {
1998                    List<LayoutModel> layoutModels = new ArrayList<LayoutModel>();
1999    
2000                    layoutModels.add(newLayoutModel(groupId, "welcome", "58,", "47,"));
2001                    layoutModels.add(newLayoutModel(groupId, "blogs", "", "33,"));
2002                    layoutModels.add(
2003                            newLayoutModel(groupId, "document_library", "", "20,"));
2004                    layoutModels.add(newLayoutModel(groupId, "forums", "", "19,"));
2005                    layoutModels.add(newLayoutModel(groupId, "wiki", "", "36,"));
2006    
2007                    return layoutModels;
2008            }
2009    
2010            public List<ResourcePermissionModel> newResourcePermissionModels(
2011                    AssetCategoryModel assetCategoryModel) {
2012    
2013                    return newResourcePermissionModels(
2014                            AssetCategory.class.getName(),
2015                            String.valueOf(assetCategoryModel.getCategoryId()), _sampleUserId);
2016            }
2017    
2018            public List<ResourcePermissionModel> newResourcePermissionModels(
2019                    AssetTagModel assetTagModel) {
2020    
2021                    return newResourcePermissionModels(
2022                            AssetTag.class.getName(), String.valueOf(assetTagModel.getTagId()),
2023                            _sampleUserId);
2024            }
2025    
2026            public List<ResourcePermissionModel> newResourcePermissionModels(
2027                    AssetVocabularyModel assetVocabularyModel) {
2028    
2029                    if (assetVocabularyModel.getUserId() == _defaultUserId) {
2030                            List<ResourcePermissionModel> resourcePermissionModels =
2031                                    new ArrayList<ResourcePermissionModel>(1);
2032    
2033                            resourcePermissionModels.add(
2034                                    newResourcePermissionModel(
2035                                            AssetVocabulary.class.getName(),
2036                                            String.valueOf(assetVocabularyModel.getVocabularyId()),
2037                                            _ownerRoleModel.getRoleId(), _defaultUserId));
2038    
2039                            return resourcePermissionModels;
2040                    }
2041    
2042                    return newResourcePermissionModels(
2043                            AssetVocabulary.class.getName(),
2044                            String.valueOf(assetVocabularyModel.getVocabularyId()),
2045                            _sampleUserId);
2046            }
2047    
2048            public List<ResourcePermissionModel> newResourcePermissionModels(
2049                    BlogsEntryModel blogsEntryModel) {
2050    
2051                    return newResourcePermissionModels(
2052                            BlogsEntry.class.getName(),
2053                            String.valueOf(blogsEntryModel.getEntryId()), _sampleUserId);
2054            }
2055    
2056            public List<ResourcePermissionModel> newResourcePermissionModels(
2057                    DDLRecordSetModel ddlRecordSetModel) {
2058    
2059                    List<ResourcePermissionModel> resourcePermissionModels =
2060                            new ArrayList<ResourcePermissionModel>(1);
2061    
2062                    resourcePermissionModels.add(
2063                            newResourcePermissionModel(
2064                                    DDLRecordSet.class.getName(),
2065                                    String.valueOf(ddlRecordSetModel.getRecordSetId()),
2066                                    _ownerRoleModel.getRoleId(), _defaultUserId));
2067    
2068                    return resourcePermissionModels;
2069            }
2070    
2071            public List<ResourcePermissionModel> newResourcePermissionModels(
2072                    DDMStructureModel ddmStructureModel) {
2073    
2074                    List<ResourcePermissionModel> resourcePermissionModels =
2075                            new ArrayList<ResourcePermissionModel>(1);
2076    
2077                    resourcePermissionModels.add(
2078                            newResourcePermissionModel(
2079                                    DDMStructure.class.getName(),
2080                                    String.valueOf(ddmStructureModel.getStructureId()),
2081                                    _ownerRoleModel.getRoleId(), _defaultUserId));
2082    
2083                    return resourcePermissionModels;
2084            }
2085    
2086            public List<ResourcePermissionModel> newResourcePermissionModels(
2087                    DLFileEntryModel dlFileEntryModel) {
2088    
2089                    return newResourcePermissionModels(
2090                            DLFileEntry.class.getName(),
2091                            String.valueOf(dlFileEntryModel.getFileEntryId()), _sampleUserId);
2092            }
2093    
2094            public List<ResourcePermissionModel> newResourcePermissionModels(
2095                    DLFolderModel dlFolderModel) {
2096    
2097                    return newResourcePermissionModels(
2098                            DLFolder.class.getName(),
2099                            String.valueOf(dlFolderModel.getFolderId()), _sampleUserId);
2100            }
2101    
2102            public List<ResourcePermissionModel> newResourcePermissionModels(
2103                    JournalArticleResourceModel journalArticleResourceModel) {
2104    
2105                    return newResourcePermissionModels(
2106                            JournalArticle.class.getName(),
2107                            String.valueOf(journalArticleResourceModel.getResourcePrimKey()),
2108                            _sampleUserId);
2109            }
2110    
2111            public List<ResourcePermissionModel> newResourcePermissionModels(
2112                    LayoutModel layoutModel) {
2113    
2114                    return newResourcePermissionModels(
2115                            Layout.class.getName(), String.valueOf(layoutModel.getPlid()),
2116                            _sampleUserId);
2117            }
2118    
2119            public List<ResourcePermissionModel> newResourcePermissionModels(
2120                    MBCategoryModel mbCategoryModel) {
2121    
2122                    return newResourcePermissionModels(
2123                            MBCategory.class.getName(),
2124                            String.valueOf(mbCategoryModel.getCategoryId()), _sampleUserId);
2125            }
2126    
2127            public List<ResourcePermissionModel> newResourcePermissionModels(
2128                    MBMessageModel mbMessageModel) {
2129    
2130                    return newResourcePermissionModels(
2131                            MBMessage.class.getName(),
2132                            String.valueOf(mbMessageModel.getMessageId()), _sampleUserId);
2133            }
2134    
2135            public List<ResourcePermissionModel> newResourcePermissionModels(
2136                    PortletPreferencesModel portletPreferencesModel) {
2137    
2138                    String portletId = portletPreferencesModel.getPortletId();
2139    
2140                    String name = portletId;
2141    
2142                    int index = portletId.indexOf(StringPool.UNDERLINE);
2143    
2144                    if (index > 0) {
2145                            name = portletId.substring(0, index);
2146                    }
2147    
2148                    String primKey = PortletPermissionUtil.getPrimaryKey(
2149                            portletPreferencesModel.getPlid(), portletId);
2150    
2151                    return newResourcePermissionModels(name, primKey, 0);
2152            }
2153    
2154            public List<ResourcePermissionModel> newResourcePermissionModels(
2155                    String name, long primKey) {
2156    
2157                    return newResourcePermissionModels(
2158                            name, String.valueOf(primKey), _sampleUserId);
2159            }
2160    
2161            public List<ResourcePermissionModel> newResourcePermissionModels(
2162                    WikiNodeModel wikiNodeModel) {
2163    
2164                    return newResourcePermissionModels(
2165                            WikiNode.class.getName(), String.valueOf(wikiNodeModel.getNodeId()),
2166                            _sampleUserId);
2167            }
2168    
2169            public List<ResourcePermissionModel> newResourcePermissionModels(
2170                    WikiPageModel wikiPageModel) {
2171    
2172                    return newResourcePermissionModels(
2173                            WikiPage.class.getName(),
2174                            String.valueOf(wikiPageModel.getResourcePrimKey()), _sampleUserId);
2175            }
2176    
2177            public SocialActivityModel newSocialActivityModel(
2178                    BlogsEntryModel blogsEntryModel) {
2179    
2180                    return newSocialActivityModel(
2181                            blogsEntryModel.getGroupId(),
2182                            _classNameModelsMap.get(BlogsEntry.class.getName()),
2183                            blogsEntryModel.getEntryId(), BlogsActivityKeys.ADD_ENTRY,
2184                            "{\"title\":\""+ blogsEntryModel.getTitle() +"\"}");
2185            }
2186    
2187            public SocialActivityModel newSocialActivityModel(
2188                    DLFileEntryModel dlFileEntryModel) {
2189    
2190                    return newSocialActivityModel(
2191                            dlFileEntryModel.getGroupId(), getDLFileEntryClassNameId(),
2192                            dlFileEntryModel.getFileEntryId(), DLActivityKeys.ADD_FILE_ENTRY,
2193                            StringPool.BLANK);
2194            }
2195    
2196            public SocialActivityModel newSocialActivityModel(
2197                    JournalArticleModel journalArticleModel) {
2198    
2199                    int type = JournalActivityKeys.UPDATE_ARTICLE;
2200    
2201                    if (journalArticleModel.getVersion() ==
2202                                    JournalArticleConstants.VERSION_DEFAULT) {
2203    
2204                            type = JournalActivityKeys.ADD_ARTICLE;
2205                    }
2206    
2207                    return newSocialActivityModel(
2208                            journalArticleModel.getGroupId(), getJournalArticleClassNameId(),
2209                            journalArticleModel.getResourcePrimKey(), type,
2210                            "{\"title\":\""+ journalArticleModel.getUrlTitle() +"\"}");
2211            }
2212    
2213            public SocialActivityModel newSocialActivityModel(
2214                    MBMessageModel mbMessageModel) {
2215    
2216                    long classNameId = mbMessageModel.getClassNameId();
2217                    long classPK = mbMessageModel.getClassPK();
2218    
2219                    int type = 0;
2220                    String extraData = null;
2221    
2222                    if (classNameId == _classNameModelsMap.get(WikiPage.class.getName())) {
2223                            extraData = "{\"version\":1}";
2224    
2225                            type = WikiActivityKeys.ADD_PAGE;
2226                    }
2227                    else if (classNameId == 0) {
2228                            extraData = "{\"title\":\"" + mbMessageModel.getSubject() + "\"}";
2229    
2230                            type = MBActivityKeys.ADD_MESSAGE;
2231    
2232                            classNameId = _classNameModelsMap.get(MBMessage.class.getName());
2233                            classPK = mbMessageModel.getMessageId();
2234                    }
2235                    else {
2236                            StringBundler sb = new StringBundler(5);
2237    
2238                            sb.append("{\"messageId\":\"");
2239                            sb.append(mbMessageModel.getMessageId());
2240                            sb.append("\", \"title\":");
2241                            sb.append(mbMessageModel.getSubject());
2242                            sb.append("}");
2243    
2244                            extraData = sb.toString();
2245    
2246                            type = SocialActivityConstants.TYPE_ADD_COMMENT;
2247                    }
2248    
2249                    return newSocialActivityModel(
2250                            mbMessageModel.getGroupId(), classNameId, classPK, type, extraData);
2251            }
2252    
2253            public SubscriptionModel newSubscriptionModel(
2254                    BlogsEntryModel blogsEntryModel) {
2255    
2256                    return newSubscriptionModel(
2257                            _classNameModelsMap.get(BlogsEntry.class.getName()),
2258                            blogsEntryModel.getEntryId());
2259            }
2260    
2261            public SubscriptionModel newSubscriptionModel(MBThreadModel mBThreadModel) {
2262                    return newSubscriptionModel(
2263                            _classNameModelsMap.get(MBThread.class.getName()),
2264                            mBThreadModel.getThreadId());
2265            }
2266    
2267            public SubscriptionModel newSubscriptionModel(WikiPageModel wikiPageModel) {
2268                    return newSubscriptionModel(
2269                            _classNameModelsMap.get(WikiPage.class.getName()),
2270                            wikiPageModel.getResourcePrimKey());
2271            }
2272    
2273            public List<UserModel> newUserModels() {
2274                    List<UserModel> userModels = new ArrayList<UserModel>(_maxUserCount);
2275    
2276                    for (int i = 0; i < _maxUserCount; i++) {
2277                            String[] userName = nextUserName(i);
2278                            userModels.add(
2279                                    newUserModel(
2280                                            _counter.get(), userName[0], userName[1],
2281                                            "test" + _userScreenNameCounter.get(), false));
2282                    }
2283    
2284                    return userModels;
2285            }
2286    
2287            public List<WikiNodeModel> newWikiNodeModels(long groupId) {
2288                    List<WikiNodeModel> wikiNodeModels = new ArrayList<WikiNodeModel>(
2289                            _maxWikiNodeCount);
2290    
2291                    for (int i = 1; i <= _maxWikiNodeCount; i++) {
2292                            wikiNodeModels.add(newWikiNodeModel(groupId, i));
2293                    }
2294    
2295                    return wikiNodeModels;
2296            }
2297    
2298            public List<WikiPageModel> newWikiPageModels(WikiNodeModel wikiNodeModel) {
2299                    List<WikiPageModel> wikiPageModels = new ArrayList<WikiPageModel>(
2300                            _maxWikiPageCount);
2301    
2302                    for (int i = 1; i <= _maxWikiPageCount; i++) {
2303                            wikiPageModels.add(newWikiPageModel(wikiNodeModel, i));
2304                    }
2305    
2306                    return wikiPageModels;
2307            }
2308    
2309            public WikiPageResourceModel newWikiPageResourceModel(
2310                    WikiPageModel wikiPageModel) {
2311    
2312                    WikiPageResourceModel wikiPageResourceModel =
2313                            new WikiPageResourceModelImpl();
2314    
2315                    wikiPageResourceModel.setUuid(SequentialUUID.generate());
2316                    wikiPageResourceModel.setResourcePrimKey(
2317                            wikiPageModel.getResourcePrimKey());
2318                    wikiPageResourceModel.setNodeId(wikiPageModel.getNodeId());
2319                    wikiPageResourceModel.setTitle(wikiPageModel.getTitle());
2320    
2321                    return wikiPageResourceModel;
2322            }
2323    
2324            public String[] nextUserName(long index) {
2325                    String[] userName = new String[2];
2326    
2327                    userName[0] = _firstNames.get(
2328                            (int)(index / _lastNames.size()) % _firstNames.size());
2329                    userName[1] = _lastNames.get((int)(index % _lastNames.size()));
2330    
2331                    return userName;
2332            }
2333    
2334            protected String[] getAssetPublisherAssetCategoriesQueryValues(
2335                    List<AssetCategoryModel> assetCategoryModels, int index) {
2336    
2337                    AssetCategoryModel assetCategoryModel0 = assetCategoryModels.get(
2338                            index % assetCategoryModels.size());
2339                    AssetCategoryModel assetCategoryModel1 = assetCategoryModels.get(
2340                            (index + _maxAssetEntryToAssetCategoryCount) %
2341                                    assetCategoryModels.size());
2342                    AssetCategoryModel assetCategoryModel2 = assetCategoryModels.get(
2343                            (index + _maxAssetEntryToAssetCategoryCount * 2) %
2344                                    assetCategoryModels.size());
2345                    AssetCategoryModel assetCategoryModel3 = assetCategoryModels.get(
2346                            (index + _maxAssetEntryToAssetCategoryCount * 3) %
2347                                    assetCategoryModels.size());
2348    
2349                    return new String[] {
2350                            String.valueOf(assetCategoryModel0.getCategoryId()),
2351                            String.valueOf(assetCategoryModel1.getCategoryId()),
2352                            String.valueOf(assetCategoryModel2.getCategoryId()),
2353                            String.valueOf(assetCategoryModel3.getCategoryId())
2354                    };
2355            }
2356    
2357            protected String[] getAssetPublisherAssetTagsQueryValues(
2358                    List<AssetTagModel> assetTagModels, int index) {
2359    
2360                    AssetTagModel assetTagModel0 = assetTagModels.get(
2361                            index % assetTagModels.size());
2362                    AssetTagModel assetTagModel1 = assetTagModels.get(
2363                            (index + _maxAssetEntryToAssetTagCount) % assetTagModels.size());
2364                    AssetTagModel assetTagModel2 = assetTagModels.get(
2365                            (index + _maxAssetEntryToAssetTagCount * 2) %
2366                                    assetTagModels.size());
2367                    AssetTagModel assetTagModel3 = assetTagModels.get(
2368                            (index + _maxAssetEntryToAssetTagCount * 3) %
2369                                    assetTagModels.size());
2370    
2371                    return new String[] {
2372                            assetTagModel0.getName(), assetTagModel1.getName(),
2373                            assetTagModel2.getName(), assetTagModel3.getName()
2374                    };
2375            }
2376    
2377            protected InputStream getResourceInputStream(String resourceName) {
2378                    Class<?> clazz = getClass();
2379    
2380                    ClassLoader classLoader = clazz.getClassLoader();
2381    
2382                    return classLoader.getResourceAsStream(
2383                            _DEPENDENCIES_DIR + resourceName);
2384            }
2385    
2386            protected AssetCategoryModel newAssetCategoryModel(
2387                    long groupId, long lastRightCategoryId, String name,
2388                    long vocabularyId) {
2389    
2390                    AssetCategoryModel assetCategoryModel = new AssetCategoryModelImpl();
2391    
2392                    assetCategoryModel.setUuid(SequentialUUID.generate());
2393                    assetCategoryModel.setCategoryId(_counter.get());
2394                    assetCategoryModel.setGroupId(groupId);
2395                    assetCategoryModel.setCompanyId(_companyId);
2396                    assetCategoryModel.setUserId(_sampleUserId);
2397                    assetCategoryModel.setUserName(_SAMPLE_USER_NAME);
2398                    assetCategoryModel.setCreateDate(new Date());
2399                    assetCategoryModel.setModifiedDate(new Date());
2400                    assetCategoryModel.setParentCategoryId(
2401                            AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
2402                    assetCategoryModel.setLeftCategoryId(lastRightCategoryId++);
2403                    assetCategoryModel.setRightCategoryId(lastRightCategoryId++);
2404                    assetCategoryModel.setName(name);
2405    
2406                    StringBundler sb = new StringBundler(5);
2407    
2408                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
2409                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
2410                    sb.append("<Title language-id=\"en_US\">");
2411                    sb.append(name);
2412                    sb.append("</Title></root>");
2413    
2414                    assetCategoryModel.setTitle(sb.toString());
2415    
2416                    assetCategoryModel.setVocabularyId(vocabularyId);
2417    
2418                    return assetCategoryModel;
2419            }
2420    
2421            protected AssetEntryModel newAssetEntryModel(
2422                    long groupId, Date createDate, Date modifiedDate, long classNameId,
2423                    long classPK, String uuid, long classTypeId, boolean listable,
2424                    boolean visible, String mimeType, String title) {
2425    
2426                    AssetEntryModel assetEntryModel = new AssetEntryModelImpl();
2427    
2428                    assetEntryModel.setEntryId(_counter.get());
2429                    assetEntryModel.setGroupId(groupId);
2430                    assetEntryModel.setCompanyId(_companyId);
2431                    assetEntryModel.setUserId(_sampleUserId);
2432                    assetEntryModel.setUserName(_SAMPLE_USER_NAME);
2433                    assetEntryModel.setCreateDate(createDate);
2434                    assetEntryModel.setModifiedDate(modifiedDate);
2435                    assetEntryModel.setClassNameId(classNameId);
2436                    assetEntryModel.setClassPK(classPK);
2437                    assetEntryModel.setClassUuid(uuid);
2438                    assetEntryModel.setClassTypeId(classTypeId);
2439                    assetEntryModel.setListable(listable);
2440                    assetEntryModel.setVisible(visible);
2441                    assetEntryModel.setStartDate(createDate);
2442                    assetEntryModel.setEndDate(nextFutureDate());
2443                    assetEntryModel.setPublishDate(createDate);
2444                    assetEntryModel.setExpirationDate(nextFutureDate());
2445                    assetEntryModel.setMimeType(mimeType);
2446                    assetEntryModel.setTitle(title);
2447    
2448                    return assetEntryModel;
2449            }
2450    
2451            protected AssetTagStatsModel newAssetTagStatsModel(
2452                    long tagId, long classNameId) {
2453    
2454                    AssetTagStatsModel assetTagStatsModel = new AssetTagStatsModelImpl();
2455    
2456                    assetTagStatsModel.setTagStatsId(_counter.get());
2457                    assetTagStatsModel.setTagId(tagId);
2458                    assetTagStatsModel.setClassNameId(classNameId);
2459    
2460                    return assetTagStatsModel;
2461            }
2462    
2463            protected AssetVocabularyModel newAssetVocabularyModel(
2464                    long grouId, long userId, String userName, String name) {
2465    
2466                    AssetVocabularyModel assetVocabularyModel =
2467                            new AssetVocabularyModelImpl();
2468    
2469                    assetVocabularyModel.setUuid(SequentialUUID.generate());
2470                    assetVocabularyModel.setVocabularyId(_counter.get());
2471                    assetVocabularyModel.setGroupId(grouId);
2472                    assetVocabularyModel.setCompanyId(_companyId);
2473                    assetVocabularyModel.setUserId(userId);
2474                    assetVocabularyModel.setUserName(userName);
2475                    assetVocabularyModel.setCreateDate(new Date());
2476                    assetVocabularyModel.setModifiedDate(new Date());
2477                    assetVocabularyModel.setName(name);
2478    
2479                    StringBundler sb = new StringBundler(5);
2480    
2481                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
2482                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
2483                    sb.append("<Title language-id=\"en_US\">");
2484                    sb.append(name);
2485                    sb.append("</Title></root>");
2486    
2487                    assetVocabularyModel.setTitle(sb.toString());
2488    
2489                    assetVocabularyModel.setSettings(
2490                            "multiValued=true\\nselectedClassNameIds=0");
2491    
2492                    return assetVocabularyModel;
2493            }
2494    
2495            protected BlogsEntryModel newBlogsEntryModel(long groupId, int index) {
2496                    BlogsEntryModel blogsEntryModel = new BlogsEntryModelImpl();
2497    
2498                    blogsEntryModel.setUuid(SequentialUUID.generate());
2499                    blogsEntryModel.setEntryId(_counter.get());
2500                    blogsEntryModel.setGroupId(groupId);
2501                    blogsEntryModel.setCompanyId(_companyId);
2502                    blogsEntryModel.setUserId(_sampleUserId);
2503                    blogsEntryModel.setUserName(_SAMPLE_USER_NAME);
2504                    blogsEntryModel.setCreateDate(new Date());
2505                    blogsEntryModel.setModifiedDate(new Date());
2506                    blogsEntryModel.setTitle("Test Blog " + index);
2507                    blogsEntryModel.setSubtitle("Subtitle of Test Blog " + index);
2508                    blogsEntryModel.setUrlTitle("testblog" + index);
2509                    blogsEntryModel.setContent("This is test blog " + index + ".");
2510                    blogsEntryModel.setDisplayDate(new Date());
2511                    blogsEntryModel.setStatusDate(new Date());
2512    
2513                    return blogsEntryModel;
2514            }
2515    
2516            protected DDMContentModel newDDMContentModel(
2517                    long contentId, long groupId, String data) {
2518    
2519                    DDMContentModel ddmContentModel = new DDMContentModelImpl();
2520    
2521                    ddmContentModel.setUuid(SequentialUUID.generate());
2522                    ddmContentModel.setContentId(contentId);
2523                    ddmContentModel.setGroupId(groupId);
2524                    ddmContentModel.setCompanyId(_companyId);
2525                    ddmContentModel.setUserId(_sampleUserId);
2526                    ddmContentModel.setUserName(_SAMPLE_USER_NAME);
2527                    ddmContentModel.setCreateDate(nextFutureDate());
2528                    ddmContentModel.setModifiedDate(nextFutureDate());
2529                    ddmContentModel.setName(DDMStorageLink.class.getName());
2530                    ddmContentModel.setData(data);
2531    
2532                    return ddmContentModel;
2533            }
2534    
2535            protected DDMStructureLinkModel newDDMStructureLinkModel(
2536                    long classNameId, long classPK, long structureId) {
2537    
2538                    DDMStructureLinkModel ddmStructureLinkModel =
2539                            new DDMStructureLinkModelImpl();
2540    
2541                    ddmStructureLinkModel.setStructureLinkId(_counter.get());
2542                    ddmStructureLinkModel.setClassNameId(classNameId);
2543                    ddmStructureLinkModel.setClassPK(classPK);
2544                    ddmStructureLinkModel.setStructureId(structureId);
2545    
2546                    return ddmStructureLinkModel;
2547            }
2548    
2549            protected DDMStructureModel newDDMStructureModel(
2550                    long groupId, long userId, long classNameId, String structureKey,
2551                    String definition) {
2552    
2553                    DDMStructureModel dDMStructureModel = new DDMStructureModelImpl();
2554    
2555                    dDMStructureModel.setUuid(SequentialUUID.generate());
2556                    dDMStructureModel.setStructureId(_counter.get());
2557                    dDMStructureModel.setGroupId(groupId);
2558                    dDMStructureModel.setCompanyId(_companyId);
2559                    dDMStructureModel.setUserId(userId);
2560                    dDMStructureModel.setUserName(_SAMPLE_USER_NAME);
2561                    dDMStructureModel.setCreateDate(nextFutureDate());
2562                    dDMStructureModel.setModifiedDate(nextFutureDate());
2563                    dDMStructureModel.setClassNameId(classNameId);
2564                    dDMStructureModel.setStructureKey(structureKey);
2565                    dDMStructureModel.setVersion(DDMStructureConstants.VERSION_DEFAULT);
2566    
2567                    StringBundler sb = new StringBundler(5);
2568    
2569                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
2570                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
2571                    sb.append("<name language-id=\"en_US\">");
2572                    sb.append(structureKey);
2573                    sb.append("</name></root>");
2574    
2575                    dDMStructureModel.setName(sb.toString());
2576    
2577                    dDMStructureModel.setDefinition(definition);
2578                    dDMStructureModel.setStorageType("xml");
2579    
2580                    return dDMStructureModel;
2581            }
2582    
2583            protected DDMTemplateModel newDDMTemplateModel(
2584                    long groupId, long userId, long structureId) {
2585    
2586                    DDMTemplateModel ddmTemplateModel = new DDMTemplateModelImpl();
2587    
2588                    ddmTemplateModel.setUuid(SequentialUUID.generate());
2589                    ddmTemplateModel.setTemplateId(_counter.get());
2590                    ddmTemplateModel.setGroupId(groupId);
2591                    ddmTemplateModel.setCompanyId(_companyId);
2592                    ddmTemplateModel.setUserId(userId);
2593                    ddmTemplateModel.setCreateDate(nextFutureDate());
2594                    ddmTemplateModel.setModifiedDate(nextFutureDate());
2595                    ddmTemplateModel.setClassNameId(
2596                            _classNameModelsMap.get(DDMStructure.class.getName()));
2597                    ddmTemplateModel.setClassPK(structureId);
2598                    ddmTemplateModel.setTemplateKey(String.valueOf(_counter.get()));
2599                    ddmTemplateModel.setVersion(DDMTemplateConstants.VERSION_DEFAULT);
2600    
2601                    StringBundler sb = new StringBundler(3);
2602    
2603                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root ");
2604                    sb.append("available-locales=\"en_US\" default-locale=\"en_US\">");
2605                    sb.append(
2606                            "<name language-id=\"en_US\">Basic Web Content</name></root>");
2607    
2608                    ddmTemplateModel.setName(sb.toString());
2609    
2610                    ddmTemplateModel.setType(DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY);
2611                    ddmTemplateModel.setMode(DDMTemplateConstants.TEMPLATE_MODE_CREATE);
2612                    ddmTemplateModel.setLanguage(TemplateConstants.LANG_TYPE_FTL);
2613                    ddmTemplateModel.setScript("${content.getData()}");
2614                    ddmTemplateModel.setCacheable(false);
2615                    ddmTemplateModel.setSmallImage(false);
2616    
2617                    return ddmTemplateModel;
2618            }
2619    
2620            protected DLFileEntryModel newDlFileEntryModel(
2621                    DLFolderModel dlFolerModel, int index) {
2622    
2623                    DLFileEntryModel dlFileEntryModel = new DLFileEntryModelImpl();
2624    
2625                    dlFileEntryModel.setUuid(SequentialUUID.generate());
2626                    dlFileEntryModel.setFileEntryId(_counter.get());
2627                    dlFileEntryModel.setGroupId(dlFolerModel.getGroupId());
2628                    dlFileEntryModel.setCompanyId(_companyId);
2629                    dlFileEntryModel.setUserId(_sampleUserId);
2630                    dlFileEntryModel.setUserName(_SAMPLE_USER_NAME);
2631                    dlFileEntryModel.setCreateDate(nextFutureDate());
2632                    dlFileEntryModel.setModifiedDate(nextFutureDate());
2633                    dlFileEntryModel.setRepositoryId(dlFolerModel.getRepositoryId());
2634                    dlFileEntryModel.setFolderId(dlFolerModel.getFolderId());
2635                    dlFileEntryModel.setName("TestFile" + index);
2636                    dlFileEntryModel.setFileName("TestFile" + index + ".txt");
2637                    dlFileEntryModel.setExtension("txt");
2638                    dlFileEntryModel.setMimeType(ContentTypes.TEXT_PLAIN);
2639                    dlFileEntryModel.setTitle("TestFile" + index + ".txt");
2640                    dlFileEntryModel.setFileEntryTypeId(
2641                            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);
2642                    dlFileEntryModel.setVersion(DLFileEntryConstants.VERSION_DEFAULT);
2643                    dlFileEntryModel.setSize(_maxDLFileEntrySize);
2644    
2645                    return dlFileEntryModel;
2646            }
2647    
2648            protected DLFolderModel newDLFolderModel(
2649                    long groupId, long parentFolderId, int index) {
2650    
2651                    DLFolderModel dlFolderModel = new DLFolderModelImpl();
2652    
2653                    dlFolderModel.setUuid(SequentialUUID.generate());
2654                    dlFolderModel.setFolderId(_counter.get());
2655                    dlFolderModel.setGroupId(groupId);
2656                    dlFolderModel.setCompanyId(_companyId);
2657                    dlFolderModel.setUserId(_sampleUserId);
2658                    dlFolderModel.setUserName(_SAMPLE_USER_NAME);
2659                    dlFolderModel.setCreateDate(nextFutureDate());
2660                    dlFolderModel.setModifiedDate(nextFutureDate());
2661                    dlFolderModel.setRepositoryId(groupId);
2662                    dlFolderModel.setParentFolderId(parentFolderId);
2663                    dlFolderModel.setName("Test Folder " + index);
2664                    dlFolderModel.setLastPostDate(nextFutureDate());
2665                    dlFolderModel.setDefaultFileEntryTypeId(
2666                            _defaultDLFileEntryTypeModel.getFileEntryTypeId());
2667                    dlFolderModel.setStatusDate(nextFutureDate());
2668    
2669                    return dlFolderModel;
2670            }
2671    
2672            protected GroupModel newGroupModel(
2673                            long groupId, long classNameId, long classPK, String name,
2674                            boolean site)
2675                    throws Exception {
2676    
2677                    GroupModel groupModel = new GroupModelImpl();
2678    
2679                    groupModel.setUuid(SequentialUUID.generate());
2680                    groupModel.setGroupId(groupId);
2681                    groupModel.setCompanyId(_companyId);
2682                    groupModel.setCreatorUserId(_sampleUserId);
2683                    groupModel.setClassNameId(classNameId);
2684                    groupModel.setClassPK(classPK);
2685                    groupModel.setTreePath(
2686                            StringPool.SLASH + groupModel.getGroupId() + StringPool.SLASH);
2687                    groupModel.setName(name);
2688                    groupModel.setManualMembership(true);
2689                    groupModel.setMembershipRestriction(
2690                            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION);
2691                    groupModel.setFriendlyURL(
2692                            StringPool.FORWARD_SLASH +
2693                                    FriendlyURLNormalizerUtil.normalize(name));
2694                    groupModel.setSite(site);
2695                    groupModel.setActive(true);
2696    
2697                    return groupModel;
2698            }
2699    
2700            protected LayoutSetModel newLayoutSetModel(
2701                    long groupId, boolean privateLayout, int pageCount) {
2702    
2703                    LayoutSetModel layoutSetModel = new LayoutSetModelImpl();
2704    
2705                    layoutSetModel.setLayoutSetId(_counter.get());
2706                    layoutSetModel.setGroupId(groupId);
2707                    layoutSetModel.setCompanyId(_companyId);
2708                    layoutSetModel.setCreateDate(new Date());
2709                    layoutSetModel.setModifiedDate(new Date());
2710                    layoutSetModel.setPrivateLayout(privateLayout);
2711                    layoutSetModel.setThemeId("classic");
2712                    layoutSetModel.setColorSchemeId("01");
2713                    layoutSetModel.setWapThemeId("mobile");
2714                    layoutSetModel.setWapColorSchemeId("01");
2715                    layoutSetModel.setPageCount(pageCount);
2716    
2717                    return layoutSetModel;
2718            }
2719    
2720            protected MBCategoryModel newMBCategoryModel(long groupId, int index) {
2721                    MBCategoryModel mbCategoryModel = new MBCategoryModelImpl();
2722    
2723                    mbCategoryModel.setUuid(SequentialUUID.generate());
2724                    mbCategoryModel.setCategoryId(_counter.get());
2725                    mbCategoryModel.setGroupId(groupId);
2726                    mbCategoryModel.setCompanyId(_companyId);
2727                    mbCategoryModel.setUserId(_sampleUserId);
2728                    mbCategoryModel.setUserName(_SAMPLE_USER_NAME);
2729                    mbCategoryModel.setCreateDate(new Date());
2730                    mbCategoryModel.setModifiedDate(new Date());
2731                    mbCategoryModel.setParentCategoryId(
2732                            MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
2733                    mbCategoryModel.setName("Test Category " + index);
2734                    mbCategoryModel.setDisplayStyle(
2735                            MBCategoryConstants.DEFAULT_DISPLAY_STYLE);
2736                    mbCategoryModel.setThreadCount(_maxMBThreadCount);
2737                    mbCategoryModel.setMessageCount(_maxMBThreadCount * _maxMBMessageCount);
2738                    mbCategoryModel.setLastPostDate(new Date());
2739                    mbCategoryModel.setStatusDate(new Date());
2740    
2741                    return mbCategoryModel;
2742            }
2743    
2744            protected MBMessageModel newMBMessageModel(
2745                    long groupId, long classNameId, long classPK, long categoryId,
2746                    long threadId, long messageId, long rootMessageId, long parentMessageId,
2747                    String subject, String body) {
2748    
2749                    MBMessageModel mBMessageModel = new MBMessageModelImpl();
2750    
2751                    mBMessageModel.setUuid(SequentialUUID.generate());
2752                    mBMessageModel.setMessageId(messageId);
2753                    mBMessageModel.setGroupId(groupId);
2754                    mBMessageModel.setCompanyId(_companyId);
2755                    mBMessageModel.setUserId(_sampleUserId);
2756                    mBMessageModel.setUserName(_SAMPLE_USER_NAME);
2757                    mBMessageModel.setCreateDate(new Date());
2758                    mBMessageModel.setModifiedDate(new Date());
2759                    mBMessageModel.setClassNameId(classNameId);
2760                    mBMessageModel.setClassPK(classPK);
2761                    mBMessageModel.setCategoryId(categoryId);
2762                    mBMessageModel.setThreadId(threadId);
2763                    mBMessageModel.setRootMessageId(rootMessageId);
2764                    mBMessageModel.setParentMessageId(parentMessageId);
2765                    mBMessageModel.setSubject(subject);
2766                    mBMessageModel.setBody(body);
2767                    mBMessageModel.setFormat(MBMessageConstants.DEFAULT_FORMAT);
2768                    mBMessageModel.setStatusDate(new Date());
2769    
2770                    return mBMessageModel;
2771            }
2772    
2773            protected MBThreadModel newMBThreadModel(
2774                    long threadId, long groupId, long categoryId, long rootMessageId,
2775                    int messageCount) {
2776    
2777                    MBThreadModel mbThreadModel = new MBThreadModelImpl();
2778    
2779                    mbThreadModel.setUuid(SequentialUUID.generate());
2780                    mbThreadModel.setThreadId(threadId);
2781                    mbThreadModel.setGroupId(groupId);
2782                    mbThreadModel.setCompanyId(_companyId);
2783                    mbThreadModel.setUserId(_sampleUserId);
2784                    mbThreadModel.setUserName(_SAMPLE_USER_NAME);
2785                    mbThreadModel.setCreateDate(new Date());
2786                    mbThreadModel.setModifiedDate(new Date());
2787                    mbThreadModel.setCategoryId(categoryId);
2788                    mbThreadModel.setRootMessageId(rootMessageId);
2789                    mbThreadModel.setRootMessageUserId(_sampleUserId);
2790                    mbThreadModel.setMessageCount(messageCount);
2791                    mbThreadModel.setLastPostByUserId(_sampleUserId);
2792                    mbThreadModel.setLastPostDate(new Date());
2793                    mbThreadModel.setStatusDate(new Date());
2794    
2795                    return mbThreadModel;
2796            }
2797    
2798            protected PortletPreferencesModel newPortletPreferencesModel(
2799                    long plid, String portletId, String preferences) {
2800    
2801                    PortletPreferencesModel portletPreferencesModel =
2802                            new PortletPreferencesModelImpl();
2803    
2804                    portletPreferencesModel.setPortletPreferencesId(_counter.get());
2805                    portletPreferencesModel.setOwnerId(PortletKeys.PREFS_OWNER_ID_DEFAULT);
2806                    portletPreferencesModel.setOwnerType(
2807                            PortletKeys.PREFS_OWNER_TYPE_LAYOUT);
2808                    portletPreferencesModel.setPlid(plid);
2809                    portletPreferencesModel.setPortletId(portletId);
2810                    portletPreferencesModel.setPreferences(preferences);
2811    
2812                    return portletPreferencesModel;
2813            }
2814    
2815            protected ResourcePermissionModel newResourcePermissionModel(
2816                    String name, String primKey, long roleId, long ownerId) {
2817    
2818                    ResourcePermissionModel resourcePermissionModel =
2819                            new ResourcePermissionModelImpl();
2820    
2821                    resourcePermissionModel.setResourcePermissionId(
2822                            _resourcePermissionCounter.get());
2823                    resourcePermissionModel.setCompanyId(_companyId);
2824                    resourcePermissionModel.setName(name);
2825                    resourcePermissionModel.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
2826                    resourcePermissionModel.setPrimKey(primKey);
2827                    resourcePermissionModel.setRoleId(roleId);
2828                    resourcePermissionModel.setOwnerId(ownerId);
2829                    resourcePermissionModel.setActionIds(1);
2830    
2831                    return resourcePermissionModel;
2832            }
2833    
2834            protected List<ResourcePermissionModel> newResourcePermissionModels(
2835                    String name, String primKey, long ownerId) {
2836    
2837                    List<ResourcePermissionModel> resourcePermissionModels =
2838                            new ArrayList<ResourcePermissionModel>(3);
2839    
2840                    resourcePermissionModels.add(
2841                            newResourcePermissionModel(
2842                                    name, primKey, _guestRoleModel.getRoleId(), 0));
2843                    resourcePermissionModels.add(
2844                            newResourcePermissionModel(
2845                                    name, primKey, _ownerRoleModel.getRoleId(), ownerId));
2846                    resourcePermissionModels.add(
2847                            newResourcePermissionModel(
2848                                    name, primKey, _siteMemberRoleModel.getRoleId(), 0));
2849    
2850                    return resourcePermissionModels;
2851            }
2852    
2853            protected RoleModel newRoleModel(String name, int type) {
2854                    RoleModel roleModel = new RoleModelImpl();
2855    
2856                    roleModel.setUuid(SequentialUUID.generate());
2857                    roleModel.setRoleId(_counter.get());
2858                    roleModel.setCompanyId(_companyId);
2859                    roleModel.setUserId(_sampleUserId);
2860                    roleModel.setUserName(_SAMPLE_USER_NAME);
2861                    roleModel.setCreateDate(new Date());
2862                    roleModel.setModifiedDate(new Date());
2863                    roleModel.setClassNameId(_classNameModelsMap.get(Role.class.getName()));
2864                    roleModel.setClassPK(roleModel.getRoleId());
2865                    roleModel.setName(name);
2866                    roleModel.setType(type);
2867    
2868                    return roleModel;
2869            }
2870    
2871            protected SocialActivityModel newSocialActivityModel(
2872                    long groupId, long classNameId, long classPK, int type,
2873                    String extraData) {
2874    
2875                    SocialActivityModel socialActivityModel = new SocialActivityModelImpl();
2876    
2877                    socialActivityModel.setActivityId(_socialActivityCounter.get());
2878                    socialActivityModel.setGroupId(groupId);
2879                    socialActivityModel.setCompanyId(_companyId);
2880                    socialActivityModel.setUserId(_sampleUserId);
2881                    socialActivityModel.setCreateDate(_CURRENT_TIME + _timeCounter.get());
2882                    socialActivityModel.setClassNameId(classNameId);
2883                    socialActivityModel.setClassPK(classPK);
2884                    socialActivityModel.setType(type);
2885                    socialActivityModel.setExtraData(extraData);
2886    
2887                    return socialActivityModel;
2888            }
2889    
2890            protected SubscriptionModel newSubscriptionModel(
2891                    long classNameId, long classPK) {
2892    
2893                    SubscriptionModel subscriptionModel = new SubscriptionModelImpl();
2894    
2895                    subscriptionModel.setSubscriptionId(_counter.get());
2896                    subscriptionModel.setCompanyId(_companyId);
2897                    subscriptionModel.setUserId(_sampleUserId);
2898                    subscriptionModel.setUserName(_SAMPLE_USER_NAME);
2899                    subscriptionModel.setCreateDate(new Date());
2900                    subscriptionModel.setModifiedDate(new Date());
2901                    subscriptionModel.setClassNameId(classNameId);
2902                    subscriptionModel.setClassPK(classPK);
2903                    subscriptionModel.setFrequency(SubscriptionConstants.FREQUENCY_INSTANT);
2904    
2905                    return subscriptionModel;
2906            }
2907    
2908            protected UserModel newUserModel(
2909                    long userId, String firstName, String lastName, String screenName,
2910                    boolean defaultUser) {
2911    
2912                    if (Validator.isNull(screenName)) {
2913                            screenName = String.valueOf(userId);
2914                    }
2915    
2916                    UserModel userModel = new UserModelImpl();
2917    
2918                    userModel.setUuid(SequentialUUID.generate());
2919                    userModel.setUserId(userId);
2920                    userModel.setCompanyId(_companyId);
2921                    userModel.setCreateDate(new Date());
2922                    userModel.setModifiedDate(new Date());
2923                    userModel.setDefaultUser(defaultUser);
2924                    userModel.setContactId(_counter.get());
2925                    userModel.setPassword("test");
2926                    userModel.setPasswordModifiedDate(new Date());
2927                    userModel.setReminderQueryQuestion("What is your screen name?");
2928                    userModel.setReminderQueryAnswer(screenName);
2929                    userModel.setEmailAddress(screenName + "@liferay.com");
2930                    userModel.setScreenName(screenName);
2931                    userModel.setLanguageId("en_US");
2932                    userModel.setGreeting("Welcome " + screenName + StringPool.EXCLAMATION);
2933                    userModel.setFirstName(firstName);
2934                    userModel.setLastName(lastName);
2935                    userModel.setLoginDate(new Date());
2936                    userModel.setLastLoginDate(new Date());
2937                    userModel.setLastFailedLoginDate(new Date());
2938                    userModel.setLockoutDate(new Date());
2939                    userModel.setAgreedToTermsOfUse(true);
2940                    userModel.setEmailAddressVerified(true);
2941    
2942                    return userModel;
2943            }
2944    
2945            protected WikiNodeModel newWikiNodeModel(long groupId, int index) {
2946                    WikiNodeModel wikiNodeModel = new WikiNodeModelImpl();
2947    
2948                    wikiNodeModel.setUuid(SequentialUUID.generate());
2949                    wikiNodeModel.setNodeId(_counter.get());
2950                    wikiNodeModel.setGroupId(groupId);
2951                    wikiNodeModel.setCompanyId(_companyId);
2952                    wikiNodeModel.setUserId(_sampleUserId);
2953                    wikiNodeModel.setUserName(_SAMPLE_USER_NAME);
2954                    wikiNodeModel.setCreateDate(new Date());
2955                    wikiNodeModel.setModifiedDate(new Date());
2956                    wikiNodeModel.setName("Test Node " + index);
2957                    wikiNodeModel.setLastPostDate(new Date());
2958                    wikiNodeModel.setStatusDate(new Date());
2959    
2960                    return wikiNodeModel;
2961            }
2962    
2963            protected WikiPageModel newWikiPageModel(
2964                    WikiNodeModel wikiNodeModel, int index) {
2965    
2966                    WikiPageModel wikiPageModel = new WikiPageModelImpl();
2967    
2968                    wikiPageModel.setUuid(SequentialUUID.generate());
2969                    wikiPageModel.setPageId(_counter.get());
2970                    wikiPageModel.setResourcePrimKey(_counter.get());
2971                    wikiPageModel.setGroupId(wikiNodeModel.getGroupId());
2972                    wikiPageModel.setCompanyId(_companyId);
2973                    wikiPageModel.setUserId(_sampleUserId);
2974                    wikiPageModel.setUserName(_SAMPLE_USER_NAME);
2975                    wikiPageModel.setCreateDate(new Date());
2976                    wikiPageModel.setModifiedDate(new Date());
2977                    wikiPageModel.setNodeId(wikiNodeModel.getNodeId());
2978                    wikiPageModel.setTitle("Test Page " + index);
2979                    wikiPageModel.setVersion(WikiPageConstants.VERSION_DEFAULT);
2980                    wikiPageModel.setContent("This is test page " + index + ".");
2981                    wikiPageModel.setFormat(WikiPageConstants.DEFAULT_FORMAT);
2982                    wikiPageModel.setHead(true);
2983    
2984                    return wikiPageModel;
2985            }
2986    
2987            protected String nextDDLCustomFieldName(
2988                    long groupId, int customFieldIndex) {
2989    
2990                    StringBundler sb = new StringBundler(4);
2991    
2992                    sb.append("costom_field_text_");
2993                    sb.append(groupId);
2994                    sb.append("_");
2995                    sb.append(customFieldIndex);
2996    
2997                    return sb.toString();
2998            }
2999    
3000            protected Date nextFutureDate() {
3001                    return new Date(
3002                            _FUTURE_TIME + (_futureDateCounter.get() * Time.SECOND));
3003            }
3004    
3005            private static final long _CURRENT_TIME = System.currentTimeMillis();
3006    
3007            private static final String _DEPENDENCIES_DIR =
3008                    "com/liferay/portal/tools/samplesqlbuilder/dependencies/";
3009    
3010            private static final long _FUTURE_TIME =
3011                    System.currentTimeMillis() + Time.YEAR;
3012    
3013            private static final String _SAMPLE_USER_NAME = "Sample";
3014    
3015            private static PortletPreferencesFactory _portletPreferencesFactory =
3016                    new PortletPreferencesFactoryImpl();
3017    
3018            private long _accountId;
3019            private AccountModel _accountModel;
3020            private RoleModel _administratorRoleModel;
3021            private Map<Long, SimpleCounter> _assetCategoryCounters =
3022                    new HashMap<Long, SimpleCounter>();
3023            private List<AssetCategoryModel>[] _assetCategoryModelsArray;
3024            private Map<Long, SimpleCounter> _assetPublisherQueryCounter =
3025                    new HashMap<Long, SimpleCounter>();
3026            private String _assetPublisherQueryName;
3027            private Map<Long, SimpleCounter> _assetTagCounters =
3028                    new HashMap<Long, SimpleCounter>();
3029            private List<AssetTagModel>[] _assetTagModelsArray;
3030            private List<AssetTagStatsModel>[] _assetTagStatsModelsArray;
3031            private List<AssetVocabularyModel>[] _assetVocabularyModelsArray;
3032            private List<ClassNameModel> _classNameModels;
3033            private Map<String, Long> _classNameModelsMap = new HashMap<String, Long>();
3034            private long _companyId;
3035            private CompanyModel _companyModel;
3036            private SimpleCounter _counter;
3037            private PortletPreferencesImpl _defaultAssetPublisherPortletPreference;
3038            private AssetVocabularyModel _defaultAssetVocabularyModel;
3039            private DDMStructureModel _defaultDLDDMStructureModel;
3040            private DLFileEntryTypeModel _defaultDLFileEntryTypeModel;
3041            private DDMStructureModel _defaultJournalDDMStructureModel;
3042            private DDMTemplateModel _defaultJournalDDMTemplateModel;
3043            private long _defaultUserId;
3044            private UserModel _defaultUserModel;
3045            private String _dlDDMStructureContent;
3046            private List<String> _firstNames;
3047            private SimpleCounter _futureDateCounter;
3048            private long _globalGroupId;
3049            private GroupModel _globalGroupModel;
3050            private List<GroupModel> _groupModels;
3051            private long _guestGroupId;
3052            private GroupModel _guestGroupModel;
3053            private RoleModel _guestRoleModel;
3054            private UserModel _guestUserModel;
3055            private String _journalArticleContent;
3056            private Map<Long, String> _journalArticleResourceUUIDs =
3057                    new HashMap<Long, String>();
3058            private String _journalDDMStructureContent;
3059            private List<String> _lastNames;
3060            private Map<Long, SimpleCounter> _layoutCounters =
3061                    new HashMap<Long, SimpleCounter>();
3062            private int _maxAssetCategoryCount;
3063            private int _maxAssetEntryToAssetCategoryCount;
3064            private int _maxAssetEntryToAssetTagCount;
3065            private int _maxAssetPublisherPageCount;
3066            private int _maxAssetTagCount;
3067            private int _maxAssetVocabularyCount;
3068            private int _maxBlogsEntryCommentCount;
3069            private int _maxBlogsEntryCount;
3070            private int _maxDDLCustomFieldCount;
3071            private int _maxDDLRecordCount;
3072            private int _maxDDLRecordSetCount;
3073            private int _maxDLFileEntryCount;
3074            private int _maxDLFileEntrySize;
3075            private int _maxDLFolderCount;
3076            private int _maxDLFolderDepth;
3077            private int _maxGroupsCount;
3078            private int _maxJournalArticleCount;
3079            private int _maxJournalArticlePageCount;
3080            private int _maxJournalArticleVersionCount;
3081            private int _maxMBCategoryCount;
3082            private int _maxMBMessageCount;
3083            private int _maxMBThreadCount;
3084            private int _maxUserCount;
3085            private int _maxUserToGroupCount;
3086            private int _maxWikiNodeCount;
3087            private int _maxWikiPageCommentCount;
3088            private int _maxWikiPageCount;
3089            private RoleModel _ownerRoleModel;
3090            private RoleModel _powerUserRoleModel;
3091            private SimpleCounter _resourcePermissionCounter;
3092            private List<RoleModel> _roleModels;
3093            private long _sampleUserId;
3094            private UserModel _sampleUserModel;
3095            private Format _simpleDateFormat =
3096                    FastDateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
3097            private RoleModel _siteMemberRoleModel;
3098            private SimpleCounter _socialActivityCounter;
3099            private SimpleCounter _timeCounter;
3100            private RoleModel _userRoleModel;
3101            private SimpleCounter _userScreenNameCounter;
3102            private VirtualHostModel _virtualHostModel;
3103    
3104    }