View Javadoc

1   /*
2    * ----------------------------------------------------------------------
3    * Copyright (C) 2009 Enrique Lara (k957@68k.org)
4    *
5    * TinLizard is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public License
7    * as published by the Free Software Foundation; either version 3.0
8    * of the License, or (at your option) any later version.
9    *
10   * TinLizard is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with TinLizard. If not, see http://www.gnu.org/licenses/.
17   * ----------------------------------------------------------------------
18   */
19  package tinlizard.dataload;
20  
21  import tinlizard.dao.jpa.JpaDao;
22  
23  import tinlizard.model.Codeline;
24  import tinlizard.model.Dependency;
25  import tinlizard.model.Policy;
26  import tinlizard.model.Project;
27  import tinlizard.model.User;
28  import tinlizard.model.View;
29  
30  /***
31   * Utility Class to load test data.
32   */
33  public final class DataLoader implements Runnable {
34      private final JpaDao dao = JpaDao.getInstance();
35      private final Data data = new Data();
36  
37      public Data loadTestData() {
38          loadUserData();
39          loadPolicyData();
40          loadViewData();
41          loadProjectData();
42  
43          dao.flush();
44  
45          return data;
46      }
47  
48      private void loadUserData() {
49          data.systemUser = addUser("SYSTEM");
50          data.userUser = addUser("user");
51          data.jqhaxorUser = addUser("jqhaxor");
52          data.adminUser = addUser("admin");
53      }
54  
55      private User addUser(final String name) {
56          User user = new User();
57          user.setName(name);
58          dao.add(user);
59  
60          return user;
61      }
62  
63      private void loadPolicyData() {
64          data.retiredPolicy = addPolicy("RETIRED", "These codelines should no longer be used.", false);
65          data.devPolicy = addPolicy("DEV", "Under active development, code checked in must be buildable.", true);
66          data.releasePolicy = addPolicy("RELEASE", "Released Software, code checked in must build and pass regression tests; changes should be limited to bug fixes.", true);
67      }
68  
69      private void loadProjectData() {
70          data.tinlizardProject = addProject(Data.TIN_LIZARD, Data.TIN_LIZARD_SCM_URL, "default", data.rewriteView);
71  
72          data.jmorseProject = addProject(Data.JMORSE, Data.JMORSE_SCM_URL, "HEAD", data.rewriteView);
73  
74          Codeline pb = addCodeline(data.jmorseProject, data.defaultRetiredView, data.retiredPolicy, Data.JMORSE_SCM_URL, "TEST_BRANCH", false);
75          Dependency dep = new Dependency();
76          dep.setCodeline(pb);
77          dep.setGroupId(Data.TIN_LIZARD);
78          dep.setArtifactId(Data.TIN_LIZARD);
79          dep.setVersion("default-SNAPSHOT");
80          pb.addDependency(dep);
81          dao.add(dep);
82  
83          data.mavenWarPluginProject = addProject(Data.MAVEN_WAR_PLUGIN, Data.MAVEN_WAR_PLUGIN_SCM_URL, "trunk", data.defaultView);
84          data.mavenScmHGPluginProject = addProject(Data.MAVEN_SCM_HG_PLUGIN, Data.MAVEN_SCM_HG_PLUGIN_SCM_URL, "trunk", data.defaultView);
85      }
86  
87      private Project addProject(final String name, final String scmConnection, final String mainLineName, final View c) {
88          Project p = new Project();
89          p.setName(name);
90          p.setDescription(name + " is a rockn' project.");
91          dao.add(p);
92  
93          addCodeline(p, c, data.devPolicy, scmConnection, mainLineName, true);
94  
95          return p;
96      }
97  
98      private Codeline addCodeline(final Project p, final View view, final Policy policy, final String scmConnection, final String codelineName, final boolean isMainLine) {
99          Codeline codeline = new Codeline();
100 
101         codeline.setName(codelineName);
102         codeline.setDescription("This codeline will bring the heat");
103         codeline.setScmConnection(scmConnection);
104         codeline.setMainLine(isMainLine);
105         codeline.setGroupId(p.getName());
106         codeline.setArtifactId(p.getName());
107         codeline.setVersion(codelineName + "-SNAPSHOT");
108         codeline.setOwner(data.systemUser);
109         codeline.setPolicy(policy);
110         codeline.setView(view);
111         codeline.setProject(p);
112         dao.add(codeline);
113 
114         return codeline;
115     }
116 
117     private void loadViewData() {
118         data.defaultView = addView("Default", "Default View.");
119         data.rewriteView = addView("RewriteStack1", "Re-Write of components implemented in foo to use jBar.");
120         data.defaultRetiredView = addView("DefaultRetired", "Default location for codelines that are not in active use.");
121     }
122 
123     private View addView(final String name, final String description) {
124         View c = new View();
125         c.setName(name);
126         c.setDescription(description);
127         dao.add(c);
128 
129         return c;
130     }
131 
132     private Policy addPolicy(final String name, final String description, final boolean active) {
133         Policy policy = new Policy();
134         policy.setName(name);
135         policy.setDescription(description);
136         policy.setActive(active);
137         dao.add(policy);
138 
139         return policy;
140     }
141 
142     public void run() {
143         loadTestData();
144     }
145 }