Search in sources :

Example 1 with ReportException

use of com.buschmais.jqassistant.core.report.api.ReportException in project jqa-core-framework by buschmais.

the class SubGraphFactory method convert.

private <I extends Identifiable> I convert(Object value) throws ReportException {
    if (value == null) {
        return null;
    } else if (value instanceof Map) {
        Map<String, Object> virtualObject = (Map) value;
        Object role = virtualObject.get(ROLE);
        if (role != null) {
            Map<String, Object> properties = (Map<String, Object>) virtualObject.get(PROPERTIES);
            switch(role.toString().toLowerCase()) {
                case NODE:
                    Node node = new Node();
                    node.setId(nodeId--);
                    Collection<String> labels = (Collection<String>) virtualObject.get(LABELS);
                    node.getLabels().addAll(labels);
                    node.getProperties().putAll(properties);
                    node.setLabel((String) virtualObject.get(LABEL));
                    return (I) node;
                case RELATIONSHIP:
                    Relationship relationship = new Relationship();
                    relationship.setId(relationshipId--);
                    Node startNode = convert(virtualObject.get(START_NODE));
                    Node endNode = convert(virtualObject.get(END_NODE));
                    String type = (String) virtualObject.get(TYPE);
                    relationship.setType(type);
                    relationship.setStartNode(startNode);
                    relationship.setEndNode(endNode);
                    relationship.getProperties().putAll(properties);
                    relationship.setLabel((String) virtualObject.get(LABEL));
                    if (startNode == null || endNode == null || type == null) {
                        throw new ReportException("The virtual relationship does not contain either start node, end node or type: " + relationship);
                    }
                    return (I) relationship;
                case GRAPH:
                    SubGraph subgraph = new SubGraph();
                    subgraph.setId(subgraphId--);
                    subgraph.setParent((Node) convert(subgraph, virtualObject.get(PARENT)));
                    addSubGraphChildren(subgraph, virtualObject, NODES, subgraph.getNodes());
                    addSubGraphChildren(subgraph, virtualObject, RELATIONSHIPS, subgraph.getRelationships());
                    return (I) subgraph;
            }
        }
    } else if (value instanceof CompositeObject) {
        CompositeObject compositeObject = (CompositeObject) value;
        I identifiable = convert(compositeObject.getDelegate());
        identifiable.setLabel(ReportHelper.getLabel(value));
        return identifiable;
    } else if (value instanceof Neo4jNode) {
        Neo4jNode<Neo4jLabel, ?, ?, ?> neo4jNode = (Neo4jNode<Neo4jLabel, ?, ?, ?>) value;
        Node node = new Node();
        node.setId(neo4jNode.getId());
        for (Neo4jLabel label : neo4jNode.getLabels()) {
            node.getLabels().add(label.getName());
        }
        node.getProperties().putAll(neo4jNode.getProperties());
        return (I) node;
    } else if (value instanceof Neo4jRelationship) {
        Neo4jRelationship<?, ?, ?, ?, ?> neo4jRelationship = (Neo4jRelationship) value;
        Relationship relationship = new Relationship();
        relationship.setId(neo4jRelationship.getId());
        relationship.setType(neo4jRelationship.getType().getName());
        relationship.setStartNode((Node) convert(neo4jRelationship.getStartNode()));
        relationship.setEndNode((Node) convert(neo4jRelationship.getEndNode()));
        relationship.getProperties().putAll(neo4jRelationship.getProperties());
        return (I) relationship;
    }
    throw new ReportException("Element type not supported: " + value);
}
Also used : Neo4jLabel(com.buschmais.xo.neo4j.api.model.Neo4jLabel) Node(com.buschmais.jqassistant.core.report.api.graph.model.Node) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) Neo4jRelationship(com.buschmais.xo.neo4j.api.model.Neo4jRelationship) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) CompositeObject(com.buschmais.xo.api.CompositeObject) Neo4jRelationship(com.buschmais.xo.neo4j.api.model.Neo4jRelationship) Relationship(com.buschmais.jqassistant.core.report.api.graph.model.Relationship) Collection(java.util.Collection) ReportException(com.buschmais.jqassistant.core.report.api.ReportException) CompositeObject(com.buschmais.xo.api.CompositeObject) Map(java.util.Map) SubGraph(com.buschmais.jqassistant.core.report.api.graph.model.SubGraph)

Example 2 with ReportException

use of com.buschmais.jqassistant.core.report.api.ReportException in project jqa-core-framework by buschmais.

the class CompositeReportPlugin method selectReportWriter.

/**
     * Select the report writers for the given rule.
     *
     * @param rule The rule.
     * @throws ReportException If no writer exists for a specified id.
     */
private void selectReportWriter(ExecutableRule rule) throws ReportException {
    Set<String> selection = rule.getReport().getSelectedTypes();
    if (selection == null) {
        // no writer explicitly selected, use all registered.
        selectedReportWriters = reportWriters.values();
    } else {
        List<ReportPlugin> reportPlugins = new ArrayList<>();
        for (String type : selection) {
            ReportPlugin reportPlugin = this.reportWriters.get(type);
            if (reportPlugin == null) {
                throw new ReportException("Unknown report selection '" + type + "' selected for '" + rule + "'");
            }
            reportPlugins.add(reportPlugin);
        }
        this.selectedReportWriters = reportPlugins;
    }
}
Also used : ReportPlugin(com.buschmais.jqassistant.core.report.api.ReportPlugin) ReportException(com.buschmais.jqassistant.core.report.api.ReportException)

Example 3 with ReportException

use of com.buschmais.jqassistant.core.report.api.ReportException in project jqa-core-framework by buschmais.

the class ReportPluginRepositoryImpl method getReportPlugins.

private Map<String, ReportPlugin> getReportPlugins(List<JqassistantPlugin> plugins) throws PluginRepositoryException {
    Map<String, ReportPlugin> reportPlugins = new HashMap<>();
    for (JqassistantPlugin plugin : plugins) {
        ReportType reportType = plugin.getReport();
        if (reportType != null) {
            for (IdClassType classType : reportType.getClazz()) {
                ReportPlugin reportPlugin = createInstance(classType.getValue());
                if (reportPlugin != null) {
                    try {
                        reportPlugin.initialize();
                    } catch (ReportException e) {
                        throw new PluginRepositoryException("Cannot initialize report plugin " + reportPlugin, e);
                    }
                    String id = classType.getId();
                    if (id == null) {
                        id = reportPlugin.getClass().getSimpleName();
                    }
                    reportPlugins.put(id, reportPlugin);
                }
            }
        }
    }
    return reportPlugins;
}
Also used : IdClassType(com.buschmais.jqassistant.core.plugin.schema.v1.IdClassType) PluginRepositoryException(com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException) ReportPlugin(com.buschmais.jqassistant.core.report.api.ReportPlugin) HashMap(java.util.HashMap) JqassistantPlugin(com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin) ReportException(com.buschmais.jqassistant.core.report.api.ReportException) ReportType(com.buschmais.jqassistant.core.plugin.schema.v1.ReportType)

Aggregations

ReportException (com.buschmais.jqassistant.core.report.api.ReportException)3 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)2 PluginRepositoryException (com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException)1 IdClassType (com.buschmais.jqassistant.core.plugin.schema.v1.IdClassType)1 JqassistantPlugin (com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin)1 ReportType (com.buschmais.jqassistant.core.plugin.schema.v1.ReportType)1 Node (com.buschmais.jqassistant.core.report.api.graph.model.Node)1 Relationship (com.buschmais.jqassistant.core.report.api.graph.model.Relationship)1 SubGraph (com.buschmais.jqassistant.core.report.api.graph.model.SubGraph)1 CompositeObject (com.buschmais.xo.api.CompositeObject)1 Neo4jLabel (com.buschmais.xo.neo4j.api.model.Neo4jLabel)1 Neo4jNode (com.buschmais.xo.neo4j.api.model.Neo4jNode)1 Neo4jRelationship (com.buschmais.xo.neo4j.api.model.Neo4jRelationship)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1