Search in sources :

Example 1 with FileChangeEvent

use of org.apache.commons.vfs2.FileChangeEvent in project motech by motech.

the class ConfigFileMonitorTest method shouldSaveConfigWhenFileIsChanged.

@Test
public void shouldSaveConfigWhenFileIsChanged() throws IOException {
    final String fileName = "res:config/org.motechproject.motech-module1/somemodule.properties";
    FileObject fileObject = VFS.getManager().resolveFile(fileName);
    configFileMonitor.fileChanged(new FileChangeEvent(fileObject));
    verify(configurationService).addOrUpdate(new File(fileObject.getName().getPath()));
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileChangeEvent(org.apache.commons.vfs2.FileChangeEvent) File(java.io.File) Test(org.junit.Test)

Example 2 with FileChangeEvent

use of org.apache.commons.vfs2.FileChangeEvent in project motech by motech.

the class ConfigFileMonitorTest method shouldDeleteConfigWhenFileIsDeleted.

@Test
public void shouldDeleteConfigWhenFileIsDeleted() throws FileSystemException {
    final String fileName = "res:config/org.motechproject.motech-module1/somemodule.properties";
    FileObject fileObject = VFS.getManager().resolveFile(fileName);
    configFileMonitor.fileDeleted(new FileChangeEvent(fileObject));
    verify(configurationService).deleteByBundle(new File(fileObject.getName().getPath()).getParentFile().getName());
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileChangeEvent(org.apache.commons.vfs2.FileChangeEvent) File(java.io.File) Test(org.junit.Test)

Example 3 with FileChangeEvent

use of org.apache.commons.vfs2.FileChangeEvent in project motech by motech.

the class ConfigFileMonitor method fileChanged.

@Override
public void fileChanged(FileChangeEvent fileChangeEvent) {
    FileObject fileObject = fileChangeEvent.getFile();
    LOGGER.info(String.format("Received file update event for file: %s", fileObject));
    File file = new File(fileObject.getName().getPath());
    if (ConfigFileFilter.isFileSupported(file)) {
        configurationService.addOrUpdate(file);
        Map<String, Object> params = new HashMap<>();
        params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath());
        sendEvent(ConfigurationConstants.FILE_CHANGED_EVENT_SUBJECT, params);
    }
}
Also used : HashMap(java.util.HashMap) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File)

Example 4 with FileChangeEvent

use of org.apache.commons.vfs2.FileChangeEvent in project motech by motech.

the class ConfigFileMonitor method fileDeleted.

@Override
public void fileDeleted(FileChangeEvent fileChangeEvent) throws FileSystemException {
    FileObject fileObject = fileChangeEvent.getFile();
    LOGGER.info(String.format("Received file deletion event for file: %s", fileObject));
    File file = new File(fileObject.getName().getPath());
    if (ConfigFileFilter.isFileSupported(file)) {
        configurationService.deleteByBundle(file.getParentFile().getName());
        Map<String, Object> params = new HashMap<>();
        params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath());
        sendEvent(ConfigurationConstants.FILE_DELETED_EVENT_SUBJECT, params);
    }
}
Also used : HashMap(java.util.HashMap) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File)

Example 5 with FileChangeEvent

use of org.apache.commons.vfs2.FileChangeEvent in project motech by motech.

the class ConfigFileMonitor method fileCreated.

@Override
public void fileCreated(FileChangeEvent fileChangeEvent) throws IOException {
    FileObject fileObject = fileChangeEvent.getFile();
    LOGGER.info(String.format("Received file creation event for file: %s", fileObject));
    File file = new File(fileObject.getName().getPath());
    if (ConfigFileFilter.isFileSupported(file)) {
        configurationService.addOrUpdate(file);
        Map<String, Object> params = new HashMap<>();
        params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath());
        sendEvent(ConfigurationConstants.FILE_CREATED_EVENT_SUBJECT, params);
    }
}
Also used : HashMap(java.util.HashMap) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)7 File (java.io.File)6 FileChangeEvent (org.apache.commons.vfs2.FileChangeEvent)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3