Source Code Cross Referenced for Upgrade11To12.java in  » Content-Management-System » dspace » org » dspace » administer » 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 » Content Management System » dspace » org.dspace.administer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Upgrade11To12.java
003:         *
004:         * Version: $Revision: 1303 $
005:         *
006:         * Date: $Date: 2005-08-25 12:20:29 -0500 (Thu, 25 Aug 2005) $
007:         *
008:         * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009:         * Institute of Technology.  All rights reserved.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions are
013:         * met:
014:         *
015:         * - Redistributions of source code must retain the above copyright
016:         * notice, this list of conditions and the following disclaimer.
017:         *
018:         * - Redistributions in binary form must reproduce the above copyright
019:         * notice, this list of conditions and the following disclaimer in the
020:         * documentation and/or other materials provided with the distribution.
021:         *
022:         * - Neither the name of the Hewlett-Packard Company nor the name of the
023:         * Massachusetts Institute of Technology nor the names of their
024:         * contributors may be used to endorse or promote products derived from
025:         * this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028:         * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031:         * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038:         * DAMAGE.
039:         */
040:        package org.dspace.administer;
041:
042:        import org.dspace.content.Bitstream;
043:        import org.dspace.content.BitstreamFormat;
044:        import org.dspace.content.Bundle;
045:        import org.dspace.content.Collection;
046:        import org.dspace.content.Item;
047:        import org.dspace.content.ItemIterator;
048:        import org.dspace.core.Context;
049:
050:        /**
051:         * Command-line tool for making changes to DSpace database when updating from
052:         * version 1.1/1.1.1 to 1.2.
053:         * <P>
054:         * The changes are:
055:         * <ul>
056:         * <li>Setting owning collection field for items
057:         * <li>Reorganising content bitstreams into one bundle named ORIGINAL, license
058:         * bitstreams into a bundle named LICENSE
059:         * <li>Setting the sequence_id numbers in the bitstream table. This happens as
060:         * item.update() is called on every item.
061:         * <li>If a (newly-reorganised) 'ORIGINAL' bundle contains a text/html
062:         * bitstream, that bitstream is set to the primary bitstream for HTML support.
063:         * </ul>
064:         */
065:        public class Upgrade11To12 {
066:            public static void main(String[] argv) throws Exception {
067:                Context c = new Context();
068:
069:                // ve are superuser!
070:                c.setIgnoreAuthorization(true);
071:
072:                ItemIterator ii = null;
073:
074:                // first set owning Collections
075:                Collection[] collections = Collection.findAll(c);
076:
077:                System.out
078:                        .println("Setting item owningCollection fields in database");
079:
080:                for (int q = 0; q < collections.length; q++) {
081:                    ii = collections[q].getItems();
082:
083:                    while (ii.hasNext()) {
084:                        Item myItem = ii.next();
085:
086:                        // set it if it's not already set
087:                        if (myItem.getOwningCollection() == null) {
088:                            myItem.setOwningCollection(collections[q]);
089:                            myItem.update();
090:                            System.out.println("Set owner of item "
091:                                    + myItem.getID() + " to collection "
092:                                    + collections[q].getID());
093:                        }
094:                    }
095:                }
096:
097:                // commit pending transactions before continuing
098:                c.commit();
099:
100:                // now combine some bundles
101:                ii = Item.findAll(c);
102:
103:                while (ii.hasNext()) {
104:                    boolean skipItem = false;
105:                    Item myItem = ii.next();
106:
107:                    int licenseBundleIndex = -1; // array index of license bundle (we'll
108:                    // skip this one often)
109:                    int primaryBundleIndex = -1; // array index of our primary bundle
110:                    // (all bitstreams assemble here)
111:
112:                    System.out.println("Processing item #: " + myItem.getID());
113:
114:                    Bundle[] myBundles = myItem.getBundles();
115:
116:                    // look for bundles with multiple bitstreams
117:                    // (if any found, we'll skip this item)
118:                    for (int i = 0; i < myBundles.length; i++) {
119:                        // skip if bundle is already named
120:                        if (myBundles[i].getName() != null) {
121:                            System.out
122:                                    .println("Skipping this item - named bundles already found");
123:                            skipItem = true;
124:
125:                            break;
126:                        }
127:
128:                        Bitstream[] bitstreams = myBundles[i].getBitstreams();
129:
130:                        // skip this item if we already have bundles combined in this
131:                        // item
132:                        if (bitstreams.length > 1) {
133:                            System.out
134:                                    .println("Skipping this item - compound bundles already found");
135:                            skipItem = true;
136:
137:                            break;
138:                        }
139:
140:                        // is this the license? check the format
141:                        BitstreamFormat bf = bitstreams[0].getFormat();
142:
143:                        if (bf.getShortDescription().equals("License")) {
144:                            System.out.println("Found license!");
145:
146:                            if (licenseBundleIndex == -1) {
147:                                licenseBundleIndex = i;
148:                                System.out.println("License bundle set to: "
149:                                        + i);
150:                            } else {
151:                                System.out
152:                                        .println("ERROR - multiple license bundles in item - skipping");
153:                                skipItem = true;
154:
155:                                break;
156:                            }
157:                        } else {
158:                            // not a license, if primary isn't set yet, set it
159:                            if (primaryBundleIndex == -1) {
160:                                primaryBundleIndex = i;
161:                                System.out.println("Primary bundle set to: "
162:                                        + i);
163:                            }
164:                        }
165:                    }
166:
167:                    if (!skipItem) {
168:                        // name the primary and license bundles
169:                        if (primaryBundleIndex != -1) {
170:                            myBundles[primaryBundleIndex].setName("ORIGINAL");
171:                            myBundles[primaryBundleIndex].update();
172:                        }
173:
174:                        if (licenseBundleIndex != -1) {
175:                            myBundles[licenseBundleIndex].setName("LICENSE");
176:                            myBundles[licenseBundleIndex].update();
177:                        }
178:
179:                        for (int i = 0; i < myBundles.length; i++) {
180:                            Bitstream[] bitstreams = myBundles[i]
181:                                    .getBitstreams();
182:
183:                            // now we can safely assume no bundles with multiple
184:                            // bitstreams
185:                            if (bitstreams.length > 0) {
186:                                if ((i != primaryBundleIndex)
187:                                        && (i != licenseBundleIndex)) {
188:                                    // only option left is a bitstream to be combined
189:                                    // with primary bundle
190:                                    // and remove now-redundant bundle
191:                                    myBundles[primaryBundleIndex]
192:                                            .addBitstream(bitstreams[0]); // add to
193:                                    // primary
194:                                    myItem.removeBundle(myBundles[i]); // remove this
195:                                    // bundle
196:
197:                                    System.out.println("Bitstream from bundle "
198:                                            + i + " moved to primary bundle");
199:
200:                                    // flag if HTML bitstream
201:                                    if (bitstreams[0].getFormat().getMIMEType()
202:                                            .equals("text/html")) {
203:                                        System.out
204:                                                .println("Set primary bitstream to HTML file in item #"
205:                                                        + myItem.getID()
206:                                                        + " for HTML support.");
207:                                    }
208:                                }
209:                            }
210:                        }
211:                    }
212:                }
213:
214:                c.complete();
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.