📄 historymanager.java
字号:
.createProperty(uriPrefix + "/dublincore/" + type); model.add(res, p, dc.value); } // FIXME Ignoring Bundles for now, as they simply hold // bitstreams in the Early Adopters release. // When Bundles have their own metadata, they should be recorded Property hasPart = model.createProperty(getHarmonyId("hasPart")); // FIXME Not clear that we should ignore the internal bitstreams Bitstream[] bitstreams = item.getNonInternalBitstreams(); for (int i = 0; i < bitstreams.length; i++) { Bitstream bitstream = bitstreams[i]; model.add(res, hasPart, getUniqueId(bitstream)); // Serialize the bitstream's metadata serializeInternal(context, bitstream, model); } } /** * Add workspace-item-specific data to the model. * * @param context * The current DSpace context * @param wi * The WorkspaceItem * @param res * The RDF Resource representing the WorkspaceItem * @param model * The RDF Model * @exception SQLException * If an error occurs reading data about the WorkspaceItem * from the database * @exception RDFException * If an error occurs adding RDF statements to the model */ private static void addData(Context context, WorkspaceItem wi, Resource res, Model model) throws SQLException, RDFException { Item item = Item.find(context, wi.getItem().getID()); serializeInternal(context, item, model); } /** * Add workflow-item-specific data to the model. * * @param context * The current DSpace context * @param wi * The WorkflowItem * @param res * The RDF Resource representing the WorkflowItem * @param model * The RDF Model * @exception SQLException * If an error occurs reading data about the WorkflowItem * from the database * @exception RDFException * If an error occurs adding RDF statements to the model */ private static void addData(Context context, WorkflowItem wi, Resource res, Model model) throws SQLException, RDFException { Item item = Item.find(context, wi.getItem().getID()); serializeInternal(context, item, model); } /** * Add eperson-specific data to the model. * * @param context * The current DSpace context * @param eperson * The EPerson * @param res * The RDF Resource representing the EPerson * @param model * The RDF Model * @exception SQLException * If an error occurs reading data about the EPerson from the * database * @exception RDFException * If an error occurs adding RDF statements to the model */ private static void addData(Context context, EPerson eperson, Resource res, Model model) throws SQLException, RDFException { String shortname = getShortName(eperson); model.add(res, model.createProperty(getPropertyId(shortname, "ID")), eperson.getID()); model.add(res, model.createProperty(getPropertyId(shortname, "email")), eperson.getEmail()); model.add(res, model.createProperty(getPropertyId(shortname, "firstname")), eperson.getFirstName()); model.add(res, model .createProperty(getPropertyId(shortname, "lastname")), eperson .getLastName()); model.add(res, model.createProperty(getPropertyId(shortname, "active")), eperson.canLogIn()); model.add(res, model.createProperty(getPropertyId(shortname, "require_certificate")), eperson.getRequireCertificate()); String[] metadata = new String[] { "phone" }; for (int i = 0; i < metadata.length; i++) { String meta = metadata[i]; addMetadata(model, res, shortname, meta, eperson.getMetadata(meta)); } } /** * Convenience method to add a metadata statement to a model. * * @param model * The RDF graph * @param res * RDF resource * @param object * The name of the object * @param property * The name of a property of the object * @param value * The value of the property * @exception RDFException * If an error occurs while constructing an RDF graph */ private static void addMetadata(Model model, Resource res, String object, String property, String value) throws RDFException { if (value == null) { return; } model.add(res, model.createProperty(getPropertyId(object, property)), value); } //////////////////////////////////////// // File storage methods (stolen from BitstreamStorageManager) //////////////////////////////////////// /** * Return the File corresponding to id. * * @param id * The id * @param create * If true, the file will be created if it does not exist. * Otherwise, null will be returned. * @return The File corresponding to id * @exception IOException * If a filesystem error occurs while determining the * corresponding file. */ private static File forId(int id, boolean create) throws IOException { File file = new File(id2Filename(id)); if (!file.exists()) { if (!create) { return null; } File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } file.createNewFile(); } return file; } /** * Return the filename corresponding to id. * * @param id * The id * @return The filename corresponding to id * @exception IOException * If a filesystem error occurs while determining the name. */ private static String id2Filename(int id) throws IOException { NumberFormat nf = NumberFormat.getInstance(); // Do not use commas to separate digits nf.setGroupingUsed(false); // Ensure numbers are at least 8 digits nf.setMinimumIntegerDigits(8); String ID = nf.format(new Integer(id)); // Start with the root directory StringBuffer result = new StringBuffer().append(historyDirectory); // Split the id into groups for (int i = 0; i < directoryLevels; i++) { int digits = i * digitsPerLevel; result.append(File.separator).append( ID.substring(digits, digits + digitsPerLevel)); } // Lastly, add the id itself String theName = result.append(File.separator).append(id).toString(); if (log.isDebugEnabled()) { log.debug("Filename for " + id + " is " + theName); } return theName; } //////////////////////////////////////// // Utility methods //////////////////////////////////////// /** * Return a basic idea of which tool was used to do something. * * @return A String indicating the tool used */ private static String getTool() { String stacktrace = getStackTrace(); // Find the highest stack frame that contains org.dspace. try { BufferedReader reader = new BufferedReader(new StringReader( stacktrace)); String line = null; String match = null; while ((line = reader.readLine()) != null) { if (line.indexOf("org.dspace") != -1) { match = line.trim(); } } // If nothing matched, maybe the stacktrace will give a clue return (match == null) ? stacktrace : match; } // Should never get here -- no real I/O catch (Exception e) { return stacktrace; } } /** * Return a String containing the stack trace of the caller. * * @return A String containing the stack trace of the caller. */ public static String getStackTrace() { StringWriter writer = new StringWriter(); new Throwable().printStackTrace(new PrintWriter(writer)); return writer.toString(); } /** * Return the unqualified classname for object. * * @param obj * The object to check * @return The object's unqualified classname */ private static String getShortName(Object obj) { if (obj == null) { return null; } String classname = obj.getClass().getName(); int index = classname.lastIndexOf("."); return (index == -1) ? classname : classname.substring(index + 1); } /** * Return the current instant as an SQL timestamp. * * @return The current instant as an SQL timestamp. */ private static Timestamp nowAsTimeStamp() { return new java.sql.Timestamp(new java.util.Date().getTime()); } //////////////////////////////////////// // Main //////////////////////////////////////// /** * Embedded test harness * * @param argv - * Command-line arguments */ public static void main(String[] argv) { Context context = null; try { context = new Context(); Community c = Community.find(context, 1); if (c != null) { System.out.println("Got unique id " + getUniqueId(c)); saveHistory(context, c, CREATE, null, null); } Collection collection = Collection.find(context, 3); if (collection != null) { System.out.println("Got unique id " + getUniqueId(collection)); saveHistory(context, collection, CREATE, null, null); } // New eperson String email = "historytestuser@HistoryManager"; EPerson nep = EPerson.findByEmail(context, email); if (nep == null) { nep = EPerson.create(context); } nep.setFirstName("History"); nep.setEmail(email); nep.update(); saveHistory(context, nep, CREATE, null, null); // Change some things around nep.setFirstName("History Test"); nep.setLastName("User"); nep.update(); saveHistory(context, nep, MODIFY, null, null); Item item = Item.find(context, 1); if (item != null) { saveHistory(context, item, CREATE, null, null); } System.exit(0); } catch (Exception e) { e.printStackTrace(); } finally { if (context != null) { context.abort(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -