From: <aca...@us...> - 2008-05-26 07:36:37
|
Revision: 1296 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1296&view=rev Author: acarboni Date: 2008-05-26 00:36:41 -0700 (Mon, 26 May 2008) Log Message: ----------- GAST: Added possibility to change siteId, added possibility to specify siteId and group owner during MEF export Modified Paths: -------------- trunk/gast/data/gui.xml trunk/src/org/fao/gast/gui/panels/config/siteid/MainPanel.java trunk/src/org/fao/gast/gui/panels/manag/mefexport/SearchPanel.java trunk/src/org/fao/gast/lib/SiteLib.java Modified: trunk/gast/data/gui.xml =================================================================== --- trunk/gast/data/gui.xml 2008-05-22 11:29:03 UTC (rev 1295) +++ trunk/gast/data/gui.xml 2008-05-26 07:36:41 UTC (rev 1296) @@ -26,7 +26,7 @@ <image>22x22/configure.png</image> <label>Configuration</label> - <!-- Site ID - - - - - - - - - - - - - - - - - - - - - - - - + <!-- Site ID - - - - - - - - - - - - - - - - - - - - - - - --> <form> <id>siteid</id> @@ -35,24 +35,22 @@ <title>Site ID change</title> <class>config.siteid.MainPanel</class> <description> - Here you can change your installation's site ID. Because a site ID - must be unique, you are not allowed to enter a value but it will be - automatically generated. + *** WARNING *** Here you can change your installation's site ID + but you should not do this by hand, unless you are migrating + from a previous installation </description> <button> - <image>16x16/reload.png</image> - <label>Generate</label> - <action>generate</action> + <image>16x16/filesave.png</image> + <label>Change</label> + <action>change</action> </button> <precon type="stopped"> - GeoNetwork must be stopped because the SettingManager caches data. - There are also some other operations that it is better to do with - GeoNetwork stopped. + GeoNetwork must be stopped </precon> </form> - --> + <!-- Jetty - - - - - - - - - - - - - - - - - - - - - - - - --> <form> Modified: trunk/src/org/fao/gast/gui/panels/config/siteid/MainPanel.java =================================================================== --- trunk/src/org/fao/gast/gui/panels/config/siteid/MainPanel.java 2008-05-22 11:29:03 UTC (rev 1295) +++ trunk/src/org/fao/gast/gui/panels/config/siteid/MainPanel.java 2008-05-26 07:36:41 UTC (rev 1296) @@ -23,12 +23,16 @@ package org.fao.gast.gui.panels.config.siteid; +import java.awt.event.ActionEvent; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import jeeves.resources.dbms.Dbms; import org.dlib.gui.FlexLayout; import org.fao.gast.gui.panels.FormPanel; +import org.fao.gast.lib.Lib; +import org.fao.gast.lib.Resource; //============================================================================== @@ -48,7 +52,7 @@ fl.setColProp(1, FlexLayout.EXPAND); p.setLayout(fl); - p.add("0,0", new JLabel("Current")); + p.add("0,0", new JLabel("Site ID")); p.add("1,0,x", txtSiteID); return p; @@ -56,12 +60,39 @@ //--------------------------------------------------------------------------- //--- - //--- API methods + //--- ActionListener //--- //--------------------------------------------------------------------------- - public void refresh() + public void actionPerformed(ActionEvent ae) { + String siteId = txtSiteID.getText().trim(); + + Resource resource = null; + Dbms dbms = null; + + try + { + resource = Lib.config.createResource(); + dbms = (Dbms) resource.open(); + + Lib.site.setSiteId(dbms, siteId); + dbms.commit(); + + Lib.gui.showInfo(this, "Site ID changed"); + } + catch (Exception e) + { + Lib.gui.showError(this, e); + + if (dbms != null) + dbms.abort(); + } + finally + { + if (resource != null) + resource.close(); + } } //--------------------------------------------------------------------------- Modified: trunk/src/org/fao/gast/gui/panels/manag/mefexport/SearchPanel.java =================================================================== --- trunk/src/org/fao/gast/gui/panels/manag/mefexport/SearchPanel.java 2008-05-22 11:29:03 UTC (rev 1295) +++ trunk/src/org/fao/gast/gui/panels/manag/mefexport/SearchPanel.java 2008-05-26 07:36:41 UTC (rev 1296) @@ -23,17 +23,26 @@ package org.fao.gast.gui.panels.manag.mefexport; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JTextField; +import jeeves.utils.XmlRequest; import org.dlib.gui.FlexLayout; import org.dlib.gui.TPanel; -import org.fao.geonet.lib.Lib; +import org.fao.gast.app.App; +import org.fao.gast.app.Configuration; +import org.fao.gast.lib.Lib; +import org.fao.geonet.constants.Geonet; import org.jdom.Element; //============================================================================== -public class SearchPanel extends TPanel +public class SearchPanel extends TPanel implements ActionListener { //--------------------------------------------------------------------------- //--- @@ -45,15 +54,27 @@ { super("Search"); - FlexLayout fl = new FlexLayout(2,2); + FlexLayout fl = new FlexLayout(3,4); fl.setColProp(1, FlexLayout.EXPAND); setLayout(fl); add("0,0", new JLabel("Free text")); add("1,0,x", txtAny); - add("0,1", new JLabel("Templates")); - add("1,1", chbTemp); + add("0,1", new JLabel("Site ID")); + add("1,1,x", cmbSiteId); + add("2,1", btnRetrieve); + + add("0,2", new JLabel("Group owner")); + add("1,2,x", cmbGroup); + + add("0,3", new JLabel("Templates")); + add("1,3", chbTemp); + + btnRetrieve.addActionListener(this); + + cmbSiteId.addItem(new ComboInfo()); + cmbGroup .addItem(new ComboInfo()); } //--------------------------------------------------------------------------- @@ -64,23 +85,142 @@ public Element createRequest() { - Element req = new Element("request"); + Element req = new Element("request") + .addContent(new Element("any").setText(txtAny.getText())) + .addContent(new Element("template").setText(chbTemp.isSelected() ? "y" : "n")); - Lib.element.add(req, "any", txtAny.getText()); - Lib.element.add(req, "template", chbTemp.isSelected() ? "y" : "n"); + ComboInfo site = (ComboInfo) cmbSiteId.getSelectedItem(); + ComboInfo group = (ComboInfo) cmbGroup .getSelectedItem(); + if (site.id != null) + req.addContent(new Element("siteId").setText(site.id)); + + if (group.id != null) + req.addContent(new Element("group").setText(group.id)); + return req; } //--------------------------------------------------------------------------- + + public void actionPerformed(ActionEvent ae) + { + try + { + Configuration cfg = App.config; + + XmlRequest req = new XmlRequest(cfg.getHost(), cfg.getPort()); + + //--- login + + if (cfg.useAccount()) + Lib.service.login(req); + + //--- search + + req.setAddress("/"+ cfg.getServlet() +"/srv/en/"+ Geonet.Service.XML_INFO); + + Element params = new Element("request") + .addContent(new Element("type").setText("groups")) + .addContent(new Element("type").setText("sources")); + + handleInfo(req.execute(params)); + + + //--- logout + + if (cfg.useAccount()) + Lib.service.logout(req); + } + catch(Exception e) + { + Lib.gui.showError(this, e); + } + } + + //--------------------------------------------------------------------------- //--- + //--- Private + //--- + //--------------------------------------------------------------------------- + + private void handleInfo(Element info) + { + cmbSiteId.removeAllItems(); + cmbGroup .removeAllItems(); + + //--- handle sources + + for (Object o : info.getChild("sources").getChildren()) + { + Element source = (Element) o; + + String uuid = source.getChildText("uuid"); + String name = source.getChildText("name"); + + cmbSiteId.addItem(new ComboInfo(uuid, name)); + } + + //--- handle groups + + for (Object o : info.getChild("groups").getChildren()) + { + Element group = (Element) o; + + String id = group.getAttributeValue("id"); + String name = null; + + for (Object o2 : group.getChild("label").getChildren()) + { + Element grpLabel = (Element) o2; + + if (grpLabel.getName().equals("en") || name == null) + name = grpLabel.getText(); + } + + cmbGroup.addItem(new ComboInfo(id, name)); + } + + cmbSiteId.addItem(new ComboInfo()); + cmbGroup .addItem(new ComboInfo()); + } + + //--------------------------------------------------------------------------- + //--- //--- Variables //--- //--------------------------------------------------------------------------- - private JTextField txtAny = new JTextField(20); - private JCheckBox chbTemp = new JCheckBox(); + private JTextField txtAny = new JTextField(20); + private JComboBox cmbSiteId = new JComboBox(); + private JComboBox cmbGroup = new JComboBox(); + private JCheckBox chbTemp = new JCheckBox(); + private JButton btnRetrieve= new JButton("Retrieve"); } //============================================================================== +class ComboInfo +{ + public String id; + public String name; + + //--------------------------------------------------------------------------- + + public ComboInfo() {} + + //--------------------------------------------------------------------------- + + public ComboInfo(String id, String name) + { + this.id = id; + this.name = name; + } + + //--------------------------------------------------------------------------- + + public String toString() { return name; } +} + +//============================================================================== + Modified: trunk/src/org/fao/gast/lib/SiteLib.java =================================================================== --- trunk/src/org/fao/gast/lib/SiteLib.java 2008-05-22 11:29:03 UTC (rev 1295) +++ trunk/src/org/fao/gast/lib/SiteLib.java 2008-05-26 07:36:41 UTC (rev 1296) @@ -23,6 +23,7 @@ package org.fao.gast.lib; +import java.io.File; import java.sql.SQLException; import jeeves.constants.Jeeves; import jeeves.resources.dbms.Dbms; @@ -64,6 +65,23 @@ } //--------------------------------------------------------------------------- + + public void setSiteId(Dbms dbms, String uuid) throws SQLException + { + String oldUuid = getSiteId(dbms); + String appPath = Lib.server.getAppPath(); + + dbms.execute("UPDATE Metadata SET source=? WHERE isHarvested='n'", uuid); + dbms.execute("UPDATE Settings SET value=? WHERE name='siteId'", uuid); + dbms.execute("UPDATE Sources SET uuid=? WHERE uuid=?", uuid, oldUuid); + + File srcImg = new File(appPath +"/web/geonetwork/images/logos/"+ oldUuid +".gif"); + File desImg = new File(appPath +"/web/geonetwork/images/logos/"+ uuid +".gif"); + + srcImg.renameTo(desImg); + } + + //--------------------------------------------------------------------------- //--- //--- Variables //--- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |