TiffImporter implements ImageImporter { public BatchItemObject consume(FileSet fileSet, ImportOptions ctx) { FileEntry tiffEntry = findTiff(fileSet); if (tiffEntry == null) { return null; } ImportProfile config = ctx.getConfig(); File f = tiffEntry.getFile(); String originalFilename = fileSet.getName(); LocalObject localObj = createObject(originalFilename, ctx); BatchItemObject batchLocalObject = ibm.addLocalObject(ctx.getBatch(), localObj); try { if (!InputUtils.isTiff(f)) { throw new IllegalStateException("Not a TIFF content: " + f); } DigitalObjectHandler dobjHandler = DigitalObjectManager.getDefault().createHandler(localObj); createRelsExt(dobjHandler, f, ctx); createMetadata(dobjHandler, ctx); createImages(ctx.getTargetFolder(), f, originalFilename, localObj, config); importArchivalCopy(fileSet, f, localObj, ctx); importUserCopy(fileSet, f, localObj, ctx); importOcr(fileSet, localObj, ctx); createTechnicalMetadata(localObj, ctx); dobjHandler.commit(); ibm.addChildRelation(ctx.getBatch(), null, localObj.getPid()); batchLocalObject.setState(ObjectState.LOADED); } catch (Throwable ex) { LOG.log(Level.SEVERE, f.toString(), ex); batchLocalObject.setState(ObjectState.LOADING_FAILED); batchLocalObject.setLog(ImportBatchManager.toString(ex)); } ibm.update(batchLocalObject); return batchLocalObject; } TiffImporter(ImportBatchManager ibm); boolean accept(FileSet fileSet); BatchItemObject consume(FileSet fileSet, ImportOptions ctx); void doOcrEditor(File tempBatchFolder, String originalFilename, File ocrEntry, ImportProfile config, FedoraObject fo);  }
@Test public void testConsume() throws Exception { temp.setDeleteOnExit(true); File targetFolder = ImportProcess.createTargetFolder(temp.getRoot(), config.getImportConfiguration()); assertTrue(targetFolder.exists()); String mimetype = ImportProcess.findMimeType(tiff1); assertNotNull(mimetype); ImportOptions ctx = new ImportOptions(tiff1.getParentFile(), "scanner:scanner1", true, junit, config.getImportConfiguration()); ctx.setTargetFolder(targetFolder); Batch batch = new Batch(); batch.setId(1); batch.setFolder(ibm.relativizeBatchFile(tiff1.getParentFile())); ctx.setBatch(batch); FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(tiff1, ocr1, alto1, ac1, uc1)).get(0); ctx.setJhoveContext(jhoveContext); TiffImporter instance = new TiffImporter(ibm); BatchItemObject result = instance.consume(fileSet, ctx); String pid = result.getPid(); assertTrue(pid.startsWith("uuid")); assertEquals(ObjectState.LOADED, result.getState()); File foxml = result.getFile(); assertTrue(foxml.toString(), foxml.exists()); File rootFoxml = new File(foxml.getParent(), ImportBatchManager.ROOT_ITEM_FILENAME); assertTrue(rootFoxml.toString(), rootFoxml.exists()); File raw1 = new File(targetFolder, "img1.full.jpg"); assertTrue(raw1.exists() && raw1.length() > 0); File preview1 = new File(targetFolder, "img1.preview.jpg"); assertTrue(preview1.exists() && preview1.length() > 0); File thumb1 = new File(targetFolder, "img1.thumb.jpg"); assertTrue(thumb1.exists() && thumb1.length() > 0); SchemaFactory sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL foxmlXsdUrl = ObjectFactory.class.getResource("/xsd/foxml/foxml1-1.xsd"); assertNotNull(foxmlXsdUrl); Schema foxmlXsd = sfactory.newSchema(foxmlXsdUrl); foxmlXsd.newValidator().validate(new StreamSource(foxml)); HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("f", "info:fedora/fedora-system:def/foxml#"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); String foxmlSystemId = foxml.toURI().toASCIIString(); XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(StringEditor.OCR_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(AltoDatastream.ALTO_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.FULL_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.PREVIEW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.THUMB_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.RAW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(MixEditor.RAW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_USER_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(MixEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId)); String rootSystemId = rootFoxml.toURI().toASCIIString(); XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(rootSystemId)); EasyMock.verify(toVerify.toArray()); }
@Test public void testMissingRequiredContent() throws Exception { assertTrue(alto1.delete()); assertTrue(config.getImportConfiguration().getRequiredDatastreamId().contains(AltoDatastream.ALTO_ID)); File targetFolder = ImportProcess.createTargetFolder(temp.getRoot(), config.getImportConfiguration()); assertTrue(targetFolder.exists()); String mimetype = ImportProcess.findMimeType(tiff1); assertNotNull(mimetype); ImportOptions ctx = new ImportOptions(tiff1.getParentFile(), "scanner:scanner1", true, junit, config.getImportConfiguration()); ctx.setTargetFolder(targetFolder); Batch batch = new Batch(); batch.setId(1); batch.setFolder(ibm.relativizeBatchFile(tiff1.getParentFile())); ctx.setBatch(batch); FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(tiff1, ocr1, ac1, uc1)).get(0); ctx.setJhoveContext(jhoveContext); TiffImporter instance = new TiffImporter(ibm); BatchItemObject result = instance.consume(fileSet, ctx); assertEquals(ObjectState.LOADING_FAILED, result.getState()); String log = result.getLog(); assertNotNull(log); assertTrue(log, log.contains("Missing ALTO")); }