FedoraImport { public BatchItemObject importItem(BatchItemObject item, String importer, boolean repair) { try { if (item.getState() == ObjectState.EXCLUDED) { return null; } if (repair) { item = repairItemImpl(item, importer); } else { item = importItemImpl(item, importer); } } catch (Throwable t) { LOG.log(Level.SEVERE, String.valueOf(item), t); item.setState(ObjectState.INGESTING_FAILED); item.setLog(ImportBatchManager.toString(t)); } if (item != null) { ibm.update(item); } return item; } FedoraImport(AppConfiguration config, RemoteStorage fedora, ImportBatchManager ibm, UserProfile user); Batch importBatch(Batch batch, String importer, String message); BatchItemObject importItem(BatchItemObject item, String importer, boolean repair); File resolveBatchFile(String file);  }
@Test public void testImportItem() throws Exception { File batchFolder = temp.newFolder("batch"); LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml")); lobj.setOwner(fedoraSupport.getTestUser()); lobj.setLabel("item1"); RelationEditor locRels = new RelationEditor(lobj); locRels.setModel("model:page"); locRels.write(locRels.getLastModified(), "test"); lobj.flush(); RemoteObject parent = createParent(testName.getMethodName() + "_parent"); ReplacementDataSet db = database( dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"), dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml") ); db.addReplacementObject("{$parent_pid}", parent.getPid()); SqlTransaction tx = daos.createTransaction(); dbsupport.cleanInsert(dbsupport.getConnection(tx), db); tx.commit(); Batch batch = ibm.get(1); assertNotNull(batch); BatchItemObject item1 = ibm.addLocalObject(batch, lobj); item1.setState(ObjectState.LOADED); ibm.update(item1); BatchItemObject result = fedoraImport.importItem( item1, fedoraSupport.getTestUser(), false); assertNotNull(result); assertEquals(ObjectState.INGESTED, result.getState()); result = ibm.findBatchObject(batch.getId(), item1.getPid()); assertEquals(ObjectState.INGESTED, result.getState()); List<Item> fItems = search.find(lobj.getPid()); assertEquals(1, fItems.size()); FedoraTestSupport.assertItem(fItems, lobj.getPid()); }
@Test public void testImportItemFailure() throws Exception { File batchFolder = temp.newFolder("batch"); LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml")); lobj.setOwner(fedoraSupport.getTestUser()); lobj.setLabel("item1"); RelationEditor locRels = new RelationEditor(lobj); locRels.setModel("model:page"); locRels.write(locRels.getLastModified(), "test"); lobj.flush(); RemoteObject parent = createParent(testName.getMethodName() + "_parent"); ReplacementDataSet db = database( dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"), dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml") ); db.addReplacementObject("{$parent_pid}", parent.getPid()); SqlTransaction tx = daos.createTransaction(); dbsupport.cleanInsert(dbsupport.getConnection(tx), db); tx.commit(); Batch batch = ibm.get(1); assertNotNull(batch); BatchItemObject item1 = ibm.addLocalObject(batch, lobj); item1.setState(ObjectState.LOADED); ibm.update(item1); assertTrue(lobj.getFoxml().delete()); BatchItemObject result = fedoraImport.importItem( item1, fedoraSupport.getTestUser(), false); assertNotNull(result); assertEquals(ObjectState.INGESTING_FAILED, result.getState()); assertNotNull(result.getLog()); result = ibm.findBatchObject(batch.getId(), item1.getPid()); assertEquals(ObjectState.INGESTING_FAILED, result.getState()); assertNotNull(result.getLog()); List<Item> fItems = search.find(lobj.getPid()); assertEquals(0, fItems.size()); }
@Test public void testImportItemRepairFailure() throws Exception { File batchFolder = temp.newFolder("batch"); LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml")); lobj.setOwner(fedoraSupport.getTestUser()); lobj.setLabel("item1"); RelationEditor locRels = new RelationEditor(lobj); locRels.setModel("model:page"); locRels.write(locRels.getLastModified(), "test"); lobj.flush(); RemoteObject parent = createParent(testName.getMethodName() + "_parent"); ReplacementDataSet db = database( dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"), dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml") ); db.addReplacementObject("{$parent_pid}", parent.getPid()); SqlTransaction tx = daos.createTransaction(); dbsupport.cleanInsert(dbsupport.getConnection(tx), db); tx.commit(); Batch batch = ibm.get(1); assertNotNull(batch); BatchItemObject item1 = ibm.addLocalObject(batch, lobj); item1.setState(ObjectState.INGESTING_FAILED); item1.setLog("failure"); ibm.update(item1); BatchItemObject result = fedoraImport.importItem( item1, fedoraSupport.getTestUser(), true); assertNotNull(result); assertEquals(ObjectState.INGESTED, result.getState()); assertNull(result.getLog()); result = ibm.findBatchObject(batch.getId(), item1.getPid()); assertEquals(ObjectState.INGESTED, result.getState()); assertNull(result.getLog()); List<Item> fItems = search.find(lobj.getPid()); assertEquals(1, fItems.size()); FedoraTestSupport.assertItem(fItems, lobj.getPid()); }
@Test public void testImportItemRepairNotLinked() throws Exception { File batchFolder = temp.newFolder("batch"); LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml")); lobj.setOwner(fedoraSupport.getTestUser()); lobj.setLabel("item1"); RelationEditor locRels = new RelationEditor(lobj); locRels.setModel("model:page"); locRels.write(locRels.getLastModified(), "test"); lobj.flush(); remoteStorage.ingest(lobj, fedoraSupport.getTestUser(), "junit"); RemoteObject parent = createParent(testName.getMethodName() + "_parent"); ReplacementDataSet db = database( dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"), dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml") ); db.addReplacementObject("{$parent_pid}", parent.getPid()); SqlTransaction tx = daos.createTransaction(); dbsupport.cleanInsert(dbsupport.getConnection(tx), db); tx.commit(); Batch batch = ibm.get(1); assertNotNull(batch); BatchItemObject item1 = ibm.addLocalObject(batch, lobj); item1.setState(ObjectState.INGESTED); ibm.update(item1); BatchItemObject result = fedoraImport.importItem( item1, fedoraSupport.getTestUser(), true); assertNotNull(result); assertEquals(ObjectState.INGESTED, result.getState()); result = ibm.findBatchObject(batch.getId(), item1.getPid()); assertEquals(ObjectState.INGESTED, result.getState()); List<Item> fItems = search.find(lobj.getPid()); assertEquals(1, fItems.size()); FedoraTestSupport.assertItem(fItems, lobj.getPid()); }
@Test public void testImportItemRepairLinked() throws Exception { File batchFolder = temp.newFolder("batch"); LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml")); lobj.setOwner(fedoraSupport.getTestUser()); lobj.setLabel("item1"); RelationEditor locRels = new RelationEditor(lobj); locRels.setModel("model:page"); locRels.write(locRels.getLastModified(), "test"); lobj.flush(); remoteStorage.ingest(lobj, fedoraSupport.getTestUser(), "junit"); RemoteObject parent = createParent(testName.getMethodName() + "_parent", lobj.getPid()); ReplacementDataSet db = database( dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"), dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml") ); db.addReplacementObject("{$parent_pid}", parent.getPid()); SqlTransaction tx = daos.createTransaction(); dbsupport.cleanInsert(dbsupport.getConnection(tx), db); tx.commit(); Batch batch = ibm.get(1); assertNotNull(batch); BatchItemObject item1 = ibm.addLocalObject(batch, lobj); item1.setState(ObjectState.INGESTED); ibm.update(item1); BatchItemObject result = fedoraImport.importItem( item1, fedoraSupport.getTestUser(), true); assertNull(result); result = ibm.findBatchObject(batch.getId(), item1.getPid()); assertEquals(ObjectState.INGESTED, result.getState()); List<Item> fItems = search.find(lobj.getPid()); assertEquals(1, fItems.size()); FedoraTestSupport.assertItem(fItems, lobj.getPid()); }