List of usage examples for java.util Vector addAll
public boolean addAll(Collection<? extends E> c)
From source file:lu.fisch.unimozer.Diagram.java
private StringList getBlueJSaveContent(Package pack) { StringList content = new StringList(); content.add("#BlueJ package file"); // dependency int dependencyCounter = 0; // composition Hashtable<String, StringList> classUsage = new Hashtable<String, StringList>(); /* Set<String> set = classes.keySet(); Iterator<String> itr = set.iterator(); while (itr.hasNext())// w w w .jav a 2s . c om { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); Vector<MyClass> useWho = new Vector<MyClass>(); StringList usesClassNames = new StringList(); StringList uses = thisClass.getFieldTypes(); for (int u = 0; u < uses.count(); u++) { MyClass otherClass = classes.get(uses.get(u)); if (otherClass != null) // means this class uses the other ones { useWho.add(otherClass); usesClassNames.add(otherClass.getShortName()); dependencyCounter++; content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName()); content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName()); content.add("dependency" + dependencyCounter + ".type=UsesDependency"); } } thisClass.setUsesMyClass(useWho); classUsage.put(thisClass.getShortName(), usesClassNames); } // usage /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next();*/ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); Vector<MyClass> useWho = new Vector<MyClass>(); useWho.addAll(thisClass.getUsesMyClass()); StringList usesClassNames = classUsage.get(thisClass.getShortName()); StringList foundUsage = thisClass.getUsesWho(); for (int f = 0; f < foundUsage.count(); f++) { String usage = foundUsage.get(f); if (!usesClassNames.contains(usage)) { MyClass otherClass = getClass(usage); if (otherClass != null) // menange "otherClass" is a class used by thisClass { useWho.add(otherClass); dependencyCounter++; content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName()); content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName()); content.add("dependency" + dependencyCounter + ".type=UsesDependency"); } } } thisClass.setUsesMyClass(useWho); } /**/ content.add("package.editor.height=900"); content.add("package.editor.width=700"); content.add("package.editor.x=0"); content.add("package.editor.y=0"); content.add("package.numDependencies=" + dependencyCounter); content.add("package.showExtends=true"); content.add("package.showUses=true"); int count = 0; /* itr = set.iterator(); while (itr.hasNext()) { String str = itr.next();*/ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); if (thisClass.getPackagename().equals(pack.getName())) { count++; String type = "ClassTarget"; if (thisClass.getName().contains("abstract")) type = "AbstractTarget"; content.add("target" + count + ".editor.height=700"); content.add("target" + count + ".editor.width=400"); content.add("target" + count + ".editor.x=0"); content.add("target" + count + ".editor.y=0"); content.add("target" + count + ".height=50"); content.add("target" + count + ".name=" + thisClass.getShortName()); content.add("target" + count + ".showInterface=false"); content.add("target" + count + ".type=" + type); content.add("target" + count + ".width=80"); content.add("target" + count + ".x=" + thisClass.getPosition().x); content.add("target" + count + ".y=" + thisClass.getPosition().y); } } StringList added = new StringList(); int i = 0; for (Package myPack : packages.values()) { //System.out.println("Saving package: "+pack.getName()); //System.out.println("Is: "+myPack.getName()+" contained in: "+pack.getName()+" ? "+pack.contains(myPack)); String addPack = myPack.getRelativeName(pack); if (pack.contains(myPack) && !added.contains(addPack)) { /* target2.height=62 target2.name=lu target2.type=PackageTarget target2.width=80 target2.x=200 target2.y=40 */ count++; i++; content.add("target" + count + ".height=80"); content.add("target" + count + ".name=" + addPack); content.add("target" + count + ".type=PackageTarget"); content.add("target" + count + ".width=80"); content.add("target" + count + ".x=" + (i * 100) + ""); content.add("target" + count + ".y=10"); added.add(addPack); } } content.add("package.numTargets=" + (count)); return content; }
From source file:lu.fisch.unimozer.Diagram.java
private StringList getBlueJSaveContent() { StringList content = new StringList(); content.add("#BlueJ package file"); // dependency int dependencyCounter = 0; // composition Hashtable<String, StringList> classUsage = new Hashtable<String, StringList>(); /*//from ww w. j a v a 2 s . c o m Set<String> set = classes.keySet(); Iterator<String> itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); Vector<MyClass> useWho = new Vector<MyClass>(); StringList usesClassNames = new StringList(); StringList uses = thisClass.getFieldTypes(); for (int u = 0; u < uses.count(); u++) { MyClass otherClass = classes.get(uses.get(u)); if (otherClass != null) // means this class uses the other ones { useWho.add(otherClass); usesClassNames.add(otherClass.getShortName()); dependencyCounter++; content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName()); content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName()); content.add("dependency" + dependencyCounter + ".type=UsesDependency"); } } thisClass.setUsesMyClass(useWho); classUsage.put(thisClass.getShortName(), usesClassNames); } // usage /* itr = set.iterator(); while (itr.hasNext()) { String str = itr.next();*/ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); Vector<MyClass> useWho = new Vector<MyClass>(); useWho.addAll(thisClass.getUsesMyClass()); StringList usesClassNames = classUsage.get(thisClass.getShortName()); StringList foundUsage = thisClass.getUsesWho(); for (int f = 0; f < foundUsage.count(); f++) { String usage = foundUsage.get(f); if (!usesClassNames.contains(usage)) { MyClass otherClass = getClass(usage); if (otherClass != null) // menange "otherClass" is a class used by thisClass { useWho.add(otherClass); dependencyCounter++; content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName()); content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName()); content.add("dependency" + dependencyCounter + ".type=UsesDependency"); } } } thisClass.setUsesMyClass(useWho); } /**/ content.add("package.editor.height=900"); content.add("package.editor.width=700"); content.add("package.editor.x=0"); content.add("package.editor.y=0"); content.add("package.numDependencies=" + dependencyCounter); content.add("package.numTargets=" + classes.size()); content.add("package.showExtends=true"); content.add("package.showUses=true"); int count = 0; /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); count++; String type = "ClassTarget"; if (thisClass.getName().contains("abstract")) type = "AbstractTarget"; content.add("target" + count + ".editor.height=700"); content.add("target" + count + ".editor.width=400"); content.add("target" + count + ".editor.x=0"); content.add("target" + count + ".editor.y=0"); content.add("target" + count + ".height=50"); content.add("target" + count + ".name=" + thisClass.getShortName()); content.add("target" + count + ".showInterface=false"); content.add("target" + count + ".type=" + type); content.add("target" + count + ".width=80"); content.add("target" + count + ".x=" + thisClass.getPosition().x); content.add("target" + count + ".y=" + thisClass.getPosition().y); } return content; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * @param taxonTreeDef/* www . j a v a2s .c o m*/ * @return */ public static List<Object> createSimpleBotanyTaxonTree(final TaxonTreeDef taxonTreeDef) { log.info("createSimpleBotanyTaxonTree " + taxonTreeDef.getName()); Vector<Object> newObjs = new Vector<Object>(); Set<TaxonTreeDefItem> newItems; Object[][] taxonItems = { { TaxonTreeDef.TAXONOMY_ROOT, "Taxonomy Root", true, false }, { TaxonTreeDef.KINGDOM, "Kingdom", true, false }, { TaxonTreeDef.PHYLUM, "Division", false, false }, { TaxonTreeDef.CLASS, "Class", false, false }, { TaxonTreeDef.ORDER, "Order", false, false }, { TaxonTreeDef.FAMILY, "Family", false, false }, { TaxonTreeDef.GENUS, "Genus", true, true }, { TaxonTreeDef.SPECIES, "Species", false, true }, { TaxonTreeDef.VARIETY, "Variety", false, true }, }; newItems = TreeFactory.addStandardTaxonDefItems(taxonTreeDef, taxonItems); newObjs.addAll(newItems); // 0 - 27 for (TaxonTreeDefItem item : newItems) { if (item.getRankId().equals(TaxonTreeDef.GENUS)) { item.setFormatToken("%G"); } else if (item.getRankId().equals(TaxonTreeDef.SPECIES)) { item.setFormatToken("%S"); } else if (item.getRankId().equals(TaxonTreeDef.SUBSPECIES)) { item.setFormatToken("%SS"); } } Taxon life = createTaxon(taxonTreeDef, null, "Life", TaxonTreeDef.TAXONOMY_ROOT); Taxon Plantae = createTaxon(taxonTreeDef, life, "Plantae", TaxonTreeDef.KINGDOM); Taxon Magnoliophyta = createTaxon(taxonTreeDef, Plantae, "Magnoliophyta", TaxonTreeDef.PHYLUM); Taxon Magnoliopsida = createTaxon(taxonTreeDef, Magnoliophyta, "Magnoliopsida", TaxonTreeDef.CLASS); Taxon Sapindales = createTaxon(taxonTreeDef, Magnoliopsida, "Sapindales", TaxonTreeDef.ORDER); Taxon Sapindaceae = createTaxon(taxonTreeDef, Sapindales, "Sapindaceae", TaxonTreeDef.FAMILY); Taxon Acer = createTaxon(taxonTreeDef, Sapindaceae, "Acer", TaxonTreeDef.GENUS); newObjs.add(life); newObjs.add(Plantae); newObjs.add(Magnoliophyta); newObjs.add(Magnoliopsida); newObjs.add(Sapindales); newObjs.add(Sapindaceae); newObjs.add(Acer); String[] speciesNames = { "saccharum", "platanoides", "circinatum", "palmatum" }; String[] commonNames = { "Sugar Maple", "Norway Maple", "Vine Maple", "apanese Maple" }; List<Object> kids = createTaxonChildren(taxonTreeDef, Acer, speciesNames, commonNames, TaxonTreeDef.SPECIES); newObjs.addAll(kids); Taxon Aesculus = createTaxon(taxonTreeDef, Sapindaceae, "Aesculus", TaxonTreeDef.GENUS); newObjs.add(Aesculus); String[] speciesNames2 = { "arguta", "californica", "chinensis", "glabra" }; String[] commonNames2 = { "Texas Buckeye", "California Buckeye", "Chinese Horse-chestnut", "Ohio Buckeye" }; kids = createTaxonChildren(taxonTreeDef, Aesculus, speciesNames2, commonNames2, TaxonTreeDef.SPECIES); newObjs.addAll(kids); TreeHelper.fixFullnameForNodeAndDescendants(life); life.setNodeNumber(1); fixNodeNumbersFromRoot(life); return newObjs; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * @param taxonTreeDef/* ww w .java 2 s . co m*/ * @param doShallow * @return */ public static List<Object> createSimpleFishTaxonTree(final TaxonTreeDef taxonTreeDef, final boolean doShallow) { log.info("createSimpleFishTaxonTree " + taxonTreeDef.getName()); Vector<Object> newObjs = new Vector<Object>(); Set<TaxonTreeDefItem> newItems; if (doShallow) { Object[][] taxonItems = { { TaxonTreeDef.TAXONOMY_ROOT, "Taxonomy Root", true, false }, { TaxonTreeDef.ORDER, "Order", true, false }, { TaxonTreeDef.SUBORDER, "Suborder", false, false }, { TaxonTreeDef.FAMILY, "Family", false, false }, { TaxonTreeDef.GENUS, "Genus", true, true }, { TaxonTreeDef.SPECIES, "Species", false, true }, }; newItems = TreeFactory.addStandardTaxonDefItems(taxonTreeDef, taxonItems); } else { newItems = TreeFactory.addStandardTaxonDefItems(taxonTreeDef); } newObjs.addAll(newItems); // 0 - 27 for (TaxonTreeDefItem item : newItems) { if (item.getRankId().equals(TaxonTreeDef.GENUS)) { item.setFormatToken("%G"); } else if (item.getRankId().equals(TaxonTreeDef.SPECIES)) { item.setFormatToken("%S"); } else if (item.getRankId().equals(TaxonTreeDef.SUBSPECIES)) { item.setFormatToken("%SS"); } } Taxon life = createTaxon(taxonTreeDef, null, "Life", TaxonTreeDef.TAXONOMY_ROOT); Taxon animalia = null; Taxon chordata = null; Taxon vertebrata = null; Taxon osteichthyes = null; Taxon actinopterygii = null; Taxon neopterygii = null; Taxon teleostei = null; Taxon acanthopterygii = null; if (!doShallow) { animalia = createTaxon(taxonTreeDef, life, "Animalia", TaxonTreeDef.KINGDOM); chordata = createTaxon(taxonTreeDef, animalia, "Chordata", TaxonTreeDef.PHYLUM); vertebrata = createTaxon(taxonTreeDef, chordata, "Vertebrata", TaxonTreeDef.SUBPHYLUM); osteichthyes = createTaxon(taxonTreeDef, vertebrata, "Osteichthyes", TaxonTreeDef.SUPERCLASS); actinopterygii = createTaxon(taxonTreeDef, osteichthyes, "Actinopterygii", TaxonTreeDef.CLASS); neopterygii = createTaxon(taxonTreeDef, actinopterygii, "Neopterygii", TaxonTreeDef.SUBCLASS); teleostei = createTaxon(taxonTreeDef, neopterygii, "Teleostei", TaxonTreeDef.INFRACLASS); acanthopterygii = createTaxon(taxonTreeDef, teleostei, "Acanthopterygii", TaxonTreeDef.SUPERORDER); } Taxon perciformes = createTaxon(taxonTreeDef, doShallow ? life : acanthopterygii, "Perciformes", TaxonTreeDef.ORDER); Taxon percoidei = createTaxon(taxonTreeDef, perciformes, "Percoidei", TaxonTreeDef.SUBORDER); Taxon percidae = createTaxon(taxonTreeDef, percoidei, "Percidae", TaxonTreeDef.FAMILY); Taxon ammocrypta = createTaxon(taxonTreeDef, percidae, "Ammocrypta", TaxonTreeDef.GENUS); ammocrypta.setCommonName("sand darters"); newObjs.add(life); if (!doShallow) { newObjs.add(animalia); newObjs.add(chordata); newObjs.add(vertebrata); newObjs.add(osteichthyes); newObjs.add(actinopterygii); newObjs.add(neopterygii); newObjs.add(teleostei); newObjs.add(acanthopterygii); } newObjs.add(perciformes); newObjs.add(percoidei); newObjs.add(percidae); newObjs.add(ammocrypta); // 28 - 40 String[] speciesNames = { "asprella", "beanii", "bifascia", "clara", "meridiana", "pellucida", "vivax" }; String[] commonNames = { "crystal darter", "naked sand darter", "Florida sand darter", "western sand darter", "southern sand darter", "eastern sand darter", "scaly sand darter" }; List<Object> kids = createTaxonChildren(taxonTreeDef, ammocrypta, speciesNames, commonNames, TaxonTreeDef.SPECIES); // 41 - 47 newObjs.addAll(kids); Taxon carangidae = createTaxon(taxonTreeDef, percoidei, "Carangidae", TaxonTreeDef.FAMILY); Taxon caranx = createTaxon(taxonTreeDef, carangidae, "Caranx", TaxonTreeDef.GENUS); // 48 newObjs.add(carangidae); // 49 newObjs.add(caranx); String[] speciesNames2 = { "bartholomaei", "caballus", "caninus", "crysos", "dentex", "hippos", "latus" }; String[] commonNames2 = { "yellow jack", "green jack", "Pacific crevalle jack", "blue runner", "white trevally", "crevalle jack", "horse-eye jack" }; kids = createTaxonChildren(taxonTreeDef, caranx, speciesNames2, commonNames2, TaxonTreeDef.SPECIES); // 50 - 56 newObjs.addAll(kids); int baseInx = 53 - (doShallow ? 30 : 0); // setup a couple of synonyms (and supporting nodes) Taxon fusus = createTaxon(taxonTreeDef, caranx, "fusus", TaxonTreeDef.SPECIES); fusus.setCommonName("Blue runner"); Taxon crysos = (Taxon) newObjs.get(baseInx); fusus.setAcceptedTaxon(crysos); fusus.setIsAccepted(false); Taxon carangus = createTaxon(taxonTreeDef, caranx, "carangus", TaxonTreeDef.SPECIES); carangus.setCommonName("Blacktailed trevally"); Taxon hippos = (Taxon) newObjs.get(baseInx + 2); carangus.setAcceptedTaxon(hippos); carangus.setIsAccepted(false); Taxon etheostoma = createTaxon(taxonTreeDef, percidae, "Etheostoma", TaxonTreeDef.GENUS); etheostoma.setCommonName("smoothbelly darters"); Taxon meridianum = createTaxon(taxonTreeDef, etheostoma, "meridianum", TaxonTreeDef.SPECIES); meridianum.setCommonName("southern sand darter"); Taxon merdiana = (Taxon) newObjs.get(baseInx - 8); merdiana.setAcceptedTaxon(meridianum); merdiana.setIsAccepted(false); Taxon pellucidum = createTaxon(taxonTreeDef, etheostoma, "pellucidum", TaxonTreeDef.SPECIES); pellucidum.setCommonName("eastern sand darter"); Taxon pellucida = (Taxon) newObjs.get(baseInx - 7); pellucidum.setAcceptedTaxon(pellucida); pellucidum.setIsAccepted(false); Taxon ethVivax = createTaxon(taxonTreeDef, etheostoma, "vivax", TaxonTreeDef.SPECIES); ethVivax.setCommonName("scaly sand darter"); Taxon vivax = (Taxon) newObjs.get(baseInx - 6); ethVivax.setAcceptedTaxon(vivax); ethVivax.setIsAccepted(false); Taxon beani = createTaxon(taxonTreeDef, ammocrypta, "beani", TaxonTreeDef.SPECIES); beani.setCommonName("naked sand darter"); Taxon beanii = (Taxon) newObjs.get(baseInx - 11); beani.setAcceptedTaxon(beanii); beani.setIsAccepted(false); Taxon crystallaria = createTaxon(taxonTreeDef, percidae, "Crystallaria", TaxonTreeDef.GENUS); crystallaria.setCommonName("crystal darters"); Taxon crysAsprella = createTaxon(taxonTreeDef, crystallaria, "asprella", TaxonTreeDef.SPECIES); crysAsprella.setCommonName("crystal darter"); Taxon asprella = (Taxon) newObjs.get(baseInx - 12); asprella.setAcceptedTaxon(crysAsprella); asprella.setIsAccepted(false); newObjs.add(fusus); newObjs.add(carangus); newObjs.add(etheostoma); newObjs.add(meridianum); newObjs.add(pellucidum); newObjs.add(ethVivax); newObjs.add(beani); newObjs.add(crystallaria); newObjs.add(crysAsprella); // 57 - 65 TreeHelper.fixFullnameForNodeAndDescendants(life); life.setNodeNumber(1); fixNodeNumbersFromRoot(life); return newObjs; }
From source file:org.unitime.timetable.test.StudentSectioningTest.java
private static void testSectioning(Element studentElement, Element response, Session session) { try {/*from w w w .j a v a2 s . c o m*/ System.out.print("Request:"); new XMLWriter(System.out, OutputFormat.createPrettyPrint()).write(studentElement); } catch (Exception e) { } Student student = new Student(Long.parseLong(studentElement.attributeValue("key"))); sLog.info(" loading student " + student.getId()); String courseNumbersMustBeUnique = ApplicationProperties.getProperty("tmtbl.courseNumber.unique", "true"); StudentSctBBTest sbt = null; boolean commit = false; Vector messages = new Vector(); if (studentElement.element("retrieveCourseRequests") != null) { loadStudent(session, student, messages); sbt = new StudentSctBBTest(student); for (Iterator e = student.getRequests().iterator(); e.hasNext();) { Request request = (Request) e.next(); if (request.getInitialAssignment() != null) request.assign(0, request.getInitialAssignment()); } for (Iterator e = student.getRequests().iterator(); e.hasNext();) { Request request = (Request) e.next(); if (request instanceof FreeTimeRequest) { Enrollment enrollment = (Enrollment) request.values().get(0); if (sbt.conflictValues(enrollment).isEmpty()) request.assign(0, enrollment); } } } Element courseRequestsElement = studentElement.element("updateCourseRequests"); if (courseRequestsElement == null) { sLog.warn(" No course requests for student " + student.getId()); } else { long reqId = 0; int priority = 0; commit = "true".equals(courseRequestsElement.attributeValue("commit")); for (Iterator i = courseRequestsElement.elementIterator(); i.hasNext();) { Element requestElement = (Element) i.next(); boolean alternative = "true".equals(requestElement.attributeValue("alternative")); if ("freeTime".equals(requestElement.getName())) { String days = requestElement.attributeValue("days"); String startTime = requestElement.attributeValue("startTime"); String length = requestElement.attributeValue("length"); String endTime = requestElement.attributeValue("endTime"); FreeTimeRequest ftRequest = new FreeTimeRequest(reqId++, priority++, alternative, student, makeTime(session.getDefaultDatePattern(), days, startTime, endTime, length)); sLog.info(" added " + ftRequest); } else if ("courseOffering".equals(requestElement.getName())) { String subjectArea = requestElement.attributeValue("subjectArea"); String courseNumber = requestElement.attributeValue("courseNumber"); boolean waitlist = "true".equals(requestElement.attributeValue("waitlist", "false")); Long timeStamp = (requestElement.attributeValue("timeStamp") == null ? null : Long.parseLong(requestElement.attributeValue("timeStamp"))); CourseOffering co = null; if (courseNumbersMustBeUnique.equalsIgnoreCase("true")) { co = CourseOffering.findBySessionSubjAreaAbbvCourseNbr(session.getUniqueId(), subjectArea, courseNumber); } else { String title = requestElement.attributeValue("title"); co = CourseOffering.findBySessionSubjAreaAbbvCourseNbrTitle(session.getUniqueId(), subjectArea, courseNumber, title); } if (co == null) { sLog.warn(" Course " + subjectArea + " " + courseNumber + " not found."); continue; } Vector courses = new Vector(); courses.add(loadCourse(co, student.getId())); for (Iterator j = requestElement.elementIterator("alternative"); j.hasNext();) { Element altElement = (Element) j.next(); String altSubjectArea = altElement.attributeValue("subjectArea"); String altCourseNumber = altElement.attributeValue("courseNumber"); CourseOffering aco = null; if (courseNumbersMustBeUnique.equalsIgnoreCase("true")) { aco = CourseOffering.findBySessionSubjAreaAbbvCourseNbr(session.getUniqueId(), altSubjectArea, altCourseNumber); } else { String altTitle = altElement.attributeValue("title"); aco = CourseOffering.findBySessionSubjAreaAbbvCourseNbrTitle(session.getUniqueId(), altSubjectArea, altCourseNumber, altTitle); } if (aco != null) courses.add(loadCourse(aco, student.getId())); } CourseRequest cRequest = new CourseRequest(reqId++, priority++, alternative, student, courses, waitlist, timeStamp); cRequest.values(); sLog.info(" added " + cRequest); } } Element requestScheduleElement = studentElement.element("requestSchedule"); if (requestScheduleElement != null) { for (Iterator i = requestScheduleElement.elementIterator("courseOffering"); i.hasNext();) { Element courseOfferingElement = (Element) i.next(); String subjectArea = courseOfferingElement.attributeValue("subjectArea"); String courseNumber = courseOfferingElement.attributeValue("courseNumber"); CourseOffering co = null; if (courseNumbersMustBeUnique.equalsIgnoreCase("true")) { co = CourseOffering.findBySessionSubjAreaAbbvCourseNbr(session.getUniqueId(), subjectArea, courseNumber); } else { String title = courseOfferingElement.attributeValue("title"); co = CourseOffering.findBySessionSubjAreaAbbvCourseNbrTitle(session.getUniqueId(), subjectArea, courseNumber, title); } if (co == null) { sLog.warn(" Course " + subjectArea + " " + courseNumber + " not found."); continue; } for (Iterator e = student.getRequests().iterator(); e.hasNext();) { Request request = (Request) e.next(); if (request instanceof CourseRequest) { CourseRequest courseRequest = (CourseRequest) request; Course course = courseRequest.getCourse(co.getUniqueId().longValue()); Config config = null; if (course == null) continue; Set assignedSections = new HashSet(); int nrClasses = 0; for (Iterator j = courseOfferingElement.elementIterator("class"); j .hasNext(); nrClasses++) { Element classEl = (Element) j.next(); String assignmentId = classEl.attributeValue("assignmentId"); Section section = (assignmentId == null ? null : course.getOffering().getSection(Long.parseLong(assignmentId))); if (section != null) { assignedSections.add(section); if (config == null) config = section.getSubpart().getConfig(); } for (Iterator k = classEl.elementIterator("choice"); k.hasNext();) { Element choiceEl = (Element) k.next(); Choice choice = new Choice(course.getOffering(), choiceEl.attributeValue("id")); if ("select".equals(choiceEl.attributeValue("selection"))) { courseRequest.getSelectedChoices().add(choice); sLog.info(" add selection " + choice); } else { courseRequest.getWaitlistedChoices().add(choice); sLog.info(" add waitlist " + choice); } } } if (nrClasses == assignedSections.size()) { courseRequest .setInitialAssignment(new Enrollment(request, 0, config, assignedSections)); sLog.info(" initial assignment " + courseRequest.getInitialAssignment()); } } } } } else { sLog.warn(" No schedule requests for student " + student.getId()); } sLog.info(" sectioning student " + student.getId()); sbt = new StudentSctBBTest(student); Model model = sbt.getSolution().getModel(); messages.addAll(sbt.getMessages()); sLog.info(" info: " + model.getInfo()); if (commit) saveStudent(session, student, messages); } Element studentResponseElement = response.addElement("student"); studentResponseElement.addAttribute("key", String.valueOf(student.getId())); Element ackResponseElement = studentResponseElement.addElement("acknowledgement"); ackResponseElement.addAttribute("result", "ok"); Element courseReqResponseElement = studentResponseElement.addElement("courseRequests"); for (Iterator e = messages.iterator(); e.hasNext();) { StudentSctBBTest.Message message = (StudentSctBBTest.Message) e.next(); ackResponseElement.addElement("message").addAttribute("type", message.getLevelString()) .setText(message.getMessage()); } for (Iterator e = student.getRequests().iterator(); e.hasNext();) { Request request = (Request) e.next(); Element reqElement = null; if (request instanceof FreeTimeRequest) { FreeTimeRequest ftRequest = (FreeTimeRequest) request; reqElement = courseReqResponseElement.addElement("freeTime"); reqElement.addAttribute("days", dayCode2days(ftRequest.getTime().getDayCode())); reqElement.addAttribute("startTime", startSlot2startTime(ftRequest.getTime().getStartSlot())); reqElement.addAttribute("endTime", timeLocation2endTime(ftRequest.getTime())); reqElement.addAttribute("length", String.valueOf(Constants.SLOT_LENGTH_MIN * ftRequest.getTime().getLength())); sLog.info(" added " + ftRequest); } else { CourseRequest courseRequest = (CourseRequest) request; reqElement = courseReqResponseElement.addElement("courseOffering"); for (Iterator f = courseRequest.getCourses().iterator(); f.hasNext();) { Course course = (Course) f.next(); Element element = (reqElement.attribute("subjectArea") == null ? reqElement : reqElement.addElement("alternative")); element.addAttribute("subjectArea", course.getSubjectArea()); element.addAttribute("courseNumber", course.getCourseNumber()); CourseOffering co = CourseOffering.findByUniqueId(course.getId()); element.addAttribute("title", (co.getTitle() != null ? co.getTitle() : "")); } reqElement.addAttribute("waitlist", courseRequest.isWaitlist() ? "true" : "false"); if (courseRequest.getTimeStamp() != null) reqElement.addAttribute("timeStamp", courseRequest.getTimeStamp().toString()); sLog.info(" added " + courseRequest); } if (request.isAlternative()) reqElement.addAttribute("alternative", "true"); } Comparator choiceComparator = new Comparator() { public int compare(Object o1, Object o2) { Choice c1 = (Choice) o1; Choice c2 = (Choice) o2; if (c1.getTime() == null) { if (c2.getTime() != null) return -1; } else if (c2.getTime() == null) return 1; if (c1.getTime() != null) { int cmp = -Double.compare(c1.getTime().getDayCode(), c2.getTime().getDayCode()); if (cmp != 0) return cmp; cmp = Double.compare(c1.getTime().getStartSlot(), c2.getTime().getStartSlot()); if (cmp != 0) return cmp; cmp = c1.getTime().getDatePatternName().compareTo(c2.getTime().getDatePatternName()); if (cmp != 0) return cmp; } if (c1.getInstructorNames() == null) { if (c2.getInstructorNames() != null) return -1; } else if (c2.getInstructorNames() == null) return 1; if (c1.getInstructorNames() != null) { int cmp = c1.getInstructorNames().compareTo(c2.getInstructorNames()); if (cmp != 0) return cmp; } return c1.getId().compareTo(c2.getId()); } }; boolean generateRandomAvailability = (student.getId() < 0); Element scheduleResponseElement = studentResponseElement.addElement("schedule"); scheduleResponseElement.addAttribute("type", (commit ? "actual" : "proposed")); for (Iterator e = student.getRequests().iterator(); e.hasNext();) { Request request = (Request) e.next(); if (request.getAssignment() == null) { sLog.info(" request " + request + " has no assignment"); if (request instanceof CourseRequest && ((CourseRequest) request).isWaitlist() && request.getStudent().canAssign(request)) { Element courseOfferingElement = scheduleResponseElement.addElement("courseOffering"); Course course = (Course) ((CourseRequest) request).getCourses().get(0); courseOfferingElement.addAttribute("subjectArea", course.getSubjectArea()); courseOfferingElement.addAttribute("courseNumber", course.getCourseNumber()); CourseOffering co = CourseOffering.findByUniqueId(course.getId()); courseOfferingElement.addAttribute("title", co.getTitle()); courseOfferingElement.addAttribute("waitlist", ((CourseRequest) request).isWaitlist() ? "true" : "false"); if (((CourseRequest) request).getTimeStamp() != null) courseOfferingElement.addAttribute("timeStamp", ((CourseRequest) request).getTimeStamp().toString()); } continue; } if (request instanceof FreeTimeRequest) { FreeTimeRequest ftRequest = (FreeTimeRequest) request; Element ftElement = scheduleResponseElement.addElement("freeTime"); ftElement.addAttribute("days", dayCode2days(ftRequest.getTime().getDayCode())); ftElement.addAttribute("startTime", startSlot2startTime(ftRequest.getTime().getStartSlot())); ftElement.addAttribute("endTime", timeLocation2endTime(ftRequest.getTime())); ftElement.addAttribute("length", String.valueOf(Constants.SLOT_LENGTH_MIN * ftRequest.getTime().getLength())); if (ftRequest.getTime() != null) ftElement.addAttribute("time", ftRequest.getTime().getDayHeader() + " " + ftRequest.getTime().getStartTimeHeader() + " - " + ftRequest.getTime().getEndTimeHeader()); else ftElement.addAttribute("time", "Arr Hrs"); } else { CourseRequest courseRequest = (CourseRequest) request; Element courseOfferingElement = scheduleResponseElement.addElement("courseOffering"); Enrollment enrollment = (Enrollment) request.getAssignment(); Set unusedInstructionalTypes = null; Offering offering = null; HashSet availableChoices = null; Vector assignments = new Vector(enrollment.getAssignments()); Collections.sort(assignments, new Comparator() { public int compare(Object o1, Object o2) { Section s1 = (Section) o1; Section s2 = (Section) o2; return s1.getSubpart().compareTo(s2.getSubpart()); } }); for (Iterator i = assignments.iterator(); i.hasNext();) { Section section = (Section) i.next(); if (courseOfferingElement.attribute("subjectArea") == null) { Course course = enrollment.getCourse(); courseOfferingElement.addAttribute("subjectArea", course.getSubjectArea()); courseOfferingElement.addAttribute("courseNumber", course.getCourseNumber()); CourseOffering co = CourseOffering.findByUniqueId(course.getId()); courseOfferingElement.addAttribute("title", co.getTitle()); } if (offering == null) { offering = section.getSubpart().getConfig().getOffering(); if (generateRandomAvailability) { availableChoices = generateAvailableChoices(offering, new Random(13031978l), 0.75); } else { availableChoices = new HashSet(); for (Iterator j = courseRequest.getAvaiableEnrollmentsSkipSameTime().iterator(); j .hasNext();) { Enrollment enr = (Enrollment) j.next(); for (Iterator k = enr.getAssignments().iterator(); k.hasNext();) { Section s = (Section) k.next(); if (s.getLimit() > 0 && s.getPenalty() <= sAvailableThreshold) availableChoices.add(s.getChoice()); } } } } if (unusedInstructionalTypes == null) unusedInstructionalTypes = section.getSubpart().getConfig().getOffering() .getInstructionalTypes(); unusedInstructionalTypes.remove(section.getSubpart().getInstructionalType()); Element classElement = courseOfferingElement.addElement("class"); classElement.addAttribute("id", section.getSubpart().getInstructionalType()); classElement.addAttribute("assignmentId", String.valueOf(section.getId())); if (section.getSubpart().getParent() != null) classElement.addAttribute("parent", section.getSubpart().getParent().getInstructionalType()); classElement.addAttribute("name", section.getSubpart().getName()); if (section.getTime() != null) { classElement.addAttribute("days", dayCode2days(section.getTime().getDayCode())); classElement.addAttribute("startTime", startSlot2startTime(section.getTime().getStartSlot())); classElement.addAttribute("endTime", timeLocation2endTime(section.getTime())); //classElement.addAttribute("length", String.valueOf(Constants.SLOT_LENGTH_MIN*section.getTime().getLength())); if (section.getTime().getDatePatternName() != null) classElement.addAttribute("date", section.getTime().getDatePatternName()); classElement.addAttribute("time", section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader() + " - " + section.getTime().getEndTimeHeader()); } else classElement.addAttribute("time", "Arr Hrs"); if (section.getNrRooms() > 0) { String location = ""; for (Iterator f = section.getRooms().iterator(); f.hasNext();) { RoomLocation rl = (RoomLocation) f.next(); location += rl.getName(); if (f.hasNext()) location += ","; } classElement.addAttribute("location", location); } if (section.getChoice().getInstructorNames() != null) classElement.addAttribute("instructor", section.getChoice().getInstructorNames()); Vector choices = new Vector(section.getSubpart().getConfig().getOffering() .getChoices(section.getSubpart().getInstructionalType())); Collections.sort(choices, choiceComparator); for (Iterator f = choices.iterator(); f.hasNext();) { Choice choice = (Choice) f.next(); Element choiceEl = classElement.addElement("choice"); choiceEl.addAttribute("id", choice.getId()); choiceEl.addAttribute("available", (availableChoices == null ? "true" : availableChoices.contains(choice) ? "true" : "false")); if (choice.getTime() != null) { choiceEl.addAttribute("days", dayCode2days(choice.getTime().getDayCode())); choiceEl.addAttribute("startTime", startSlot2startTime(choice.getTime().getStartSlot())); choiceEl.addAttribute("endTime", timeLocation2endTime(choice.getTime())); if (choice.getTime().getDatePatternName() != null) choiceEl.addAttribute("date", choice.getTime().getDatePatternName()); choiceEl.addAttribute("time", choice.getTime().getDayHeader() + " " + choice.getTime().getStartTimeHeader() + " - " + choice.getTime().getEndTimeHeader()); } else choiceEl.addAttribute("time", "Arr Hrs"); if (choice.equals(section.getChoice())) choiceEl.addAttribute("available", "true"); if (courseRequest.getSelectedChoices().isEmpty() && choice.equals(section.getChoice())) { choiceEl.addAttribute("selection", "select"); } else if (courseRequest.getSelectedChoices().contains(choice)) { choiceEl.addAttribute("selection", "select"); if (generateRandomAvailability) choiceEl.addAttribute("available", "true"); } else if (courseRequest.getWaitlistedChoices().contains(choice)) { choiceEl.addAttribute("selection", "wait"); if (generateRandomAvailability) choiceEl.addAttribute("available", "false"); } if (choice.getInstructorNames() != null) choiceEl.addAttribute("instructor", choice.getInstructorNames()); exportDependencies(choiceEl, choice, choice.getParentSections()); } } if (unusedInstructionalTypes != null) { for (Iterator i = unusedInstructionalTypes.iterator(); i.hasNext();) { String unusedInstructionalType = (String) i.next(); Element classElement = courseOfferingElement.addElement("class"); classElement.addAttribute("id", unusedInstructionalType); classElement.addAttribute("name", ((Subpart) offering.getSubparts(unusedInstructionalType).iterator().next()) .getName()); Vector choices = new Vector(offering.getChoices(unusedInstructionalType)); Collections.sort(choices, choiceComparator); for (Iterator f = choices.iterator(); f.hasNext();) { Choice choice = (Choice) f.next(); Element choiceEl = classElement.addElement("choice"); choiceEl.addAttribute("id", choice.getId()); choiceEl.addAttribute("available", (availableChoices == null ? "true" : availableChoices.contains(choice) ? "true" : "false")); if (choice.getTime() != null) { choiceEl.addAttribute("days", dayCode2days(choice.getTime().getDayCode())); choiceEl.addAttribute("startTime", startSlot2startTime(choice.getTime().getStartSlot())); choiceEl.addAttribute("endTime", timeLocation2endTime(choice.getTime())); if (choice.getTime().getDatePatternName() != null) choiceEl.addAttribute("date", choice.getTime().getDatePatternName()); choiceEl.addAttribute("time", choice.getTime().getDayHeader() + " " + choice.getTime().getStartTimeHeader() + " - " + choice.getTime().getEndTimeHeader()); } else choiceEl.addAttribute("time", "Arr Hrs"); if (courseRequest.getWaitlistedChoices().contains(choice)) choiceEl.addAttribute("selection", "wait"); if (choice.getInstructorNames() != null) choiceEl.addAttribute("instructor", choice.getInstructorNames()); exportDependencies(choiceEl, choice, choice.getParentSections()); } } } } sLog.info(" added " + request.getAssignment()); } /* try { System.out.print("Response:"); new XMLWriter(System.out,OutputFormat.createPrettyPrint()).write(studentResponseElement); } catch (Exception e) {} */ }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * Creates a single disciplineType collection. * @param disciplineName the name of the Discipline to use * @param disciplineName the disciplineType name * @return the entire list of DB object to be persisted *//* w ww . j a v a 2 s . com*/ public List<Object> createHugeBotanyCollection(final DisciplineType disciplineType, final Institution institution, final SpecifyUser user, final CollectionChoice choice) { frame.setProcess(0, 16); frame.setDesc("Creating Botany..."); createStep = 0; startTx(); Division division = createDivision(institution, disciplineType.getName(), "Botany", "BT", "Botany"); // create tree defs (later we will make the def items and nodes) TaxonTreeDef taxonTreeDef = createTaxonTreeDef("Taxon", TreeDefIface.FORWARD); GeographyTreeDef geoTreeDef = createGeographyTreeDef("Geography", TreeDefIface.REVERSE); GeologicTimePeriodTreeDef gtpTreeDef = createGeologicTimePeriodTreeDef("Chronos Stratigraphy", TreeDefIface.REVERSE); LithoStratTreeDef lithoStratTreeDef = createLithoStratTreeDef("LithoStrat"); boolean buildStorageTree = false; if (stgTreeDef == null) { stgTreeDef = createStorageTreeDef("Storage", TreeDefIface.REVERSE); institution.setStorageTreeDef(stgTreeDef); buildStorageTree = true; } lithoStratTreeDef.setRemarks("A simple super, group, formation, member, bed Litho Stratigraphy tree"); Discipline discipline = createDiscipline(division, disciplineType.getName(), disciplineType.getTitle(), dataType, taxonTreeDef, geoTreeDef, gtpTreeDef, lithoStratTreeDef); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); persist(institution); persist(division); persist(discipline); AppContextMgr.getInstance().setClassObject(Division.class, division); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); loadSchemaLocalization(discipline, SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance(), choice.getCatalogNumberingFmtName(), choice.getAccessionNumberingFmtName()); //////////////////////////////// // Create the really high-level stuff //////////////////////////////// String title = initPrefs.getProperty("useragent.title", "mr"); String firstName = initPrefs.getProperty("useragent.firstname", "Test"); String lastName = initPrefs.getProperty("useragent.lastname", "User"); String midInit = initPrefs.getProperty("useragent.midinit", "A"); String abbrev = initPrefs.getProperty("useragent.abbrev", "tu"); String email = initPrefs.getProperty("useragent.email", "testuser@ku.edu"); String userType = initPrefs.getProperty("useragent.usertype", SpecifyUserTypes.UserType.Manager.toString()); System.out.println("----- User Agent -----"); System.out.println("Title: " + title); System.out.println("FirstName: " + firstName); System.out.println("LastName: " + lastName); System.out.println("MidInit: " + midInit); System.out.println("Abbrev: " + abbrev); System.out.println("Email: " + email); System.out.println("UserType: " + userType); Agent userAgent = createAgent(title, firstName, midInit, lastName, abbrev, email); discipline.addReference(userAgent, "agents"); user.addReference(userAgent, "agents"); persist(discipline); persist(userAgent); persist(user); frame.setProcess(++createStep); Pair<AutoNumberingScheme, AutoNumberingScheme> pairANS = createAutoNumberingSchemes(choice); AutoNumberingScheme cns = pairANS.first; AutoNumberingScheme accessionNS = pairANS.second; persist(cns); persist(accessionNS); commitTx(); startTx(); //////////////////////////////// // Create Collection //////////////////////////////// log.info("Creating a Collection"); Collection collection = createCollection("KUBOT", "Botany", choice.getCatalogNumberingFmtName(), cns, discipline); persist(collection); AppContextMgr.getInstance().setClassObject(Collection.class, collection); division.addReference(accessionNS, "numberingSchemes"); persist(division); commitTx(); doShowHideTablesAndFields(null, discipline); doShowHideTablesAndFields(disciplineType.getName(), discipline); frame.setProcess(++createStep); startTx(); //DBTableIdMgr schema = new DBTableIdMgr(false); //schema.initialize(new File(XMLHelper.getConfigDirPath("specify_datamodel.xml"))); //loadSchemaLocalization(discipline, SpLocaleContainer, schema); //buildDarwinCoreSchema(discipline); AppContextMgr.getInstance().setClassObject(SpecifyUser.class, user); user.addReference(userAgent, "agents"); persist(user); Journal journal = createJournalsAndReferenceWork(); frame.setProcess(++createStep); //////////////////////////////// // build the tree def items and nodes //////////////////////////////// List<Object> taxa = createSimpleBotanyTaxonTree(taxonTreeDef); List<Object> geos = createSimpleGeography(geoTreeDef, true); List<Object> gtps = createSimpleGeologicTimePeriod(gtpTreeDef, true); List<Object> lithoStrats = createSimpleLithoStrat(lithoStratTreeDef, true); persist(journal); persist(taxa); persist(geos); persist(buildStorageTree ? createSimpleStorage(stgTreeDef) : null); persist(gtps); persist(lithoStrats); commitTx(); frame.setProcess(++createStep); //////////////////////////////// // picklists //////////////////////////////// log.info("Creating picklists"); frame.setDesc("Creating PickLists..."); //frame.setProcess(++createStep); createPickLists(session, null); createPickLists(session, discipline); Vector<Object> dataObjects = new Vector<Object>(); startTx(); standardQueries(dataObjects, userAgent); persist(dataObjects); dataObjects.clear(); //BldrPickList colMethods = createPickLists(); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // localities //////////////////////////////// String POINT = "Point"; frame.setDesc("Creating localities"); log.info("Creating localities"); frame.setProcess(0, NUM_LOCALTIES); Vector<Locality> localities = new Vector<Locality>(); Vector<Object> evictList = new Vector<Object>(); for (int i = 0; i < NUM_LOCALTIES; i++) { Locality locality = createLocality("Unnamed forest stream pond", (Geography) geos.get(12)); locality.setLatLongType(POINT); locality.setOriginalLatLongUnit(0); locality.setLat1text("38.925467 deg N"); locality.setLatitude1(new BigDecimal(38.925467)); locality.setLong1text("94.984867 deg W"); locality.setLongitude1(new BigDecimal(-94.984867)); persist(locality); evictList.add(locality); localities.add(locality); if ((i + 1) % 10 == 0) { commitTx(); for (Object obj : evictList) { session.evict(obj); } evictList.clear(); startTx(); frame.setProcess(i); } } commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // agents and addresses //////////////////////////////// log.info("Creating agents and addresses"); List<Agent> agents = new Vector<Agent>(); lastName = userAgent.getLastName(); Agent steveBoyd = createAgent("mr", "Steve", "D", "Boyd", "jb", "jb@net.edu"); if (!lastName.equals("Cooper")) agents.add(createAgent("mr", "Peter", "D", "Cooper", "ds", "ds@whitehouse.gov")); if (!lastName.equals("Peck")) agents.add(createAgent("mr", "David", "H", "Peck", "rb", "beach@net.edu")); if (!lastName.equals("Appleton")) agents.add(createAgent("mrs", "Sally", "H", "Appleton", "jm", "jm@net.edu")); if (!lastName.equals("Brown")) agents.add(createAgent("mr", "Taylor", "C", "Brown", "kcs", "taylor.brown@ku.edu")); if (!lastName.equals("Boyd")) agents.add(steveBoyd); if (!lastName.equals("Thomas")) agents.add(createAgent("Mr", "James", "X", "Thomas", "dxt", "")); if (!lastName.equals("Peterson")) agents.add(createAgent("mr", "Pete", "A", "Peterson", "jb", "")); if (!lastName.equals("Guttenburg")) agents.add(createAgent("mr", "Mitch", "A", "Guttenburg", "jb", "")); if (!lastName.equals("Ford")) agents.add(createAgent("mr", "Daniel", "A", "Ford", "mas", "mas@ku.edu")); agents.add(userAgent); Agent ku = new Agent(); ku.initialize(); ku.setAbbreviation("KU"); ku.setAgentType(Agent.ORG); ku.setLastName("University of Kansas"); ku.setEmail("webadmin@ku.edu"); ku.setTimestampCreated(new Timestamp(System.currentTimeMillis())); ku.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(ku); agents.get(0).setOrganization(ku); agents.get(1).setOrganization(ku); agents.get(2).setOrganization(ku); agents.get(3).setOrganization(ku); agents.get(8).setOrganization(ku); Agent otherAgent = new Agent(); otherAgent.initialize(); otherAgent.setAbbreviation("O"); otherAgent.setAgentType(Agent.OTHER); otherAgent.setLastName("The Other Guys"); otherAgent.setEmail("other@other.com"); otherAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); otherAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(otherAgent); commitTx(); List<GroupPerson> gpList = new ArrayList<GroupPerson>(); if (true) { startTx(); Agent gm1 = createAgent("mr", "John", "A", "Lyon", "jal", "jal@group.edu"); Agent gm2 = createAgent("mr", "Dave", "D", "Jones", "ddj", "ddj@group.edu"); persist(gm1); persist(gm2); commitTx(); Agent groupAgent = new Agent(); groupAgent.initialize(); groupAgent.setAbbreviation("GRP"); groupAgent.setAgentType(Agent.GROUP); groupAgent.setLastName("The Group"); groupAgent.setEmail("group@group.com"); groupAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); groupAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(groupAgent); gpList.add(createGroupPerson(groupAgent, gm1, 0, division)); gpList.add(createGroupPerson(groupAgent, gm2, 1, division)); } startTx(); List<AgentVariant> agentVariants = new Vector<AgentVariant>(); agentVariants.add(createAgentVariant(AgentVariant.VARIANT, "James Variant #1", steveBoyd)); agentVariants.add(createAgentVariant(AgentVariant.VERNACULAR, "James VERNACULAR #1", steveBoyd)); List<Address> addrs = new Vector<Address>(); addrs.add(createAddress(agents.get(1), "1600 Pennsylvania Avenue NW", null, "Washington", "DC", "USA", "20500", 0)); addrs.add(createAddress(agents.get(1), "??? Mississippi", null, "Lawrence", "KS", "USA", "66045", 1)); addrs.add(createAddress(agents.get(2), "1 Main St", "", "Lenexa", "KS", "USA", "66071")); addrs.add(createAddress(agents.get(3), "13355 Inverness", "Bldg #3", "Lawrence", "KS", "USA", "66047")); addrs.add(createAddress(agents.get(4), "Natural History Museum", "Cromwell Rd", "London", null, "UK", "SW7 5BD")); addrs.add(createAddress(agents.get(6), "1212 Apple Street", null, "Chicago", "IL", "USA", "01010")); addrs.add(createAddress(agents.get(8), "11911 Oak Ln", null, "Orion", "KS", "USA", "66061")); addrs.add(createAddress(ku, null, null, "Lawrence", "KS", "USA", "66045")); // User Agent Address addrs.add(createAddress(userAgent, "1214 East Street", null, "Grinnell", "IA", "USA", "56060")); userAgent.setDivision(division); persist(agents); persist(agentVariants); persist(gpList); commitTx(); startTx(); //////////////////////////////// // Determination Status (Must be done here) //////////////////////////////// // log.info("Creating determinations status"); // current = createDeterminationStatus(discipline, "Current", "", DeterminationStatus.CURRENT); // currentAccepted = createDeterminationStatus(discipline, "Current Accepted", "", DeterminationStatus.CURRENTTOACCEPTED); // notCurrent = createDeterminationStatus(discipline, "Not current","", DeterminationStatus.NOTCURRENT); // incorrect = createDeterminationStatus(discipline, "Incorrect", "", DeterminationStatus.USERDEFINED); // oldDet = createDeterminationStatus(discipline, "Old Determination","", DeterminationStatus.OLDDETERMINATION); // persist(current); // persist(currentAccepted); // persist(notCurrent); // persist(incorrect); // persist(oldDet); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); //////////////////////////////// // collection objects //////////////////////////////// log.info("Creating collection objects"); Calendar[] catDates = new Calendar[300]; for (int i = 0; i < catDates.length; i++) { catDates[i] = Calendar.getInstance(); int year = 1980 + (int) (rand.nextDouble() * 20.0); catDates[i].set(year, 01, 12 + i); } Vector<PrepType> prepTypesForSaving = loadPrepTypes(discipline.getType()); dataObjects.addAll(prepTypesForSaving); persist(dataObjects); dataObjects.clear(); frame.setProcess(++createStep); commitTx(); PrepType pressed = prepTypesForSaving.get(0); startTx(); frame.setProcess(0, NUM_COLOBJS); evictList.clear(); frame.setDesc("Creating Collection Objects"); int catNo = 100; for (int i = 0; i < NUM_COLOBJS; i++) { int years20 = (int) (rand.nextDouble() * 20.0); int years10 = (int) (rand.nextDouble() * 10.0); int years50 = (int) (rand.nextDouble() * 50.0); Calendar recent = Calendar.getInstance(); recent.set(1950 + years20 + years10, 10, 27, 13, 44, 00); Calendar longAgo = Calendar.getInstance(); longAgo.set(1900 + years50, 01, 29, 8, 12, 00); Calendar whileBack = Calendar.getInstance(); whileBack.set(1960 + years20, 7, 4, 9, 33, 12); String catNumStr = String.format("%09d", catNo); int inx = (int) (rand.nextDouble() * localities.size()); int agentInx = (int) (rand.nextDouble() * agents.size()); int agentInx2 = (int) (rand.nextDouble() * agents.size()); int calInx = (int) (rand.nextDouble() * catDates.length); CollectingEvent ce = createFakeCollectingEvent(agents, localities.get(inx), "cut"); CollectionObject co = createCollectionObject(catNumStr, "RSC" + Integer.toString(catNo), agents.get(agentInx), collection, 1, ce, catDates[calInx], "BuildSampleDatabase"); Determination dt = createDetermination(co, getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent); Calendar prepDate = Calendar.getInstance(); Preparation prep = createPreparation(pressed, agents.get(agentInx2), co, (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate); persist(ce); persist(co); persist(dt); persist(prep); evictList.add(ce); evictList.add(co); evictList.add(dt); evictList.add(prep); if ((i + 1) % 10 == 0) { commitTx(); for (Object obj : evictList) { session.evict(obj); } evictList.clear(); startTx(); frame.setProcess(i); } catNo++; } commitTx(); frame.setProcess(++createStep); buildDarwinCoreSchema(discipline); // done log.info("Done creating Botany disciplineType database: " + disciplineType.getTitle()); return dataObjects; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java
/** * @param row/*from www . ja v a 2 s. com*/ * @param uploadData * @param invalidValues * * Validates user-entered fields for the row. * Validation issues are added to invalidValues vector. */ public void validateRowValues(int row, UploadData uploadData, Vector<UploadTableInvalidValue> invalidValues) { if (uploadData.isEmptyRow(row)) { if (attachmentsPresent(uploadData, row)) { invalidValues.add(new UploadTableInvalidValue(null, this, this.uploadFields.get(0), row, new Exception(String.format(getResourceString("UploadTable.AttachmentPresentButNoData"), getTable().getTableInfo().getTitle())))); } return; } try { validatingValues = true; int seq = 0; boolean gotABlank = false; // for Locality table only LatLonConverter.FORMAT llFmt1 = null; LatLonConverter.FORMAT llFmt2 = null; // GeoRefConverter gc = new GeoRefConverter(); UploadField llFld = null; // for 'generic' latlon errors. Vector<UploadTableInvalidValue> invalidNulls = new Vector<UploadTableInvalidValue>(); Vector<Integer> blankSeqsLocal = new Vector<Integer>(); for (Vector<UploadField> flds : uploadFields) { boolean isBlank = true; UploadField currFirstFld = null; for (UploadField fld : flds) { if (fld.getIndex() != -1) { if (currFirstFld == null) { currFirstFld = fld; } fld.setValue(uploadData.get(row, fld.getIndex())); isBlank &= isBlankVal(fld, seq, row, uploadData); ; try { if (invalidNull(fld, uploadData, row, seq)) { if (shouldEnforceNonNullConstraint(row, uploadData, seq)) { //throw new Exception( // getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA")); invalidNulls.add(new UploadTableInvalidValue( getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA"), this, fld, row, null)); continue; } } if (fld.getValue() != null && !"".equals(fld.getValue()) && fld.isAutoAssignForUpload()/* && fld == autoAssignedField*/) { throw new Exception( UIRegistry.getResourceString("WB_UPLOAD_AutoAssMustBeBlankErrMsg")); } if (!pickListCheck(fld)) { if (!fld.isReadOnlyValidValues()) { if (uploader != Uploader.currentUpload) { invalidValues.add(new UploadTableInvalidValue(null, this, fld, null, row, new Exception(getInvalidPicklistValErrMsg(fld)), true)); continue; } } else { throw new Exception(getInvalidPicklistValErrMsg(fld)); } } Object[] finalVal = getArgForSetter(fld); if (!updateMatches) { //XXX But what if catnum has been changed... Shouldn't CatNum be made unchangeable??? checkUniqueness(finalVal, fld); } } catch (Exception e) { invalidValues.add(new UploadTableInvalidValue(null, this, fld, row, e)); } } if (tblClass.equals(Locality.class)) { // Check row to see that lat/long formats are the same. String fldName = fld.getField().getName(); if (fldName.equalsIgnoreCase("latitude1") || fldName.equalsIgnoreCase("latitude2") || fldName.equalsIgnoreCase("longitude1") || fldName.equalsIgnoreCase("longitude2")) { llFld = fld; LatLonConverter.FORMAT fmt = geoRefConverter .getLatLonFormat(StringUtils.stripToNull(fld.getValue())); LatLonConverter.FORMAT llFmt = fldName.endsWith("1") ? llFmt1 : llFmt2; boolean checkDecimalPlaces = true; if (llFmt == null) { llFmt = fmt; if (fldName.endsWith("1")) { llFmt1 = fmt; } else { llFmt2 = fmt; } } else { if (!llFmt.equals(fmt)) { checkDecimalPlaces = false; invalidValues.add(new UploadTableInvalidValue(null, this, getLatLongFlds(), row, new Exception( UIRegistry.getResourceString("WB_UPLOADER_INVALID_LATLONG")))); } } if (checkDecimalPlaces && fmt != null && fmt != LatLonConverter.FORMAT.None) { //check decimal places //lame int c = fld.getValue().indexOf(decSep); if (c > -1) { int d; String points = fld.getValue().substring(c + 1); for (d = 0; d < points.length(); d++) { //System.out.println(points.substring(d, d+1)); if (!"0123456789".contains(points.substring(d, d + 1))) break; } if (d > LatLonConverter.DECIMAL_SIZES[fmt.ordinal()]) { invalidValues.add(new UploadTableInvalidValue(null, this, fld, row, new Exception(String.format( UIRegistry.getResourceString( "WB_UPLOADER_TOO_MANY_FRACTION_DIGITS"), LatLonConverter.DECIMAL_SIZES[fmt.ordinal()])))); } } } } //Check LatLongType if (fldName.equalsIgnoreCase("LatLongType")) { boolean hasLat1 = false, hasLong1 = false, hasLat2 = false, hasLong2 = false; for (UploadField f : getLatLongFlds()) { f.setValue(uploadData.get(row, f.getIndex())); String coordName = f.getField().getName(); if (coordName.equalsIgnoreCase("latitude1") && StringUtils.isNotBlank(f.getValue())) { hasLat1 = true; } else if (coordName.equalsIgnoreCase("longitude1") && StringUtils.isNotBlank(f.getValue())) { hasLong1 = true; } else if (coordName.equalsIgnoreCase("latitude2") && StringUtils.isNotBlank(f.getValue())) { hasLat2 = true; } else if (coordName.equalsIgnoreCase("longitude2") && StringUtils.isNotBlank(f.getValue())) { hasLong2 = true; } } boolean hasCoord1 = hasLat1 && hasLong1; boolean hasCoord2 = hasLat2 && hasLong2; if ((hasCoord1 || hasCoord2) && StringUtils.isBlank(fld.getValue())) { invalidNulls.add(new UploadTableInvalidValue( getResourceString("WB_UPLOAD_FIELD_MUST_CONTAIN_DATA"), this, fld, row, null)); continue; } if (!hasCoord1 && !hasCoord2 && StringUtils.isBlank(fld.getValue())) { continue; } //Assuming the pick list is localized... String pntStr = UIRegistry.getResourceString("Locality.LL_TYPE_POINT"); String lineStr = UIRegistry.getResourceString("Locality.LL_TYPE_LINE"); String rectStr = UIRegistry.getResourceString("Locality.LL_TYPE_RECTANGLE"); Set<String> validValues = new TreeSet<String>(); for (String item : fld.getValidValues().keySet()) { if (item.equals(pntStr) && hasCoord1 && !hasCoord2) { validValues.add(item); } else if ((item.equals(lineStr) || item.equals(rectStr)) && hasCoord1 && hasCoord2) { validValues.add(item); } } if (!validValues.contains(fld.getValue())) { if (uploader != Uploader.currentUpload) { invalidValues.add(new UploadTableInvalidValue(null, this, fld, null, row, new Exception(getInvalidPicklistValErrMsg(fld, validValues)), false)); continue; } } } } } if (tblClass.equals(Locality.class)) { if (llFmt1 != llFmt2 && llFmt2 != null && llFmt2 != LatLonConverter.FORMAT.None) { invalidValues.add(new UploadTableInvalidValue(null, this, llFld, row, new Exception(UIRegistry.getResourceString("WB_UPLOADER_INVALID_LATLONG")))); } } if (isBlank) { if (attachmentsPresent(uploadData, row)) { invalidValues .add(new UploadTableInvalidValue(null, this, flds, row, new Exception(String.format( getResourceString("UploadTable.AttachmentPresentButNoData"), getTable().getTableInfo().getTitle())))); } } isBlank = isBlankSequence(isBlank, uploadData, row, seq, null); blankSeqs.set(seq, isBlank); if (isBlank) /* * Disallow situations where 1-many lists have 'holes' - eg. * CollectorLastName2 is blank but CollectorLastName1 and -3 are * not. */ { gotABlank = true; blankSeqsLocal.add(seq); } else if (!isBlank && gotABlank && plugHoles) { for (Integer blank : blankSeqsLocal) { for (UploadField blankSeqFld : getBlankFields(blank, row, uploadData)) { addInvalidValueMsgForOneToManySkip(invalidValues, blankSeqFld, toString(), row, blank); } } blankSeqsLocal.clear(); } invalidValues.addAll(invalidNulls); invalidNulls.clear(); seq++; } if (tblClass.equals(Determination.class)) { // check that isCurrent is ok. 1 and only one true. boolean isCurrentPresent = false; UploadField anIsCurrentFld = null; boolean isBlank = true; // for (int row = 0; row < uploadData.getRows(); row++) // { int trueCount = 0; for (Vector<UploadField> flds : uploadFields) { for (UploadField fld : flds) { if (isBlank && StringUtils.isNotBlank(uploadData.get(row, fld.getIndex()))) { isBlank = false; } if (fld.getField().getName().equalsIgnoreCase("iscurrent")) { isCurrentPresent = true; if (anIsCurrentFld == null) { anIsCurrentFld = fld; } fld.setValue(uploadData.get(row, fld.getIndex())); try { Object[] boolVal = getArgForSetter(fld); if (boolVal[0] != null && (Boolean) boolVal[0]) { trueCount++; } } catch (Exception e) { // ignore. assuming problem was already caught // above. } } } } if (isCurrentPresent && !isBlank && trueCount != 1) { invalidValues.add(new UploadTableInvalidValue(null, this, anIsCurrentFld, row, new Exception(getResourceString("WB_UPLOAD_ONE_CURRENT_DETERMINATION")))); } // } } if (tblClass.equals(Agent.class)) { // check that isCurrent is ok. 1 and only one true. boolean nonPersonNonEmpty = false; boolean isNonPerson = false; Vector<UploadField> personOnlyFlds = new Vector<UploadField>(); for (Vector<UploadField> flds : uploadFields) { for (UploadField fld : flds) { try { if (fld.getField().getName().equalsIgnoreCase("firstName") || fld.getField().getName().equalsIgnoreCase("middleInitial") || fld.getField().getName().equalsIgnoreCase("title")) { Object[] val = getArgForSetter(fld); nonPersonNonEmpty = StringUtils.isNotEmpty((String) val[0]); personOnlyFlds.add(fld); } if (fld.getField().getName().equalsIgnoreCase("agenttype")) { Object[] val = getArgForSetter(fld); isNonPerson = val[0] != null && !((Byte) val[0]).equals(Agent.PERSON); if (!isNonPerson) { break; } } } catch (Exception e) { // ignore. assuming problem was already caught // above. } } if (isNonPerson && nonPersonNonEmpty) { for (UploadField poFld : personOnlyFlds) { invalidValues.add(new UploadTableInvalidValue(null, this, poFld, row, new Exception( getResourceString("UploadTable.FieldNotApplicableForAgentType")))); } } } } } finally { validatingValues = false; } }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * Creates a single disciplineType collection. * @param disciplineName the name of the Discipline to use * @param disciplineName the disciplineType name * @return the entire list of DB object to be persisted *///from ww w .j a v a 2s .c o m public List<Object> createSingleInvertPaleoCollection(final DisciplineType disciplineType, final Institution institution, final SpecifyUser user, final CollectionChoice choice) { frame.setProcess(0, 16); frame.setDesc("Creating " + disciplineType.getTitle() + "..."); createStep = 0; startTx(); Division division = createDivision(institution, disciplineType.getName(), disciplineType.getTitle(), "INVP", disciplineType.getTitle()); // create tree defs (later we will make the def items and nodes) TaxonTreeDef taxonTreeDef = createTaxonTreeDef("Taxon", TreeDefIface.FORWARD); GeographyTreeDef geoTreeDef = createGeographyTreeDef("Geography", TreeDefIface.REVERSE); GeologicTimePeriodTreeDef gtpTreeDef = createGeologicTimePeriodTreeDef("Chronos Stratigraphy", TreeDefIface.REVERSE); LithoStratTreeDef lithoStratTreeDef = createLithoStratTreeDef("LithoStrat"); boolean buildStorageTree = false; if (stgTreeDef == null) { stgTreeDef = createStorageTreeDef("Storage", TreeDefIface.REVERSE); institution.setStorageTreeDef(stgTreeDef); buildStorageTree = true; } lithoStratTreeDef.setRemarks("A simple super, group, formation, member, bed Litho Stratigraphy tree"); Discipline discipline = createDiscipline(division, disciplineType.getName(), disciplineType.getTitle(), dataType, taxonTreeDef, geoTreeDef, gtpTreeDef, lithoStratTreeDef); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); persist(institution); persist(division); persist(discipline); AppContextMgr.getInstance().setClassObject(Division.class, division); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); loadSchemaLocalization(discipline, SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance(), choice.getCatalogNumberingFmtName(), choice.getAccessionNumberingFmtName()); //////////////////////////////// // Create the really high-level stuff //////////////////////////////// String title = initPrefs.getProperty("useragent.title", "mr"); String firstName = initPrefs.getProperty("useragent.firstname", "Test"); String lastName = initPrefs.getProperty("useragent.lastname", "User"); String midInit = initPrefs.getProperty("useragent.midinit", "A"); String abbrev = initPrefs.getProperty("useragent.abbrev", "tu"); String email = initPrefs.getProperty("useragent.email", "testuser@ku.edu"); String userType = initPrefs.getProperty("useragent.usertype", SpecifyUserTypes.UserType.Manager.toString()); System.out.println("----- User Agent -----"); System.out.println("Title: " + title); System.out.println("FirstName: " + firstName); System.out.println("LastName: " + lastName); System.out.println("MidInit: " + midInit); System.out.println("Abbrev: " + abbrev); System.out.println("Email: " + email); System.out.println("UserType: " + userType); Agent userAgent = createAgent(title, firstName, midInit, lastName, abbrev, email); discipline.addReference(userAgent, "agents"); user.addReference(userAgent, "agents"); persist(discipline); persist(userAgent); persist(user); // LithoStratTreeDefItem earth = createLithoStratTreeDefItem(lithoStratTreeDef, "Earth", 0, false); // LithoStratTreeDefItem superGrp = createLithoStratTreeDefItem(earth, "Super Group", 100, false); // LithoStratTreeDefItem lithoGrp = createLithoStratTreeDefItem(superGrp, "Litho Group", 200, false); // LithoStratTreeDefItem formation = createLithoStratTreeDefItem(lithoGrp, "Formation", 300, false); // LithoStratTreeDefItem member = createLithoStratTreeDefItem(formation, "Member", 400, false); // @SuppressWarnings("unused") // LithoStratTreeDefItem bed = createLithoStratTreeDefItem(member, "Bed", 500, true); frame.setProcess(++createStep); Pair<AutoNumberingScheme, AutoNumberingScheme> pairANS = createAutoNumberingSchemes(choice); AutoNumberingScheme cns = pairANS.first; AutoNumberingScheme accessionNS = pairANS.second; persist(cns); persist(accessionNS); //persist(earth); commitTx(); startTx(); //////////////////////////////// // Create Collection //////////////////////////////// log.info("Creating a Collection"); Collection collection = createCollection("KUIVP", disciplineType.getTitle(), choice.getCatalogNumberingFmtName(), cns, discipline); persist(collection); // create the standard user groups for this collection Map<String, SpPrincipal> groupMap = DataBuilder.createStandardGroups(session, collection); // add the administrator as a Collections Manager in this group user.addUserToSpPrincipalGroup(groupMap.get(SpecifyUserTypes.UserType.Manager.toString())); // Tester createAndAddTesterToCollection(session, "ivpuser", "InvertPaleo@ku.edu", "ivpuser", "mr", "Joe", "", "InvertPaleo", "", discipline, division, collection, groupMap, "Guest"); AppContextMgr.getInstance().setClassObject(Collection.class, collection); division.addReference(accessionNS, "numberingSchemes"); persist(division); commitTx(); doShowHideTablesAndFields(null, discipline); doShowHideTablesAndFields(disciplineType.getName(), discipline); frame.setProcess(++createStep); startTx(); //DBTableIdMgr schema = new DBTableIdMgr(false); //schema.initialize(new File(XMLHelper.getConfigDirPath("specify_datamodel.xml"))); //loadSchemaLocalization(discipline, SpLocaleContainer, schema); AppContextMgr.getInstance().setClassObject(SpecifyUser.class, user); user.addReference(userAgent, "agents"); persist(user); Journal journal = createJournalsAndReferenceWork(); frame.setProcess(++createStep); //////////////////////////////// // build the tree def items and nodes //////////////////////////////// List<Object> taxa = createSimpleBotanyTaxonTree(taxonTreeDef); List<Object> geos = createSimpleGeography(geoTreeDef, true); List<Object> gtps = createSimpleGeologicTimePeriod(gtpTreeDef, true); //List<Object> lithoStrats = createSimpleLithoStrat(lithoStratTreeDef, true); persist(journal); persist(taxa); persist(geos); persist(buildStorageTree ? createSimpleStorage(stgTreeDef) : null); persist(gtps); //persist(lithoStrats); commitTx(); LithoStrat earthLithoStrat = convertLithoStratFromCSV(lithoStratTreeDef); if (earthLithoStrat == null) { //throw new RuntimeException("No Tree"); startTx(); List<Object> lithoStrats = createSimpleLithoStrat(lithoStratTreeDef, true); persist(lithoStrats); commitTx(); } frame.setProcess(++createStep); //////////////////////////////// // picklists //////////////////////////////// log.info("Creating picklists"); frame.setDesc("Creating Common PickLists..."); //frame.setProcess(++createStep); createPickLists(session, null); frame.setDesc("Creating PickLists..."); createPickLists(session, discipline); Vector<Object> dataObjects = new Vector<Object>(); startTx(); frame.setDesc("Creating Queries..."); standardQueries(dataObjects, userAgent); persist(dataObjects); dataObjects.clear(); //BldrPickList colMethods = createPickLists(); persist(dataObjects); dataObjects.clear(); frame.setDesc("Intermediate save...."); commitTx(); frame.setDesc("Creating Localities...."); startTx(); frame.setProcess(++createStep); //////////////////////////////// // localities //////////////////////////////// String POINT = "Point"; String LINE = "Line"; String RECT = "Rectangle"; log.info("Creating localities"); Locality forestStream = createLocality("Gravel Pit", (Geography) geos.get(12)); forestStream.setLatLongType(POINT); forestStream.setOriginalLatLongUnit(0); forestStream.setLat1text("38.925467 deg N"); forestStream.setLatitude1(new BigDecimal(38.925467)); forestStream.setLong1text("94.984867 deg W"); forestStream.setLongitude1(new BigDecimal(-94.984867)); Locality lake = createLocality("Deep, dark lake pond", (Geography) geos.get(17)); lake.setLatLongType(RECT); lake.setOriginalLatLongUnit(1); lake.setLat1text("41.548842 deg N"); lake.setLatitude1(new BigDecimal(41.548842)); lake.setLong1text("93.732129 deg W"); lake.setLongitude1(new BigDecimal(-93.732129)); lake.setLat2text("41.642195 deg N"); lake.setLatitude2(new BigDecimal(41.642195)); lake.setLong2text("100.403180 deg W"); lake.setLongitude2(new BigDecimal(-100.403180)); Locality farmpond = createLocality("Shoal Creek at Schermerhorn Park, S of Galena at Rt. 26", (Geography) geos.get(11)); farmpond.setLatLongType(LINE); farmpond.setOriginalLatLongUnit(2); farmpond.setLat1text("41.642187 deg N"); farmpond.setLatitude1(new BigDecimal(41.642187)); farmpond.setLong1text("100.403163 deg W"); farmpond.setLongitude1(new BigDecimal(-100.403163)); farmpond.setLat2text("49.647435 deg N"); farmpond.setLatitude2(new BigDecimal(49.647435)); farmpond.setLong2text("-55.112163 deg W"); farmpond.setLongitude2(new BigDecimal(-55.112163)); persist(forestStream); persist(lake); persist(farmpond); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // agents and addresses //////////////////////////////// log.info("Creating agents and addresses"); List<Agent> agents = new Vector<Agent>(); lastName = userAgent.getLastName(); Agent steveBoyd = createAgent("mr", "Steve", "D", "Boyd", "jb", "jb@net.edu"); if (!lastName.equals("Cooper")) agents.add(createAgent("mr", "Peter", "D", "Cooper", "ds", "ds@whitehouse.gov")); if (!lastName.equals("Peck")) agents.add(createAgent("mr", "David", "H", "Peck", "rb", "beach@net.edu")); if (!lastName.equals("Appleton")) agents.add(createAgent("mrs", "Sally", "H", "Appleton", "jm", "jm@net.edu")); if (!lastName.equals("Brown")) agents.add(createAgent("mr", "Taylor", "C", "Brown", "kcs", "taylor.brown@ku.edu")); if (!lastName.equals("Boyd")) agents.add(steveBoyd); if (!lastName.equals("Thomas")) agents.add(createAgent("Mr", "James", "X", "Thomas", "dxt", "")); if (!lastName.equals("Peterson")) agents.add(createAgent("mr", "Pete", "A", "Peterson", "jb", "")); if (!lastName.equals("Guttenburg")) agents.add(createAgent("mr", "Mitch", "A", "Guttenburg", "jb", "")); if (!lastName.equals("Ford")) agents.add(createAgent("mr", "Daniel", "A", "Ford", "mas", "mas@ku.edu")); agents.add(userAgent); Agent ku = new Agent(); ku.initialize(); ku.setAbbreviation("KU"); ku.setAgentType(Agent.ORG); ku.setLastName("University of Kansas"); ku.setEmail("webadmin@ku.edu"); ku.setTimestampCreated(new Timestamp(System.currentTimeMillis())); ku.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(ku); agents.get(0).setOrganization(ku); agents.get(1).setOrganization(ku); agents.get(2).setOrganization(ku); agents.get(3).setOrganization(ku); agents.get(8).setOrganization(ku); Agent otherAgent = new Agent(); otherAgent.initialize(); otherAgent.setAbbreviation("O"); otherAgent.setAgentType(Agent.OTHER); otherAgent.setLastName("The Other Guys"); otherAgent.setEmail("other@other.com"); otherAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); otherAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(otherAgent); commitTx(); List<GroupPerson> gpList = new ArrayList<GroupPerson>(); if (true) { startTx(); Agent gm1 = createAgent("mr", "John", "A", "Lyon", "jal", "jal@group.edu"); Agent gm2 = createAgent("mr", "Dave", "D", "Jones", "ddj", "ddj@group.edu"); persist(gm1); persist(gm2); commitTx(); Agent groupAgent = new Agent(); groupAgent.initialize(); groupAgent.setAbbreviation("GRP"); groupAgent.setAgentType(Agent.GROUP); groupAgent.setLastName("The Group"); groupAgent.setEmail("group@group.com"); groupAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); groupAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(groupAgent); gpList.add(createGroupPerson(groupAgent, gm1, 0, division)); gpList.add(createGroupPerson(groupAgent, gm2, 1, division)); } startTx(); List<Address> addrs = new Vector<Address>(); addrs.add(createAddress(agents.get(1), "1600 Pennsylvania Avenue NW", null, "Washington", "DC", "USA", "20500", 0)); addrs.add(createAddress(agents.get(1), "??? Mississippi", null, "Lawrence", "KS", "USA", "66045", 1)); addrs.add(createAddress(agents.get(2), "1 Main St", "", "Lenexa", "KS", "USA", "66071")); addrs.add(createAddress(agents.get(3), "13355 Inverness", "Bldg #3", "Lawrence", "KS", "USA", "66047")); addrs.add(createAddress(agents.get(4), "Natural History Museum", "Cromwell Rd", "London", null, "UK", "SW7 5BD")); addrs.add(createAddress(agents.get(6), "1212 Apple Street", null, "Chicago", "IL", "USA", "01010")); addrs.add(createAddress(agents.get(8), "11911 Oak Ln", null, "Orion", "KS", "USA", "66061")); addrs.add(createAddress(ku, null, null, "Lawrence", "KS", "USA", "66045")); // User Agent Address addrs.add(createAddress(userAgent, "1214 East Street", null, "Grinnell", "IA", "USA", "56060")); userAgent.setDivision(division); persist(agents); persist(gpList); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // collecting events (collectors, collecting trip) //////////////////////////////// log.info("Creating collecting events, collectors and a collecting trip"); Collector collectorMitch = createCollector(agents.get(7), 2); Collector collectorJim = createCollector(agents.get(2), 1); String stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); calendar.set(1994, 4, 21, 11, 56, 00); CollectingEvent ce1 = createCollectingEvent(forestStream, calendar, stationFieldNumber, new Collector[] { collectorMitch, collectorJim }); ce1.setStartDateVerbatim("21 Apr 1994, 11:56 AM"); calendar.set(1994, 4, 21, 13, 03, 00); ce1.setEndDate(calendar); ce1.setEndDateVerbatim("21 Apr 1994, 1:03 PM"); ce1.setMethod("Picked"); AttributeDef cevAttrDef = createAttributeDef(AttributeIFace.FieldType.StringType, "ParkName", discipline, null);//meg added cod persist(cevAttrDef); commitTx(); startTx(); CollectingEventAttr cevAttr = createCollectingEventAttr(ce1, cevAttrDef, "Sleepy Hollow", null); Collector collectorMeg = createCollector(agents.get(2), 1); Collector collectorRod = createCollector(agents.get(3), 2); stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); calendar.set(1994, 4, 22, 06, 12, 00); CollectingEvent ce2 = createCollectingEvent(farmpond, calendar, stationFieldNumber, new Collector[] { collectorMeg, collectorRod }); ce2.setStartDateVerbatim("22 Apr 1994, 6:12 AM"); calendar.set(1994, 4, 22, 07, 31, 00); ce2.setEndDate(calendar); ce2.setEndDateVerbatim("22 Apr 1994, 7:31 AM"); ce2.setMethod("Picked"); //CollectingTrip trip = createCollectingTrip("Sample collecting trip", new CollectingEvent[]{ce1,ce2}); //dataObjects.add(trip); dataObjects.add(ce1); dataObjects.add(cevAttr); dataObjects.add(ce2); dataObjects.add(collectorMitch); dataObjects.add(collectorJim); dataObjects.add(collectorMeg); dataObjects.add(collectorRod); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); //////////////////////////////// // permit //////////////////////////////// log.info("Creating a permit"); Calendar issuedDate = Calendar.getInstance(); issuedDate.set(1993, 1, 12); Calendar startDate = Calendar.getInstance(); startDate.set(1993, 2, 1); Calendar endDate = Calendar.getInstance(); endDate.set(1993, 5, 30); Permit permit = createPermit("1980-INVRTP-0001", "US Dept Wildlife", issuedDate, startDate, endDate, null); permit.setIssuedTo(ku); permit.setIssuedBy(agents.get(4)); dataObjects.add(permit); log.info("Creating a repository agreement"); RepositoryAgreement repoAg = new RepositoryAgreement(); repoAg.initialize(); repoAg.setDivision(division); repoAg.setRepositoryAgreementNumber("KU-1979-01"); repoAg.setOriginator(ku); Calendar received = Calendar.getInstance(); received.set(1992, 2, 10); repoAg.setDateReceived(received); Calendar repoEndDate = Calendar.getInstance(); received.set(2010, 2, 9); repoAg.setEndDate(repoEndDate); dataObjects.add(repoAg); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); log.info("Creating collection objects"); List<CollectionObject> collObjs = new Vector<CollectionObject>(); Collection col = collection; Calendar[] catDates = new Calendar[8]; for (int i = 0; i < catDates.length; i++) { catDates[i] = Calendar.getInstance(); int year = 1980 + (int) (rand.nextDouble() * 20.0); catDates[i].set(year, 01, 12 + i); } String prefix = "000000"; int catNo = 100; CollectingEvent[] colEves = new CollectingEvent[8]; for (int i = 0; i < colEves.length; i++) { colEves[i] = createFakeCollectingEvent(agents, farmpond, "Dug"); collObjs.add(createCollectionObject(prefix + Integer.toString(catNo), "RSC" + Integer.toString(catNo), agents.get(i), col, 1, colEves[i], catDates[i], "BuildSampleDatabase")); catNo++; } dataObjects.addAll(collObjs); for (CollectingEvent ce : colEves) { persist(ce); } persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // determinations (determination status) //////////////////////////////// log.info("Creating determinations"); List<Determination> determs = new Vector<Determination>(); Calendar recent = Calendar.getInstance(); recent.set(2005, 10, 27, 13, 44, 00); Calendar longAgo = Calendar.getInstance(); longAgo.set(1976, 01, 29, 8, 12, 00); Calendar whileBack = Calendar.getInstance(); whileBack.set(2000, 7, 4, 9, 33, 12); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(5), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(6), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(7), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.get(13).setRemarks("This determination is totally wrong. What a foolish determination."); persist(determs); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // preparations (prep types) //////////////////////////////// log.info("Creating preparations"); Vector<PrepType> prepTypesForSaving = loadPrepTypes(discipline.getType()); PrepType pressed = prepTypesForSaving.get(0); List<Preparation> preps = new Vector<Preparation>(); Calendar prepDate = Calendar.getInstance(); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(4), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(5), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(6), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(7), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(10), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(3), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(5), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(6), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(7), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); dataObjects.addAll(prepTypesForSaving); dataObjects.addAll(preps); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // accessions (accession agents) //////////////////////////////// log.info("Creating accessions and accession agents"); calendar.set(2006, 10, 27, 23, 59, 59); Accession acc1 = createAccession(division, "gift", "complete", "2000-IP-001", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); acc1.setText1(disciplineType.getTitle()); acc1.setRepositoryAgreement(repoAg); Agent donor = agents.get(4); Agent receiver = agents.get(1); Agent reviewer = agents.get(2); List<AccessionAgent> accAgents = new Vector<AccessionAgent>(); accAgents.add(createAccessionAgent("donor", donor, acc1, null)); accAgents.add(createAccessionAgent("receiver", receiver, acc1, null)); accAgents.add(createAccessionAgent("reviewer", reviewer, acc1, null)); Accession acc2 = createAccession(division, "field_work", "inprocess", "2004-IP-002", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); Agent donor2 = agents.get(5); Agent receiver2 = agents.get(3); Agent reviewer2 = agents.get(1); accAgents.add(createAccessionAgent("donor", donor2, acc2, null)); accAgents.add(createAccessionAgent("receiver", receiver2, acc2, null)); accAgents.add(createAccessionAgent("reviewer", reviewer2, acc2, null)); dataObjects.add(acc1); dataObjects.add(acc2); dataObjects.addAll(accAgents); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); createLoanExamples(preps, agents, dataObjects); frame.setProcess(++createStep); persist(dataObjects); dataObjects.clear(); persist(dataObjects); dataObjects.clear(); frame.setProcess(++createStep); commitTx(); frame.setProcess(++createStep); buildDarwinCoreSchema(discipline); // done log.info("Done creating " + disciplineType.getTitle() + " disciplineType database: " + disciplineType.getTitle()); return dataObjects; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * Creates a single disciplineType collection. * @param disciplineName the name of the Discipline to use * @param disciplineName the disciplineType name * @return the entire list of DB object to be persisted *///from w w w . j a v a2 s . c om public List<Object> createSingleBotanyCollection(final DisciplineType disciplineType, final Institution institution, final SpecifyUser user, final CollectionChoice choice) { frame.setProcess(0, 16); frame.setDesc("Creating Botany..."); createStep = 0; startTx(); Division division = createDivision(institution, disciplineType.getName(), "Botany", "BT", "Botany"); // create tree defs (later we will make the def items and nodes) TaxonTreeDef taxonTreeDef = createTaxonTreeDef("Taxon", TreeDefIface.FORWARD); GeographyTreeDef geoTreeDef = createGeographyTreeDef("Geography", TreeDefIface.REVERSE); GeologicTimePeriodTreeDef gtpTreeDef = createGeologicTimePeriodTreeDef("Chronos Stratigraphy", TreeDefIface.REVERSE); LithoStratTreeDef lithoStratTreeDef = createLithoStratTreeDef("LithoStrat"); boolean buildStorageTree = false; if (stgTreeDef == null) { stgTreeDef = createStorageTreeDef("Storage", TreeDefIface.REVERSE); institution.setStorageTreeDef(stgTreeDef); buildStorageTree = true; } lithoStratTreeDef.setRemarks("A simple super, group, formation, member, bed Litho Stratigraphy tree"); Discipline discipline = createDiscipline(division, disciplineType.getName(), disciplineType.getTitle(), dataType, taxonTreeDef, geoTreeDef, gtpTreeDef, lithoStratTreeDef); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); List<SpPrincipal> groups = new ArrayList<SpPrincipal>(); persist(institution); persist(division); persist(discipline); AppContextMgr.getInstance().setClassObject(Division.class, division); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); loadSchemaLocalization(discipline, SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance(), choice.getCatalogNumberingFmtName(), choice.getAccessionNumberingFmtName()); //////////////////////////////// // Create the really high-level stuff //////////////////////////////// String title = initPrefs.getProperty("useragent.title", "mr"); String firstName = initPrefs.getProperty("useragent.firstname", "Test"); String lastName = initPrefs.getProperty("useragent.lastname", "User"); String midInit = initPrefs.getProperty("useragent.midinit", "A"); String abbrev = initPrefs.getProperty("useragent.abbrev", "tu"); String email = initPrefs.getProperty("useragent.email", "testuser@ku.edu"); String userType = initPrefs.getProperty("useragent.usertype", SpecifyUserTypes.UserType.Manager.toString()); //String password = initPrefs.getProperty("useragent.password", "rods"); System.out.println("----- User Agent -----"); System.out.println("Title: " + title); System.out.println("FirstName: " + firstName); System.out.println("LastName: " + lastName); System.out.println("MidInit: " + midInit); System.out.println("Abbrev: " + abbrev); System.out.println("Email: " + email); System.out.println("UserType: " + userType); Agent userAgent = createAgent(title, firstName, midInit, lastName, abbrev, email); discipline.addReference(userAgent, "agents"); user.addReference(userAgent, "agents"); persist(userAgent); persist(user); frame.setProcess(++createStep); Pair<AutoNumberingScheme, AutoNumberingScheme> pairANS = createAutoNumberingSchemes(choice); AutoNumberingScheme cns = pairANS.first; AutoNumberingScheme accessionNS = pairANS.second; persist(cns); persist(accessionNS); commitTx(); startTx(); //////////////////////////////// // Create Collection //////////////////////////////// log.info("Creating a Collection"); Collection collection = createCollection("KUBOT", "Botany", choice.getCatalogNumberingFmtName(), cns, discipline); persist(collection); // create the standard user groups for this collection Map<String, SpPrincipal> groupMap = DataBuilder.createStandardGroups(session, collection); // add the administrator as a Collections Manager in this group user.addUserToSpPrincipalGroup(groupMap.get(SpecifyUserTypes.UserType.Manager.toString())); // Tester createAndAddTesterToCollection(session, "botanyuser", "botanyuser@ku.edu", "botanyuser", "mr", "Bob", "", "Botony", "", discipline, division, collection, groupMap, "Guest"); persist(discipline); AppContextMgr.getInstance().setClassObject(Collection.class, collection); persist(groups); division.addReference(accessionNS, "numberingSchemes"); persist(division); commitTx(); doShowHideTablesAndFields(null, discipline); doShowHideTablesAndFields(disciplineType.getName(), discipline); frame.setProcess(++createStep); startTx(); //DBTableIdMgr schema = new DBTableIdMgr(false); //schema.initialize(new File(XMLHelper.getConfigDirPath("specify_datamodel.xml"))); //loadSchemaLocalization(discipline, SpLocaleContainer, schema); //buildDarwinCoreSchema(discipline); AppContextMgr.getInstance().setClassObject(SpecifyUser.class, user); user.addReference(userAgent, "agents"); persist(user); Journal journal = createJournalsAndReferenceWork(); frame.setProcess(++createStep); //////////////////////////////// // build the tree def items and nodes //////////////////////////////// List<Object> taxa = createSimpleBotanyTaxonTree(taxonTreeDef); List<Object> geos = createSimpleGeography(geoTreeDef, true); List<Object> gtps = createSimpleGeologicTimePeriod(gtpTreeDef, true); List<Object> lithoStrats = createSimpleLithoStrat(lithoStratTreeDef, true); institution.setStorageTreeDef(stgTreeDef); persist(institution); persist(journal); persist(taxa); persist(geos); persist(buildStorageTree ? createSimpleStorage(stgTreeDef) : null); persist(gtps); persist(lithoStrats); commitTx(); AppContextMgr.getInstance().setClassObject(Division.class, division); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); frame.setProcess(++createStep); //////////////////////////////// // picklists //////////////////////////////// log.info("Creating picklists"); frame.setDesc("Creating PickLists..."); //frame.setProcess(++createStep); createPickLists(session, null); createPickLists(session, discipline); Vector<Object> dataObjects = new Vector<Object>(); startTx(); standardQueries(dataObjects, userAgent); persist(dataObjects); dataObjects.clear(); //BldrPickList colMethods = createPickLists(); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // localities //////////////////////////////// String POINT = "Point"; String LINE = "Line"; String RECT = "Rectangle"; log.info("Creating localities"); Locality forestStream = createLocality("Unnamed forest stream pond", (Geography) geos.get(12)); forestStream.setLatLongType(POINT); forestStream.setOriginalLatLongUnit(0); forestStream.setLat1text("38.925467 deg N"); forestStream.setLatitude1(new BigDecimal(38.925467)); forestStream.setLong1text("94.984867 deg W"); forestStream.setLongitude1(new BigDecimal(-94.984867)); Locality lake = createLocality("Deep, dark lake pond", (Geography) geos.get(17)); lake.setLatLongType(RECT); lake.setOriginalLatLongUnit(1); lake.setLat1text("41.548842 deg N"); lake.setLatitude1(new BigDecimal(41.548842)); lake.setLong1text("93.732129 deg W"); lake.setLongitude1(new BigDecimal(-93.732129)); lake.setLat2text("41.642195 deg N"); lake.setLatitude2(new BigDecimal(41.642195)); lake.setLong2text("100.403180 deg W"); lake.setLongitude2(new BigDecimal(-100.403180)); Locality farmpond = createLocality("Shoal Creek at Schermerhorn Park, S of Galena at Rt. 26", (Geography) geos.get(11)); farmpond.setLatLongType(LINE); farmpond.setOriginalLatLongUnit(2); farmpond.setLat1text("41.642187 deg N"); farmpond.setLatitude1(new BigDecimal(41.642187)); farmpond.setLong1text("100.403163 deg W"); farmpond.setLongitude1(new BigDecimal(-100.403163)); farmpond.setLat2text("49.647435 deg N"); farmpond.setLatitude2(new BigDecimal(49.647435)); farmpond.setLong2text("-55.112163 deg W"); farmpond.setLongitude2(new BigDecimal(-55.112163)); persist(forestStream); persist(lake); persist(farmpond); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // agents and addresses //////////////////////////////// log.info("Creating agents and addresses"); List<Agent> agents = new Vector<Agent>(); lastName = userAgent.getLastName(); Agent steveBoyd = createAgent("mr", "Steve", "D", "Boyd", "jb", "jb@net.edu"); if (!lastName.equals("Cooper")) agents.add(createAgent("mr", "Peter", "D", "Cooper", "ds", "ds@whitehouse.gov")); if (!lastName.equals("Peck")) agents.add(createAgent("mr", "David", "H", "Peck", "rb", "beach@net.edu")); if (!lastName.equals("Appleton")) agents.add(createAgent("mrs", "Sally", "H", "Appleton", "jm", "jm@net.edu")); if (!lastName.equals("Brown")) agents.add(createAgent("mr", "Taylor", "C", "Brown", "kcs", "taylor.brown@ku.edu")); if (!lastName.equals("Boyd")) agents.add(steveBoyd); if (!lastName.equals("Thomas")) agents.add(createAgent("Mr", "James", "X", "Thomas", "dxt", "")); if (!lastName.equals("Peterson")) agents.add(createAgent("mr", "Pete", "A", "Peterson", "jb", "")); if (!lastName.equals("Guttenburg")) agents.add(createAgent("mr", "Mitch", "A", "Guttenburg", "jb", "")); if (!lastName.equals("Ford")) agents.add(createAgent("mr", "Daniel", "A", "Ford", "mas", "mas@ku.edu")); agents.add(userAgent); Agent ku = new Agent(); ku.initialize(); ku.setAbbreviation("KU"); ku.setAgentType(Agent.ORG); ku.setLastName("University of Kansas"); ku.setEmail("webadmin@ku.edu"); ku.setTimestampCreated(new Timestamp(System.currentTimeMillis())); ku.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(ku); agents.get(0).setOrganization(ku); agents.get(1).setOrganization(ku); agents.get(2).setOrganization(ku); agents.get(3).setOrganization(ku); agents.get(8).setOrganization(ku); Agent otherAgent = new Agent(); otherAgent.initialize(); otherAgent.setAbbreviation("O"); otherAgent.setAgentType(Agent.OTHER); otherAgent.setLastName("The Other Guys"); otherAgent.setEmail("other@other.com"); otherAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); otherAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(otherAgent); commitTx(); List<GroupPerson> gpList = new ArrayList<GroupPerson>(); if (true) { startTx(); Agent gm1 = createAgent("mr", "John", "A", "Lyon", "jal", "jal@group.edu"); Agent gm2 = createAgent("mr", "Dave", "D", "Jones", "ddj", "ddj@group.edu"); persist(gm1); persist(gm2); commitTx(); Agent groupAgent = new Agent(); groupAgent.initialize(); groupAgent.setAbbreviation("GRP"); groupAgent.setAgentType(Agent.GROUP); groupAgent.setLastName("The Group"); groupAgent.setEmail("group@group.com"); groupAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); groupAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(groupAgent); gpList.add(createGroupPerson(groupAgent, gm1, 0, division)); gpList.add(createGroupPerson(groupAgent, gm2, 1, division)); } startTx(); List<AgentVariant> agentVariants = new Vector<AgentVariant>(); agentVariants.add(createAgentVariant(AgentVariant.VARIANT, "James Variant #1", steveBoyd)); agentVariants.add(createAgentVariant(AgentVariant.VERNACULAR, "James VERNACULAR #1", steveBoyd)); List<Address> addrs = new Vector<Address>(); addrs.add(createAddress(agents.get(1), "1600 Pennsylvania Avenue NW", null, "Washington", "DC", "USA", "20500", 0)); addrs.add(createAddress(agents.get(1), "??? Mississippi", null, "Lawrence", "KS", "USA", "66045", 1)); addrs.add(createAddress(agents.get(2), "1 Main St", "", "Lenexa", "KS", "USA", "66071")); addrs.add(createAddress(agents.get(3), "13355 Inverness", "Bldg #3", "Lawrence", "KS", "USA", "66047")); addrs.add(createAddress(agents.get(4), "Natural History Museum", "Cromwell Rd", "London", null, "UK", "SW7 5BD")); addrs.add(createAddress(agents.get(6), "1212 Apple Street", null, "Chicago", "IL", "USA", "01010")); addrs.add(createAddress(agents.get(8), "11911 Oak Ln", null, "Orion", "KS", "USA", "66061")); addrs.add(createAddress(ku, null, null, "Lawrence", "KS", "USA", "66045")); // User Agent Address addrs.add(createAddress(userAgent, "1214 East Street", null, "Grinnell", "IA", "USA", "56060")); userAgent.setDivision(division); persist(agents); persist(agentVariants); persist(gpList); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // collecting events (collectors, collecting trip) //////////////////////////////// log.info("Creating collecting events, collectors and a collecting trip"); Collector collectorMitch = createCollector(agents.get(7), 2); Collector collectorJim = createCollector(agents.get(2), 1); calendar.set(1994, 4, 21, 11, 56, 00); String stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); CollectingEvent ce1 = createCollectingEvent(forestStream, calendar, stationFieldNumber, new Collector[] { collectorMitch, collectorJim }); ce1.setStartDateVerbatim("21 Apr 1994, 11:56 AM"); calendar.set(1994, 4, 21, 13, 03, 00); ce1.setEndDate(calendar); ce1.setEndDateVerbatim("21 Apr 1994, 1:03 PM"); ce1.setMethod("Picked"); AttributeDef cevAttrDef = createAttributeDef(AttributeIFace.FieldType.StringType, "ParkName", discipline, null);//meg added cod persist(cevAttrDef); commitTx(); startTx(); CollectingEventAttr cevAttr = createCollectingEventAttr(ce1, cevAttrDef, "Sleepy Hollow", null); Collector collectorMeg = createCollector(agents.get(2), 1); Collector collectorRod = createCollector(agents.get(3), 2); stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); calendar.set(1994, 4, 22, 06, 12, 00); CollectingEvent ce2 = createCollectingEvent(farmpond, calendar, stationFieldNumber, new Collector[] { collectorMeg, collectorRod }); ce2.setStartDateVerbatim("22 Apr 1994, 6:12 AM"); calendar.set(1994, 4, 22, 07, 31, 00); ce2.setEndDate(calendar); ce2.setEndDateVerbatim("22 Apr 1994, 7:31 AM"); ce2.setMethod("Picked"); //CollectingTrip trip = createCollectingTrip("Sample collecting trip", new CollectingEvent[]{ce1,ce2}); //dataObjects.add(trip); dataObjects.add(ce1); dataObjects.add(cevAttr); dataObjects.add(ce2); dataObjects.add(collectorMitch); dataObjects.add(collectorJim); dataObjects.add(collectorMeg); dataObjects.add(collectorRod); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); //////////////////////////////// // permit //////////////////////////////// log.info("Creating a permit"); Calendar issuedDate = Calendar.getInstance(); issuedDate.set(1993, 1, 12); Calendar startDate = Calendar.getInstance(); startDate.set(1993, 2, 1); Calendar endDate = Calendar.getInstance(); endDate.set(1993, 5, 30); Permit permit = createPermit("1991-PLAN-0001", "US Dept Wildlife", issuedDate, startDate, endDate, null); permit.setIssuedTo(ku); permit.setIssuedBy(agents.get(4)); dataObjects.add(permit); log.info("Creating a repository agreement"); RepositoryAgreement repoAg = new RepositoryAgreement(); repoAg.initialize(); repoAg.setDivision(division); repoAg.setRepositoryAgreementNumber("KU-1990-01"); repoAg.setOriginator(ku); Calendar received = Calendar.getInstance(); received.set(1992, 2, 10); repoAg.setDateReceived(received); Calendar repoEndDate = Calendar.getInstance(); received.set(2010, 2, 9); repoAg.setEndDate(repoEndDate); dataObjects.add(repoAg); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // collection objects //////////////////////////////// log.info("Creating collection objects"); List<CollectionObject> collObjs = new Vector<CollectionObject>(); Collection col = collection; Calendar[] catDates = new Calendar[8]; for (int i = 0; i < catDates.length; i++) { catDates[i] = Calendar.getInstance(); int year = 1980 + (int) (rand.nextDouble() * 20.0); catDates[i].set(year, 01, 12 + i); } String prefix = "000000"; int catNo = 100; CollectingEvent[] colEves = new CollectingEvent[8]; for (int i = 0; i < colEves.length; i++) { colEves[i] = createFakeCollectingEvent(agents, farmpond, "cut"); collObjs.add(createCollectionObject(prefix + Integer.toString(catNo), "RSC" + Integer.toString(catNo), agents.get(i), col, 1, colEves[i], catDates[i], "BuildSampleDatabase")); catNo++; } dataObjects.addAll(collObjs); for (CollectingEvent ce : colEves) { persist(ce); } persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // determinations (determination status) //////////////////////////////// log.info("Creating determinations"); List<Determination> determs = new Vector<Determination>(); Calendar recent = Calendar.getInstance(); recent.set(2005, 10, 27, 13, 44, 00); Calendar longAgo = Calendar.getInstance(); longAgo.set(1976, 01, 29, 8, 12, 00); Calendar whileBack = Calendar.getInstance(); whileBack.set(2000, 7, 4, 9, 33, 12); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(5), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(6), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(7), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.get(13).setRemarks("This determination is totally wrong. What a foolish determination."); persist(determs); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // preparations (prep types) //////////////////////////////// log.info("Creating preparations"); Vector<PrepType> prepTypesForSaving = loadPrepTypes(discipline.getType()); PrepType pressed = prepTypesForSaving.get(0); List<Preparation> preps = new Vector<Preparation>(); Calendar prepDate = Calendar.getInstance(); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(4), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(5), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(6), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(7), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(10), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(3), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(5), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(6), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(7), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); dataObjects.addAll(prepTypesForSaving); dataObjects.addAll(preps); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // accessions (accession agents) //////////////////////////////// log.info("Creating accessions and accession agents"); calendar.set(2006, 10, 27, 23, 59, 59); Accession acc1 = createAccession(division, "gift", "complete", "2000-PL-001", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); acc1.setText1("Ichthyology"); acc1.setRepositoryAgreement(repoAg); Agent donor = agents.get(4); Agent receiver = agents.get(1); Agent reviewer = agents.get(2); List<AccessionAgent> accAgents = new Vector<AccessionAgent>(); accAgents.add(createAccessionAgent("donor", donor, acc1, null)); accAgents.add(createAccessionAgent("receiver", receiver, acc1, null)); accAgents.add(createAccessionAgent("reviewer", reviewer, acc1, null)); Accession acc2 = createAccession(division, "field_work", "inprocess", "2004-PL-002", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); Agent donor2 = agents.get(5); Agent receiver2 = agents.get(3); Agent reviewer2 = agents.get(1); accAgents.add(createAccessionAgent("donor", donor2, acc2, null)); accAgents.add(createAccessionAgent("receiver", receiver2, acc2, null)); accAgents.add(createAccessionAgent("reviewer", reviewer2, acc2, null)); dataObjects.add(acc1); dataObjects.add(acc2); dataObjects.addAll(accAgents); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); createLoanExamples(preps, agents, dataObjects); frame.setProcess(++createStep); persist(dataObjects); dataObjects.clear(); persist(dataObjects); dataObjects.clear(); frame.setProcess(++createStep); commitTx(); frame.setProcess(++createStep); buildDarwinCoreSchema(discipline); // done log.info("Done creating Botany disciplineType database: " + disciplineType.getTitle()); return dataObjects; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * Creates a single disciplineType collection. * @param disciplineName the name of the Discipline to use * @param disciplineName the disciplineType name * @return the entire list of DB object to be persisted *//*w ww . ja v a 2s . co m*/ public List<Object> createGenericCollection(final DisciplineType disciplineType, final Institution institution, final SpecifyUser user, final CollectionChoice choice, final String method) { frame.setProcess(0, 16); frame.setDesc("Creating " + disciplineType.getTitle() + "..."); createStep = 0; startTx(); Division division = createDivision(institution, disciplineType.getName(), disciplineType.getTitle(), disciplineType.getAbbrev(), disciplineType.getTitle()); // create tree defs (later we will make the def items and nodes) TaxonTreeDef taxonTreeDef = createTaxonTreeDef("Taxon", TreeDefIface.FORWARD); GeographyTreeDef geoTreeDef = createGeographyTreeDef("Geography", TreeDefIface.REVERSE); GeologicTimePeriodTreeDef gtpTreeDef = createGeologicTimePeriodTreeDef("Chronos Stratigraphy", TreeDefIface.REVERSE); LithoStratTreeDef lithoStratTreeDef = createLithoStratTreeDef("LithoStrat"); boolean buildStorageTree = false; if (stgTreeDef == null) { stgTreeDef = createStorageTreeDef("Storage", TreeDefIface.REVERSE); institution.setStorageTreeDef(stgTreeDef); buildStorageTree = true; } Discipline discipline = createDiscipline(division, disciplineType.getName(), disciplineType.getTitle(), dataType, taxonTreeDef, geoTreeDef, gtpTreeDef, lithoStratTreeDef); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); persist(institution); persist(division); persist(discipline); AppContextMgr.getInstance().setClassObject(Division.class, division); AppContextMgr.getInstance().setClassObject(Discipline.class, discipline); AppContextMgr.getInstance().setClassObject(Institution.class, institution); frame.setDesc("Loading Schema..."); loadSchemaLocalization(discipline, SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance(), choice.getCatalogNumberingFmtName(), choice.getAccessionNumberingFmtName()); //////////////////////////////// // Create the really high-level stuff //////////////////////////////// String title = initPrefs.getProperty("useragent.title", "mr"); String firstName = initPrefs.getProperty("useragent.firstname", "Test"); String lastName = initPrefs.getProperty("useragent.lastname", "User"); String midInit = initPrefs.getProperty("useragent.midinit", "A"); String abbrev = initPrefs.getProperty("useragent.abbrev", "tu"); String email = initPrefs.getProperty("useragent.email", "testuser@ku.edu"); String userType = initPrefs.getProperty("useragent.usertype", SpecifyUserTypes.UserType.Manager.toString()); System.out.println("----- User Agent -----"); System.out.println("Title: " + title); System.out.println("FirstName: " + firstName); System.out.println("LastName: " + lastName); System.out.println("MidInit: " + midInit); System.out.println("Abbrev: " + abbrev); System.out.println("Email: " + email); System.out.println("UserType: " + userType); Agent userAgent = createAgent(title, firstName, midInit, lastName, abbrev, email); discipline.addReference(userAgent, "agents"); user.addReference(userAgent, "agents"); persist(discipline); persist(userAgent); persist(user); frame.setProcess(++createStep); Pair<AutoNumberingScheme, AutoNumberingScheme> pairANS = createAutoNumberingSchemes(choice); AutoNumberingScheme cns = pairANS.first; AutoNumberingScheme accessionNS = pairANS.second; persist(cns); persist(accessionNS); commitTx(); startTx(); //////////////////////////////// // Create Collection //////////////////////////////// log.info("Creating a Collection"); frame.setDesc("Creating a Collection"); Collection collection = createCollection("KU", disciplineType.getTitle(), choice.getCatalogNumberingFmtName(), cns, discipline, disciplineType.isEmbeddedCollecingEvent()); persist(collection); // create the standard user groups for this collection Map<String, SpPrincipal> groupMap = DataBuilder.createStandardGroups(session, collection); // add the administrator as a Collections Manager in this group user.addUserToSpPrincipalGroup(groupMap.get(SpecifyUserTypes.UserType.Manager.toString())); // Tester String dspAbbrev = disciplineType.getAbbrev(); createAndAddTesterToCollection(session, dspAbbrev + "Tester", dspAbbrev + "tester@brc.ku.edu", dspAbbrev + "Tester", "", dspAbbrev, "", "Tester", "", discipline, division, collection, groupMap, "Guest"); AppContextMgr.getInstance().setClassObject(Collection.class, collection); division.addReference(accessionNS, "numberingSchemes"); persist(division); commitTx(); doShowHideTablesAndFields(null, discipline); doShowHideTablesAndFields(disciplineType.getName(), discipline); frame.setProcess(++createStep); startTx(); createTaxonTreeDefFromXML(taxonTreeDef, disciplineType); persist(taxonTreeDef); //DBTableIdMgr schema = new DBTableIdMgr(false); //schema.initialize(new File(XMLHelper.getConfigDirPath("specify_datamodel.xml"))); //loadSchemaLocalization(discipline, SpLocaleContainer, schema); //buildDarwinCoreSchema(discipline); AppContextMgr.getInstance().setClassObject(SpecifyUser.class, user); user.addReference(userAgent, "agents"); persist(user); Journal journal = createJournalsAndReferenceWork(); frame.setProcess(++createStep); //////////////////////////////// // build the tree def items and nodes //////////////////////////////// frame.setDesc("Building Trees..."); Vector<Object> taxa = new Vector<Object>(); createTaxonTreeFromXML(taxa, taxonTreeDef, disciplineType); boolean isPaleo = disciplineType.getDisciplineType() == DisciplineType.STD_DISCIPLINES.paleobotany || disciplineType.getDisciplineType() == DisciplineType.STD_DISCIPLINES.vertpaleo || disciplineType.getDisciplineType() == DisciplineType.STD_DISCIPLINES.invertpaleo; if (isPaleo) { // LithoStratTreeDefItem earth = createLithoStratTreeDefItem(lithoStratTreeDef, "Earth", 0, false); // LithoStratTreeDefItem superGrp = createLithoStratTreeDefItem(earth, "Super Group", 100, false); // LithoStratTreeDefItem lithoGrp = createLithoStratTreeDefItem(superGrp, "Litho Group", 200, false); // LithoStratTreeDefItem formation = createLithoStratTreeDefItem(lithoGrp, "Formation", 300, false); // LithoStratTreeDefItem member = createLithoStratTreeDefItem(formation, "Member", 400, false); // @SuppressWarnings("unused") // LithoStratTreeDefItem bed = createLithoStratTreeDefItem(member, "Bed", 500, true); // persist(earth); } List<Object> geos = createSimpleGeography(geoTreeDef, true); List<Object> gtps = createSimpleGeologicTimePeriod(gtpTreeDef, true); List<Object> lithoStrats = isPaleo ? null : createSimpleLithoStrat(lithoStratTreeDef, true); persist(journal); persist(taxa); persist(geos); persist(buildStorageTree ? createSimpleStorage(stgTreeDef) : null); persist(gtps); if (lithoStrats != null) { persist(lithoStrats); } commitTx(); if (isPaleo) { LithoStrat earthLithoStrat = convertLithoStratFromCSV(lithoStratTreeDef);// does startTx() / commitTx if (earthLithoStrat == null) { startTx(); lithoStrats = createSimpleLithoStrat(lithoStratTreeDef, true); persist(lithoStrats); commitTx(); } } frame.setProcess(++createStep); //////////////////////////////// // picklists //////////////////////////////// log.info("Creating picklists"); frame.setDesc("Creating Common PickLists..."); //frame.setProcess(++createStep); createPickLists(session, null); frame.setDesc("Creating PickLists..."); createPickLists(session, discipline); startTx(); Vector<Object> dataObjects = new Vector<Object>(); frame.setDesc("Creating Queries..."); standardQueries(dataObjects, userAgent); persist(dataObjects); dataObjects.clear(); persist(dataObjects); dataObjects.clear(); frame.setDesc("Intermediate save...."); commitTx(); frame.setDesc("Creating Localities...."); startTx(); frame.setProcess(++createStep); //////////////////////////////// // localities //////////////////////////////// String POINT = "Point"; String LINE = "Line"; String RECT = "Rectangle"; log.info("Creating localities"); frame.setDesc("Creating localities..."); Locality forestStream = createLocality("Gravel Pit", (Geography) geos.get(12)); forestStream.setLatLongType(POINT); forestStream.setOriginalLatLongUnit(0); forestStream.setLat1text("38.925467 deg N"); forestStream.setLatitude1(new BigDecimal(38.925467)); forestStream.setLong1text("94.984867 deg W"); forestStream.setLongitude1(new BigDecimal(-94.984867)); Locality lake = createLocality("Deep, dark lake pond", (Geography) geos.get(17)); lake.setLatLongType(RECT); lake.setOriginalLatLongUnit(1); lake.setLat1text("41.548842 deg N"); lake.setLatitude1(new BigDecimal(41.548842)); lake.setLong1text("93.732129 deg W"); lake.setLongitude1(new BigDecimal(-93.732129)); lake.setLat2text("41.642195 deg N"); lake.setLatitude2(new BigDecimal(41.642195)); lake.setLong2text("100.403180 deg W"); lake.setLongitude2(new BigDecimal(-100.403180)); Locality farmpond = createLocality("Shoal Creek at Schermerhorn Park, S of Galena at Rt. 26", (Geography) geos.get(11)); farmpond.setLatLongType(LINE); farmpond.setOriginalLatLongUnit(2); farmpond.setLat1text("41.642187 deg N"); farmpond.setLatitude1(new BigDecimal(41.642187)); farmpond.setLong1text("100.403163 deg W"); farmpond.setLongitude1(new BigDecimal(-100.403163)); farmpond.setLat2text("49.647435 deg N"); farmpond.setLatitude2(new BigDecimal(49.647435)); farmpond.setLong2text("-55.112163 deg W"); farmpond.setLongitude2(new BigDecimal(-55.112163)); persist(forestStream); persist(lake); persist(farmpond); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // agents and addresses //////////////////////////////// log.info("Creating agents and addresses"); frame.setDesc("Creating agents and addresses"); List<Agent> agents = new Vector<Agent>(); lastName = userAgent.getLastName(); Agent steveBoyd = createAgent("mr", "Steve", "D", "Boyd", "jb", "jb@net.edu"); if (!lastName.equals("Cooper")) agents.add(createAgent("mr", "Peter", "D", "Cooper", "ds", "ds@whitehouse.gov")); if (!lastName.equals("Peck")) agents.add(createAgent("mr", "David", "H", "Peck", "rb", "beach@net.edu")); if (!lastName.equals("Appleton")) agents.add(createAgent("mrs", "Sally", "H", "Appleton", "jm", "jm@net.edu")); if (!lastName.equals("Brown")) agents.add(createAgent("mr", "Taylor", "C", "Brown", "kcs", "taylor.brown@ku.edu")); if (!lastName.equals("Boyd")) agents.add(steveBoyd); if (!lastName.equals("Thomas")) agents.add(createAgent("Mr", "James", "X", "Thomas", "dxt", "")); if (!lastName.equals("Peterson")) agents.add(createAgent("mr", "Pete", "A", "Peterson", "jb", "")); if (!lastName.equals("Guttenburg")) agents.add(createAgent("mr", "Mitch", "A", "Guttenburg", "jb", "")); if (!lastName.equals("Ford")) agents.add(createAgent("mr", "Daniel", "A", "Ford", "mas", "mas@ku.edu")); agents.add(userAgent); Agent ku = new Agent(); ku.initialize(); ku.setAbbreviation("KU"); ku.setAgentType(Agent.ORG); ku.setLastName("University of Kansas"); ku.setEmail("webadmin@ku.edu"); ku.setTimestampCreated(new Timestamp(System.currentTimeMillis())); ku.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(ku); agents.get(0).setOrganization(ku); agents.get(1).setOrganization(ku); agents.get(2).setOrganization(ku); agents.get(3).setOrganization(ku); agents.get(8).setOrganization(ku); Agent otherAgent = new Agent(); otherAgent.initialize(); otherAgent.setAbbreviation("O"); otherAgent.setAgentType(Agent.OTHER); otherAgent.setLastName("The Other Guys"); otherAgent.setEmail("other@other.com"); otherAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); otherAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(otherAgent); commitTx(); frame.setDesc("Group Persons..."); List<GroupPerson> gpList = new ArrayList<GroupPerson>(); if (true) { startTx(); Agent gm1 = createAgent("mr", "John", "A", "Lyon", "jal", "jal@group.edu"); Agent gm2 = createAgent("mr", "Dave", "D", "Jones", "ddj", "ddj@group.edu"); persist(gm1); persist(gm2); commitTx(); Agent groupAgent = new Agent(); groupAgent.initialize(); groupAgent.setAbbreviation("GRP"); groupAgent.setAgentType(Agent.GROUP); groupAgent.setLastName("The Group"); groupAgent.setEmail("group@group.com"); groupAgent.setTimestampCreated(new Timestamp(System.currentTimeMillis())); groupAgent.setDivision(AppContextMgr.getInstance().getClassObject(Division.class)); agents.add(groupAgent); gpList.add(createGroupPerson(groupAgent, gm1, 0, division)); gpList.add(createGroupPerson(groupAgent, gm2, 1, division)); } startTx(); List<Address> addrs = new Vector<Address>(); addrs.add(createAddress(agents.get(1), "1600 Pennsylvania Avenue NW", null, "Washington", "DC", "USA", "20500", 0)); addrs.add(createAddress(agents.get(1), "??? Mississippi", null, "Lawrence", "KS", "USA", "66045", 1)); addrs.add(createAddress(agents.get(2), "1 Main St", "", "Lenexa", "KS", "USA", "66071")); addrs.add(createAddress(agents.get(3), "13355 Inverness", "Bldg #3", "Lawrence", "KS", "USA", "66047")); addrs.add(createAddress(agents.get(4), "Natural History Museum", "Cromwell Rd", "London", null, "UK", "SW7 5BD")); addrs.add(createAddress(agents.get(6), "1212 Apple Street", null, "Chicago", "IL", "USA", "01010")); addrs.add(createAddress(agents.get(8), "11911 Oak Ln", null, "Orion", "KS", "USA", "66061")); addrs.add(createAddress(ku, null, null, "Lawrence", "KS", "USA", "66045")); // User Agent Address addrs.add(createAddress(userAgent, "1214 East Street", null, "Grinnell", "IA", "USA", "56060")); userAgent.setDivision(division); persist(agents); persist(gpList); commitTx(); startTx(); frame.setProcess(++createStep); frame.setDesc("Creating collecting events, collectors and a collecting trip..."); ////////////////////////////////////////////////// // collecting events (collectors, collecting trip) /////////////////////////////////////////////////// log.info("Creating collecting events, collectors and a collecting trip"); Collector collectorMitch = createCollector(agents.get(7), 2); Collector collectorJim = createCollector(agents.get(2), 1); calendar.set(1994, 4, 21, 11, 56, 00); String stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); CollectingEvent ce1 = createCollectingEvent(forestStream, calendar, stationFieldNumber, new Collector[] { collectorMitch, collectorJim }); ce1.setStartDateVerbatim("21 Apr 1994, 11:56 AM"); calendar.set(1994, 4, 21, 13, 03, 00); ce1.setEndDate(calendar); ce1.setEndDateVerbatim("21 Apr 1994, 1:03 PM"); ce1.setMethod("Picked"); AttributeDef cevAttrDef = createAttributeDef(AttributeIFace.FieldType.StringType, "ParkName", discipline, null);//meg added cod persist(cevAttrDef); commitTx(); startTx(); CollectingEventAttr cevAttr = createCollectingEventAttr(ce1, cevAttrDef, "Sleepy Hollow", null); Collector collectorMeg = createCollector(agents.get(2), 1); Collector collectorRod = createCollector(agents.get(3), 2); calendar.set(1994, 4, 22, 06, 12, 00); stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); CollectingEvent ce2 = createCollectingEvent(farmpond, calendar, stationFieldNumber, new Collector[] { collectorMeg, collectorRod }); ce2.setStartDateVerbatim("22 Apr 1994, 6:12 AM"); calendar.set(1994, 4, 22, 07, 31, 00); ce2.setEndDate(calendar); ce2.setEndDateVerbatim("22 Apr 1994, 7:31 AM"); ce2.setMethod("Picked"); //CollectingTrip trip = createCollectingTrip("Sample collecting trip", new CollectingEvent[]{ce1,ce2}); //dataObjects.add(trip); dataObjects.add(ce1); dataObjects.add(cevAttr); dataObjects.add(ce2); dataObjects.add(collectorMitch); dataObjects.add(collectorJim); dataObjects.add(collectorMeg); dataObjects.add(collectorRod); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); //////////////////////////////// // permit //////////////////////////////// log.info("Creating a permit"); frame.setDesc("Creating a permit..."); Calendar issuedDate = Calendar.getInstance(); issuedDate.set(1993, 1, 12); Calendar startDate = Calendar.getInstance(); startDate.set(1993, 2, 1); Calendar endDate = Calendar.getInstance(); endDate.set(1993, 5, 30); Permit permit = createPermit("1980-" + disciplineType.getAbbrev().substring(0, 2) + "-0001", "US Dept Wildlife", issuedDate, startDate, endDate, null); permit.setIssuedTo(ku); permit.setIssuedBy(agents.get(4)); dataObjects.add(permit); log.info("Creating a repository agreement"); RepositoryAgreement repoAg = new RepositoryAgreement(); repoAg.initialize(); repoAg.setDivision(division); repoAg.setRepositoryAgreementNumber("KU-" + disciplineType.getAbbrev() + "-01"); repoAg.setOriginator(ku); Calendar received = Calendar.getInstance(); received.set(1992, 2, 10); repoAg.setDateReceived(received); Calendar repoEndDate = Calendar.getInstance(); received.set(2010, 2, 9); repoAg.setEndDate(repoEndDate); dataObjects.add(repoAg); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // collection objects //////////////////////////////// log.info("Creating collection objects"); frame.setDesc("Creating collection objects..."); List<CollectionObject> collObjs = new Vector<CollectionObject>(); Collection col = collection; Calendar[] catDates = new Calendar[8]; for (int i = 0; i < catDates.length; i++) { catDates[i] = Calendar.getInstance(); int year = 1980 + (int) (rand.nextDouble() * 20.0); catDates[i].set(year, 01, 12 + i); } String prefix = "000000"; int catNo = 100; CollectingEvent[] colEves = new CollectingEvent[8]; for (int i = 0; i < colEves.length; i++) { colEves[i] = createFakeCollectingEvent(agents, farmpond, method); collObjs.add(createCollectionObject(prefix + Integer.toString(catNo), "RSC" + Integer.toString(catNo), agents.get(i), col, 1, colEves[i], catDates[i], "BuildSampleDatabase")); catNo++; } dataObjects.addAll(collObjs); for (CollectingEvent ce : colEves) { persist(ce); } persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // determinations (determination status) //////////////////////////////// log.info("Creating determinations"); frame.setDesc("Creating determinations..."); List<Determination> determs = new Vector<Determination>(); Calendar recent = Calendar.getInstance(); recent.set(2005, 10, 27, 13, 44, 00); Calendar longAgo = Calendar.getInstance(); longAgo.set(1976, 01, 29, 8, 12, 00); Calendar whileBack = Calendar.getInstance(); whileBack.set(2000, 7, 4, 9, 33, 12); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(5), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(6), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(7), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), true, recent)); determs.add(createDetermination(collObjs.get(0), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(1), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(2), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(3), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, whileBack)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.add(createDetermination(collObjs.get(4), getRandomAgent(agents), getRandomTaxon(TaxonTreeDef.SPECIES, taxa), false, longAgo)); determs.get(13).setRemarks("This determination is totally wrong. What a foolish determination."); persist(determs); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // preparations (prep types) //////////////////////////////// log.info("Creating preparations"); frame.setDesc("Creating preparations..."); Vector<PrepType> prepTypesForSaving = loadPrepTypes(discipline.getType()); PrepType pressed = prepTypesForSaving.get(0); List<Preparation> preps = new Vector<Preparation>(); Calendar prepDate = Calendar.getInstance(); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(4), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(5), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(6), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(7), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(10), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(2), collObjs.get(3), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(3), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(0), collObjs.get(5), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(6), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(7), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(3), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pressed, agents.get(1), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); dataObjects.addAll(prepTypesForSaving); dataObjects.addAll(preps); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); //////////////////////////////// // accessions (accession agents) //////////////////////////////// log.info("Creating accessions and accession agents"); frame.setDesc("Creating accessions..."); calendar.set(2006, 10, 27, 23, 59, 59); Accession acc1 = createAccession(division, "gift", "complete", "2000-" + disciplineType.getAbbrev().substring(0, 2) + "-001", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); acc1.setText1(disciplineType.getTitle()); acc1.setRepositoryAgreement(repoAg); Agent donor = agents.get(4); Agent receiver = agents.get(1); Agent reviewer = agents.get(2); List<AccessionAgent> accAgents = new Vector<AccessionAgent>(); accAgents.add(createAccessionAgent("donor", donor, acc1, null)); accAgents.add(createAccessionAgent("receiver", receiver, acc1, null)); accAgents.add(createAccessionAgent("reviewer", reviewer, acc1, null)); Accession acc2 = createAccession(division, "field_work", "inprocess", "2004-" + disciplineType.getAbbrev().substring(0, 2) + "-002", DateFormat.getInstance().format(calendar.getTime()), calendar, calendar); Agent donor2 = agents.get(5); Agent receiver2 = agents.get(3); Agent reviewer2 = agents.get(1); accAgents.add(createAccessionAgent("donor", donor2, acc2, null)); accAgents.add(createAccessionAgent("receiver", receiver2, acc2, null)); accAgents.add(createAccessionAgent("reviewer", reviewer2, acc2, null)); dataObjects.add(acc1); dataObjects.add(acc2); dataObjects.addAll(accAgents); persist(dataObjects); dataObjects.clear(); commitTx(); startTx(); frame.setProcess(++createStep); createLoanExamples(preps, agents, dataObjects); frame.setProcess(++createStep); persist(dataObjects); dataObjects.clear(); persist(dataObjects); dataObjects.clear(); frame.setProcess(++createStep); commitTx(); frame.setProcess(++createStep); buildDarwinCoreSchema(discipline); // done log.info("Done creating " + disciplineType.getTitle() + " disciplineType database: " + disciplineType.getTitle()); return dataObjects; }