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);
}
}
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);
}
});
}
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;
});
}
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);
}
}
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);
}
}
Aggregations