Search in sources :

Example 6 with SchemaFactory

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);
    }
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 7 with SchemaFactory

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);
    }
}
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 8 with SchemaFactory

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;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Pos(javafx.geometry.Pos) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) GraphManagerListener(au.gov.asd.tac.constellation.graph.manager.GraphManagerListener) VBox(javafx.scene.layout.VBox) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Graph(au.gov.asd.tac.constellation.graph.Graph) Insets(javafx.geometry.Insets) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TableView(javafx.scene.control.TableView) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaConceptUtilities(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Collection(java.util.Collection) StaticResource(org.netbeans.api.annotations.common.StaticResource) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) RadioButton(javafx.scene.control.RadioButton) ImageView(javafx.scene.image.ImageView) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) HashMap(java.util.HashMap) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) ArrayList(java.util.ArrayList) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 9 with SchemaFactory

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();
    });
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) Label(javafx.scene.control.Label) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)

Example 10 with SchemaFactory

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);
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Aggregations

SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)16 Graph (au.gov.asd.tac.constellation.graph.Graph)6 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)4 ArrayList (java.util.ArrayList)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Label (javafx.scene.control.Label)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 AttributeType (au.gov.asd.tac.constellation.plugins.importexport.AttributeType)2 ImportAttributeDefinition (au.gov.asd.tac.constellation.plugins.importexport.ImportAttributeDefinition)2 ImportDefinition (au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition)2 NewAttribute (au.gov.asd.tac.constellation.plugins.importexport.NewAttribute)2 RowFilter (au.gov.asd.tac.constellation.plugins.importexport.RowFilter)2 SchemaDestination (au.gov.asd.tac.constellation.plugins.importexport.SchemaDestination)2 AttributeTranslator (au.gov.asd.tac.constellation.plugins.importexport.translator.AttributeTranslator)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2