/** * main * * <p>Australian National University Data Commons * * <p>Entry point for this class when called from the command line. Checks that the parameters * passed to it are correct, then creates a job for each file that needs to be referenced. * * <pre> * Version Date Developer Description * 0.1 30/03/2012 Rahul Khanna (RK) Initial * </pre> * * @param args Command line arguments as String[] */ public static void main(String[] args) { // Check if an argument is provided. If not, display syntax help. if (args.length > 0) { FedoraClient client = FedoraProps.getFedoraClient(); for (int i = 0; i < args.length; i++) { if (args[i].indexOf(".properties") != -1) { System.out.print("Processing file " + args[i] + "..."); try { FileJob job; job = new FileJob(new File(args[i]), FedoraProps.getUploadBaseUri()); job.execute(client); System.out.println("done."); } catch (FileNotFoundException e) { e.printStackTrace(); System.out.println("failed. Unable to open the file " + args[i]); } catch (IOException e) { e.printStackTrace(); System.out.println("failed. Unable to open the file " + args[i]); } catch (FedoraClientException e) { e.printStackTrace(); System.out.println("failed. Unable to execute request to the Fedora repository. "); } } else { System.out.println("Skipping non-properties file " + args[i]); } } } else { // Display help. dispHelp(); } }
@Override public void generateDoi(String pid, String tmplt, Long rid) throws FedoraObjectException { InputStream datastream = null; try { Unmarshaller um = dataContext.createUnmarshaller(); datastream = FedoraBroker.getDatastreamAsStream(pid, Constants.XML_SOURCE); Data itemData = (Data) um.unmarshal(datastream); // Check if it's a collection. String type = itemData.getFirstElementByName("type").getValue(); if (!type.equalsIgnoreCase("collection")) throw new FedoraObjectException( "Item is not of type 'collection'. Digital Object Identifiers can only be minted for collections."); // Check if a DOI already exists. if (itemData.getFirstElementByName("doi") != null) { throw new FedoraObjectException("Collection already has a Digital Object Identifier."); } // TODO Change the following code as required for checking if the item's published or not. // List<DatastreamType> datastreams = FedoraBroker.getDatastreamList(pid); // for (DatastreamType iDs : datastreams) // { // if (iDs.getDsid().equals(Constants.XML_PUBLISHED)) // { // throw new FedoraObjectException("Item's already published."); // } // } org.datacite.schema.kernel_2.Resource doiResource = new DoiResourceAdapter(itemData).createDoiResource(); DoiClient doiClient = new DoiClient(); doiClient.mint(pid, doiResource); String mintedDoi = doiClient.getDoiResponse().getDoi(); FedoraObject fedoraObject = getItemByPid(pid); Map<String, List<String>> form = new HashMap<String, List<String>>(); form.put("doi", Arrays.asList(mintedDoi)); saveEdit(fedoraObject, tmplt, form, rid); } catch (FedoraClientException e) { throw new FedoraObjectException(e.getMessage(), e); } catch (JAXBException e) { throw new FedoraObjectException(e.getMessage(), e); } catch (DoiException e) { throw new FedoraObjectException(e.getMessage(), e); } finally { IOUtils.closeQuietly(datastream); } }