Search in sources :

Example 1 with PID

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

the class WorkObjectImpl method getPrimaryObject.

/**
 * Get the primary object for this work if one is assigned, otherwise return null.
 *
 * @return
 */
@Override
public FileObject getPrimaryObject() {
    Resource resc = getResource();
    // Find the primary object relation if it is present
    Statement primaryStmt = resc.getProperty(Cdr.primaryObject);
    if (primaryStmt == null) {
        return null;
    }
    PID primaryPid = PIDs.get(primaryStmt.getResource().getURI());
    return driver.getRepositoryObject(primaryPid, FileObject.class);
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) PID(edu.unc.lib.boxc.model.api.ids.PID)

Example 2 with PID

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

the class ContentPathFactoryImpl method getAncestorPids.

/**
 * Returns the list of PIDs for content objects which are parents of the provided
 * PID, ordered from the base of the hierarchy to the immediate parent of the PID.
 *
 * @param pid
 * @return
 */
@Override
public List<PID> getAncestorPids(PID pid) {
    try {
        if (pid.getComponentPath() == null) {
            return buildPath(pid);
        } else {
            // Get the PID of the parent by removing the component path
            PID parentPid = PIDs.get(pid.getId());
            List<PID> ancestors = buildPath(parentPid);
            ancestors.add(parentPid);
            return ancestors;
        }
    } catch (UncheckedExecutionException e) {
        throw (RuntimeException) e.getCause();
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) PID(edu.unc.lib.boxc.model.api.ids.PID)

Example 3 with PID

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

the class RepositoryObjectFactoryTest method createBinaryTest.

@Test
public void createBinaryTest() throws FcrepoOperationFailedException {
    PID pid = pidMinter.mintContentPid();
    URI binaryUri = pid.getRepositoryUri();
    when(mockResponse.getLocation()).thenReturn(binaryUri);
    BinaryObject mockBinary = mock(BinaryObject.class);
    when(mockBinary.getPid()).thenReturn(pid);
    when(repoObjLoader.getBinaryObject(any(PID.class))).thenReturn(mockBinary);
    String slug = "slug";
    InputStream content = mock(InputStream.class);
    String filename = "file.ext";
    String mimetype = "application/octet-stream";
    String sha1Checksum = "checksum";
    BinaryObject obj = repoObjFactory.createBinary(binaryUri, slug, content, filename, mimetype, sha1Checksum, null, null);
    assertTrue(obj.getPid().getRepositoryPath().startsWith(binaryUri.toString()));
    // check to see that client creates FcrepoResponse
    verify(mockPostBuilder).perform();
}
Also used : BinaryObject(edu.unc.lib.boxc.model.api.objects.BinaryObject) InputStream(java.io.InputStream) PID(edu.unc.lib.boxc.model.api.ids.PID) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 4 with PID

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

the class RepositoryObjectFactoryTest method addMemberTest.

@Test
public void addMemberTest() {
    PID parentPid = pidMinter.mintContentPid();
    ContentObject parent = mock(ContentObject.class);
    when(parent.getPid()).thenReturn(parentPid);
    when(parent.getUri()).thenReturn(parentPid.getRepositoryUri());
    when(parent.getResource()).thenReturn(createResource(parentPid.getRepositoryPath()));
    Model memberModel = ModelFactory.createDefaultModel();
    PID memberPid = pidMinter.mintContentPid();
    ContentObject member = mock(ContentObject.class);
    when(member.getPid()).thenReturn(memberPid);
    when(member.getModel(true)).thenReturn(memberModel);
    when(member.getMetadataUri()).thenReturn(memberPid.getRepositoryUri());
    repoObjFactory.addMember(parent, member);
    verify(sparqlUpdateService).executeUpdate(eq(memberPid.getRepositoryPath()), anyString());
}
Also used : Model(org.apache.jena.rdf.model.Model) PID(edu.unc.lib.boxc.model.api.ids.PID) ContentObject(edu.unc.lib.boxc.model.api.objects.ContentObject) Test(org.junit.Test)

Example 5 with PID

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

the class RepositoryObjectFactoryTest method createFolderWithPidTest.

@Test
public void createFolderWithPidTest() {
    PID pid = pidMinter.mintContentPid();
    FileObject mockFile = mock(FileObject.class);
    when(mockFile.getPid()).thenReturn(pid);
    when(repoObjLoader.getFileObject(pid)).thenReturn(mockFile);
    FileObject obj = repoObjFactory.createFileObject(pid, null);
    assertNotNull(obj);
    assertEquals(pid, obj.getPid());
}
Also used : PID(edu.unc.lib.boxc.model.api.ids.PID) FileObject(edu.unc.lib.boxc.model.api.objects.FileObject) Test(org.junit.Test)

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