Search in sources :

Example 36 with Attribute

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

the class ImportJDBCIO method loadParameterFile.

private static void loadParameterFile(final JDBCImportController importController, final File delimIoDir, final String templName) {
    try {
        final ObjectMapper mapper = new ObjectMapper();
        final JsonNode root = mapper.readTree(new File(delimIoDir, FilenameEncoder.encode(templName) + FileExtensionConstants.JSON));
        final JsonNode source = root.get(SOURCE);
        final boolean schemaInit = source.get(SCHEMA_INIT).booleanValue();
        importController.setSchemaInitialised(schemaInit);
        final String destination = source.get(DESTINATION).textValue();
        final SchemaFactory schemaFactory = SchemaFactoryUtilities.getSchemaFactory(destination);
        if (schemaFactory != null) {
            importController.setDestination(new SchemaDestination(schemaFactory));
            final List<ImportDefinition> definitions = new ArrayList<>();
            final ArrayNode definitionsArray = (ArrayNode) root.withArray(DEFINITIONS);
            for (final JsonNode definitionNode : definitionsArray) {
                final int firstRow = definitionNode.get(FIRST_ROW).intValue();
                final RowFilter filter = new RowFilter();
                if (definitionNode.has(FILTER)) {
                    final JsonNode filterNode = definitionNode.get(FILTER);
                    final String script = filterNode.get(SCRIPT).textValue();
                    final JsonNode columnsArray = filterNode.withArray(COLUMNS);
                    final List<String> columns = new ArrayList<>();
                    for (final JsonNode column : columnsArray) {
                        columns.add(column.textValue());
                    }
                    filter.setScript(script);
                    filter.setColumns(columns.toArray(new String[columns.size()]));
                }
                final ImportDefinition impdef = new ImportDefinition("", firstRow, filter);
                final JsonNode attributesNode = definitionNode.get(ATTRIBUTES);
                for (final AttributeType attrType : AttributeType.values()) {
                    final ArrayNode columnArray = (ArrayNode) attributesNode.withArray(attrType.toString());
                    for (final JsonNode column : columnArray) {
                        final String columnLabel = column.get(COLUMN_LABEL).textValue();
                        final String label = column.get(ATTRIBUTE_LABEL).textValue();
                        if (!importController.hasAttribute(attrType.getElementType(), label)) {
                            // Manually created attribute.
                            final String type = column.get(ATTRIBUTE_TYPE).textValue();
                            final String descr = column.get(ATTRIBUTE_DESCRIPTION).textValue();
                            final NewAttribute a = new NewAttribute(attrType.getElementType(), type, label, descr);
                            importController.createManualAttribute(a);
                        }
                        final Attribute attribute = importController.getAttribute(attrType.getElementType(), label);
                        final AttributeTranslator translator = AttributeTranslator.getTranslator(column.get(TRANSLATOR).textValue());
                        final String args = column.get(TRANSLATOR_ARGS).textValue();
                        final String defaultValue = column.get(DEFAULT_VALUE).textValue();
                        final PluginParameters params = translator.createParameters();
                        translator.setParameterValues(params, args);
                        final ImportAttributeDefinition iad = new ImportAttributeDefinition(columnLabel, defaultValue, attribute, translator, params);
                        impdef.addDefinition(attrType, iad);
                    }
                }
                definitions.add(impdef);
            }
            importController.setClearManuallyAdded(false);
            try {
                ((JDBCImportPane) importController.getStage()).update(importController, definitions);
            } finally {
                importController.setClearManuallyAdded(true);
            }
        } else {
            final String msg = String.format("Can't find schema factory '%s'", destination);
            final NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(nd);
        }
    } catch (final IOException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) NewAttribute(au.gov.asd.tac.constellation.plugins.importexport.NewAttribute) SchemaDestination(au.gov.asd.tac.constellation.plugins.importexport.SchemaDestination) NewAttribute(au.gov.asd.tac.constellation.plugins.importexport.NewAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ImportDefinition(au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition) AttributeTranslator(au.gov.asd.tac.constellation.plugins.importexport.translator.AttributeTranslator) NotifyDescriptor(org.openide.NotifyDescriptor) ImportAttributeDefinition(au.gov.asd.tac.constellation.plugins.importexport.ImportAttributeDefinition) RowFilter(au.gov.asd.tac.constellation.plugins.importexport.RowFilter) AttributeType(au.gov.asd.tac.constellation.plugins.importexport.AttributeType) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 37 with Attribute

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

the class ImportJDBCPlugin method addAttributes.

/**
 * Add the attribute to the graph
 *
 * @param graph
 * @param elementType Graph element type
 * @param attributeDefinitions
 */
private static void addAttributes(final GraphWriteMethods graph, final GraphElementType elementType, final List<ImportAttributeDefinition> attributeDefinitions) {
    attributeDefinitions.forEach(attributeDefinition -> {
        final Attribute attribute = attributeDefinition.getAttribute();
        // the attribute to the graph and store the attribute id
        if ((attributeDefinition.getColumnIndex() == ImportConstants.ATTRIBUTE_NOT_ASSIGNED_TO_COLUMN && attributeDefinition.getDefaultValue() != null) || (attributeDefinition.getColumnIndex() != ImportConstants.ATTRIBUTE_NOT_ASSIGNED_TO_COLUMN)) {
            int attributeId = graph.getSchema() != null ? graph.getSchema().getFactory().ensureAttribute(graph, elementType, attribute.getName()) : Graph.NOT_FOUND;
            if (attributeId == Graph.NOT_FOUND) {
                attributeId = graph.addAttribute(elementType, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), attribute.getAttributeMerger() == null ? null : attribute.getAttributeMerger().getId());
            }
            attributeDefinition.setOverriddenAttributeId(attributeId);
        }
    });
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute)

Example 38 with Attribute

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

the class ScatterOptionsPane method refreshOptions.

/**
 * Refresh the state of the ScatterOptionsPane based on the given
 * ScatterPlotState.
 *
 * @param state the ScatterPlotState.
 */
protected void refreshOptions(ScatterPlotState state) {
    if (scatterPlot.getScatterPlot().getCurrentGraph() == null || state == null) {
        return;
    }
    Platform.runLater(() -> {
        isUpdating = true;
        final ObservableList<Attribute> attributes = FXCollections.observableArrayList();
        ReadableGraph readableGraph = scatterPlot.getScatterPlot().getCurrentGraph().getReadableGraph();
        try {
            final int attributeCount = readableGraph.getAttributeCount(state.getElementType());
            for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
                final int attributeId = readableGraph.getAttribute(state.getElementType(), attributePosition);
                final Attribute attribute = new GraphAttribute(readableGraph, attributeId);
                attributes.add(attribute);
            }
        } finally {
            readableGraph.release();
        }
        FXCollections.sort(attributes, (attribute1, attribute2) -> attribute1.getName().compareTo(attribute2.getName()));
        xAttributeComboBox.setItems(attributes);
        yAttributeComboBox.setItems(attributes);
        elementTypeComboBox.getSelectionModel().select(state.getElementType().getShortLabel());
        xAttributeComboBox.getSelectionModel().select(state.getXAttribute());
        yAttributeComboBox.getSelectionModel().select(state.getYAttribute());
        selectedOnlyButton.setSelected(state.isSelectedOnly());
        isUpdating = false;
    });
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 39 with Attribute

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

the class ScatterPlotStateIoProvider method readObject.

@Override
public void readObject(int attributeId, int elementId, JsonNode jnode, GraphWriteMethods graph, Map<Integer, Integer> vertexMap, Map<Integer, Integer> transactionMap, GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
    if (!jnode.isNull()) {
        final ScatterPlotState state = new ScatterPlotState();
        GraphElementType elementType = GraphElementType.valueOf(jnode.get("elementType").asText());
        final Attribute xAttribute = "null".equalsIgnoreCase(jnode.get(X_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(X_ATTRIBUTE).asText()));
        final Attribute yAttribute = "null".equalsIgnoreCase(jnode.get(Y_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(Y_ATTRIBUTE).asText()));
        state.setElementType(elementType);
        state.setXAttribute(xAttribute);
        state.setYAttribute(yAttribute);
        state.setSelectedOnly(jnode.get("selectedOnly").asBoolean());
        graph.setObjectValue(attributeId, elementId, state);
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 40 with Attribute

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

the class ActiveTableReferenceNGTest method updateVisibleColumnsRemove.

@Test
public void updateVisibleColumnsRemove() {
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final Graph graph = mock(Graph.class);
        final Attribute attribute = mock(Attribute.class);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
        final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute));
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setColumnAttributes(stateColumnAttributes);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("stateAttr", attribute))));
        activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.REMOVE);
        verify(pluginExecution).executeLater(graph);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)94 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)55 ArrayList (java.util.ArrayList)30 Test (org.testng.annotations.Test)23 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)18 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)15 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)13 Graph (au.gov.asd.tac.constellation.graph.Graph)12 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObservableList (javafx.collections.ObservableList)8 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)7 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)7 TableColumn (javafx.scene.control.TableColumn)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)5 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5