Source Code Cross Referenced for GeonetHarvester.java in  » GIS » geonetwork » org » fao » geonet » kernel » harvest » harvester » geonet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » geonetwork » org.fao.geonet.kernel.harvest.harvester.geonet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.geonet.kernel.harvest.harvester.geonet;
025:
026:        import java.io.File;
027:        import java.sql.SQLException;
028:        import java.util.UUID;
029:        import jeeves.exceptions.BadInputEx;
030:        import jeeves.interfaces.Logger;
031:        import jeeves.resources.dbms.Dbms;
032:        import jeeves.server.context.ServiceContext;
033:        import jeeves.server.resources.ResourceManager;
034:        import org.fao.geonet.constants.Geonet;
035:        import org.fao.geonet.kernel.harvest.harvester.AbstractHarvester;
036:        import org.fao.geonet.kernel.harvest.harvester.AbstractParams;
037:        import org.fao.geonet.lib.Lib;
038:        import org.jdom.Element;
039:
040:        //=============================================================================
041:
042:        public class GeonetHarvester extends AbstractHarvester {
043:            public static final String TYPE = "geonetwork";
044:
045:            //--------------------------------------------------------------------------
046:            //---
047:            //--- Static init
048:            //---
049:            //--------------------------------------------------------------------------
050:
051:            public static void init(ServiceContext context) throws Exception {
052:            }
053:
054:            //--------------------------------------------------------------------------
055:            //---
056:            //--- Harvesting type
057:            //---
058:            //--------------------------------------------------------------------------
059:
060:            public String getType() {
061:                return TYPE;
062:            }
063:
064:            //--------------------------------------------------------------------------
065:            //---
066:            //--- Init
067:            //---
068:            //--------------------------------------------------------------------------
069:
070:            protected void doInit(Element node) throws BadInputEx {
071:                params = new GeonetParams(dataMan);
072:                params.create(node);
073:            }
074:
075:            //---------------------------------------------------------------------------
076:            //---
077:            //--- doDestroy
078:            //---
079:            //---------------------------------------------------------------------------
080:
081:            protected void doDestroy(Dbms dbms) throws SQLException {
082:                File icon = new File(context.getAppPath() + "images/logos",
083:                        params.uuid + ".gif");
084:
085:                icon.delete();
086:                Lib.sources.delete(dbms, params.uuid);
087:            }
088:
089:            //---------------------------------------------------------------------------
090:            //---
091:            //--- Add
092:            //---
093:            //---------------------------------------------------------------------------
094:
095:            protected String doAdd(Dbms dbms, Element node) throws BadInputEx,
096:                    SQLException {
097:                params = new GeonetParams(dataMan);
098:
099:                //--- retrieve/initialize information
100:                params.create(node);
101:
102:                //--- force the creation of a new uuid
103:                params.uuid = UUID.randomUUID().toString();
104:
105:                String id = settingMan.add(dbms, "harvesting", "node",
106:                        getType());
107:
108:                storeNode(dbms, params, "id:" + id);
109:                Lib.sources.update(dbms, params.uuid, params.name, false);
110:
111:                return id;
112:            }
113:
114:            //---------------------------------------------------------------------------
115:            //---
116:            //--- Update
117:            //---
118:            //---------------------------------------------------------------------------
119:
120:            protected void doUpdate(Dbms dbms, String id, Element node)
121:                    throws BadInputEx, SQLException {
122:                GeonetParams copy = params.copy();
123:
124:                //--- update variables
125:                copy.update(node);
126:
127:                String path = "harvesting/id:" + id;
128:
129:                settingMan.removeChildren(dbms, path);
130:
131:                //--- update database
132:                storeNode(dbms, copy, path);
133:
134:                //--- we update a copy first because if there is an exception GeonetParams
135:                //--- could be half updated and so it could be in an inconsistent state
136:
137:                Lib.sources.update(dbms, copy.uuid, copy.name, false);
138:
139:                params = copy;
140:            }
141:
142:            //---------------------------------------------------------------------------
143:
144:            protected void storeNodeExtra(Dbms dbms, AbstractParams p,
145:                    String path, String siteId, String optionsId)
146:                    throws SQLException {
147:                GeonetParams params = (GeonetParams) p;
148:
149:                settingMan.add(dbms, "id:" + siteId, "host", params.host);
150:                settingMan.add(dbms, "id:" + siteId, "port", params.port);
151:                settingMan.add(dbms, "id:" + siteId, "servlet", params.servlet);
152:
153:                //--- store search nodes
154:
155:                for (Search s : params.getSearches()) {
156:                    String searchID = settingMan.add(dbms, path, "search", "");
157:
158:                    settingMan.add(dbms, "id:" + searchID, "freeText",
159:                            s.freeText);
160:                    settingMan.add(dbms, "id:" + searchID, "title", s.title);
161:                    settingMan.add(dbms, "id:" + searchID, "abstract",
162:                            s.abstrac);
163:                    settingMan.add(dbms, "id:" + searchID, "keywords",
164:                            s.keywords);
165:                    settingMan
166:                            .add(dbms, "id:" + searchID, "digital", s.digital);
167:                    settingMan.add(dbms, "id:" + searchID, "hardcopy",
168:                            s.hardcopy);
169:                    settingMan.add(dbms, "id:" + searchID, "sourceUuid",
170:                            s.sourceUuid);
171:                    settingMan.add(dbms, "id:" + searchID, "sourceName",
172:                            s.sourceName);
173:                }
174:
175:                //--- store group mapping
176:
177:                for (Group g : params.getGroupCopyPolicy()) {
178:                    String groupID = settingMan.add(dbms, path,
179:                            "groupCopyPolicy", "");
180:
181:                    settingMan.add(dbms, "id:" + groupID, "name", g.name);
182:                    settingMan.add(dbms, "id:" + groupID, "policy", g.policy);
183:                }
184:            }
185:
186:            //---------------------------------------------------------------------------
187:            //---
188:            //--- addHarvestInfo
189:            //---
190:            //---------------------------------------------------------------------------
191:
192:            public void addHarvestInfo(Element info, String id, String uuid) {
193:                super .addHarvestInfo(info, id, uuid);
194:
195:                String small = context.getBaseUrl()
196:                        + "/srv/en/resources.get?access=public&id=" + id
197:                        + "&fname=";
198:
199:                String large = context.getBaseUrl()
200:                        + "/srv/en/graphover.show?access=public&id=" + id
201:                        + "&fname=";
202:
203:                info.addContent(new Element("smallThumbnail").setText(small));
204:                info.addContent(new Element("largeThumbnail").setText(large));
205:            }
206:
207:            //---------------------------------------------------------------------------
208:            //---
209:            //--- AbstractParameters
210:            //---
211:            //---------------------------------------------------------------------------
212:
213:            public AbstractParams getParams() {
214:                return params;
215:            }
216:
217:            //---------------------------------------------------------------------------
218:            //---
219:            //--- AddInfo
220:            //---
221:            //---------------------------------------------------------------------------
222:
223:            protected void doAddInfo(Element node) {
224:                //--- if the harvesting is not started yet, we don't have any info
225:
226:                if (result == null)
227:                    return;
228:
229:                //--- ok, add proper info
230:
231:                Element info = node.getChild("info");
232:                Element res = new Element("result");
233:
234:                add(res, "total", result.totalMetadata);
235:                add(res, "added", result.addedMetadata);
236:                add(res, "updated", result.updatedMetadata);
237:                add(res, "unchanged", result.unchangedMetadata);
238:                add(res, "unknownSchema", result.unknownSchema);
239:                add(res, "removed", result.locallyRemoved);
240:                add(res, "unretrievable", result.unretrievable);
241:
242:                info.addContent(res);
243:            }
244:
245:            //---------------------------------------------------------------------------
246:            //---
247:            //--- Harvest
248:            //---
249:            //---------------------------------------------------------------------------
250:
251:            protected void doHarvest(Logger log, ResourceManager rm)
252:                    throws Exception {
253:                Dbms dbms = (Dbms) rm.open(Geonet.Res.MAIN_DB);
254:
255:                Harvester h = new Harvester(log, context, dbms, params);
256:                result = h.harvest();
257:            }
258:
259:            //---------------------------------------------------------------------------
260:            //---
261:            //--- Variables
262:            //---
263:            //---------------------------------------------------------------------------
264:
265:            private GeonetParams params;
266:            private GeonetResult result;
267:        }
268:
269:        //=============================================================================
270:
271:        class GeonetResult {
272:            public int totalMetadata;
273:            public int addedMetadata;
274:            public int updatedMetadata;
275:            public int unchangedMetadata;
276:            public int locallyRemoved;
277:            public int unknownSchema;
278:            public int unretrievable;
279:        }
280:
281:        //=============================================================================
w__ww___.___j_av_a___2__s.__com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.