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);
}
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();
}
}
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();
}
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());
}
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());
}
Aggregations