/ecat-checklistbank/src/test/java/org/gbif/manualtests/CreateDefaultDb.java
http://gbif-ecat.googlecode.com/ · Java · 132 lines · 89 code · 20 blank · 23 comment · 2 complexity · 54a1538973c2d5f5578a23627310ecf6 MD5 · raw file
- /***************************************************************************
- * Copyright 2010 Global Biodiversity Information Facility Secretariat
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- ***************************************************************************/
- package org.gbif.manualtests;
- import org.gbif.checklistbank.Constants;
- import org.gbif.checklistbank.TestConstants;
- import org.gbif.checklistbank.guice.BasicModule;
- import org.gbif.checklistbank.guice.ConfigModuleMaven;
- import org.gbif.checklistbank.model.Checklist;
- import org.gbif.checklistbank.model.voc.ChecklistType;
- import org.gbif.checklistbank.service.ChecklistImportService;
- import org.gbif.checklistbank.service.ChecklistService;
- import java.util.ArrayList;
- import java.util.List;
- import com.google.inject.Guice;
- import com.google.inject.Injector;
- /**
- * This class creates a new default test clb database to be dumped into a sql
- * file for testing. Dump the db into a sql file with:
- * pg_dump -U postgres -n public -i --inserts --no-owner clb-test > defaultdb.sql
- *
- * @author markus
- */
- public class CreateDefaultDb {
- private ChecklistImportService importService;
- private ChecklistService checklistService;
- public CreateDefaultDb(ChecklistImportService importService, ChecklistService checklistService) {
- super();
- this.importService = importService;
- this.checklistService = checklistService;
- }
- public static void main(String[] args) {
- Injector injector = Guice.createInjector(new ConfigModuleMaven(), new BasicModule(false));
- CreateDefaultDb db = new CreateDefaultDb(injector.getInstance(ChecklistImportService.class),
- injector.getInstance(ChecklistService.class));
- System.out.println("\n*** START POPULATING THE DEFAULT DATABASE ***");
- db.initDefaultDb();
- //db.initNubTestDb();
- System.out.println("\n\n\n*** DEFAULT DATABASE CREATED ***");
- System.out
- .println("\n dump db with:\n pg_dump -U postgres -n public -i --inserts --no-owner clb-test > defaultdb.sql");
- }
- private List<Checklist> checklists() {
- List<Checklist> lists = new ArrayList<Checklist>();
- Checklist c = new Checklist();
- c.setId(TestConstants.checklistId1Denormed);
- c.setNubPriority(c.getId());
- c.setResourceKey(TestConstants.resourceKey1Denormed);
- c.setType(ChecklistType.inventory);
- checklistService.insert(c);
- lists.add(checklistService.updateChecklistWithArchiveMetadata(c));
- c = new Checklist();
- c.setId(TestConstants.checklistId7Plants);
- c.setNubPriority(c.getId());
- c.setResourceKey(TestConstants.resourceKey7Plants);
- c.setType(ChecklistType.taxonomic);
- checklistService.insert(c);
- lists.add(checklistService.updateChecklistWithArchiveMetadata(c));
- c = new Checklist();
- c.setId(TestConstants.checklistId9Mammals);
- c.setNubPriority(c.getId());
- c.setResourceKey(TestConstants.resourceKey9Mammals);
- c.setType(ChecklistType.taxonomic);
- checklistService.insert(c);
- lists.add(checklistService.updateChecklistWithArchiveMetadata(c));
- return lists;
- }
- protected void initDefaultDb() {
- importService.initDatabase();
- for (Checklist c : checklists()) {
- importService.importChecklist(c, true);
- }
- }
- protected void initNubTestDb() {
- importService.initDatabase();
- for (Checklist c : nubChecklists()) {
- importService.importChecklist(c, false);
- }
- }
- private List<Checklist> nubChecklists() {
- List<Checklist> lists = new ArrayList<Checklist>();
- lists.add(checklistService.get(Constants.COL_CHECKLIST_ID));
- lists.add(checklistService.get(Constants.HOMONYM_CHECKLIST_ID));
- Checklist c = new Checklist();
- c.setType(ChecklistType.nomenclator);
- c.setTitle("IPNI");
- c.setDownloadUri("http://ecat-dev.gbif.org/repository/protected/nomenclators/ipni.zip");
- c.setNubPriority(10);
- checklistService.insert(c);
- lists.add(checklistService.updateChecklistWithArchiveMetadata(c));
- c = new Checklist();
- c.setType(ChecklistType.nomenclator);
- c.setTitle("Index Fungorum");
- c.setDownloadUri("http://ecat-dev.gbif.org/repository/protected/nomenclators/index_fungorum.zip");
- c.setNubPriority(9);
- checklistService.insert(c);
- lists.add(checklistService.updateChecklistWithArchiveMetadata(c));
- return lists;
- }
- }