List of usage examples for java.text DateFormat getInstance
public static final DateFormat getInstance()
From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
private String printTooltip(int index) { String str = ""; str += dcModel.getInstance(index) + " | " + dcModel.getTask(index) + " | " + dcModel.getOriginator(index); long temp = dcModel.getTime(dcop.getTimeOption(), index); if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { str += " | " + DateFormat.getInstance().format(temp);// - // timeOffset); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_TIME)) { str += " | " + uiUtil.formatDate(temp); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_RATIO)) { str += " | " + uiUtil.formatRatio(temp); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL_RELATIVE)) { str += " | " + uiUtil.formatString(temp, 5); }//from ww w . ja va2s. c o m str += " | " + dcModel.getEvent(index); str += "<br>"; return str; }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private void setXYToolTipGenerator(XYPlot plot, UIChart comp) { UIAxis xAxis = comp.getxAxis();//from www . j a va 2 s . co m UIAxis yAxis = comp.getyAxis(); String xLabel = comp.getxAxisLabel(); if (xLabel == null && xAxis != null) xLabel = xAxis.getLabel(); String yLabel = comp.getyAxisLabel(); if (yLabel == null && yAxis != null) yLabel = yAxis.getLabel(); String labelFormat; if (xLabel != null && yLabel != null) { labelFormat = String.format("<h3>{0}</h3>%s: {1}<br/>%s: {2}", xLabel, yLabel); } else { labelFormat = "<h3>{0}</h3>({1}, {2})"; } if (comp.getDataSeries() instanceof UITimeSeries) { DateFormat xfmt; if (xAxis != null && xAxis.getItemTipFormat() != null) { xfmt = new SimpleDateFormat(xAxis.getItemTipFormat()); } else { xfmt = DateFormat.getInstance(); } NumberFormat yfmt; if (yAxis != null && yAxis.getItemTipFormat() != null) { yfmt = new DecimalFormat(yAxis.getItemTipFormat()); } else { yfmt = NumberFormat.getInstance(); } plot.getRenderer().setToolTipGenerator(new StandardXYToolTipGenerator(labelFormat, xfmt, yfmt)); } else { NumberFormat xfmt; if (xAxis != null && xAxis.getItemTipFormat() != null) { xfmt = new DecimalFormat(xAxis.getItemTipFormat()); } else { xfmt = NumberFormat.getInstance(); } NumberFormat yfmt; if (yAxis != null && yAxis.getItemTipFormat() != null) { yfmt = new DecimalFormat(yAxis.getItemTipFormat()); } else { yfmt = NumberFormat.getInstance(); } plot.getRenderer().setToolTipGenerator(new StandardXYToolTipGenerator(labelFormat, xfmt, yfmt)); } }
From source file:org.prom5.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
private String printTooltip(int index) { String str = ""; str += dcModel.getInstance(index) + " | " + dcModel.getTask(index) + " | " + dcModel.getOriginator(index); long temp = dcModel.getTime(dcop.getTimeOption(), index); if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { str += " | " + DateFormat.getInstance().format(temp);//- timeOffset); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_TIME)) { str += " | " + uiUtil.formatDate(temp); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_RATIO)) { str += " | " + uiUtil.formatRatio(temp); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL_RELATIVE)) { str += " | " + uiUtil.formatString(temp, 5); }//w w w .j a v a 2 s . c o m str += " | " + dcModel.getEvent(index); str += "<br>"; return str; }
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 w w . ja v a 2s . com 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:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private XYPlot getXYPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle, String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle, String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement, int height, int gridLines) throws cfmRunTimeException { // Create an XY plot XYPlot plot = new XYPlot(); ValueAxis domainAxis;/*from ww w . j ava 2s. com*/ if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_NUMERIC_SERIES) { if (bShow3D) domainAxis = new NumberAxis3D(xAxisTitle); else domainAxis = new NumberAxis(xAxisTitle); } else { domainAxis = new DateAxis(xAxisTitle); } plot.setDomainAxis(domainAxis); ValueAxis valueAxis; DateFormat dateFormat = null; NumberFormat numberFormat = null; if (labelFormat.equals("date")) { valueAxis = new DateAxis(yAxisTitle); dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); ((DateAxis) valueAxis).setDateFormatOverride(dateFormat); } else { if (bShow3D) valueAxis = new NumberAxis3D(yAxisTitle); else valueAxis = new NumberAxis(yAxisTitle); if (labelFormat.equals("currency")) { ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance()); numberFormat = NumberFormat.getCurrencyInstance(); } else if (labelFormat.equals("percent")) { numberFormat = NumberFormat.getPercentInstance(); numberFormat.setMaximumFractionDigits(3); // without this change .11443 // would be displayed as 11% // instead of 11.443% ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat); } else { numberFormat = NumberFormat.getInstance(); } if (yAxisUnits != 0) ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } plot.setRangeAxis(valueAxis); // Add a dataset and renderer for each series int barChartDatasetIndex = -1; int hBarChartDatasetIndex = -1; int num = 0; MinMaxData minMax = new MinMaxData(); for (int i = 0; i < series.size(); i++) { cfCHARTSERIESData seriesData = series.get(i); XYSeriesCollection dataset; if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) { dataset = (XYSeriesCollection) plot.getDataset(barChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex), dataset.getSeriesCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) { dataset = (XYSeriesCollection) plot.getDataset(hBarChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex), dataset.getSeriesCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else { dataset = new XYSeriesCollection(); addSeriesDataToDataset(seriesData, dataset, minMax); } plot.setDataset(num, dataset); XYItemRenderer renderer = null; if (seriesData.getType().equals("bar")) { plot.setOrientation(PlotOrientation.VERTICAL); renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setNegativeItemLabelPosition(position2); ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each // category barChartDatasetIndex = num; } else if (seriesData.getType().equals("horizontalbar")) { plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setNegativeItemLabelPosition(position2); ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each // category hBarChartDatasetIndex = num; } else if (seriesData.getType().equals("line")) { renderer = new XYLineAndShapeRenderer(true, false); // Enable/Disable displaying of markers ((XYLineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers); // Set the shape of the markers based on the markerSize value ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } else if (seriesData.getType().equals("area")) { renderer = new CustomXYAreaRenderer(); } else if (seriesData.getType().equals("step")) { renderer = new CustomXYStepRenderer(); } else if (seriesData.getType().equals("scatter")) { renderer = new XYLineAndShapeRenderer(false, true); // Set the shape of the markers based on the markerSize value ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } if (!tipStyle.equals("none")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {1}", DateFormat.getInstance(), DateFormat.getInstance())); } else { if (dateFormat != null) renderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator("{0}: {2}", dateFormat, dateFormat)); else renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", numberFormat, NumberFormat.getInstance())); } } if (drillDownUrl != null) { if (dateFormat != null) renderer.setURLGenerator( new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, dateFormat)); else renderer.setURLGenerator( new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, numberFormat)); } if (seriesData.getSeriesColor() != null) renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor())); String dataLabelStyle = seriesData.getDataLabelStyle(); if (labelFormat.equals("date")) { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setXYItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{2}", dateFormat, dateFormat)); else if (dataLabelStyle.equals("rowlabel")) renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{0}", NumberFormat.getInstance(), NumberFormat.getInstance())); else if (dataLabelStyle.equals("columnlabel")) renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", NumberFormat.getInstance(), NumberFormat.getInstance())); else if (dataLabelStyle.equals("pattern")) renderer.setItemLabelGenerator(new XYItemLabelGenerator("{2}", dateFormat, dateFormat)); else renderer.setItemLabelGenerator( new XYItemLabelGenerator(dataLabelStyle, dateFormat, dateFormat)); } } else { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setXYItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) { renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{2}", numberFormat, numberFormat)); } else if (dataLabelStyle.equals("rowlabel")) { renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{0}", numberFormat, numberFormat)); } else if (dataLabelStyle.equals("columnlabel")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", SimpleDateFormat.getInstance(), NumberFormat.getInstance())); } else { renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", NumberFormat.getInstance(), NumberFormat.getInstance())); } } else if (dataLabelStyle.equals("pattern")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})", SimpleDateFormat.getInstance(), numberFormat)); } else { renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})", NumberFormat.getInstance(), numberFormat)); } } else { renderer.setItemLabelGenerator( new XYItemLabelGenerator(dataLabelStyle, NumberFormat.getInstance(), numberFormat)); } } } // Add the renderer to the plot. // NOTE: this must be done before the setPaintStyle() call so the // DrawingSupplier object // will be set up properly for the generation of default colors. plot.setRenderer(num, renderer); // Set the paint style for this series (series 0) if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar") || seriesData.getType().equals("area")) setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height); num++; } // If gridLines was specified then we need to calculate the yAxisUnits if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) { // Calculate the yAxisUnits we need to use to create the number of // gridLines yAxisUnits = calculateYAxisUnits(gridLines, minMax); // Set the yAxisUnits ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } return plot; }
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.ja v a2s .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 .ja v a2 s.c o 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; }
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 va 2 s .c om @SuppressWarnings("unchecked") public Collection createFishCollection(final Discipline discipline, final SpecifyUser user, final Agent userAgent, final Division division, final Journal journal, final List<Object> taxa, final List<Object> geos, final String colPrefix, final String colName, final boolean isVoucherCol, final boolean doTissues, final CollectionChoice choice) { createStep = 0; frame.setProcess(0, 15); frame.setDesc("Creating Collection " + colName); startTx(); 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(colPrefix, colName, choice.getCatalogNumberingFmtName(), cns, discipline, false); persist(collection); AppContextMgr.getInstance().setClassObject(Collection.class, collection); division.addReference(accessionNS, "numberingSchemes"); persist(division); //////////////////////////////// // Default user groups and test user //////////////////////////////// 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())); persist(user); // Tester String userPrefix = (isVoucherCol) ? "" : "Tis"; createAndAddTesterToCollection(session, userPrefix + "FishTester", "fishtester@brc.ku.edu", userPrefix + "FishTester", "", "Fish", "", "Tester", "", discipline, division, collection, groupMap, "Guest"); commitTx(); //////////////////////////////// // picklists //////////////////////////////// log.info("Creating picklists"); createPickLists(session, null); BldrPickList colMethods = createPickLists(session, 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); frame.setProcess(++createStep); Vector<Object> dataObjects = new Vector<Object>(); standardQueries(dataObjects, userAgent); persist(dataObjects); dataObjects.clear(); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // localities //////////////////////////////// List<Locality> localities = new Vector<Locality>(); String POINT = "Point"; String LINE = "Line"; String RECT = "Rectangle"; Locality forestStream; Locality lake; Locality clintonLake; Locality farmpond; if (isVoucherCol) { log.info("Creating localities"); forestStream = createLocality("Unnamed forest stream pond", (Geography) geos.get(12)); localities.add(forestStream); globalLocalities.add(forestStream); 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)); lake = createLocality("Deep, dark lake pond", (Geography) geos.get(17)); localities.add(lake); globalLocalities.add(lake); 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)); Geography douglasKS = null; for (Object o : geos) { if (o instanceof Geography) { Geography g = (Geography) o; if (g.getFullName().indexOf("Douglas") == 0) { douglasKS = g; } } } clintonLake = createLocality("Clinton Lake", douglasKS); localities.add(clintonLake); globalLocalities.add(clintonLake); farmpond = createLocality("Shoal Creek at Schermerhorn Park, S of Galena at Rt. 26", (Geography) geos.get(11)); localities.add(farmpond); globalLocalities.add(farmpond); 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); persist(clintonLake); } else { forestStream = globalLocalities.get(0); lake = globalLocalities.get(1); farmpond = globalLocalities.get(2); localities.addAll(globalLocalities); } frame.setProcess(++createStep); //////////////////////////////// // agents and addresses //////////////////////////////// log.info("Creating agents and addresses"); List<Agent> agents = new Vector<Agent>(); Agent johnByrn = null; Agent ku = new Agent(); if (isVoucherCol) { johnByrn = createAgent("mr", "John", "D", "Byrn", "jb", "jb@net.edu"); agents.add(createAgent("mr", "David", "D", "Smith", "ds", "ds@whitehouse.gov")); agents.add(createAgent("mr", "Robert", "H", "Burk", "rb", "beach@net.edu")); agents.add(createAgent("mrs", "Margaret", "H", "Johnson", "jm", "jm@net.edu")); agents.add(createAgent("mr", "Kip", "C", "Spencer", "kcs", "kip@ku.edu")); agents.add(johnByrn); agents.add(createAgent("sir", "Dudley", "X", "Thompson", "dxt", "")); agents.add(createAgent("mr", "Joe", "A", "Campbell", "jb", "")); agents.add(createAgent("mr", "Joe", "A", "Tester", "jb", "")); agents.add(createAgent("mr", "Mitch", "A", "Smyth", "mas", "mas@ku.edu")); agents.add(userAgent); 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); 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(); //Discipline dsp = AppContextMgr.getInstance().getClassObject(Discipline.class); 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)); } globalAgents.addAll(agents); List<AgentVariant> agentVariants = new Vector<AgentVariant>(); agentVariants.add(createAgentVariant(AgentVariant.VARIANT, "John Variant #1", johnByrn)); agentVariants.add(createAgentVariant(AgentVariant.VERNACULAR, "John VERNACULAR #1", johnByrn)); 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")); addrs.add(createAddress(userAgent, "1214 East Street", null, "Grinnell", "IA", "USA", "56060")); persist(agents); persist(agentVariants); persist(gpList); } else { agents.addAll(globalAgents); johnByrn = agents.get(4); ku = agents.get(10); } frame.setProcess(++createStep); //////////////////////////////// // collecting events (collectors, collecting trip) //////////////////////////////// log.info("Creating collecting events, collectors and a collecting trip"); Collector collectorMitch = createCollector(agents.get(8), 2); Collector collectorJim = createCollector(agents.get(1), 1); calendar.set(1993, 3, 19, 11, 56, 00); String stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); CollectingEvent ce1 = createCollectingEvent(forestStream, calendar, stationFieldNumber, new Collector[] { collectorMitch, collectorJim }); ce1.setStartDateVerbatim("19 Mar 1993, 11:56 AM"); calendar.set(1993, 3, 19, 13, 03, 00); ce1.setEndDate(calendar); ce1.setEndDateVerbatim("19 Mar 1993, 1:03 PM"); ce1.setMethod(colMethods.getItem(1).getValue()); AttributeDef cevAttrDef = createAttributeDef(AttributeIFace.FieldType.StringType, "ParkName", discipline, null);//meg added cod //startTx(); persist(cevAttrDef); //commitTx(); CollectingEventAttr cevAttr = createCollectingEventAttr(ce1, cevAttrDef, "Sleepy Hollow", null); Collector collectorMeg = createCollector(agents.get(2), 1); Collector collectorRod = createCollector(agents.get(3), 2); calendar.set(1993, 3, 20, 06, 12, 00); stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); CollectingEvent ce2 = createCollectingEvent(farmpond, calendar, stationFieldNumber, new Collector[] { collectorMeg, collectorRod }); ce2.setStartDateVerbatim("20 Mar 1993, 6:12 AM"); calendar.set(1993, 3, 20, 07, 31, 00); ce2.setEndDate(calendar); ce2.setEndDateVerbatim("20 Mar 1993, 7:31 AM"); ce2.setMethod(colMethods.getItem(2).getValue()); CollectingTrip trip = createCollectingTrip("My Collecint Trip", "Sample collecting trip", new CollectingEvent[] { ce1, ce2 }); int[] mn = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Vector<CollectingEvent> ceList = new Vector<CollectingEvent>(); boolean oldWay = false; if (!oldWay) { int monInx = rand.nextInt(12); int dayInx = rand.nextInt(mn[monInx]); calendar.set(1990 + rand.nextInt(15), monInx + 1, dayInx + 1, rand.nextInt(24), rand.nextInt(60), rand.nextInt(60)); stationFieldNumber = String.format(STATION_FIELD_FORMAT, stationFieldNumberCounter++); Collector collector = null; int coltrInx = rand.nextInt(4); switch (coltrInx) { case 0: collector = collectorMitch; break; case 1: collector = collectorJim; break; case 2: collector = collectorMeg; break; case 3: collector = collectorRod; break; default: collector = collectorRod; break; } Locality loc = globalLocalities.get(rand.nextInt(globalLocalities.size())); CollectingEvent ce = createCollectingEvent(loc, calendar, stationFieldNumber, new Collector[] { collector }); //ce1.setStartDateVerbatim("19 Mar 1993, 11:56 AM"); ceList.add(ce); dataObjects.add(ce); } dataObjects.add(trip); dataObjects.add(ce1); dataObjects.add(cevAttr); dataObjects.add(ce2); dataObjects.add(collectorMitch); dataObjects.add(collectorJim); dataObjects.add(collectorMeg); dataObjects.add(collectorRod); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); //////////////////////////////// // 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("1993-FISH-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-1992-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); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // collection objects //////////////////////////////// log.info("Creating collection objects"); List<DNASequence> dnaObjs = new Vector<DNASequence>(); List<CollectionObject> collObjs = new Vector<CollectionObject>(); Collection col = collection; Calendar[] catDates = new Calendar[oldWay ? 8 : 50]; for (int i = 0; i < catDates.length; i++) { catDates[i] = Calendar.getInstance(); catDates[i].set(catDates[i].get(Calendar.YEAR), 01, 12 + i); } String prefix = "000000"; if (oldWay) { collObjs.add(createCollectionObject(prefix + "100", "RSC100", agents.get(0), col, 3, ce1, catDates[0], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "101", "RSC101", agents.get(0), col, 2, ce1, catDates[1], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "102", "RSC102", agents.get(1), col, 7, ce1, catDates[2], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "103", "RSC103", agents.get(1), col, 12, ce1, catDates[3], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "104", "RSC104", agents.get(2), col, 8, ce2, catDates[4], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "105", "RSC105", agents.get(2), col, 1, ce2, catDates[5], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "106", "RSC106", agents.get(2), col, 1, ce2, catDates[6], "BuildSampleDatabase")); collObjs.add(createCollectionObject(prefix + "107", "RSC107", agents.get(3), col, 1, ce2, catDates[7], "BuildSampleDatabase")); } else { for (int i = 0; i < catDates.length; i++) { Integer catNum = i + 100; int agentInx = rand.nextInt(agents.size()); CollectingEvent ce = ceList.get(rand.nextInt(ceList.size())); collObjs.add(createCollectionObject(prefix + catNum, "RSC" + catNum, agents.get(agentInx), col, rand.nextInt(12) + 1, ce, catDates[i], "BuildSampleDatabase")); } /* Comp. A : 148 Comp. G : 131 Comp. C : 199 Comp. T : 174 Ambiguous : 0 123456789012345678901234567890123456789012345678901234567890123456789012345 CCTGTATTTAGTATTTGGTGCCTGAGCAGGCATAGTCGGCACAGCCCTCAGCCTTCTGATCCGTGCCGAACTGAG CCAACCCGGTGCCCTGCTTGGCGATGATCAGATCTACAATGTTATCGTCACAGCCCACGCCTTTGTCATGATTTT CTTTATAGTAATACCCATCATAATTGGCGGATTCGGAAACTGACTGGTCCCCCTAATAATTGGGGCCCCAGACAT GGCATTTCCTCGCATGAACAATATGAGCTTCTGACTCCTACCCCCATCCTTCCTACTCCTTTTAGCCTCCTCTGG GGTAGAGGCCGGAGCCGGCACAGGGTGAACTGTTTACCCCCCACTGGCGGGAAACCTGGCCCATGCAGGAGCCTC TGTAGACCTAACCATTTTCTCCCTTCACCTGGCTGGGGTTTCGTCCATTTTGGGGGCTATTAATTTTATTACCAC CATTATTAACATGAAACCCCCCGCAGTATCCCAATATCAGACACCTCTATTTGTGTGATCTGTATTAATCACGGC CGTACTTCTCCTACTATCACTGCCAGTGCTAGCTGCAGGGATCACAATGCTCCTAACAGACCGAAATTTAAACAC CACCTTCTTTGACCCAGCCGGAGGAGGAGACCCCATCCTCTACCAACACCTA */ char[] syms = { 'A', 'C', 'T', 'G', }; for (int i = 0; i < catDates.length; i++) { int monInx = rand.nextInt(12); int dayInx = rand.nextInt(mn[monInx]); Calendar cal = Calendar.getInstance(); cal.set(2006 + rand.nextInt(3), monInx + 1, dayInx + 1, rand.nextInt(24), rand.nextInt(60), rand.nextInt(60)); DNASequence dna = new DNASequence(); dna.initialize(); //dna.setSeqDate(cal); //moved to DNASequencingRun dna.setCollectionMemberId(collObjs.get(i).getCollectionMemberId()); dna.setCollectionObject(collObjs.get(i)); //dna.setGeneName("COI5'"); int agentInx = rand.nextInt(agents.size()); dna.setCreatedByAgent(agents.get(agentInx)); dna.setSequencer(agents.get(agentInx)); StringBuilder sb = new StringBuilder(); for (int j = 0; j < ((8 * 75) + 52); j++) { sb.append(syms[rand.nextInt(syms.length)]); } dna.setGeneSequence(sb.toString()); //dna.setPcrPrimerFwd("C_VF1LFt1"); //moved to DNASequencingRun (sort of) //dna.setPcrPrimerRev("C_VR1LRt1"); //moved to DNASequencingRun (sort of) //dna.setProcessIdentifier("M13R"); //moved to DNASequencingRun (sort of) if (rand.nextInt(3) < 2) { //dna.setBarCodeIdent(String.format("NOSMF%03d-%d02", rand.nextInt(1000), i)); //moved to DNASequencingRun (sort of) Calendar submDate = (Calendar) cal.clone(); submDate.add(Calendar.DAY_OF_MONTH, 12); //dna.setSubmissionDate(submDate); } dnaObjs.add(dna); } } AttributeDef colObjAttrDef = createAttributeDef(AttributeIFace.FieldType.StringType, "MoonPhase", discipline, null);//meg added cod colObjAttrDef.setDiscipline(discipline); discipline.getAttributeDefs().add(colObjAttrDef); CollectionObjectAttr colObjAttr = createCollectionObjectAttr(collObjs.get(0), colObjAttrDef, "Full", null); dataObjects.add(colObjAttrDef); dataObjects.addAll(collObjs); dataObjects.addAll(dnaObjs); dataObjects.add(colObjAttr); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // determinations (determination status) //////////////////////////////// log.info("Creating determinations"); List<Determination> determs = new Vector<Determination>(); Calendar recent = Calendar.getInstance(); recent.set(2006, 10, 27, 13, 44, 00); Calendar longAgo = Calendar.getInstance(); longAgo.set(1976, 01, 29, 8, 12, 00); Calendar whileBack = Calendar.getInstance(); whileBack.set(2002, 7, 4, 9, 33, 12); int baseInx = 41 - (doShallowTaxonTree ? 30 : 0); if (oldWay) { determs.add(createDetermination(collObjs.get(0), agents.get(0), (Taxon) taxa.get(baseInx + 1), true, recent)); determs.add(createDetermination(collObjs.get(1), agents.get(0), (Taxon) taxa.get(baseInx + 2), true, recent)); determs.add(createDetermination(collObjs.get(2), agents.get(0), (Taxon) taxa.get(baseInx + 3), true, recent)); determs.add(createDetermination(collObjs.get(3), agents.get(0), (Taxon) taxa.get(baseInx + 4), true, recent)); determs.add(createDetermination(collObjs.get(4), agents.get(0), (Taxon) taxa.get(baseInx + 5), true, recent)); determs.add(createDetermination(collObjs.get(5), agents.get(0), (Taxon) taxa.get(baseInx + 6), true, recent)); determs.add(createDetermination(collObjs.get(6), agents.get(3), (Taxon) taxa.get(baseInx + 7), true, recent)); determs.add(createDetermination(collObjs.get(7), agents.get(4), (Taxon) taxa.get(baseInx + 8), true, recent)); determs.add( createDetermination(collObjs.get(0), agents.get(0), (Taxon) taxa.get(baseInx), false, longAgo)); determs.add(createDetermination(collObjs.get(1), agents.get(1), (Taxon) taxa.get(baseInx + 7), false, whileBack)); determs.add(createDetermination(collObjs.get(2), agents.get(1), (Taxon) taxa.get(baseInx + 9), false, whileBack)); determs.add(createDetermination(collObjs.get(3), agents.get(2), (Taxon) taxa.get(baseInx + 10), false, whileBack)); determs.add(createDetermination(collObjs.get(4), agents.get(2), (Taxon) taxa.get(baseInx + 10), false, whileBack)); determs.add(createDetermination(collObjs.get(4), agents.get(3), (Taxon) taxa.get(baseInx + 13), false, longAgo)); determs.add(createDetermination(collObjs.get(4), agents.get(4), (Taxon) taxa.get(baseInx + 12), false, longAgo)); determs.get(13).setRemarks("This determination is totally wrong. What a foolish determination."); } else { for (CollectionObject co : collObjs) { determs.add(createDetermination(co, agents.get(0), (Taxon) taxa.get(baseInx + rand.nextInt(13)), true, recent)); } } //startTx(); persist(determs); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // preparations (prep types) //////////////////////////////// log.info("Creating preparations"); Vector<PrepType> prepTypesForSaving = loadPrepTypes(discipline.getType()); Vector<PrepType> pt = new Vector<PrepType>(); if (doTissues) { pt.clear(); PrepType tissuePT = createPrepType(collection, "Tissue"); for (int i = 0; i < prepTypesForSaving.size(); i++) { pt.add(tissuePT); } prepTypesForSaving.clear(); prepTypesForSaving.add(tissuePT); } else { pt.addAll(prepTypesForSaving); } List<Preparation> preps = new Vector<Preparation>(); Calendar prepDate = Calendar.getInstance(); if (oldWay) { preps.add(createPreparation(pt.get(0), agents.get(0), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(0), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(1), collObjs.get(2), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(1), collObjs.get(3), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(2), collObjs.get(4), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(2), collObjs.get(5), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(3), collObjs.get(6), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(0), agents.get(3), collObjs.get(7), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(1), collObjs.get(0), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(1), collObjs.get(1), (Storage) locs.get(11), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(1), collObjs.get(2), (Storage) locs.get(10), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(2), collObjs.get(3), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(3), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(1), agents.get(0), collObjs.get(5), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(2), agents.get(1), collObjs.get(6), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(2), agents.get(1), collObjs.get(7), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(2), agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(3), agents.get(1), collObjs.get(0), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(3), agents.get(1), collObjs.get(1), (Storage) locs.get(7), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(3), agents.get(1), collObjs.get(2), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(3), agents.get(1), collObjs.get(3), (Storage) locs.get(8), rand.nextInt(20) + 1, prepDate)); preps.add(createPreparation(pt.get(3), agents.get(1), collObjs.get(4), (Storage) locs.get(9), rand.nextInt(20) + 1, prepDate)); } else { for (CollectionObject co : collObjs) { preps.add(createPreparation(pt.get(0), agents.get(rand.nextInt(4)), co, (Storage) locs.get(rand.nextInt(6) + 7), rand.nextInt(20) + 1, prepDate)); } } dataObjects.add(collection); dataObjects.addAll(prepTypesForSaving); dataObjects.addAll(preps); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // accessions (accession agents) //////////////////////////////// log.info("Creating accessions and accession agents"); calendar.set(2006, 10, 27, 23, 59, 59); int yr = 2000 + (int) (rand.nextDouble() * 7); Accession acc1 = createAccession(division, "gift", "complete", yr + "-IC-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", yr + "-IC-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); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); frame.setProcess(++createStep); createLoanExamples(preps, agents, dataObjects); frame.setProcess(++createStep); //startTx(); persist(dataObjects); //commitTx(); dataObjects.clear(); /*if (false) { TaxonCitation taxonCitation = new TaxonCitation(); taxonCitation.initialize(); Taxon taxon11 = (Taxon)taxa.get(11); taxonCitation.setTaxon(taxon11); taxonCitation.setReferenceWork(rwList.get(0)); rwList.get(0).addTaxonCitations(taxonCitation); taxon11.getTaxonCitations().add(taxonCitation); dataObjects.add(taxonCitation); LocalityCitation localityCitation = new LocalityCitation(); localityCitation.initialize(); localityCitation.setLocality(ce1.getLocality()); ce1.getLocality().getLocalityCitations().add(localityCitation); localityCitation.setReferenceWork(rwList.get(1)); rwList.get(1).addLocalityCitations(localityCitation); dataObjects.add(localityCitation); }*/ //////////////////////////////// // Workbench //////////////////////////////// // setup a template and its mapping items String name = discipline.getName() + " DataSet"; WorkbenchTemplate wbTemplate = createWorkbenchTemplate(user, name, "These are the remarks"); WorkbenchTemplateMappingItem wbtmi0 = createWorkbenchMappingItem("CollectionObject", 1, "fieldNumber", "Field Number", 25, 0, 0, wbTemplate); WorkbenchTemplateMappingItem wbtmi1 = createWorkbenchMappingItem("CollectionObject", 1, "catalogedDate", "Cataloged Date", 25, 1, 1, wbTemplate); WorkbenchTemplateMappingItem wbtmi2 = createWorkbenchMappingItem("CollectionObject", 1, "catalogNumber", "Catalog Number", 25, 2, 2, wbTemplate); WorkbenchTemplateMappingItem wbtmi3 = createWorkbenchMappingItem("CollectionObject", 1, "collectionObjectYesNo1", "Yes/No", 8, 3, 3, wbTemplate); dataObjects.add(wbTemplate); dataObjects.add(wbtmi0); dataObjects.add(wbtmi1); dataObjects.add(wbtmi2); dataObjects.add(wbtmi3); // setup a workbench based on that template Workbench workBench = createWorkbench(user, name, "These are the remarks", "field_notebook.cvs", wbTemplate); dataObjects.add(workBench); // create a bunch of rows for the workbench for (int i = 1; i <= 14; ++i) { WorkbenchRow wbRow = workBench.addRow(); WorkbenchDataItem wbdi0 = createWorkbenchDataItem(wbRow, "RS-10" + i, 0); // just to make the dates look a little random int date = (i * 547) % 31 + 1; String dateStr = "0" + Integer.toString(date); dateStr = dateStr.substring(dateStr.length() - 2); WorkbenchDataItem wbdi1 = createWorkbenchDataItem(wbRow, "03/" + dateStr + "/2007", 1); WorkbenchDataItem wbdi2 = createWorkbenchDataItem(wbRow, "CN-10" + i, 2); String boolValAsStr = null; switch (i % 3) { case 0: { boolValAsStr = "true"; break; } case 1: { boolValAsStr = "false"; break; } case 2: { boolValAsStr = ""; break; } } boolValAsStr = ""; WorkbenchDataItem wbdi3 = createWorkbenchDataItem(wbRow, boolValAsStr, 3); WorkbenchRowImage wbRowImage = null; File f = new File(getDefaultWorkingPath() + File.separator + "demo_files" + File.separator + "card" + i + (i == 2 ? ".png" : ".jpg")); if (f.exists()) { try { int imageIndex = wbRow.addImage(f); if (imageIndex > -1) { wbRowImage = wbRow.getRowImage(imageIndex); } } catch (IOException e) { String msg = getResourceString("WB_IMG_ERR_LOAD"); getStatusBar().setErrorMessage(msg, e); log.error(msg, e); } } dataObjects.add(wbRow); dataObjects.add(wbdi0); dataObjects.add(wbdi1); dataObjects.add(wbdi2); if (wbRowImage != null) { dataObjects.add(wbRowImage); } // since some of these values will be "", the data item might be null if (wbdi3 != null) { dataObjects.add(wbdi3); } } // // create a workbench that uses the old, single-image capabilities // Workbench workBench2 = createWorkbench(user, name + " (pre-conversion)", "These are the remarks", "field_notebook.cvs", wbTemplate); // dataObjects.add(workBench2); // // // create a bunch of rows for the workbench // for (int i = 1; i <= 14; ++i) // { // WorkbenchRow wbRow = workBench2.addRow(); // WorkbenchDataItem wbdi0 = createWorkbenchDataItem(wbRow, "RS-10" + i, 0); // // // just to make the dates look a little random // int date = (i*547) % 31 + 1; // String dateStr = "0" + Integer.toString(date); // dateStr = dateStr.substring(dateStr.length()-2); // WorkbenchDataItem wbdi1 = createWorkbenchDataItem(wbRow, "03/" + dateStr + "/2007", 1); // WorkbenchDataItem wbdi2 = createWorkbenchDataItem(wbRow, "CN-10" + i, 2); // // String boolValAsStr = null; // switch (i % 3) // { // case 0: // { // boolValAsStr = "true"; // break; // } // case 1: // { // boolValAsStr = "false"; // break; // } // case 2: // { // boolValAsStr = ""; // break; // } // } // boolValAsStr = ""; // WorkbenchDataItem wbdi3 = createWorkbenchDataItem(wbRow, boolValAsStr, 3); // // WorkbenchRowImage wbRowImage = null; // // File f = new File("demo_files" + File.separator + "card" + i + (i == 2 ? ".png" : ".jpg")); // if (f.exists()) // { // try // { // // NOTE: this is not scaling the images to the proper sizes. Since this is just sample DB/test code, this isn't a problem. // byte[] imageData = FileUtils.readFileToByteArray(f); // wbRow.setCardImageData(imageData); // wbRow.setCardImageFullPath(f.getAbsolutePath()); // } // catch (IOException e) // { // log.error("Unable to add card image to workbench row", e); // } // } // // dataObjects.add(wbRow); // dataObjects.add(wbdi0); // dataObjects.add(wbdi1); // dataObjects.add(wbdi2); // if (wbRowImage != null) // { // dataObjects.add(wbRowImage); // } // // // since some of these values will be "", the data item might be null // if (wbdi3 != null) // { // dataObjects.add(wbdi3); // } // } startTx(); persist(dataObjects); commitTx(); dataObjects.clear(); frame.setProcess(++createStep); //////////////////////////////// // attachments (attachment metadata) //////////////////////////////// startTx(); log.info("Creating attachments and attachment metadata"); try { String attachmentFilesLoc = getDefaultWorkingPath() + File.separator + "demo_files" + File.separator; // String bigEyeFilePath = attachmentFilesLoc + "bigeye.jpg"; // Attachment bigEye = createAttachment(bigEyeFilePath, "image/jpeg", 0); // bigEye.setLoan(closedLoan); String[] names = { "Beach", "Smyth", "Spears", "Kumin", "Bentley" }; String[] photos = { "beach.jpg", "rod.jpg", "rod.jpg", "meg.jpg", "andy.jpg" }; for (Agent agent : agents) { for (int i = 0; i < names.length; i++) { if (agent.getLastName() != null && agent.getLastName().startsWith(names[i])) { String photoPath = attachmentFilesLoc + photos[i]; File file = new File(attachmentFilesLoc + photos[i]); if (!file.exists()) { continue; } // create the attachment record Attachment photoAttachment = createAttachment(photoPath, "image/jpeg", Agent.getClassTableId()); dataObjects.add(photoAttachment); // link the attachment to the agent AgentAttachment agentAttach = new AgentAttachment(); agentAttach.initialize(); agentAttach.setAgent(agent); agentAttach.setAttachment(photoAttachment); agentAttach.setOrderIndex(0); dataObjects.add(agentAttach); // add some metadata to the attachment record AttachmentMetadata copyrightData = new AttachmentMetadata(); copyrightData.initialize(); copyrightData.setName("Copyright"); copyrightData.setValue("2008"); photoAttachment.getMetadata().add(copyrightData); copyrightData.setAttachment(photoAttachment); dataObjects.add(copyrightData); AttachmentMetadata defPhotoIndicator = new AttachmentMetadata(); defPhotoIndicator.initialize(); defPhotoIndicator.setName("Default Photo"); defPhotoIndicator.setValue("yes"); photoAttachment.getMetadata().add(defPhotoIndicator); defPhotoIndicator.setAttachment(photoAttachment); dataObjects.add(defPhotoIndicator); // store the actual file into the attachment storage system AttachmentUtils.getAttachmentManager().setStorageLocationIntoAttachment(photoAttachment, true); photoAttachment.storeFile(false); // false means do not display an error dialog } } } // String giftPdfPath = attachmentFilesLoc + "2004-18.pdf"; // Attachment giftPDF = createAttachment(giftPdfPath, "application/pdf", 0); // giftPDF.setLoan(closedLoan); // // String accessionPdfPath = attachmentFilesLoc + "Seychelles.pdf"; // Attachment accPDF = createAttachment(accessionPdfPath, "application/pdf", 0); // // TODO: change this to setAccession() // accPDF.setPermit(permit); // // String sharkVideoPath = attachmentFilesLoc + "shark5.mpg"; // Attachment sharkVideo = createAttachment(sharkVideoPath, "video/mpeg4", 0); // sharkVideo.setLoan(closedLoan); // // Attachment sharkVideo2 = createAttachment(sharkVideoPath, "video/mpeg4", 0); // sharkVideo2.setCollectingEvent(ce1); // // String beakerPath = attachmentFilesLoc + "beaker.jpg"; // Attachment beakerAsBeach = createAttachment(beakerPath, "image/jpg", 1); // beakerAsBeach.setAgent(agents.get(1)); // // dataObjects.add(bigEye); // dataObjects.add(giftPDF); // dataObjects.add(accPDF); // dataObjects.add(sharkVideo); // dataObjects.add(sharkVideo2); // dataObjects.add(beakerAsBeach); } catch (Exception e) { log.error("Could not create attachments", e); } addConservatorData(agents, collObjs); commitTx(); frame.setProcess(++createStep); if (true) { List<Taxon> taxa2 = session.createQuery("SELECT t FROM Taxon t WHERE t.name = 'Ammocrypta'").list(); List<ReferenceWork> rwList = new Vector<ReferenceWork>(); startTx(); rwList.addAll(journal.getReferenceWorks()); TaxonCitation taxonCitation = new TaxonCitation(); taxonCitation.initialize(); Taxon ammocrypta = taxa2.get(0); taxonCitation.setTaxon(ammocrypta); taxonCitation.setReferenceWork(rwList.get(0)); rwList.get(0).addTaxonCitations(taxonCitation); ammocrypta.getTaxonCitations().add(taxonCitation); dataObjects.add(taxonCitation); persist(taxonCitation); if (isVoucherCol) { Locality locality = localities.get(0); LocalityCitation localityCitation = new LocalityCitation(); localityCitation.initialize(); localityCitation.setLocality(locality); locality.getLocalityCitations().add(localityCitation); localityCitation.setReferenceWork(rwList.get(1)); rwList.get(1).addLocalityCitations(localityCitation); dataObjects.add(localityCitation); persist(localityCitation); } commitTx(); } frame.setProcess(++createStep); //SpecifyDeleteHelper.showTableCounts("EmptyDB.txt", true); return collection; }