/** * Ingest. * * @param foxml the foxml * @param label the label * @param uuid the uuid * @param model the model * @param topLevelUuid the top level uuid * @param inputDirPath the input dir path * @return true, if successful */ public static boolean ingest( String foxml, String label, String uuid, String model, String topLevelUuid, String inputDirPath) { if (uuid != null && !uuid.startsWith(Constants.FEDORA_UUID_PREFIX)) { uuid = Constants.FEDORA_UUID_PREFIX + uuid; } if (LOGGER.isInfoEnabled()) { LOGGER.info( "Ingesting the digital object with PID" + (!uuid.contains("uuid:") ? " uuid:" : " ") + uuid + " label:" + label + ", model: " + model); } String login = config.getFedoraLogin(); String password = config.getFedoraPassword(); String url = config.getFedoraHost() + "/objects/new"; boolean success = RESTHelper.post(url, foxml, login, password, false); if (LOGGER.isInfoEnabled() && success) { LOGGER.info("Object ingested -- uuid:" + uuid + " label: " + label + ", model: " + model); } if (topLevelUuid != null && inputDirPath != null && INGEST_LOGGER.isInfoEnabled()) { INGEST_LOGGER.info(String.format("%s %16s %s", uuid, model, label)); } if (success) { if (topLevelUuid != null && inputDirPath != null) { try { if (!uuid.equals(topLevelUuid)) { // TODO-MR // digitalObjectDAO.insertNewDigitalObject(uuid, // model, // label, // inputDirPath, // topLevelUuid, // false); } else { digitalObjectDAO.updateTopObjectTime(uuid); } } catch (DatabaseException e) { LOGGER.error("DB ERROR!!!: " + e.getMessage() + ": " + e); e.printStackTrace(); } } } else { LOGGER.error( "Unable to ingest object uuid:" + uuid + " label: " + label + ", model: " + model); } return success; }
/* * (non-Javadoc) * @see * com.gwtplatform.dispatch.server.actionhandler.ActionHandler#execute(com * .gwtplatform.dispatch.shared.Action, * com.gwtplatform.dispatch.server.ExecutionContext) */ @Override public GetDigitalObjectDetailResult execute( final GetDigitalObjectDetailAction action, final ExecutionContext context) throws ActionException { LOGGER.debug("Processing action: GetDigitalObjectDetailAction " + action.getUuid()); ServerUtils.checkExpiredSession(); if (!ServerUtils.checkUserRightOrAll(EDITOR_RIGHTS.OPEN_OBJECT)) { LOGGER.warn("Bad authorization in " + this.getClass().toString()); throw new ActionException("Bad authorization in " + this.getClass().toString()); } // parse input String uuid = action.getUuid(); String storedFOXMLFilePath = null; if (action.getSavedEditedObject() != null && action.getSavedEditedObject().getFileName() != null && !action.getSavedEditedObject().getFileName().equals("")) { storedFOXMLFilePath = action.getSavedEditedObject().getFileName(); } try { if (storedFOXMLFilePath == null) { LOGGER.debug("Processing action: GetDigitalObjectDetailAction: " + action.getUuid()); } else { LOGGER.debug( "Processing action: GetDigitalObjectDetailAction: " + action.getUuid() + " from the file: " + storedFOXMLFilePath); if (!new File(storedFOXMLFilePath).exists() || FedoraUtils.getModel(uuid) == null) return new GetDigitalObjectDetailResult(null, null, null); } HttpSession ses = httpSessionProvider.get(); Injector injector = (Injector) ses.getServletContext().getAttribute(Injector.class.getName()); injector.injectMembers(descritptionHandler); injector.injectMembers(getLockInformationHandler); DigitalObjectDetail obj = null; if (storedFOXMLFilePath == null) { if (action.getModel() == null) { // lazy obj = fedoraObjectHandler.getDigitalObject(uuid); } else { // fetch uuids obj = fedoraObjectHandler.getDigitalObjectItems(uuid, action.getModel()); } } else { obj = storedObjectHandler.getStoredDigitalObject( uuid, storedFOXMLFilePath, action.getModel()); try { digObjDAO.insertDOCrudAction( Constants.TABLE_CRUD_SAVED_EDITED_OBJECT_ACTION, "saved_edited_object_id", action.getSavedEditedObject().getId(), CRUD_ACTION_TYPES.READ); } catch (DatabaseException e) { LOGGER.error(e.getMessage()); e.printStackTrace(); throw new ActionException(e); } } // TODO storedFOXMLFilePath != null------------------------------------------------------ // GetDescriptionResult result = // descritptionHandler.execute(new GetDescriptionAction(uuid), context); // // String description = result.getUserDescription(); // Date modified = result.getModified(); // -------------------------------------------------------------------------------------- String description = null; Date modified = null; try { description = descriptionDAO.getUserDescription(uuid); // TODO: is the given user authorized to this operation? } catch (DatabaseException e) { throw new ActionException(e); } LockInfo lockInfo = getLockInformationHandler .execute(new GetLockInformationAction(uuid), context) .getLockInfo(); obj.setLockInfo(lockInfo); return new GetDigitalObjectDetailResult( obj, description == null ? "" : description, modified == null ? new Date() : modified); } catch (IOException e) { String msg = null; if (ServerUtils.isCausedByException(e, FileNotFoundException.class)) { msg = "Digital object with uuid " + uuid + " is not present in the repository. "; } else if (ServerUtils.isCausedByException(e, ConnectionException.class)) { msg = "Connection cannot be established. Please check whether Fedora is running. "; } else { msg = "Unable to obtain digital object with uuid " + uuid + ". "; } LOGGER.error(msg, e); throw new ActionException(msg, e); } }