Search in sources :

Example 96 with PID

use of edu.unc.lib.boxc.model.api.ids.PID in project box-c by UNC-Libraries.

the class CdrEventToSolrUpdateProcessorTest method addPidListElement.

private void addPidListElement(Element parentEl, String elementName, List<PID> pids) {
    if (pids != null && pids.size() > 0) {
        Element listEl = new Element("subjects", CDR_MESSAGE_NS);
        parentEl.addContent(listEl);
        for (PID pid : pids) {
            listEl.addContent(new Element("pid", CDR_MESSAGE_NS).setText(pid.getId()));
        }
    }
}
Also used : Element(org.jdom2.Element) PID(edu.unc.lib.boxc.model.api.ids.PID)

Example 97 with PID

use of edu.unc.lib.boxc.model.api.ids.PID in project box-c by UNC-Libraries.

the class FedoraContentControllerIT method testInvalidDatastream.

@Test
public void testInvalidDatastream() throws Exception {
    PID filePid = makePid();
    repositoryObjectFactory.createFileObject(filePid, null);
    // Verify administrative datastream retrievable
    MvcResult result = mvc.perform(get("/content/" + filePid.getId() + "/some_ds")).andExpect(status().isNotFound()).andReturn();
    MockHttpServletResponse response = result.getResponse();
    assertEquals("Must not return file content", "", response.getContentAsString());
}
Also used : PID(edu.unc.lib.boxc.model.api.ids.PID) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 98 with PID

use of edu.unc.lib.boxc.model.api.ids.PID in project box-c by UNC-Libraries.

the class LorisContentController method getSequence.

/**
 * Handles requests for IIIF sequences
 * @param id
 * @param datastream
 * @param response
 * @return
 */
@GetMapping(value = "/jp2Proxy/{id}/{datastream}/sequence/normal", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public String getSequence(@PathVariable("id") String id, @PathVariable("datastream") String datastream, HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
    PID pid = PIDs.get(id);
    // Check if the user is allowed to view this object's manifest
    if (this.hasAccess(pid, datastream)) {
        List<ContentObjectRecord> briefObjs = getDatastreams(pid);
        response.addHeader("Access-Control-Allow-Origin", "*");
        return lorisContentService.getSequence(request, briefObjs);
    } else {
        LOG.debug("Manifest access was forbidden to {} for user {}", id, GroupsThreadStore.getUsername());
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }
    return "";
}
Also used : PID(edu.unc.lib.boxc.model.api.ids.PID) ContentObjectRecord(edu.unc.lib.boxc.search.api.models.ContentObjectRecord) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 99 with PID

use of edu.unc.lib.boxc.model.api.ids.PID in project box-c by UNC-Libraries.

the class LorisContentController method getCanvas.

/**
 * Handles requests for IIIF canvases
 * @param id
 * @param datastream
 * @param response
 * @return
 */
@GetMapping(value = "/jp2Proxy/{id}/{datastream}", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public String getCanvas(@PathVariable("id") String id, @PathVariable("datastream") String datastream, HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException {
    PID pid = PIDs.get(id);
    // Check if the user is allowed to view this object's manifest
    if (this.hasAccess(pid, datastream)) {
        SimpleIdRequest idRequest = new SimpleIdRequest(pid, GroupsThreadStore.getAgentPrincipals().getPrincipals());
        ContentObjectRecord briefObj = queryLayer.getObjectById(idRequest);
        response.addHeader("Access-Control-Allow-Origin", "*");
        return lorisContentService.getCanvas(request, briefObj);
    } else {
        LOG.debug("Manifest access was forbidden to {} for user {}", id, GroupsThreadStore.getUsername());
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }
    return "";
}
Also used : SimpleIdRequest(edu.unc.lib.boxc.search.api.requests.SimpleIdRequest) PID(edu.unc.lib.boxc.model.api.ids.PID) ContentObjectRecord(edu.unc.lib.boxc.search.api.models.ContentObjectRecord) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 100 with PID

use of edu.unc.lib.boxc.model.api.ids.PID in project box-c by UNC-Libraries.

the class LorisContentController method getRegion.

/**
 * Handles requests for individual region tiles.
 * @param id
 * @param datastream
 * @param region
 * @param size
 * @param rotation
 * @param qualityFormat
 * @param response
 */
@GetMapping("/jp2Proxy/{id}/{datastream}/{region}/{size}/{rotation}/{qualityFormat:.+}")
public void getRegion(@PathVariable("id") String id, @PathVariable("datastream") String datastream, @PathVariable("region") String region, @PathVariable("size") String size, @PathVariable("rotation") String rotation, @PathVariable("qualityFormat") String qualityFormat, HttpServletResponse response) {
    PID pid = PIDs.get(id);
    // Check if the user is allowed to view this object
    if (this.hasAccess(pid, datastream)) {
        try {
            String[] qualityFormatArray = qualityFormat.split("\\.");
            String quality = qualityFormatArray[0];
            String format = qualityFormatArray[1];
            response.addHeader("Access-Control-Allow-Origin", "*");
            lorisContentService.streamJP2(id, region, size, rotation, quality, format, datastream, response.getOutputStream(), response);
        } catch (IOException e) {
            LOG.error("Error retrieving streaming JP2 content for {}", id, e);
        }
    } else {
        LOG.debug("Access was forbidden to {} for user {}", id, GroupsThreadStore.getUsername());
        response.setStatus(HttpStatus.FORBIDDEN.value());
    }
}
Also used : PID(edu.unc.lib.boxc.model.api.ids.PID) IOException(java.io.IOException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

PID (edu.unc.lib.boxc.model.api.ids.PID)735 Test (org.junit.Test)509 Model (org.apache.jena.rdf.model.Model)130 Resource (org.apache.jena.rdf.model.Resource)122 Bag (org.apache.jena.rdf.model.Bag)100 Matchers.anyString (org.mockito.Matchers.anyString)89 RoleAssignment (edu.unc.lib.boxc.auth.api.models.RoleAssignment)85 MvcResult (org.springframework.test.web.servlet.MvcResult)78 CollectionObject (edu.unc.lib.boxc.model.api.objects.CollectionObject)65 RepositoryObject (edu.unc.lib.boxc.model.api.objects.RepositoryObject)63 AdminUnit (edu.unc.lib.boxc.model.api.objects.AdminUnit)62 WorkObject (edu.unc.lib.boxc.model.api.objects.WorkObject)62 URI (java.net.URI)62 FileObject (edu.unc.lib.boxc.model.api.objects.FileObject)61 AbstractDepositJobTest (edu.unc.lib.boxc.deposit.fcrepo4.AbstractDepositJobTest)55 BinaryObject (edu.unc.lib.boxc.model.api.objects.BinaryObject)50 Document (org.jdom2.Document)50 FolderObject (edu.unc.lib.boxc.model.api.objects.FolderObject)48 File (java.io.File)48 Path (java.nio.file.Path)48