Fedora commons: get dissemination url

146 Views Asked by At

I'm using fedora commons 3.7.1 and the REST client com.yourmediashelf.fedora.client version 0.7

I'm able in uploading files and media in FCRepo; I'm able in creating my own datastreams Now I'ld love to show contents; so far the only way I found is this code:

@Test
public void testSearch()
{
    try
    {
        FedoraCredentials fc = new FedoraCredentials("http://localhost:8080/fedora", "fedoraAdmin", "fedoraAdmin");
        FedoraClient fcRepoClient = new FedoraClient(fc);
        FedoraRequest.setDefaultClient(fcRepoClient);
        FindObjects fo = new FindObjects();

        fo.maxResults(3).pid().query("pid~chang*44");
        FindObjectsResponse fors = fo.execute();
        List<String> pids = fors.getPids();
        for (String pid : pids)
        {
            AddDatastream ads = new AddDatastream(pid, "angeloDs");
            ads.content("<test>Angelo</test>");
            ads.mimeType("text/xml");
            ads.execute();
            GetDatastream gd = new GetDatastream(pid, "Immagine.png");
            gd.format("xml");
            String resp = gd.execute().getEntity(String.class);
            logger.info(resp);
            GetDatastreams gds = new GetDatastreams(pid);
            GetDatastreamsResponse gdr = gds.execute();
            List<DatastreamProfile> dps = gdr.getDatastreamProfiles();
            for (DatastreamProfile datastreamProfile : dps)
            {
                if(!datastreamProfile.getDsID().trim().equals("DC"))
                {
                    GetDatastreamDissemination gdd = new GetDatastreamDissemination(pid, datastreamProfile.getDsID());
                    gdd.download(true);
                    FedoraResponse fr = gdd.execute();
                    StringBuilder sb = new StringBuilder();
                    InputStream is = fr.getEntityInputStream();
                    int i = -1;
                    while ((i=is.read()) != -1)
                    {
                        sb.append((char)i);
                    }
                    logger.info(sb.toString());
                }
            }
        }
    }
    catch (Exception e)
    {
        logger.error(e.getMessage(), e);
    }
}

So I have do these steps: search pids by using some query (and it's OK...I can understand it) search datastreams profile search for the datastream dissemination

Now when I have the datastream dissemination I can use the getEntityInputStream and get the InputStream of media.... My intention, now, is to get the Dissemination URL of the content...so in my HTML page I can use something like this (by assuming the media is an image):

<img src="disseminationUrlValue" >

Is this achievable? Can anybody give me any tip?

Thank you Angelo

1

There are 1 best solutions below

0
On

I think I got how to it...but it seems to me really pity.... Anyway...I saw that REST APIs always provide the datastream content by using this kind of URL:

http://host:port/fedoraWebContext/objects/PID/datastreams/dataStreamName/content

Where

  • host: host name (or IP) where the fedora web application is located
  • port: port number where the fedora web application is listening
  • fedoraWebContext: the fedora web application context (default is fedora)
  • objects: it's a fixed value
  • PID: the object PID
  • datastreams: it's a fixed value
  • dataStreamName: name of the datastream we want to display the content
  • content: it's a fixed value

Now I'm wondering if this is the right way to do it; any tips regarding this?

Thank you

Angelo