Skip to content
Snippets Groups Projects
Commit 6ad4772e authored by Eric Slenk's avatar Eric Slenk
Browse files

Implement read-only methods of StructuresSnapshotService.

parent 7afa0f09
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ apply plugin: 'war' ...@@ -4,7 +4,7 @@ apply plugin: 'war'
apply plugin: 'eclipse' apply plugin: 'eclipse'
sourceCompatibility = '1.8' sourceCompatibility = '1.8'
version = '0.1.0-8' version = '0.1.0-9'
repositories { repositories {
......
package edu.msu.anr.osgi.structuralintegrity.viewtool; package edu.msu.anr.osgi.structuralintegrity.viewtool;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.List;
import com.dotcms.repackage.org.osgi.util.tracker.ServiceTracker; import com.dotcms.repackage.org.osgi.util.tracker.ServiceTracker;
import edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshotService;
import org.apache.velocity.tools.view.tools.ViewTool; import org.apache.velocity.tools.view.tools.ViewTool;
import java.io.File; import edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshot;
import edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshotService;
/**
* A viewtool which provides access to the {@link StructuresSnapshotService} read-only methods.
*/
public class StructuresSnapshotServiceTool implements ViewTool { public class StructuresSnapshotServiceTool implements ViewTool {
private ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker; /** ServiceTracker for the {@link StructuresSnapshotService}. */
private final ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker;
/**
* Constructs the StructuresSnapshotServiceTool.
* @param structuresSnapshotServiceTracker A ServiceTracker tracking the {@link StructuresSnapshotService}.
*/
public StructuresSnapshotServiceTool (ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker) { public StructuresSnapshotServiceTool (ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker) {
this.structuresSnapshotServiceTracker = structuresSnapshotServiceTracker; this.structuresSnapshotServiceTracker = structuresSnapshotServiceTracker;
} }
/**
* Initializes the viewtool.
* @param initData Data used to initialize the viewtool.
*/
@Override @Override
public void init(Object initData) { public void init(Object initData) {
} }
public String getHelloMessage() { /**
return "Hello dotCMS World"; * Loads a saved snapshot from a snapshot file.
} * @param snapshotFile File containing a saved snapshot.
* @return The snapshot saved in the given file.
* @throws IOException If the snapshot could not be loaded and deserialized from the given file.
* @throws ClassNotFoundException If the StructuresSnapshot class could not be loaded;
*/
public StructuresSnapshot loadSnapshotFromFile(File snapshotFile) throws IOException, ClassNotFoundException {
return getService().loadSnapshotFromFile(snapshotFile);
}
public String getHelloMessage(String name) { /**
return "Hello " + name; * Loads a saved snapshot from a snapshot file.
} * @param snapshotFilePath Path to a file containing a saved snapshot.
* @return The snapshot saved in the given file.
* @throws IOException if the snapshot could not be loaded and deserialized from the given file.
* @throws ClassNotFoundException if the StructuresSnapshot class could not be loaded;
*/
public StructuresSnapshot loadSnapshotFromFile(String snapshotFilePath) throws IOException, ClassNotFoundException {
return getService().loadSnapshotFromFile(snapshotFilePath);
}
public File[] getSavedSnapshotFiles() throws Exception { /**
* Gets all saved snapshot files.
* @return Array containing all files in the snapshots directory.
*/
public File[] getSavedSnapshotFiles() {
return getService().getSavedSnapshotFiles(); return getService().getSavedSnapshotFiles();
} }
private StructuresSnapshotService getService() throws Exception { /**
StructuresSnapshotService service = (StructuresSnapshotService) this.structuresSnapshotServiceTracker.getService(); * Gets all saved snapshot files which meet the given filter criteria.
if (service == null) { * @param filter Filter object.
throw new Exception("Unable to locate service edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshotService."); * @return Array containing all files in the snapshots directory which meet the given filter criteria.
} */
return service; public File[] getSavedSnapshotFiles(FileFilter filter) {
return getService().getSavedSnapshotFiles(filter);
}
/**
* Gets all historic structures snapshots.
* @return All saved snapshot files.
* @throws IOException If the snapshot could not be loaded and deserialized from the given file.
* @throws ClassNotFoundException If the StructuresSnapshot class could not be loaded;
*/
public List<StructuresSnapshot> getSavedSnapshots() throws IOException, ClassNotFoundException {
return getService().getSavedSnapshots();
}
/**
* Gets the most recent saved structures snapshot.
* @return The most recent saved structures snapshot.
* @throws IOException if there is an error reading the snapshot from disk.
* @throws ClassNotFoundException if the StructuresSnapshot class is not found.
* @throws IndexOutOfBoundsException if there are no snapshots on disk.
*/
public StructuresSnapshot getPreviousSnapshot() throws IOException, ClassNotFoundException, IndexOutOfBoundsException {
return getService().getPreviousSnapshot();
}
/**
* Gets the {@link StructuresSnapshotService} from the ServiceTracker.
* @return The StructuresSnapshotService.
*/
private StructuresSnapshotService getService() {
return this.structuresSnapshotServiceTracker.getService();
} }
} }
...@@ -8,7 +8,7 @@ import edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshotService; ...@@ -8,7 +8,7 @@ import edu.msu.anr.osgi.structuralintegrity.service.StructuresSnapshotService;
class StructuresSnapshotServiceToolInfo extends ServletToolInfo { class StructuresSnapshotServiceToolInfo extends ServletToolInfo {
private ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker; private final ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker;
StructuresSnapshotServiceToolInfo(ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker) { StructuresSnapshotServiceToolInfo(ServiceTracker<StructuresSnapshotService, StructuresSnapshotService> structuresSnapshotServiceTracker) {
this.structuresSnapshotServiceTracker = structuresSnapshotServiceTracker; this.structuresSnapshotServiceTracker = structuresSnapshotServiceTracker;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment