1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.tools.samplesqlbuilder;
24  
25  import com.liferay.counter.model.Counter;
26  import com.liferay.portal.kernel.util.IntegerWrapper;
27  import com.liferay.portal.kernel.util.KeyValuePair;
28  import com.liferay.portal.kernel.util.ListUtil;
29  import com.liferay.portal.kernel.util.StringUtil;
30  import com.liferay.portal.kernel.util.UnicodeProperties;
31  import com.liferay.portal.kernel.util.Validator;
32  import com.liferay.portal.kernel.xml.Document;
33  import com.liferay.portal.kernel.xml.Element;
34  import com.liferay.portal.kernel.xml.SAXReaderUtil;
35  import com.liferay.portal.model.ClassName;
36  import com.liferay.portal.model.Company;
37  import com.liferay.portal.model.Contact;
38  import com.liferay.portal.model.Group;
39  import com.liferay.portal.model.GroupConstants;
40  import com.liferay.portal.model.Layout;
41  import com.liferay.portal.model.ModelHintsUtil;
42  import com.liferay.portal.model.Permission;
43  import com.liferay.portal.model.Resource;
44  import com.liferay.portal.model.ResourceCode;
45  import com.liferay.portal.model.ResourceConstants;
46  import com.liferay.portal.model.Role;
47  import com.liferay.portal.model.RoleConstants;
48  import com.liferay.portal.model.User;
49  import com.liferay.portal.model.impl.ClassNameImpl;
50  import com.liferay.portal.model.impl.CompanyImpl;
51  import com.liferay.portal.model.impl.ContactImpl;
52  import com.liferay.portal.model.impl.GroupImpl;
53  import com.liferay.portal.model.impl.LayoutImpl;
54  import com.liferay.portal.model.impl.LayoutTypePortletImpl;
55  import com.liferay.portal.model.impl.PermissionImpl;
56  import com.liferay.portal.model.impl.ResourceCodeImpl;
57  import com.liferay.portal.model.impl.ResourceImpl;
58  import com.liferay.portal.model.impl.RoleImpl;
59  import com.liferay.portal.model.impl.UserImpl;
60  import com.liferay.portal.security.permission.ResourceActionsUtil;
61  import com.liferay.portlet.blogs.model.BlogsEntry;
62  import com.liferay.portlet.blogs.model.BlogsStatsUser;
63  import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
64  import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
65  import com.liferay.portlet.messageboards.model.MBCategory;
66  import com.liferay.portlet.messageboards.model.MBDiscussion;
67  import com.liferay.portlet.messageboards.model.MBMessage;
68  import com.liferay.portlet.messageboards.model.MBStatsUser;
69  import com.liferay.portlet.messageboards.model.MBThread;
70  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
71  import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
72  import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
73  import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
74  import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
75  import com.liferay.portlet.tags.model.TagsAsset;
76  import com.liferay.portlet.tags.model.impl.TagsAssetImpl;
77  import com.liferay.portlet.wiki.model.WikiNode;
78  import com.liferay.portlet.wiki.model.WikiPage;
79  import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
80  import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
81  import com.liferay.util.SimpleCounter;
82  
83  import java.io.File;
84  
85  import java.util.ArrayList;
86  import java.util.HashMap;
87  import java.util.Iterator;
88  import java.util.List;
89  import java.util.Map;
90  
91  /**
92   * <a href="DataFactory.java.html"><b><i>View Source</i></b></a>
93   *
94   * @author Brian Wing Shun Chan
95   *
96   */
97  public class DataFactory {
98  
99      public DataFactory(
100         int maxGroupsCount, int maxUserToGroupCount, SimpleCounter counter,
101         SimpleCounter permissionCounter, SimpleCounter resourceCounter,
102         SimpleCounter resourceCodeCounter) {
103 
104         try {
105             _maxGroupsCount = maxGroupsCount;
106             _maxUserToGroupCount = maxUserToGroupCount;
107 
108             _counter = counter;
109             _permissionCounter = permissionCounter;
110             _resourceCounter = resourceCounter;
111             _resourceCodeCounter = resourceCodeCounter;
112 
113             initClassNames();
114             initCompany();
115             initDefaultUser();
116             initGroups();
117             initResourceCodes();
118             initRoles();
119             initUserNames();
120         }
121         catch (Exception e) {
122             e.printStackTrace();
123         }
124     }
125 
126     public BlogsEntry addBlogsEntry(
127             long groupId, long userId, String title, String urlTitle,
128             String content)
129         throws Exception {
130 
131         BlogsEntry blogsEntry = new BlogsEntryImpl();
132 
133         blogsEntry.setEntryId(_counter.get());
134         blogsEntry.setGroupId(groupId);
135         blogsEntry.setUserId(userId);
136         blogsEntry.setTitle(title);
137         blogsEntry.setUrlTitle(urlTitle);
138         blogsEntry.setContent(content);
139 
140         return blogsEntry;
141     }
142 
143     public BlogsStatsUser addBlogsStatsUser(long groupId, long userId)
144         throws Exception {
145 
146         BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
147 
148         blogsStatsUser.setGroupId(groupId);
149         blogsStatsUser.setUserId(userId);
150 
151         return blogsStatsUser;
152     }
153 
154     public Contact addContact(String firstName, String lastName)
155         throws Exception {
156 
157         Contact contact = new ContactImpl();
158 
159         contact.setContactId(_counter.get());
160         contact.setAccountId(_company.getAccountId());
161         contact.setFirstName(firstName);
162         contact.setLastName(lastName);
163 
164         return contact;
165     }
166 
167     public Group addGroup(
168             long groupId, long classNameId, long classPK, String name,
169             String friendlyURL)
170         throws Exception {
171 
172         Group group = new GroupImpl();
173 
174         group.setGroupId(groupId);
175         group.setClassNameId(classNameId);
176         group.setClassPK(classPK);
177         group.setName(name);
178         group.setFriendlyURL(friendlyURL);
179 
180         return group;
181     }
182 
183     public Layout addLayout(
184             int layoutId, String name, String friendlyURL, String column1,
185             String column2)
186         throws Exception {
187 
188         Layout layout = new LayoutImpl();
189 
190         layout.setPlid(_counter.get());
191         layout.setPrivateLayout(false);
192         layout.setLayoutId(layoutId);
193         layout.setName(name);
194         layout.setFriendlyURL(friendlyURL);
195 
196         UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);
197 
198         typeSettingsProperties.setProperty(
199             LayoutTypePortletImpl.LAYOUT_TEMPLATE_ID, "2_columns_ii");
200         typeSettingsProperties.setProperty("column-1", column1);
201         typeSettingsProperties.setProperty("column-2", column2);
202 
203         String typeSettings = StringUtil.replace(
204             typeSettingsProperties.toString(), "\n", "\\n");
205 
206         layout.setTypeSettings(typeSettings);
207 
208         return layout;
209     }
210 
211     public MBCategory addMBCategory(
212             long categoryId, long groupId, long companyId, long userId,
213             String name, String description, int threadCount, int messageCount)
214         throws Exception {
215 
216         MBCategory mbCategory = new MBCategoryImpl();
217 
218         mbCategory.setCategoryId(categoryId);
219         mbCategory.setGroupId(groupId);
220         mbCategory.setCompanyId(companyId);
221         mbCategory.setUserId(userId);
222         mbCategory.setName(name);
223         mbCategory.setDescription(description);
224         mbCategory.setThreadCount(threadCount);
225         mbCategory.setMessageCount(messageCount);
226 
227         return mbCategory;
228     }
229 
230     public MBDiscussion addMBDiscussion(
231             long classNameId, long classPK, long threadId)
232         throws Exception {
233 
234         MBDiscussion mbDiscussion = new MBDiscussionImpl();
235 
236         mbDiscussion.setDiscussionId(_counter.get());
237         mbDiscussion.setClassNameId(classNameId);
238         mbDiscussion.setClassPK(classPK);
239         mbDiscussion.setThreadId(threadId);
240 
241         return mbDiscussion;
242     }
243 
244     public MBMessage addMBMessage(
245             long messageId, long groupId, long userId, long classNameId,
246             long classPK, long categoryId, long threadId, long parentMessageId,
247             String subject, String body)
248         throws Exception {
249 
250         MBMessage mbMessage = new MBMessageImpl();
251 
252         mbMessage.setMessageId(messageId);
253         mbMessage.setGroupId(groupId);
254         mbMessage.setUserId(userId);
255         mbMessage.setClassNameId(classNameId);
256         mbMessage.setClassPK(classPK);
257         mbMessage.setCategoryId(categoryId);
258         mbMessage.setThreadId(threadId);
259         mbMessage.setParentMessageId(parentMessageId);
260         mbMessage.setSubject(subject);
261         mbMessage.setBody(body);
262 
263         return mbMessage;
264     }
265 
266     public MBStatsUser addMBStatsUser(long groupId, long userId)
267         throws Exception {
268 
269         MBStatsUser mbStatsUser = new MBStatsUserImpl();
270 
271         mbStatsUser.setGroupId(groupId);
272         mbStatsUser.setUserId(userId);
273 
274         return mbStatsUser;
275     }
276 
277     public MBThread addMBThread(
278             long threadId, long groupId, long categoryId, long rootMessageId,
279             int messageCount, long lastPostByUserId)
280         throws Exception {
281 
282         MBThread mbThread = new MBThreadImpl();
283 
284         mbThread.setThreadId(threadId);
285         mbThread.setGroupId(groupId);
286         mbThread.setCategoryId(categoryId);
287         mbThread.setRootMessageId(rootMessageId);
288         mbThread.setMessageCount(messageCount);
289         mbThread.setLastPostByUserId(lastPostByUserId);
290 
291         return mbThread;
292     }
293 
294     public List<Permission> addPermissions(Resource resource) throws Exception {
295         List<Permission> permissions = new ArrayList<Permission>();
296 
297         String name = _individualResourceNames.get(resource.getCodeId());
298 
299         List<String> actions = ResourceActionsUtil.getModelResourceActions(
300             name);
301 
302         for (String action : actions) {
303             Permission permission = new PermissionImpl();
304 
305             permission.setPermissionId(_permissionCounter.get());
306             permission.setCompanyId(_company.getCompanyId());
307             permission.setActionId(action);
308             permission.setResourceId(resource.getResourceId());
309 
310             permissions.add(permission);
311         }
312 
313         return permissions;
314     }
315 
316     public Resource addResource(String name, String primKey) throws Exception {
317         Long codeId = _individualResourceCodeIds.get(name);
318 
319         Resource resource = new ResourceImpl();
320 
321         resource.setResourceId(_resourceCounter.get());
322         resource.setCodeId(codeId);
323         resource.setPrimKey(primKey);
324 
325         return resource;
326     }
327 
328     public List<KeyValuePair> addRolesPermissions(
329             Resource resource, List<Permission> permissions, Role memberRole)
330         throws Exception {
331 
332         List<KeyValuePair> rolesPermissions = new ArrayList<KeyValuePair>();
333 
334         for (Permission permission : permissions) {
335             KeyValuePair kvp = new KeyValuePair();
336 
337             kvp.setKey(String.valueOf(_ownerRole.getRoleId()));
338             kvp.setValue(String.valueOf(permission.getPermissionId()));
339 
340             rolesPermissions.add(kvp);
341         }
342 
343         String name = _individualResourceNames.get(resource.getCodeId());
344 
345         if (memberRole != null) {
346             List<String> communityDefaultactions =
347                 ResourceActionsUtil.getModelResourceCommunityDefaultActions(
348                     name);
349 
350             for (Permission permission : permissions) {
351                 if (!communityDefaultactions.contains(
352                         permission.getActionId())) {
353 
354                     continue;
355                 }
356 
357                 KeyValuePair kvp = new KeyValuePair();
358 
359                 kvp.setKey(String.valueOf(memberRole.getRoleId()));
360                 kvp.setValue(String.valueOf(permission.getPermissionId()));
361 
362                 rolesPermissions.add(kvp);
363             }
364         }
365 
366         List<String> guestDefaultactions =
367             ResourceActionsUtil.getModelResourceGuestDefaultActions(name);
368 
369         for (Permission permission : permissions) {
370             if (!guestDefaultactions.contains(permission.getActionId())) {
371                 continue;
372             }
373 
374             KeyValuePair kvp = new KeyValuePair();
375 
376             kvp.setKey(String.valueOf(_guestRole.getRoleId()));
377             kvp.setValue(String.valueOf(permission.getPermissionId()));
378 
379             rolesPermissions.add(kvp);
380         }
381 
382         return rolesPermissions;
383     }
384 
385     public TagsAsset addTagsAsset(
386             long groupId, long userId, long classNameId, long classPK,
387             String mimeType, String title)
388         throws Exception {
389 
390         TagsAsset tagsAsset = new TagsAssetImpl();
391 
392         tagsAsset.setGroupId(groupId);
393         tagsAsset.setUserId(userId);
394         tagsAsset.setClassNameId(classNameId);
395         tagsAsset.setClassPK(classPK);
396         tagsAsset.setMimeType(mimeType);
397         tagsAsset.setTitle(title);
398 
399         return tagsAsset;
400     }
401 
402     public User addUser(boolean defaultUser, String screenName)
403         throws Exception {
404 
405         User user = new UserImpl();
406 
407         user.setUserId(_counter.get());
408         user.setDefaultUser(defaultUser);
409 
410         if (Validator.isNull(screenName)) {
411             screenName = String.valueOf(user.getUserId());
412         }
413 
414         user.setScreenName(screenName);
415 
416         String emailAddress = screenName + "@liferay.com";
417 
418         user.setEmailAddress(emailAddress);
419 
420         return user;
421     }
422 
423     public List<Long> addUserToGroupIds(long groupId) {
424         List<Long> groupIds = new ArrayList<Long>(_maxUserToGroupCount + 1);
425 
426         groupIds.add(_guestGroup.getGroupId());
427 
428         if ((groupId + _maxUserToGroupCount) > _maxGroupsCount) {
429             groupId = groupId - _maxUserToGroupCount + 1;
430         }
431 
432         for (int i = 0; i < _maxUserToGroupCount; i++) {
433             groupIds.add(groupId + i);
434         }
435 
436         return groupIds;
437     }
438 
439     public WikiNode addWikiNode(
440             long groupId, long userId, String name, String description)
441         throws Exception {
442 
443         WikiNode wikiNode = new WikiNodeImpl();
444 
445         wikiNode.setNodeId(_counter.get());
446         wikiNode.setGroupId(groupId);
447         wikiNode.setUserId(userId);
448         wikiNode.setName(name);
449         wikiNode.setDescription(description);
450 
451         return wikiNode;
452     }
453 
454     public WikiPage addWikiPage(
455             long groupId, long userId, long nodeId, String title,
456             double version, String content, boolean head)
457         throws Exception {
458 
459         WikiPage wikiPage = new WikiPageImpl();
460 
461         wikiPage.setPageId(_counter.get());
462         wikiPage.setResourcePrimKey(_counter.get());
463         wikiPage.setGroupId(groupId);
464         wikiPage.setUserId(userId);
465         wikiPage.setNodeId(nodeId);
466         wikiPage.setTitle(title);
467         wikiPage.setVersion(version);
468         wikiPage.setContent(content);
469         wikiPage.setHead(head);
470 
471         return wikiPage;
472     }
473 
474     public Role getAdministratorRole() {
475         return _administratorRole;
476     }
477 
478     public ClassName getBlogsEntryClassName() {
479         return _blogsEntryClassName;
480     }
481 
482     public List<ClassName> getClassNames() {
483         return _classNames;
484     }
485 
486     public Role getCommunityAdministratorRole() {
487         return _communityAdministratorRole;
488     }
489 
490     public Role getCommunityMemberRole() {
491         return _communityMemberRole;
492     }
493 
494     public Role getCommunityOwnerRole() {
495         return _communityOwnerRole;
496     }
497 
498     public Company getCompany() {
499         return _company;
500     }
501 
502     public List<Counter> getCounters() {
503         return _counters;
504     }
505 
506     public User getDefaultUser() {
507         return _defaultUser;
508     }
509 
510     public ClassName getGroupClassName() {
511         return _groupClassName;
512     }
513 
514     public List<Group> getGroups() {
515         return _groups;
516     }
517 
518     public Group getGuestGroup() {
519         return _guestGroup;
520     }
521 
522     public Role getGuestRole() {
523         return _guestRole;
524     }
525 
526     public Role getOrganizationAdministratorRole() {
527         return _organizationAdministratorRole;
528     }
529 
530     public Role getOrganizationMemberRole() {
531         return _organizationMemberRole;
532     }
533 
534     public Role getOrganizationOwnerRole() {
535         return _organizationOwnerRole;
536     }
537 
538     public Role getPowerUserRole() {
539         return _powerUserRole;
540     }
541 
542     public List<ResourceCode> getResourceCodes() {
543         return _resourceCodes;
544     }
545 
546     public ClassName getRoleClassName() {
547         return _roleClassName;
548     }
549 
550     public List<Role> getRoles() {
551         return _roles;
552     }
553 
554     public ClassName getUserClassName() {
555         return _userClassName;
556     }
557 
558     public Object[] getUserNames() {
559         return _userNames;
560     }
561 
562     public Role getUserRole() {
563         return _userRole;
564     }
565 
566     public ClassName getWikiPageClassName() {
567         return _wikiPageClassName;
568     }
569 
570     public void initClassNames() throws Exception {
571         if (_classNames != null) {
572             return;
573         }
574 
575         _classNames = new ArrayList<ClassName>();
576 
577         List<String> models = ModelHintsUtil.getModels();
578 
579         for (String model : models) {
580             ClassName className = new ClassNameImpl();
581 
582             className.setClassNameId(_counter.get());
583             className.setValue(model);
584 
585             _classNames.add(className);
586 
587             if (model.equals(BlogsEntry.class.getName())) {
588                 _blogsEntryClassName = className;
589             }
590             if (model.equals(Group.class.getName())) {
591                 _groupClassName = className;
592             }
593             else if (model.equals(Role.class.getName())) {
594                 _roleClassName = className;
595             }
596             else if (model.equals(User.class.getName())) {
597                 _userClassName = className;
598             }
599             else if (model.equals(WikiPage.class.getName())) {
600                 _wikiPageClassName = className;
601             }
602         }
603     }
604 
605     public void initCompany() throws Exception {
606         _company = new CompanyImpl();
607 
608         _company.setCompanyId(_counter.get());
609         _company.setAccountId(_counter.get());
610     }
611 
612     public void initCounters() throws Exception {
613         if (_counters != null) {
614             return;
615         }
616 
617         _counters = new ArrayList<Counter>();
618 
619         // Counter
620 
621         Counter counter = new Counter();
622 
623         counter.setName(Counter.class.getName());
624         counter.setCurrentId(_counter.get());
625 
626         _counters.add(counter);
627 
628         // Permission
629 
630         counter = new Counter();
631 
632         counter.setName(Permission.class.getName());
633         counter.setCurrentId(_permissionCounter.get());
634 
635         _counters.add(counter);
636 
637         // Resource
638 
639         counter = new Counter();
640 
641         counter.setName(Resource.class.getName());
642         counter.setCurrentId(_resourceCounter.get());
643 
644         _counters.add(counter);
645 
646         // ResourceCode
647 
648         counter = new Counter();
649 
650         counter.setName(ResourceCode.class.getName());
651         counter.setCurrentId(_resourceCodeCounter.get());
652 
653         _counters.add(counter);
654     }
655 
656     public void initDefaultUser() throws Exception {
657         _defaultUser = new UserImpl();
658 
659         _defaultUser.setUserId(_counter.get());
660     }
661 
662     public void initGroups() throws Exception {
663         if (_groups != null) {
664             return;
665         }
666 
667         _groups = new ArrayList<Group>();
668 
669         // Guest
670 
671         Group group = new GroupImpl();
672 
673         group.setGroupId(_counter.get());
674         group.setClassNameId(_groupClassName.getClassNameId());
675         group.setClassPK(group.getGroupId());
676         group.setName(GroupConstants.GUEST);
677         group.setFriendlyURL("/guest");
678 
679         _groups.add(group);
680 
681         _guestGroup = group;
682     }
683 
684     public void initResourceCodes() throws Exception {
685         if (_resourceCodes != null) {
686             return;
687         }
688 
689         _resourceCodes = new ArrayList<ResourceCode>();
690 
691         _individualResourceCodeIds = new HashMap<String, Long>();
692         _individualResourceNames = new HashMap<Long, String>();
693 
694         List<String> models = ModelHintsUtil.getModels();
695 
696         for (String model : models) {
697             initResourceCodes(model);
698         }
699 
700         Document doc = SAXReaderUtil.read(
701             new File("../portal-web/docroot/WEB-INF/portlet-custom.xml"),
702             false);
703 
704         Element root = doc.getRootElement();
705 
706         Iterator<Element> itr = root.elements("portlet").iterator();
707 
708         while (itr.hasNext()) {
709             Element portlet = itr.next();
710 
711             String portletName = portlet.elementText("portlet-name");
712 
713             initResourceCodes(portletName);
714         }
715     }
716 
717     public void initResourceCodes(String name) throws Exception {
718 
719         // Company
720 
721         ResourceCode resourceCode = newResourceCode();
722 
723         resourceCode.setName(name);
724         resourceCode.setScope(ResourceConstants.SCOPE_COMPANY);
725 
726         _resourceCodes.add(resourceCode);
727 
728         // Group
729 
730         resourceCode = newResourceCode();
731 
732         resourceCode.setName(name);
733         resourceCode.setScope(ResourceConstants.SCOPE_GROUP);
734 
735         _resourceCodes.add(resourceCode);
736 
737         // Group template
738 
739         resourceCode = newResourceCode();
740 
741         resourceCode.setName(name);
742         resourceCode.setScope(ResourceConstants.SCOPE_GROUP_TEMPLATE);
743 
744         _resourceCodes.add(resourceCode);
745 
746         // Individual
747 
748         resourceCode = newResourceCode();
749 
750         resourceCode.setName(name);
751         resourceCode.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
752 
753         _resourceCodes.add(resourceCode);
754 
755         _individualResourceCodeIds.put(name, resourceCode.getCodeId());
756         _individualResourceNames.put(resourceCode.getCodeId(), name);
757     }
758 
759     public void initRoles() throws Exception {
760         if (_roles != null) {
761             return;
762         }
763 
764         _roles = new ArrayList<Role>();
765 
766         // Administrator
767 
768         Role role = newRole();
769 
770         role.setName(RoleConstants.ADMINISTRATOR);
771         role.setType(RoleConstants.TYPE_REGULAR);
772 
773         _roles.add(role);
774 
775         _administratorRole = role;
776 
777         // Community Administrator
778 
779         role = newRole();
780 
781         role.setName(RoleConstants.COMMUNITY_ADMINISTRATOR);
782         role.setType(RoleConstants.TYPE_COMMUNITY);
783 
784         _roles.add(role);
785 
786         _communityAdministratorRole = role;
787 
788         // Community Member
789 
790         role = newRole();
791 
792         role.setName(RoleConstants.COMMUNITY_MEMBER);
793         role.setType(RoleConstants.TYPE_COMMUNITY);
794 
795         _roles.add(role);
796 
797         _communityMemberRole = role;
798 
799         // Community Owner
800 
801         role = newRole();
802 
803         role.setName(RoleConstants.COMMUNITY_OWNER);
804         role.setType(RoleConstants.TYPE_COMMUNITY);
805 
806         _roles.add(role);
807 
808         _communityOwnerRole = role;
809 
810         // Guest
811 
812         role = newRole();
813 
814         role.setName(RoleConstants.GUEST);
815         role.setType(RoleConstants.TYPE_REGULAR);
816 
817         _roles.add(role);
818 
819         _guestRole = role;
820 
821         // Organization Administrator
822 
823         role = newRole();
824 
825         role.setName(RoleConstants.ORGANIZATION_ADMINISTRATOR);
826         role.setType(RoleConstants.TYPE_ORGANIZATION);
827 
828         _roles.add(role);
829 
830         _communityAdministratorRole = role;
831 
832         // Organization Member
833 
834         role = newRole();
835 
836         role.setName(RoleConstants.ORGANIZATION_MEMBER);
837         role.setType(RoleConstants.TYPE_ORGANIZATION);
838 
839         _roles.add(role);
840 
841         _communityMemberRole = role;
842 
843         // Organization Owner
844 
845         role = newRole();
846 
847         role.setName(RoleConstants.ORGANIZATION_OWNER);
848         role.setType(RoleConstants.TYPE_ORGANIZATION);
849 
850         _roles.add(role);
851 
852         _communityOwnerRole = role;
853 
854         // Owner
855 
856         role = newRole();
857 
858         role.setName(RoleConstants.OWNER);
859         role.setType(RoleConstants.TYPE_REGULAR);
860 
861         _roles.add(role);
862 
863         _ownerRole = role;
864 
865         // Power User
866 
867         role = newRole();
868 
869         role.setName(RoleConstants.POWER_USER);
870         role.setType(RoleConstants.TYPE_REGULAR);
871 
872         _roles.add(role);
873 
874         _powerUserRole = role;
875 
876         // User
877 
878         role = newRole();
879 
880         role.setName(RoleConstants.USER);
881         role.setType(RoleConstants.TYPE_REGULAR);
882 
883         _roles.add(role);
884 
885         _userRole = role;
886     }
887 
888     public void initUserNames() throws Exception {
889         if (_userNames != null) {
890             return;
891         }
892 
893         _userNames = new Object[2];
894 
895         String dependenciesDir =
896             "../portal-impl/src/com/liferay/portal/tools/samplesqlbuilder/" +
897                 "dependencies/";
898 
899         List<String> firstNames = ListUtil.fromFile(
900             dependenciesDir + "first_names.txt");
901         List<String> lastNames = ListUtil.fromFile(
902             dependenciesDir + "last_names.txt");
903 
904         _userNames[0] = firstNames;
905         _userNames[1] = lastNames;
906     }
907 
908     public IntegerWrapper newInteger() {
909         return new IntegerWrapper();
910     }
911 
912     protected ResourceCode newResourceCode() {
913         ResourceCode resourceCode = new ResourceCodeImpl();
914 
915         resourceCode.setCodeId(_resourceCodeCounter.get());
916 
917         return resourceCode;
918     }
919 
920     protected Role newRole() {
921         Role role = new RoleImpl();
922 
923         role.setRoleId(_counter.get());
924         role.setClassNameId(_roleClassName.getClassNameId());
925         role.setClassPK(role.getRoleId());
926 
927         return role;
928     }
929 
930     private Role _administratorRole;
931     private ClassName _blogsEntryClassName;
932     private List<ClassName> _classNames;
933     private Role _communityAdministratorRole;
934     private Role _communityMemberRole;
935     private Role _communityOwnerRole;
936     private Company _company;
937     private SimpleCounter _counter;
938     private List<Counter> _counters;
939     private User _defaultUser;
940     private ClassName _groupClassName;
941     private List<Group> _groups;
942     private Group _guestGroup;
943     private Role _guestRole;
944     private Map<String, Long> _individualResourceCodeIds;
945     private Map<Long, String> _individualResourceNames;
946     private int _maxGroupsCount;
947     private int _maxUserToGroupCount;
948     private Role _organizationAdministratorRole;
949     private Role _organizationMemberRole;
950     private Role _organizationOwnerRole;
951     private Role _ownerRole;
952     private SimpleCounter _permissionCounter;
953     private Role _powerUserRole;
954     private SimpleCounter _resourceCodeCounter;
955     private List<ResourceCode> _resourceCodes;
956     private SimpleCounter _resourceCounter;
957     private ClassName _roleClassName;
958     private List<Role> _roles;
959     private ClassName _userClassName;
960     private Object[] _userNames;
961     private Role _userRole;
962     private ClassName _wikiPageClassName;
963 
964 }