001 /*
002 * ----------------------------------------------------------------------
003 * Copyright (C) 2009 Enrique Lara (k957@68k.org)
004 *
005 * TinLizard is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public License
007 * as published by the Free Software Foundation; either version 3.0
008 * of the License, or (at your option) any later version.
009 *
010 * TinLizard is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with TinLizard. If not, see http://www.gnu.org/licenses/.
017 * ----------------------------------------------------------------------
018 */
019 package tinlizard.dataload;
020
021 import tinlizard.dao.jpa.JpaDao;
022
023 import tinlizard.model.Codeline;
024 import tinlizard.model.Dependency;
025 import tinlizard.model.Policy;
026 import tinlizard.model.Project;
027 import tinlizard.model.User;
028 import tinlizard.model.View;
029
030 /**
031 * Utility Class to load test data.
032 */
033 public final class DataLoader implements Runnable {
034 private final JpaDao dao = JpaDao.getInstance();
035 private final Data data = new Data();
036
037 public Data loadTestData() {
038 loadUserData();
039 loadPolicyData();
040 loadViewData();
041 loadProjectData();
042
043 dao.flush();
044
045 return data;
046 }
047
048 private void loadUserData() {
049 data.systemUser = addUser("SYSTEM");
050 data.userUser = addUser("user");
051 data.jqhaxorUser = addUser("jqhaxor");
052 data.adminUser = addUser("admin");
053 }
054
055 private User addUser(final String name) {
056 User user = new User();
057 user.setName(name);
058 dao.add(user);
059
060 return user;
061 }
062
063 private void loadPolicyData() {
064 data.retiredPolicy = addPolicy("RETIRED", "These codelines should no longer be used.", false);
065 data.devPolicy = addPolicy("DEV", "Under active development, code checked in must be buildable.", true);
066 data.releasePolicy = addPolicy("RELEASE", "Released Software, code checked in must build and pass regression tests; changes should be limited to bug fixes.", true);
067 }
068
069 private void loadProjectData() {
070 data.tinlizardProject = addProject(Data.TIN_LIZARD, Data.TIN_LIZARD_SCM_URL, "default", data.rewriteView);
071
072 data.jmorseProject = addProject(Data.JMORSE, Data.JMORSE_SCM_URL, "HEAD", data.rewriteView);
073
074 Codeline pb = addCodeline(data.jmorseProject, data.defaultRetiredView, data.retiredPolicy, Data.JMORSE_SCM_URL, "TEST_BRANCH", false);
075 Dependency dep = new Dependency();
076 dep.setCodeline(pb);
077 dep.setGroupId(Data.TIN_LIZARD);
078 dep.setArtifactId(Data.TIN_LIZARD);
079 dep.setVersion("default-SNAPSHOT");
080 pb.addDependency(dep);
081 dao.add(dep);
082
083 data.mavenWarPluginProject = addProject(Data.MAVEN_WAR_PLUGIN, Data.MAVEN_WAR_PLUGIN_SCM_URL, "trunk", data.defaultView);
084 data.mavenScmHGPluginProject = addProject(Data.MAVEN_SCM_HG_PLUGIN, Data.MAVEN_SCM_HG_PLUGIN_SCM_URL, "trunk", data.defaultView);
085 }
086
087 private Project addProject(final String name, final String scmConnection, final String mainLineName, final View c) {
088 Project p = new Project();
089 p.setName(name);
090 p.setDescription(name + " is a rockn' project.");
091 dao.add(p);
092
093 addCodeline(p, c, data.devPolicy, scmConnection, mainLineName, true);
094
095 return p;
096 }
097
098 private Codeline addCodeline(final Project p, final View view, final Policy policy, final String scmConnection, final String codelineName, final boolean isMainLine) {
099 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 }