@Override public void execute(JobExecutionContext context) throws JobExecutionException { if (checklistNotificationsUri == null) { return; } boolean started = !HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().isActive(); if (started) { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); } try { URI researchObjectUri = (URI) context.getMergedJobDataMap().get(RESEARCH_OBJECT_URI); SyndFeedInput input = new SyndFeedInput(); URI requestedUri = createQueryUri(getTheLastFeedDate(researchObjectUri), researchObjectUri); try { context.setResult(input.build(new XmlReader(requestedUri.toURL()))); } catch (IllegalArgumentException | FeedException | IOException e) { LOGGER.error("Can't get the feed " + requestedUri.toString()); } } finally { if (started) { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } } }
private void deleteFile(String path) throws DigitalLibraryException, NotFoundException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { dl.deleteFile(RO_URI, path); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void checkFileExists(String path) throws DigitalLibraryException, NotFoundException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { Assert.assertTrue(dl.fileExists(RO_URI, path)); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void getZippedVersion() throws DigitalLibraryException, NotFoundException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { InputStream zip1 = dl.getZippedResearchObject(RO_URI); assertNotNull(zip1); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void createOrUpdateDirectory(String path) throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { ResourceMetadata r1 = dl.createOrUpdateFile(RO_URI, path, new ByteArrayInputStream(new byte[0]), "text/plain"); assertNotNull(r1); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void getZippedFolder(String path) throws DigitalLibraryException, IOException, NotFoundException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { InputStream zip = dl.getZippedFolder(RO_URI, path); assertNotNull(zip); zip.close(); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void checkNoFile(String path) throws DigitalLibraryException, IOException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { dl.getFileContents(RO_URI, path).close(); fail("Deleted file doesn't throw IdNotFoundException"); } catch (NotFoundException e) { // good } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void createOrUpdateFile(FileRecord file) throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { InputStream f = file.open(); ResourceMetadata r1 = dl.createOrUpdateFile(RO_URI, file.path, f, file.mimeType); f.close(); assertNotNull(r1); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
private void getFileContent(FileRecord file) throws DigitalLibraryException, IOException, NotFoundException, AccessDeniedException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); try { InputStream f = dl.getFileContents(RO_URI, file.path); assertNotNull(f); f.close(); assertEquals(file.mimeType, dl.getFileInfo(RO_URI, file.path).getMimeType()); } finally { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
/** @throws java.lang.Exception */ @After public void tearDown() throws Exception { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); dl = new FilesystemDL(BASE); dl.deleteResearchObject(RO_URI); dl = new FilesystemDL(BASE); dl.deleteUser(USER.getLogin()); HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); try { Files.delete(Paths.get(BASE)); } catch (DirectoryNotEmptyException | NoSuchFileException e) { // was not empty } }
private void checkCantCreateOrUpdateFile(FileRecord file) throws DigitalLibraryException, IOException, NotFoundException { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); InputStream f = file.open(); try { dl.createOrUpdateFile(RO_URI, file.path, f, file.mimeType); fail("Should throw an exception when creating file"); } catch (Exception e) { // good } finally { f.close(); HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); } }
@Test @Ignore public final void testPermissions() throws DigitalLibraryException, IOException, NotFoundException, ConflictException, AccessDeniedException { createOrUpdateFile(files[0]); createOrUpdateFile(files[1]); HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); dl = new FilesystemDL(BASE); HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); getFileContent(files[0]); getFileContent(files[1]); checkCantCreateOrUpdateFile(files[0]); checkCantCreateOrUpdateFile(files[1]); }
/** @throws java.lang.Exception */ @Before public void setUp() throws Exception { HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().begin(); dl = new FilesystemDL(BASE); dl.createOrUpdateUser(USER.getLogin(), USER_PASSWORD, USER.getName()); dl = new FilesystemDL(BASE); dl.createResearchObject( RO_URI, new ByteArrayInputStream(MAIN_FILE_CONTENT.getBytes()), MAIN_FILE_PATH, MAIN_FILE_MIME_TYPE); files[0] = new FileRecord("singleFiles/file1.txt", "file1.txt", "text/plain"); files[1] = new FileRecord("singleFiles/file2.txt", "dir/file2.txt", "text/plain"); files[2] = new FileRecord("singleFiles/file3.jpg", "testdir/file3.jpg", "image/jpg"); Files.createDirectories(Paths.get(BASE)); HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit(); }