コード例 #1
0
  /**
   * addLink
   *
   * <p>Create a link between two items
   *
   * <pre>
   * Version	Date		Developer				Description
   * 0.1		26/04/2012	Genevieve Turner (GT)	Initial
   * 0.19		27/09/2012	Genevieve Turner (GT)	Updated to generate reverse links
   * </pre>
   *
   * @param fedoraObject The item to transform to a display
   * @param form Contains the parameters from the request
   * @return A response for the web page
   * @throws FedoraClientException
   */
  @Override
  public void addLink(FedoraObject fedoraObject, String linkType, String itemId)
      throws FedoraClientException {
    String link = GlobalProps.getProperty(GlobalProps.PROP_FEDORA_RELATEDURI);

    LinkTypeDAO linkTypeDAO = new LinkTypeDAOImpl();
    LinkType linkTypeRecord = linkTypeDAO.getByCode(linkType);
    if (null == linkTypeRecord) {
      throw new WebApplicationException(
          Response.status(400).entity("Invalid relation type").build());
    }

    FedoraReference reference = new FedoraReference();
    String referenceType = linkType;
    String referenceItem = itemId;
    reference.setPredicate_(link + referenceType);
    reference.setObject_(referenceItem);
    reference.setIsLiteral_(Boolean.FALSE);
    FedoraBroker.addRelationship(fedoraObject.getObject_id(), reference);

    if (referenceItem.startsWith("info:fedora/")) {
      String referenceItemID = referenceItem.substring(12);
      FedoraReference reverseReference = new FedoraReference();
      reverseReference.setPredicate_(link + linkTypeRecord.getReverse());
      reverseReference.setObject_("info:fedora/" + fedoraObject.getObject_id());
      reverseReference.setIsLiteral_(Boolean.FALSE);
      FedoraBroker.addRelationship(referenceItemID, reverseReference);
    }
  }
コード例 #2
0
 /**
  * delete
  *
  * <p>Set the status of the given object to deleted
  *
  * @param fedoraObject The fedora object
  * @throws FedoraClientException
  */
 public void delete(FedoraObject fedoraObject) throws FedoraClientException {
   FedoraBroker.updateObjectState(fedoraObject.getObject_id(), "D");
   // Add this as a work around for the fact that commitWithin does not seem to work for
   // the Solr XML delete so we want to commit after delete
   SolrServer solrServer = SolrManager.getInstance().getSolrServer();
   try {
     solrServer.deleteById(fedoraObject.getObject_id(), 5000);
   } catch (IOException e) {
     LOGGER.debug("Exception committing delete", e);
   } catch (SolrServerException e) {
     LOGGER.debug("Exception committing delete", e);
   }
 }
コード例 #3
0
  @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);
    }
  }