use of edu.unc.lib.boxc.persist.api.storage.StorageLocation in project box-c by UNC-Libraries.
the class AddContainerService method addContainer.
/**
* Creates a new container as a child of the given parent using the agent principals provided.
*
* @param addRequest request object containing the details of the container to create
*/
public void addContainer(AddContainerRequest addRequest) {
notNull(addRequest.getParentPid(), "A parent pid must be provided");
notNull(addRequest.getContainerType(), "A type must be provided for the next container");
PID parentPid = addRequest.getParentPid();
AgentPrincipals agent = addRequest.getAgent();
ContentContainerObject child = null;
FedoraTransaction tx = txManager.startTransaction();
try (Timer.Context context = timer.time()) {
PID containerPid = PIDs.get(UUID.randomUUID().toString());
Model containerModel = createDefaultModel();
Resource containerResc = containerModel.createResource(containerPid.getRepositoryPath());
containerResc.addLiteral(DcElements.title, addRequest.getLabel());
StorageLocation storageLoc = storageLocationManager.getStorageLocation(parentPid);
containerResc.addLiteral(Cdr.storageLocation, storageLoc.getId());
log.debug("Adding new container to storage location {}", storageLoc.getId());
ResourceType containerType = addRequest.getContainerType();
// Create the appropriate container
if (ResourceType.AdminUnit.equals(containerType)) {
aclService.assertHasAccess("User does not have permissions to create admin units", parentPid, agent.getPrincipals(), Permission.createAdminUnit);
child = repoObjFactory.createAdminUnit(containerPid, containerModel);
} else if (ResourceType.Collection.equals(containerType)) {
aclService.assertHasAccess("User does not have permissions to create collections", parentPid, agent.getPrincipals(), Permission.createCollection);
child = repoObjFactory.createCollectionObject(containerPid, containerModel);
} else if (ResourceType.Folder.equals(containerType)) {
aclService.assertHasAccess("User does not have permissions to create folders", parentPid, agent.getPrincipals(), Permission.ingest);
child = repoObjFactory.createFolderObject(containerPid, containerModel);
} else if (ResourceType.Work.equals(containerType)) {
aclService.assertHasAccess("User does not have permissions to create works", parentPid, agent.getPrincipals(), Permission.ingest);
child = repoObjFactory.createWorkObject(containerPid, containerModel);
} else {
throw new AccessRestrictionException("User cannot add a container to object of type " + containerType);
}
ContentContainerObject parent = (ContentContainerObject) repoObjLoader.getRepositoryObject(parentPid);
parent.addMember(child);
if (addRequest.isStaffOnly() && !ResourceType.AdminUnit.equals(containerType)) {
PatronAccessDetails accessDetails = new PatronAccessDetails();
accessDetails.setRoles(asList(new RoleAssignment(PUBLIC_PRINC, none), new RoleAssignment(AUTHENTICATED_PRINC, none)));
patronService.updatePatronAccess(new PatronAccessAssignmentRequest(agent, containerPid, accessDetails).withFolderCreation(true));
} else if (ResourceType.Collection.equals(containerType)) {
PatronAccessDetails accessDetails = new PatronAccessDetails();
accessDetails.setRoles(asList(new RoleAssignment(PUBLIC_PRINC, canViewOriginals), new RoleAssignment(AUTHENTICATED_PRINC, canViewOriginals)));
patronService.updatePatronAccess(new PatronAccessAssignmentRequest(agent, containerPid, accessDetails));
}
storeDescription(containerPid, addRequest);
premisLoggerFactory.createPremisLogger(child).buildEvent(Premis.Creation).addImplementorAgent(AgentPids.forPerson(agent)).addEventDetail("Container added at destination " + parentPid).writeAndClose();
} catch (Exception e) {
tx.cancel(e);
} finally {
tx.close();
}
// Send message that the action completed
operationsMessageSender.sendAddOperation(agent.getUsername(), Arrays.asList(parentPid), Arrays.asList(child.getPid()), null, null);
}
use of edu.unc.lib.boxc.persist.api.storage.StorageLocation in project box-c by UNC-Libraries.
the class AbstractDepositJob method getTransferSession.
protected BinaryTransferSession getTransferSession(Model depositModel) {
Bag depositBag = depositModel.getBag(getDepositPID().getRepositoryPath());
String destLocationId = depositBag.getProperty(Cdr.storageLocation).getString();
StorageLocation destLocation = locationManager.getStorageLocationById(destLocationId);
return transferService.getSession(destLocation);
}
use of edu.unc.lib.boxc.persist.api.storage.StorageLocation in project box-c by UNC-Libraries.
the class BinaryTransferServiceImplIT method singleDestinationTransfer.
@Test
public void singleDestinationTransfer() throws Exception {
PID binPid = pidMinter.mintContentPid();
StorageLocation destination = storageManager.getStorageLocationById("loc1");
Path sourceFile = createSourceFile(sourcePath1, "myfile.txt", "some content");
try (BinaryTransferSession session = transferService.getSession(destination)) {
BinaryTransferOutcome outcome = session.transfer(binPid, sourceFile.toUri());
assertTrue(new File(outcome.getDestinationUri()).exists());
}
}
use of edu.unc.lib.boxc.persist.api.storage.StorageLocation in project box-c by UNC-Libraries.
the class StorageLocationManagerImplTest method getDefaultStorageLocationFromRepoDefault.
@Test
public void getDefaultStorageLocationFromRepoDefault() throws Exception {
PID unitPid = makePid();
mockAncestors(unitPid, getContentRootPid());
helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE);
helper.addMapping(getContentRootPid().getId(), LOC1_ID);
initializeManager();
StorageLocation loc = locManager.getDefaultStorageLocation(unitPid);
assertIsLocation1(loc);
}
use of edu.unc.lib.boxc.persist.api.storage.StorageLocation in project box-c by UNC-Libraries.
the class StorageLocationManagerImplTest method getDefaultStorageLocationFromCollection.
@Test
public void getDefaultStorageLocationFromCollection() throws Exception {
PID unitPid = makePid();
PID collPid = makePid();
PID folderPid = makePid();
PID workPid = makePid();
mockAncestors(collPid, getContentRootPid(), unitPid);
mockAncestors(workPid, getContentRootPid(), unitPid, collPid, folderPid);
helper.addStorageLocation(LOC1_ID, LOC1_NAME, LOC1_BASE);
helper.addStorageLocation(LOC2_ID, LOC2_NAME, LOC2_BASE);
helper.addMapping(unitPid.getId(), LOC1_ID);
helper.addMapping(folderPid.getId(), LOC2_ID);
initializeManager();
StorageLocation collLoc = locManager.getDefaultStorageLocation(collPid);
assertIsLocation1(collLoc);
StorageLocation workLoc = locManager.getDefaultStorageLocation(workPid);
// Assignment past the collection should be ignored
assertIsLocation1(workLoc);
}
Aggregations