001: //==============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.gast.cli.setup;
025:
026: import java.io.File;
027: import java.util.List;
028: import jeeves.resources.dbms.Dbms;
029: import org.fao.gast.lib.Lib;
030: import org.fao.gast.lib.Resource;
031:
032: //==============================================================================
033:
034: public class Setup {
035: public void exec(String appPath, List<String> args)
036: throws Exception {
037: //--- this line saves the 'gast/data/index.html' file into 'web'
038: //--- substituting the $SERVLET variable
039:
040: Lib.embeddedSC.save();
041:
042: //--- now we create the embedded database...
043:
044: Lib.embeddedDB.createDB();
045:
046: //--- ... and save the account into the config.xml file
047:
048: Lib.config.setDbmsUser(Lib.embeddedDB.getUser());
049: Lib.config.setDbmsPassword(Lib.embeddedDB.getPassword());
050: Lib.config.addActivator();
051: Lib.config.save();
052:
053: //--- proper setup: open a database connection and setup data
054:
055: Resource resource = Lib.config.createResource();
056: Lib.database.setup(resource, null);
057:
058: //--- ask for and install sample metadata
059:
060: if (Lib.gui.confirm(null, SAMPLE_MSG))
061: addSampleData(appPath);
062: }
063:
064: //---------------------------------------------------------------------------
065:
066: private void addSampleData(String appPath) throws Exception {
067: Lib.log.info("Adding sample metadata");
068:
069: Resource resource = Lib.config.createResource();
070: Dbms dbms = (Dbms) resource.open();
071:
072: try {
073: int serial = Lib.database.getNextSerial(dbms, "Metadata");
074: dbms.commit();
075:
076: File sampleDir = new File(appPath, SAMPLE_PATH);
077: File[] samples = sampleDir.listFiles();
078:
079: if (samples == null)
080: Lib.log.warning("Cannot scan directory : "
081: + sampleDir.getAbsolutePath());
082: else {
083: for (File sample : samples)
084: if (sample.getName().endsWith(".mef")) {
085: Lib.mef.doImport(dbms, serial++, sample);
086: dbms.commit();
087: }
088: }
089:
090: Lib.log.info("Synchronizing metadata");
091: Lib.metadata.sync(dbms);
092: resource.close();
093: Lib.log.info("Done");
094: } catch (Exception e) {
095: Lib.log.fatal("Raised exception : " + e.getMessage());
096: resource.abort();
097: throw e;
098: }
099: }
100:
101: //---------------------------------------------------------------------------
102: //---
103: //--- Variables
104: //---
105: //---------------------------------------------------------------------------
106:
107: private static final String SAMPLE_MSG = "Do you want to install sample metadata ?";
108: private static final String SAMPLE_PATH = "gast/setup/sample-data";
109: }
110:
111: //==============================================================================
|