class AssessmentPackageFileImporter {

    public AssessmentPackage importAssessmentPackageData(final File importSandboxDirectory,
            final MultipartFile multipartFile)
            throws AssessmentPackageDataImportException {
        Assert.notNull(importSandboxDirectory, "importSandboxDirectory");
        Assert.notNull(multipartFile, "multipartFile");
        AssessmentPackage assessmentPackage = null;

        final String contentType = ServiceUtilities.computeContentType(multipartFile);
        if ("application/xml".equals(contentType) || "text/xml".equals(contentType) || contentType.endsWith("+xml")) {
            /* Looks like an XML content type */
            logger.debug("Import data uses a known XML MIME type {} so saving to {} and treating as XML", contentType, importSandboxDirectory);
            assessmentPackage = importStandaloneXml(importSandboxDirectory, multipartFile);
        }
        else {
            /* Try to treat as a ZIP */
            final boolean zipSuccess = tryUnpackZipFile(importSandboxDirectory, multipartFile);
            if (zipSuccess) {
                logger.debug("Import data was successfully expanded as a ZIP file");
                assessmentPackage = processUnpackedZip(importSandboxDirectory);
            }
            else {
                logger.warn("Import data with MIME type {} was neither a supported XML MIME type nor a ZIP file (containing at least one entry)", contentType);
                throw new AssessmentPackageDataImportException(ImportFailureReason.NOT_XML_OR_ZIP);
            }
        }

        logger.info("Successfully imported data for new {}", assessmentPackage);
        return assessmentPackage;
    }

}

class AssessmentPackageFileImporterTest {

    private AssessmentPackageFileImporter assessmentPackageFileImporter;
    private File importSandboxDirectory;

    @Test
    public void notContentPackage() throws Exception {

        final MultipartFile multipartFile = getThisUnitTestMultipartFile("uk/ac/ed/ph/qtiworks/services/NotContentPackage.zip", "application/zip");
        try {
            assessmentPackageFileImporter.importAssessmentPackageData(importSandboxDirectory, multipartFile);
            Assert.fail("Should have failed");
        }
        catch (final AssessmentPackageDataImportException e) {
            Assert.assertEquals(ImportFailureReason.NOT_CONTENT_PACKAGE, e.getFailure().getReason());
        }
    }

}