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