/** * Take a node list of collections and create the structure from them * * @param context the context of the request * @param collections the node list of collections to be created * @param parent the parent community to whom the collections belong * @return an Element array containing additional information about the created collections (e.g. * the handle) */ private static Element[] handleCollections( Context context, NodeList collections, Community parent) throws Exception { Element[] elements = new Element[collections.getLength()]; for (int i = 0; i < collections.getLength(); i++) { Element element = new Element("collection"); Collection collection = parent.createCollection(); // default the short description to the empty string collection.setMetadata("short_description", " "); // import the rest of the metadata Node tn = collections.item(i); for (Map.Entry<String, String> entry : collectionMap.entrySet()) { NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey()); if (nl.getLength() == 1) { collection.setMetadata(entry.getValue(), getStringValue(nl.item(0))); } } collection.update(); element.setAttribute("identifier", collection.getHandle()); Element nameElement = new Element("name"); nameElement.setText(collection.getMetadata("name")); element.addContent(nameElement); if (collection.getMetadata("short_description") != null) { Element descriptionElement = new Element("description"); descriptionElement.setText(collection.getMetadata("short_description")); element.addContent(descriptionElement); } if (collection.getMetadata("introductory_text") != null) { Element introElement = new Element("intro"); introElement.setText(collection.getMetadata("introductory_text")); element.addContent(introElement); } if (collection.getMetadata("copyright_text") != null) { Element copyrightElement = new Element("copyright"); copyrightElement.setText(collection.getMetadata("copyright_text")); element.addContent(copyrightElement); } if (collection.getMetadata("side_bar_text") != null) { Element sidebarElement = new Element("sidebar"); sidebarElement.setText(collection.getMetadata("side_bar_text")); element.addContent(sidebarElement); } if (collection.getMetadata("license") != null) { Element sidebarElement = new Element("license"); sidebarElement.setText(collection.getMetadata("license")); element.addContent(sidebarElement); } if (collection.getMetadata("provenance_description") != null) { Element sidebarElement = new Element("provenance"); sidebarElement.setText(collection.getMetadata("provenance_description")); element.addContent(sidebarElement); } elements[i] = element; } return elements; }
/** * Create a new collection * * @param context The current DSpace context. * @param communityID The id of the parent community. * @return A process result's object. */ public static FlowResult processCreateCollection( Context context, int communityID, Request request) throws SQLException, AuthorizeException, IOException { FlowResult result = new FlowResult(); Community parent = Community.find(context, communityID); Collection newCollection = parent.createCollection(); // Get the metadata String name = request.getParameter("name"); String shortDescription = request.getParameter("short_description"); String introductoryText = request.getParameter("introductory_text"); String copyrightText = request.getParameter("copyright_text"); String sideBarText = request.getParameter("side_bar_text"); String license = request.getParameter("license"); String provenanceDescription = request.getParameter("provenance_description"); // If they don't have a name then make it untitled. if (name == null || name.length() == 0) { name = "Untitled"; } // If empty, make it null. if (shortDescription != null && shortDescription.length() == 0) { shortDescription = null; } if (introductoryText != null && introductoryText.length() == 0) { introductoryText = null; } if (copyrightText != null && copyrightText.length() == 0) { copyrightText = null; } if (sideBarText != null && sideBarText.length() == 0) { sideBarText = null; } if (license != null && license.length() == 0) { license = null; } if (provenanceDescription != null && provenanceDescription.length() == 0) { provenanceDescription = null; } // Save the metadata newCollection.setMetadata("name", name); newCollection.setMetadata("short_description", shortDescription); newCollection.setMetadata("introductory_text", introductoryText); newCollection.setMetadata("copyright_text", copyrightText); newCollection.setMetadata("side_bar_text", sideBarText); newCollection.setMetadata("license", license); newCollection.setMetadata("provenance_description", provenanceDescription); // Set the logo Object object = request.get("logo"); Part filePart = null; if (object instanceof Part) { filePart = (Part) object; } if (filePart != null && filePart.getSize() > 0) { InputStream is = filePart.getInputStream(); newCollection.setLogo(is); } // Save everything newCollection.update(); context.commit(); // success result.setContinue(true); result.setOutcome(true); result.setMessage(new Message("default", "The collection was successfully created.")); result.setParameter("collectionID", newCollection.getID()); return result; }