protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { Integer itemID = UIUtil.getIntParameter(request, "itemID"); Item item = Item.find(context, itemID); String submit = UIUtil.getSubmitButton(request, "submit"); if (submit != null && submit.equals("submit")) { request.setAttribute("itemID", itemID); JSPManager.showJSP(request, response, "/tools/version-summary.jsp"); return; } String summary = request.getParameter("summary"); if (submit != null && submit.equals("submit_version")) { Integer wsid = VersionUtil.processCreateNewVersion(context, itemID, summary); response.sendRedirect(request.getContextPath() + "/submit?resume=" + wsid); context.complete(); return; } else if (submit != null && submit.equals("submit_update_version")) { String versionID = request.getParameter("versionID"); request.setAttribute("itemID", itemID); request.setAttribute("versionID", versionID); JSPManager.showJSP(request, response, "/tools/version-update-summary.jsp"); return; } // Send us back to the item page if we cancel ! response.sendRedirect(request.getContextPath() + "/handle/" + item.getHandle()); context.complete(); }
private void deleteItems(Context c, String mapFile) throws Exception { System.out.println("Deleting items listed in mapfile: " + mapFile); // read in the mapfile Map<String, String> myhash = readMapFile(mapFile); // now delete everything that appeared in the mapFile Iterator<String> i = myhash.keySet().iterator(); while (i.hasNext()) { String itemID = myhash.get(i.next()); if (itemID.indexOf('/') != -1) { String myhandle = itemID; System.out.println("Deleting item " + myhandle); deleteItem(c, myhandle); } else { // it's an ID Item myitem = Item.find(c, Integer.parseInt(itemID)); System.out.println("Deleting item " + itemID); deleteItem(c, myitem); } c.clearCache(); } }
private void replaceItems( Context c, Collection[] mycollections, String sourceDir, String mapFile, boolean template) throws Exception { // verify the source directory File d = new java.io.File(sourceDir); if (d == null || !d.isDirectory()) { System.out.println("Error, cannot open source directory " + sourceDir); System.exit(1); } // read in HashMap first, to get list of handles & source dirs Map<String, String> myHash = readMapFile(mapFile); // for each handle, re-import the item, discard the new handle // and re-assign the old handle for (Map.Entry<String, String> mapEntry : myHash.entrySet()) { // get the old handle String newItemName = mapEntry.getKey(); String oldHandle = mapEntry.getValue(); Item oldItem = null; if (oldHandle.indexOf('/') != -1) { System.out.println("\tReplacing: " + oldHandle); // add new item, locate old one oldItem = (Item) HandleManager.resolveToObject(c, oldHandle); } else { oldItem = Item.find(c, Integer.parseInt(oldHandle)); } /* Rather than exposing public item methods to change handles -- * two handles can't exist at the same time due to key constraints * so would require temp handle being stored, old being copied to new and * new being copied to old, all a bit messy -- a handle file is written to * the import directory containing the old handle, the existing item is * deleted and then the import runs as though it were loading an item which * had already been assigned a handle (so a new handle is not even assigned). * As a commit does not occur until after a successful add, it is safe to * do a delete as any error results in an aborted transaction without harming * the original item */ File handleFile = new File(sourceDir + File.separatorChar + newItemName + File.separatorChar + "handle"); PrintWriter handleOut = new PrintWriter(new FileWriter(handleFile, true)); if (handleOut == null) { throw new Exception("can't open handle file: " + handleFile.getCanonicalPath()); } handleOut.println(oldHandle); handleOut.close(); deleteItem(c, oldItem); addItem(c, mycollections, sourceDir, newItemName, null, template); c.clearCache(); } }
/** * Return the results of the Browse as an Item array. * * @return The results of the Browse as an Item array. */ public Item[] getItemResults(Context context) throws BrowseException { try { BrowseItem[] bis = getBrowseItemResults(); Item[] items = new Item[bis.length]; for (int i = 0; i < bis.length; i++) { items[i] = Item.find(context, bis[i].getID()); } return items; } catch (SQLException e) { throw new BrowseException(e); } }
/** * Construct a workspace item corresponding to the given database row * * @param context the context this object exists in * @param row the database row */ WorkflowItem(Context context, TableRow row) throws SQLException { ourContext = context; wfRow = row; item = Item.find(context, wfRow.getIntColumn("item_id")); collection = Collection.find(context, wfRow.getIntColumn("collection_id")); if (wfRow.isColumnNull("owner")) { owner = null; } else { owner = EPerson.find(context, wfRow.getIntColumn("owner")); } // Cache ourselves context.cache(this, row.getIntColumn("workflow_id")); }
/** * Match Item URIs that identify the item by a database ID. Handle URIs are matched by * DAVDSpaceObject. * * @param context the context * @param request the request * @param response the response * @param pathElt the path elt * @return the DAV resource * @throws DAVStatusException the DAV status exception * @throws SQLException the SQL exception */ protected static DAVResource matchResourceURI( Context context, HttpServletRequest request, HttpServletResponse response, String pathElt[]) throws DAVStatusException, SQLException { int id = -1; String bsElt = null; try { // The "/item_db_" element in last or next-to-last element if (pathElt[pathElt.length - 1].startsWith("item_db_")) { id = Integer.parseInt(pathElt[pathElt.length - 1].substring(8)); } else if (pathElt[pathElt.length - 1].startsWith("bitstream_") && pathElt.length > 1 && pathElt[pathElt.length - 2].startsWith("item_db_")) { id = Integer.parseInt(pathElt[pathElt.length - 2].substring(8)); bsElt = pathElt[pathElt.length - 1]; } if (id >= 0) { Item item = Item.find(context, id); if (item == null) { throw new DAVStatusException( HttpServletResponse.SC_NOT_FOUND, "Item with ID=" + String.valueOf(id) + " not found."); } if (bsElt != null) { Bitstream bs = DAVBitstream.findBitstream(context, item, bsElt); if (bs == null) { throw new DAVStatusException(HttpServletResponse.SC_NOT_FOUND, "Bitstream not found."); } return new DAVBitstream(context, request, response, pathElt, item, bs); } else { return new DAVItem(context, request, response, pathElt, item); } } return null; } catch (NumberFormatException ne) { throw new DAVStatusException( HttpServletResponse.SC_BAD_REQUEST, "Error parsing number in request URI."); } }
/** * Sends an email to the given e-person with details of new items in the given dspace object (MUST * be a community or a collection), items that appeared yesterday. No e-mail is sent if there * aren't any new items in any of the dspace objects. * * @param context DSpace context object * @param eperson eperson to send to * @param rpkeys List of DSpace Objects * @param test * @throws SearchServiceException */ public static void sendEmail( Researcher researcher, Context context, EPerson eperson, List<String> rpkeys, boolean test, List<String> relationFields) throws IOException, MessagingException, SQLException, SearchServiceException { CrisSearchService searchService = researcher.getCrisSearchService(); // Get a resource bundle according to the eperson language preferences Locale supportedLocale = I18nUtil.getEPersonLocale(eperson); StringBuffer emailText = new StringBuffer(); boolean isFirst = true; for (String rpkey : rpkeys) { SolrQuery query = new SolrQuery(); query.setFields("search.resourceid"); query.addFilterQuery( "{!field f=search.resourcetype}" + Constants.ITEM, "{!field f=inarchive}true"); for (String tmpRelations : relationFields) { String fq = "{!field f=" + tmpRelations + "}" + rpkey; query.addFilterQuery(fq); } query.setRows(Integer.MAX_VALUE); if (ConfigurationManager.getBooleanProperty("eperson.subscription.onlynew", false)) { // get only the items archived yesterday query.setQuery("dateaccessioned:(NOW/DAY-1DAY)"); } else { // get all item modified yesterday but not published the day // before // and all the item modified today and archived yesterday query.setQuery( "(item.lastmodified:(NOW/DAY-1DAY) AND dateaccessioned:(NOW/DAY-1DAY)) OR ((item.lastmodified:(NOW/DAY) AND dateaccessioned:(NOW/DAY-1DAY)))"); } QueryResponse qResponse = searchService.search(query); SolrDocumentList results = qResponse.getResults(); // Only add to buffer if there are new items if (results.getNumFound() > 0) { if (!isFirst) { emailText.append("\n---------------------------------------\n"); } else { isFirst = false; } emailText .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.new-items", supportedLocale)) .append(" ") .append(rpkey) .append(": ") .append(results.getNumFound()) .append("\n\n"); for (SolrDocument solrDoc : results) { Item item = Item.find(context, (Integer) solrDoc.getFieldValue("search.resourceid")); DCValue[] titles = item.getDC("title", null, Item.ANY); emailText .append(" ") .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.title", supportedLocale)) .append(" "); if (titles.length > 0) { emailText.append(titles[0].value); } else { emailText.append( I18nUtil.getMessage("org.dspace.eperson.Subscribe.untitled", supportedLocale)); } DCValue[] authors = item.getDC("contributor", Item.ANY, Item.ANY); if (authors.length > 0) { emailText .append("\n ") .append( I18nUtil.getMessage("org.dspace.eperson.Subscribe.authors", supportedLocale)) .append(" ") .append(authors[0].value); for (int k = 1; k < authors.length; k++) { emailText.append("\n ").append(authors[k].value); } } emailText .append("\n ") .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.id", supportedLocale)) .append(" ") .append(HandleManager.getCanonicalForm(item.getHandle())) .append("\n\n"); context.removeCached(item, item.getID()); } } } // Send an e-mail if there were any new items if (emailText.length() > 0) { if (test) { log.info(LogManager.getHeader(context, "subscription:", "eperson=" + eperson.getEmail())); log.info(LogManager.getHeader(context, "subscription:", "text=" + emailText.toString())); } else { Email email = ConfigurationManager.getEmail( I18nUtil.getEmailFilename(supportedLocale, "subscription")); email.addRecipient(eperson.getEmail()); email.addArgument(emailText.toString()); email.send(); log.info( LogManager.getHeader(context, "sent_subscription", "eperson_id=" + eperson.getID())); } } }
/** * See if the last backup done is updated and if it is in cloud. DSpace Object could be community, * collection or item * * @param context DSpace context * @param ref ID of the object * @param type type of the object DSpace * @return true if the updated backup is in the cloud or false if not */ private Boolean sendDone(Context context, int ref, int type) { // see if object is a community or collection if (type == Constants.COMMUNITY || type == Constants.COLLECTION) { // see if there is a modification registry in the db Logbackup logbackup = new Logbackup(); Boolean existLog = logbackup.existsLog(context, ref, type); // if modification has been detected return false if (existLog == true) return false; } // get the DSpaceObject DSpaceObject obj = this.getDSpaceObject(context, type, ref); // if Object DSpace doesn't exist, return false if (obj == null) return false; // see if exist a regist of a backup in the table sthandfile BackupProcess backupProcess = new BackupProcess(); Boolean existRegist = backupProcess.existRegist(context, obj.getHandle()); // if doesn't exist a regist return false if (existRegist == false) return false; // see if object is an item if (type == Constants.ITEM) { // get the last modification date of the item Item item = null; try { item = Item.find(context, ref); } catch (SQLException ex) { Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex); } Date lastModification = item.getLastModified(); // get the last backup date Date lastBackup = backupProcess.getLastBackupDate(context, obj.getHandle()); // see if some modification happens after a backup if (lastModification.after(lastBackup) == true) return false; } // get the last send cloud dat Date lastSendCloud = backupProcess.getLastSendCloudDate(context, obj.getHandle()); // if doesn't exist a date relative to the last send to cloud return false if (lastSendCloud == null) return false; // get the last backup date Date lastBackup = backupProcess.getLastBackupDate(context, obj.getHandle()); // verify if a new backup happened if (lastSendCloud.before(lastBackup) == true) { // see if new md5 file backup is equal to the last md5 file backup sent to cloud Boolean equalFiles = backupProcess.equalsFiles(context, obj.getHandle()); // if equal files return true if (equalFiles == false) return false; } // see if file exists in cloud, if not returns false if (this.filesInCloud.containsKey(obj.getHandle())) { // see if ETag is correct, if not returns false if (this.filesInCloud .get(obj.getHandle()) .compareTo(backupProcess.getETag(context, obj.getHandle())) == 0) return true; else return false; } else return false; }
public void addBody(Body body) throws SQLException, WingException { // Get our parameters and state int itemID = parameters.getParameterAsInteger("itemID", -1); Item item = Item.find(context, itemID); String baseURL = contextPath + "/admin/item?administrative-continue=" + knot.getId(); // DIVISION: main div Division main = body.addInteractiveDivision( "edit-item-status", contextPath + "/admin/item", Division.METHOD_POST, "primary administrative item"); main.setHead(T_option_head); // LIST: options List options = main.addList("options", List.TYPE_SIMPLE, "horizontal"); options.addItem().addXref(baseURL + "&submit_status", T_option_status); options .addItem() .addHighlight("bold") .addXref(baseURL + "&submit_bitstreams", T_option_bitstreams); options.addItem().addXref(baseURL + "&submit_metadata", T_option_metadata); options.addItem().addXref(baseURL + "&view_item", T_option_view); // TABLE: Bitstream summary Table files = main.addTable("editItemBitstreams", 1, 1); files.setHead(T_head1); Row header = files.addRow(Row.ROLE_HEADER); header.addCellContent(T_column1); header.addCellContent(T_column2); header.addCellContent(T_column3); header.addCellContent(T_column4); header.addCellContent(T_column5); Bundle[] bundles = item.getBundles(); for (Bundle bundle : bundles) { Cell bundleCell = files.addRow().addCell(1, 5); bundleCell.addContent(T_bundle_label.parameterize(bundle.getName())); Bitstream[] bitstreams = bundle.getBitstreams(); for (Bitstream bitstream : bitstreams) { boolean primary = (bundle.getPrimaryBitstreamID() == bitstream.getID()); String name = bitstream.getName(); if (name != null && name.length() > 50) { // If the fiel name is too long the shorten it so that it will display nicely. String shortName = name.substring(0, 15); shortName += " ... "; shortName += name.substring(name.length() - 25, name.length()); name = shortName; } String description = bitstream.getDescription(); String format = null; BitstreamFormat bitstreamFormat = bitstream.getFormat(); if (bitstreamFormat != null) format = bitstreamFormat.getShortDescription(); String editURL = contextPath + "/admin/item?administrative-continue=" + knot.getId() + "&bitstreamID=" + bitstream.getID() + "&submit_edit"; String viewURL = contextPath + "/bitstream/id/" + bitstream.getID() + "/" + bitstream.getName(); Row row = files.addRow(); CheckBox remove = row.addCell().addCheckBox("remove"); remove.setLabel("remove"); remove.addOption(bundle.getID() + "/" + bitstream.getID()); if (!AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE)) { remove.setDisabled(); } if (AuthorizeManager.authorizeActionBoolean(context, bitstream, Constants.WRITE)) { // The user can edit the bitstream give them a link. Cell cell = row.addCell(); cell.addXref(editURL, name); if (primary) cell.addXref(editURL, T_primary_label); row.addCell().addXref(editURL, description); row.addCell().addXref(editURL, format); } else { // The user can't edit the bitstream just show them it. Cell cell = row.addCell(); cell.addContent(name); if (primary) cell.addContent(T_primary_label); row.addCell().addContent(description); row.addCell().addContent(format); } Highlight highlight = row.addCell().addHighlight("fade"); highlight.addContent("["); highlight.addXref(viewURL, T_view_link); highlight.addContent("]"); } } if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.ADD)) { Cell cell = files.addRow().addCell(1, 5); cell.addXref( contextPath + "/admin/item?administrative-continue=" + knot.getId() + "&submit_add", T_submit_add); } else { Cell cell = files.addRow().addCell(1, 5); cell.addHighlight("fade").addContent(T_no_upload); } // PARA: actions Para actions = main.addPara("editItemActionsP", "editItemActionsP"); if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE)) actions.addButton("submit_delete").setValue(T_submit_delete); else { Button button = actions.addButton("submit_delete"); button.setValue(T_submit_delete); button.setDisabled(); main.addPara().addHighlight("fade").addContent(T_no_remove); } actions.addButton("submit_return").setValue(T_submit_return); main.addHidden("administrative-continue").setValue(knot.getId()); }