Source:
public void addContainer(AgentPrincipals agent, PID parentPid, Resource containerType) { Model model = ModelFactory.createDefaultModel(); Resource parentResc = model.getResource(parentPid.getRepositoryPath()); ContentContainerObject child = null; if (Cdr.AdminUnit.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create admin units", parentPid, agent.getPrincipals(), Permission.createAdminUnit); child = repoObjFactory.createAdminUnit(model); repoObjFactory.createMemberLink(URI.create(parentResc.getURI()), child.getPid().getRepositoryUri()); } else if (Cdr.Collection.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create collections", parentPid, agent.getPrincipals(), Permission.createCollection); child = repoObjFactory.createCollectionObject(model); repoObjFactory.createMemberLink(URI.create(parentResc.getURI()), child.getPid().getRepositoryUri()); } else if (Cdr.Folder.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create collections", parentPid, agent.getPrincipals(), Permission.ingest); child = repoObjFactory.createFolderObject(model); repoObjFactory.createMemberLink(URI.create(parentResc.getURI()), child.getPid().getRepositoryUri()); } else if (Cdr.Work.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create collections", parentPid, agent.getPrincipals(), Permission.ingest); child = repoObjFactory.createWorkObject(model); repoObjFactory.createMemberLink(URI.create(parentResc.getURI()), child.getPid().getRepositoryUri()); } child.getPremisLog().buildEvent(Premis.Creation) .addImplementorAgent(agent.getUsernameUri()) .addEventDetail("Container added at destination " + parentPid) .write(); }

Target:
public void addContainer(AgentPrincipals agent, PID parentPid, Resource containerType) { FedoraTransaction tx = txManager.startTransaction(); try { ContentContainerObject child = null; if (Cdr.AdminUnit.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create admin units", parentPid, agent.getPrincipals(), Permission.createAdminUnit); child = repoObjFactory.createAdminUnit(null); } else if (Cdr.Collection.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create collections", parentPid, agent.getPrincipals(), Permission.createCollection); child = repoObjFactory.createCollectionObject(null); } else if (Cdr.Folder.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create folders", parentPid, agent.getPrincipals(), Permission.ingest); child = repoObjFactory.createFolderObject(null); } else if (Cdr.Work.equals(containerType)) { aclService.assertHasAccess( "User does not have permissions to create works", parentPid, agent.getPrincipals(), Permission.ingest); child = repoObjFactory.createWorkObject(null); } ContentContainerObject parent = (ContentContainerObject) repoObjLoader.getRepositoryObject(parentPid); parent.addMember(child); child.getPremisLog() .buildEvent(Premis.Creation) .addImplementorAgent(agent.getUsernameUri()) .addEventDetail("Container added at destination " + parentPid) .write(); } catch (Exception e) { tx.cancel(e); } finally { tx.close(); } }