Search in sources :

Example 16 with RecordStore

use of au.gov.asd.tac.constellation.graph.processing.RecordStore in project constellation by constellation-app.

the class ExtractTypesFromTextPlugin method query.

@Override
protected RecordStore query(final RecordStore query, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final RecordStore result = new GraphRecordStore();
    interaction.setProgress(0, 0, "Importing...", true);
    final Map<String, PluginParameter<?>> extractEntityParameters = parameters.getParameters();
    final String text = extractEntityParameters.get(TEXT_PARAMETER_ID).getStringValue();
    if (text == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "No text provided from which to extract types.");
    }
    final List<ExtractedVertexType> extractedTypes = SchemaVertexTypeUtilities.extractVertexTypes(text);
    final Map<String, SchemaVertexType> identifiers = new HashMap<>();
    extractedTypes.forEach(extractedType -> identifiers.put(extractedType.getIdentifier(), extractedType.getType()));
    for (final String identifier : identifiers.keySet()) {
        result.add();
        result.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, identifier);
        result.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.TYPE, identifiers.get(identifier));
        result.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.SEED, "true");
    }
    ConstellationLoggerHelper.createPropertyBuilder(this, result.getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), ConstellationLoggerHelper.SUCCESS);
    interaction.setProgress(1, 0, "Completed successfully - imported " + result.size() + " entities.", true);
    return result;
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType)

Example 17 with RecordStore

use of au.gov.asd.tac.constellation.graph.processing.RecordStore in project constellation by constellation-app.

the class TSVDropper method drop.

@Override
public BiConsumer<Graph, DropInfo> drop(final DropTargetDropEvent dtde) {
    // Only work on files
    final Transferable transferable = dtde.getTransferable();
    if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        try {
            // Get the data as a list of files
            final Object data = dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
            // data will be list of files which extends Object type
            @SuppressWarnings("unchecked") final List<File> files = (List<File>) data;
            // Create a record store to hold the combined results
            final RecordStore recordStore = new GraphRecordStore();
            boolean badData = false;
            // Process each file...
            for (final File file : files) {
                // Only process files
                if (file.isFile()) {
                    // Only process files that have a .tsv or .tsv.gz extension
                    // If any file does not have this extension then reject all the files.
                    final InputStream in;
                    if (StringUtils.endsWithIgnoreCase(file.getName(), FileExtensionConstants.TAB_SEPARATED_VALUE + FileExtensionConstants.GZIP)) {
                        in = new GZIPInputStream(new FileInputStream(file));
                    } else if (StringUtils.endsWithIgnoreCase(file.getName(), FileExtensionConstants.TAB_SEPARATED_VALUE)) {
                        in = new FileInputStream(file);
                    } else {
                        badData = true;
                        break;
                    }
                    // Open a reader so that we can read the file line by line
                    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8.name()))) {
                        String[] columnHeaders = null;
                        String line = reader.readLine();
                        while (line != null) {
                            String[] fields = line.split(SeparatorConstants.TAB);
                            if (columnHeaders == null) {
                                columnHeaders = fields;
                            } else {
                                recordStore.add();
                                final int fieldsCount = Math.min(columnHeaders.length, fields.length);
                                for (int i = 0; i < fieldsCount; i++) {
                                    recordStore.set(columnHeaders[i], fields[i]);
                                }
                            }
                            line = reader.readLine();
                        }
                    }
                // If any directories are encountered then don't allow the drop
                } else {
                    badData = true;
                    break;
                }
            }
            if (!badData && recordStore.size() > 0) {
                return (graph, dropInfo) -> PluginExecution.withPlugin(new TSVDropperToGraphPlugin(recordStore, files)).executeLater(graph);
            }
        } catch (final UnsupportedFlavorException | IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return null;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DataFlavor(java.awt.datatransfer.DataFlavor) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) Transferable(java.awt.datatransfer.Transferable) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) DropInfo(au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper.DropInfo) StringUtils(org.apache.commons.lang3.StringUtils) Graph(au.gov.asd.tac.constellation.graph.Graph) Exceptions(org.openide.util.Exceptions) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) BiConsumer(java.util.function.BiConsumer) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) IOException(java.io.IOException) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) GraphDropper(au.gov.asd.tac.constellation.graph.visual.dragdrop.GraphDropper) FileInputStream(java.io.FileInputStream) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) FileExtensionConstants(au.gov.asd.tac.constellation.utilities.file.FileExtensionConstants) List(java.util.List) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ConstellationLoggerHelper(au.gov.asd.tac.constellation.plugins.logging.ConstellationLoggerHelper) BufferedReader(java.io.BufferedReader) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) BufferedReader(java.io.BufferedReader) List(java.util.List) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) File(java.io.File)

Example 18 with RecordStore

use of au.gov.asd.tac.constellation.graph.processing.RecordStore in project constellation by constellation-app.

the class TestParametersPluginNGTest method testQueryResults.

/**
 * Test of query method, of class TestParametersPlugin. Tests querying
 * results from graph
 */
@Test
public void testQueryResults() throws Exception {
    System.out.println("Test Query Results");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    final GraphRecordStore recordStore = new GraphRecordStore();
    final DefaultPluginInteraction interaction = new DefaultPluginInteraction(null, null);
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    result.getParameters().get(TestParametersPlugin.LEVEL_PARAMETER_ID).setStringValue("None");
    final RecordStore queryResults = instance.query(recordStore, interaction, result);
    // Test the amount of entries in the RecordStore
    assertEquals(queryResults.size(), 1);
    final DateTimeRange dtr = result.getDateTimeRangeValue(CoreGlobalParameters.DATETIME_RANGE_PARAMETER_ID);
    final ZonedDateTime[] dtrStartEnd = dtr.getZonedStartEnd();
    // Test the values entered
    assertEquals(queryResults.get(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.RAW), "name1@domain1.com");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.TYPE), "Email");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.COMMENT), "TESTPARAMETERSPLUGIN");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.SOURCE + TemporalConcept.VertexAttribute.LAST_SEEN), DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[0]).replace("Z", ".000Z"));
    assertEquals(queryResults.get(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.RAW), "name2@domain2.com");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.TYPE), "Email");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.DESTINATION + AnalyticConcept.VertexAttribute.COMMENT), "TESTPARAMETERSPLUGIN");
    assertEquals(queryResults.get(GraphRecordStoreUtilities.DESTINATION + TemporalConcept.VertexAttribute.LAST_SEEN), DateTimeFormatter.ISO_INSTANT.format(dtrStartEnd[1]).replace("Z", ".000Z"));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DefaultPluginInteraction(au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction) DateTimeRange(au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange) Test(org.testng.annotations.Test)

Example 19 with RecordStore

use of au.gov.asd.tac.constellation.graph.processing.RecordStore in project constellation by constellation-app.

the class ExtractTypesFromTextPluginNGTest method testQuery.

/**
 * Test of query method, of class ExtractTypesFromTextPlugin.
 *
 * @throws java.lang.Exception
 */
@Test
public void testQuery() throws Exception {
    RecordStore query = new GraphRecordStore();
    ExtractTypesFromTextPlugin instance = new ExtractTypesFromTextPlugin();
    PluginInteraction interaction = new TextPluginInteraction();
    PluginParameters parameters = instance.createParameters();
    parameters.getParameters().get(ExtractTypesFromTextPlugin.TEXT_PARAMETER_ID).setStringValue("Email Person Communication");
    RecordStore expResult = new GraphRecordStore();
    RecordStore result = instance.query(query, interaction, parameters);
    assertEquals(result, expResult);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) Test(org.testng.annotations.Test)

Example 20 with RecordStore

use of au.gov.asd.tac.constellation.graph.processing.RecordStore in project constellation by constellation-app.

the class ExtractTypesFromTextPluginNGTest method testNullQuery.

/**
 * Test of query method in class ExtractTypesFromTextPlugin using a null
 * string
 *
 * @throws Exception
 */
@Test(expectedExceptions = PluginException.class)
public void testNullQuery() throws Exception {
    RecordStore query = new GraphRecordStore();
    ExtractTypesFromTextPlugin instance = new ExtractTypesFromTextPlugin();
    PluginInteraction interaction = new TextPluginInteraction();
    PluginParameters parameters = instance.createParameters();
    RecordStore result = instance.query(query, interaction, parameters);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TextPluginInteraction(au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction) Test(org.testng.annotations.Test)

Aggregations

RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)29 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)20 Test (org.testng.annotations.Test)13 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)10 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)6 File (java.io.File)4 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)2 AnalyticSchemaFactory (au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory)2 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)2 ExpandedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2 DateTimeRange (au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange)2