Search in sources :

Example 1 with MetaverseLocatorException

use of org.pentaho.metaverse.api.MetaverseLocatorException in project pentaho-metaverse by pentaho.

the class BaseLocator method startScan.

/**
 * Starts a full scan by this locator.
 *
 * @param locatorRunner The locator runner to use
 * @throws MetaverseLocatorException
 */
protected void startScan(LocatorRunner<T> locatorRunner) throws MetaverseLocatorException {
    if (futureTask != null && !futureTask.isDone()) {
        throw new MetaverseLocatorException(Messages.getString("ERROR.BaseLocator.ScanAlreadyExecuting"));
    }
    IMetaverseNode node = getLocatorNode();
    Date lastRun = new Date();
    node.setProperty("lastScan", Long.toString(lastRun.getTime()));
    metaverseBuilder.addNode(node);
    runner = locatorRunner;
    runner.setLocator(this);
    LOG.debug(Messages.getString("DEBUG.Locator.StartScan", getLocatorType()));
    futureTask = completionService.submit(runner, node.getStringID());
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Date(java.util.Date)

Example 2 with MetaverseLocatorException

use of org.pentaho.metaverse.api.MetaverseLocatorException in project pentaho-metaverse by pentaho.

the class FileSystemLocator method startScan.

@Override
public void startScan() throws MetaverseLocatorException {
    File root = new File(rootFolder);
    if (!root.exists()) {
        LOG.error(Messages.getString("ERROR.FileSystemLocator.RootFolder.DoesNotExist", root.getAbsolutePath()));
        throw new MetaverseLocatorException(Messages.getString("ERROR.FileSystemLocator.RootFolder.DoesNotExist", root.getAbsolutePath()));
    }
    if (!root.isDirectory()) {
        LOG.error(Messages.getString("ERROR.FileSystemLocator.RootFolder.NotAFolder", root.getAbsolutePath()));
        throw new MetaverseLocatorException(Messages.getString("ERROR.FileSystemLocator.RootFolder.NotAFolder", root.getAbsolutePath()));
    }
    LocatorRunner<File> lr = new FileSystemLocatorRunner();
    lr.setRoot(root);
    startScan(lr);
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) File(java.io.File)

Example 3 with MetaverseLocatorException

use of org.pentaho.metaverse.api.MetaverseLocatorException in project pentaho-metaverse by pentaho.

the class FileSystemLocatorTest method testStartLocator.

/**
 * Runs the spyLocator and checks the results
 *
 * @throws Exception When bad things happen
 */
@Test
public void testStartLocator() throws Exception {
    TinkerGraph graph = new TinkerGraph();
    IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
    spyLocator.setMetaverseBuilder(metaverseBuilder);
    spyLocator.setRepositoryId("testrepo");
    spyLocator.addDocumentListener(this);
    spyLocator.setRootFolder("src/test/resources/solution");
    assertEquals("Root folder is wrong", "src/test/resources/solution", spyLocator.getRootFolder());
    TestFileSystemLocator.delay = 0;
    spyLocator.setRootFolder("bogus");
    events = new ArrayList<IDocumentEvent>();
    try {
        spyLocator.startScan();
        MetaverseCompletionService.getInstance().waitTillEmpty();
        fail();
    } catch (MetaverseLocatorException e) {
        assertEquals("Event count is wrong", 0, events.size());
    }
    spyLocator.setRootFolder("src/test/resources/solution/folder 2/parse.ktr");
    events = new ArrayList<IDocumentEvent>();
    try {
        spyLocator.startScan();
        MetaverseCompletionService.getInstance().waitTillEmpty();
        fail();
    } catch (MetaverseLocatorException e) {
        assertEquals("Event count is wrong", 0, events.size());
    }
    spyLocator.setRootFolder("src/test/resources/solution");
    assertEquals("Repo id is wrong", "testrepo", spyLocator.getRepositoryId());
    assertNotNull("Indexer type is null", spyLocator.getLocatorType());
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    MetaverseCompletionService.getInstance().waitTillEmpty();
    assertEquals("Event count is wrong", 7, events.size());
    for (IDocumentEvent event : events) {
        System.out.println(event.getDocument().getStringID());
        assertNotNull(event.getDocument());
        MetaverseDocument document = (MetaverseDocument) event.getDocument();
        if (document.getExtension().equals("ktr")) {
            assertTrue(document.getContent() instanceof String);
        } else if (document.getExtension().equals("kjb")) {
            assertTrue(document.getContent() instanceof String);
        }
    }
    spyLocator.removeDocumentListener(this);
    events = new ArrayList<IDocumentEvent>();
    spyLocator.startScan();
    MetaverseCompletionService.getInstance().waitTillEmpty();
    assertEquals("Event count is wrong", 0, events.size());
    assertNotNull("Graph is null", graph);
    GraphMLWriter writer = new GraphMLWriter();
    writer.outputGraph(graph, new FileOutputStream(OUTPUT_FOLDER + "FileSystemLocatorTest.graphml"));
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentEvent(org.pentaho.metaverse.api.IDocumentEvent) FileOutputStream(java.io.FileOutputStream) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) GraphMLWriter(org.pentaho.metaverse.graph.GraphMLWriter) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) Test(org.junit.Test)

Example 4 with MetaverseLocatorException

use of org.pentaho.metaverse.api.MetaverseLocatorException in project pentaho-metaverse by pentaho.

the class RepositoryLocator method startScan.

@Override
public void startScan() throws MetaverseLocatorException {
    if (unifiedRepository == null) {
        try {
            unifiedRepository = getUnifiedRepository(session);
        } catch (Exception e) {
            throw new MetaverseLocatorException(Messages.getString("ERROR.RepositoryLocator.ScanAbortedNoRepo"), e);
        }
    }
    RepositoryRequest request = new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, -1, null);
    RepositoryFileTree root = unifiedRepository.getTree(request);
    List<RepositoryFileTree> children = root.getChildren();
    LocatorRunner lr = new RepositoryLocatorRunner();
    lr.setRoot(children);
    startScan(lr);
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Aggregations

MetaverseLocatorException (org.pentaho.metaverse.api.MetaverseLocatorException)4 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Date (java.util.Date)1 Test (org.junit.Test)1 IDocumentEvent (org.pentaho.metaverse.api.IDocumentEvent)1 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 MetaverseDocument (org.pentaho.metaverse.api.MetaverseDocument)1 GraphMLWriter (org.pentaho.metaverse.graph.GraphMLWriter)1 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)1 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)1 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)1