use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory in project constellation by constellation-app.
the class ImportController method updateAutoAddedAttributes.
/**
* Get the attributes that will automatically be added to the attribute
* list.
*
* @param elementType
* @param attributes
* @param rg
*/
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
attributes.clear();
// Add attributes from the graph
int attributeCount = rg.getAttributeCount(elementType);
for (int i = 0; i < attributeCount; i++) {
int attributeId = rg.getAttribute(elementType, i);
Attribute attribute = new GraphAttribute(rg, attributeId);
attributes.put(attribute.getName(), attribute);
}
// Add attributes from the schema
if (showSchemaAttributes && rg.getSchema() != null) {
final SchemaFactory factory = rg.getSchema().getFactory();
for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
if (!attributes.containsKey(attribute.getName())) {
attributes.put(attribute.getName(), attribute);
}
}
}
// Add pseudo-attributes
if (elementType == GraphElementType.TRANSACTION) {
final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
attributes.put(attribute.getName(), attribute);
}
// Add primary keys
for (int key : rg.getPrimaryKey(elementType)) {
keys.add(key);
}
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory 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.schema.SchemaFactory in project constellation by constellation-app.
the class AttributeNodeProvider method getSchemaInfo.
private List<AttributeEntry> getSchemaInfo(final Graph graph) {
final List<AttributeEntry> attrs = new ArrayList<>();
final Schema schema = graph.getSchema();
final SchemaFactory factory = schema.getFactory();
// Get the keys for each element type.
final Map<GraphElementType, List<String>> elementKeys = new HashMap<>();
for (final GraphElementType et : new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION }) {
final List<SchemaAttribute> keys = factory.getKeyAttributes(et);
final List<String> keyLabels = keys.stream().map(key -> key.getName()).collect(Collectors.toList());
elementKeys.put(et, keyLabels);
}
for (final GraphElementType et : GraphElementType.values()) {
final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(et);
attrsMap.values().stream().forEach(schemaAttribute -> {
final int keyIx = elementKeys.containsKey(schemaAttribute.getElementType()) ? elementKeys.get(schemaAttribute.getElementType()).indexOf(schemaAttribute.getName()) : -1;
final Collection<SchemaConcept> concepts = SchemaConceptUtilities.getAttributeConcepts(schemaAttribute);
final StringBuilder categories = new StringBuilder();
for (SchemaConcept concept : concepts) {
categories.append(concept.getName()).append(",");
}
if (categories.length() > 0) {
categories.deleteCharAt(categories.length() - 1);
}
attrs.add(new AttributeEntry(schemaAttribute, categories.toString(), keyIx));
});
}
return attrs;
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory in project constellation by constellation-app.
the class VertexTypeNodeProvider method newActiveGraph.
@Override
public void newActiveGraph(final Graph graph) {
// TODO: if the old graph and the new graph have the same schema, don't recalculate.
Platform.runLater(() -> {
detailsView.getChildren().clear();
final Label nameLabel = new Label("No type selected");
detailsView.getChildren().add(nameLabel);
vertexTypes.clear();
if (graph != null && graph.getSchema() != null && GraphNode.getGraphNode(graph) != null) {
final SchemaFactory schemaFactory = graph.getSchema().getFactory();
final Set<Class<? extends SchemaConcept>> concepts = schemaFactory.getRegisteredConcepts();
schemaLabel.setText(String.format("%s - %s", schemaFactory.getLabel(), GraphNode.getGraphNode(graph).getDisplayName()));
vertexTypes.addAll(SchemaVertexTypeUtilities.getTypes(concepts));
Collections.sort(vertexTypes, (final SchemaVertexType a, final SchemaVertexType b) -> a.getName().compareToIgnoreCase(b.getName()));
} else {
schemaLabel.setText("No schema available");
}
populateTree();
});
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory in project constellation by constellation-app.
the class NewGraph method callService.
@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
final String schemaParam = parameters.getStringValue(SCHEMA_PARAMETER_ID);
String schemaName = null;
for (final SchemaFactory schemaFactory : SchemaFactoryUtilities.getSchemaFactories().values()) {
if (schemaFactory.isPrimarySchema() && (schemaParam == null || schemaParam.equals(schemaFactory.getName()))) {
schemaName = schemaFactory.getName();
break;
}
}
if (schemaName == null) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, String.format("Unknown schema %s", schemaParam));
}
// Creating a new graph is asynchronous; we want to hide this from the client.
//
final Graph existingGraph = GraphManager.getDefault().getActiveGraph();
final String existingId = existingGraph != null ? existingGraph.getId() : null;
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(schemaName).createSchema();
final StoreGraph sg = new StoreGraph(schema);
schema.newGraph(sg);
final Graph dualGraph = new DualGraph(sg, false);
final String graphName = SchemaFactoryUtilities.getSchemaFactory(schemaName).getLabel().trim().toLowerCase();
GraphOpener.getDefault().openGraph(dualGraph, graphName);
final String newId = RestServiceUtilities.waitForGraphChange(existingId);
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
root.put("id", newId);
root.put("name", GraphNode.getGraphNode(newId).getDisplayName());
root.put("schema", schemaName);
mapper.writeValue(out, root);
}
Aggregations