Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'v2-alpha' into gh-981-gafferpy-fishbowl-maintain
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Aug 12, 2022
2 parents ad1d75e + 45f5fd1 commit 71a3e46
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 32 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ jobs:
env:
MAVEN_OPTS: -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=25
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup JDK
uses: actions/setup-java@v2
Expand All @@ -133,5 +135,9 @@ jobs:
- name: Test
run: mvn verify -B -P coverage -pl ${{matrix.modules}}

- name: Check Copyright Headers
if: github.event_name == 'pull_request'
run: mvn -B -q spotless:check -pl ${{matrix.modules}}

- name: Upload Coverage
uses: codecov/codecov-action@v2
4 changes: 0 additions & 4 deletions code-style/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<property name="id" value="fileTabChar"/>
<property name="eachLine" value="true"/>
</module>
<module name="RegexpHeader">
<property name="id" value="headerCheck"/>
<property name="headerFile" value="${checkstyle.header.file}"/>
</module>

<module name="RegexpSingleline">
<property name="id" value="trailingSpaces"/>
Expand Down
16 changes: 16 additions & 0 deletions code-style/licence-header-java.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright $YEAR Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

17 changes: 17 additions & 0 deletions code-style/licence-header-pom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright $YEAR Crown Copyright
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

15 changes: 0 additions & 15 deletions code-style/licenseHeader.txt

This file was deleted.

6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-2019 Crown Copyright
~ Copyright 2016-2022 Crown Copyright
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,8 +85,6 @@
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<headerLocation>code-style/licenseHeader.txt
</headerLocation>
<excludes>**/generated/**/*</excludes>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}
Expand All @@ -105,8 +103,6 @@
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<headerLocation>code-style/licenseHeader.txt
</headerLocation>
</configuration>
<goals>
<goal>check</goal>
Expand Down
44 changes: 40 additions & 4 deletions ui/src/main/webapp/app/graph/graph-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
events.unsubscribe('resultsCleared', vm.reset);

if (cytoscapeGraph) {
saveGraph();
cytoscapeGraph.destroy();
}
}
Expand All @@ -151,15 +152,35 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
createCytoscapeGraph().then(function(cy) {
cytoscapeGraph = cy;
generateStylesheets();
vm.reset()

if(graph.hasGraphJson()) {
restoreGraph();
cytoscapeGraph.elements().lock();
vm.update(results.get());
cytoscapeGraph.elements().unlock();
} else {
vm.reset();
}
vm.graphLoading = false;
var searchTerm = graph.getSearchTerm();

if (searchTerm !== null && searchTerm !== undefined && searchTerm !== "") {
vm.filter(searchTerm)
}
});
}

var saveGraph = function() {
if(cytoscapeGraph) {
graph.setGraphJson(cytoscapeGraph.json());
}
}

var restoreGraph = function() {
if(graph.hasGraphJson() && cytoscapeGraph && (results.get().edges || results.get().entities)) {
cytoscapeGraph.json(graph.getGraphJson());
cytoscapeGraph.nodes().removeClass("filtered"); // seems to be a bug in cytoscape json
}
}

/**
* Loads cytoscape graph onto an element containing the "graphCy" id. It also registers the
Expand Down Expand Up @@ -416,6 +437,7 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
cytoscapeGraph.getElementById(id).data(elementsToMergeData[id]);
}

removePreviouslyRemovedElements();
vm.redraw();
});

Expand Down Expand Up @@ -598,6 +620,8 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
*/
vm.reset = function() {
vm.clear();
graph.setRemovedElements([]);
saveGraph();
vm.update(results.get());
}

Expand All @@ -610,7 +634,7 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
searchTerm = searchTerm.toLowerCase();
cytoscapeGraph.batch(function() {
var nodes = cytoscapeGraph.nodes();
for(var i in nodes) {
for(var i = 0; i < nodes.length; i++) {
if(nodes[i].data && nodes[i].data('id')) {
if(nodes[i].data('id').toLowerCase().indexOf(searchTerm) === -1) {
nodes[i].addClass("filtered");
Expand All @@ -630,9 +654,21 @@ function GraphController($q, graph, config, error, loading, query, operationOpti
* Removes every selected element in the graph.
*/
vm.removeSelected = function() {
cytoscapeGraph.filter(":selected").remove();
var removedElements = cytoscapeGraph.filter(":selected").remove().toArray();
graph.setRemovedElements(graph.getRemovedElements().concat(removedElements));

cytoscapeGraph.elements().unselect();
vm.selectedElements.entities = [];
vm.selectedElements.edges = [];
}

var removePreviouslyRemovedElements = function() {
var elements = cytoscapeGraph.elements();
graph.getRemovedElements().forEach(function(removedElement) {
var element = elements.getElementById(removedElement.id());
if(element && element.id()) {
element.remove();
}
});
}
}
40 changes: 40 additions & 0 deletions ui/src/main/webapp/app/graph/graph-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ angular.module('app').factory('graph', function() {

var graphConfiguration = null;

var removedElements = [];
var graphJson = {};

var selectedElements = {
entities: [],
edges: []
Expand Down Expand Up @@ -76,6 +79,43 @@ angular.module('app').factory('graph', function() {
searchTerm = angular.copy(search);
}

/**
* Gets the removed elements.
*/
service.getRemovedElements = function() {
return removedElements;
}

/**
* Sets the removed elements.
* @param removedElements;
*/
service.setRemovedElements = function(newRemovedElements) {
removedElements = newRemovedElements
}

/**
* Checks if the graph json has been set.
*/
service.hasGraphJson = function() {
return graphJson && Object.keys(graphJson).length > 0 && Object.keys(graphJson.elements).length > 0;
}

/**
* Gets the graph json.
*/
service.getGraphJson = function() {
return graphJson;
}

/**
* Sets the graph json.
* @param graphJson;
*/
service.setGraphJson = function(newGraphJson) {
graphJson = newGraphJson;
}

/**
* Resets the value of the selected elements
*/
Expand Down
4 changes: 3 additions & 1 deletion ui/src/main/webapp/app/toolbar/toolbar-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function toolbar() {
};
}

function ToolbarController($rootScope, $mdDialog, operationService, results, query, config, loading, events, properties, error, $mdToast, $cookies) {
function ToolbarController($rootScope, $mdDialog, operationService, results, query, config, loading, events, properties, error, $mdToast, $cookies, graph) {
var vm = this;
vm.addMultipleSeeds = false;
vm.appTitle;
Expand Down Expand Up @@ -165,6 +165,7 @@ function ToolbarController($rootScope, $mdDialog, operationService, results, que

vm.executeAll = function() {
var ops = query.getOperations();
graph.setGraphJson(null);
if (ops.length > 0) {
results.clear(false);
loading.load();
Expand All @@ -175,6 +176,7 @@ function ToolbarController($rootScope, $mdDialog, operationService, results, que
}

vm.clearResults = function() {
graph.setGraphJson(null);
results.clear();
}

Expand Down
46 changes: 44 additions & 2 deletions ui/src/test/webapp/app/graph/graph-component-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,24 @@ describe("The Graph Component", function() {
expect(ctrl.update).toHaveBeenCalled();
})

it('should load the graph from the saved graph json when it exists', function() {
var graphJson = {elements: [1,2]};
spyOn(ctrl, 'update').and.stub();
$httpBackend.whenGET('config/config.json').respond(200, {});
graph.setGraphJson(graphJson);
spyOn(injectableCytoscape, 'json')

ctrl.$onInit();

$httpBackend.flush();
jasmine.clock().tick(101);

scope.$digest();

expect(injectableCytoscape.json).toHaveBeenCalledWith(graphJson);
expect(ctrl.update).toHaveBeenCalled();
})

it('should run the filter once loaded if the service holds a filter', function() {
spyOn(ctrl, 'filter').and.stub();
spyOn(ctrl, 'update').and.stub();
Expand Down Expand Up @@ -447,7 +465,16 @@ describe("The Graph Component", function() {

expect(events.unsubscribe).toHaveBeenCalledWith("incomingResults", jasmine.any(Function));
});


it('should save the graph json', function() {
var graphJson = {elements: [1,2]};
spyOn(injectableCytoscape, 'json').and.returnValue(graphJson);

ctrl.$onDestroy();
expect(injectableCytoscape.json).toHaveBeenCalled();
expect(graph.getGraphJson()).toEqual(graphJson);
});

it('should destroy the cytoscape graph cleanly', function() {
spyOn(injectableCytoscape, 'destroy');

Expand Down Expand Up @@ -649,7 +676,15 @@ describe("The Graph Component", function() {

expect(injectableCytoscape.nodes().size()).toEqual(1);
});


it('should save the removed elements', function() {
graph.setRemovedElements([]);
ctrl.removeSelected();

expect(injectableCytoscape.nodes().size()).toEqual(1);
expect(graph.getRemovedElements().length).toEqual(2);
});

it('should unselect all the elements', function() {
expect(injectableCytoscape.elements(':selected').size()).toEqual(1);

Expand Down Expand Up @@ -680,6 +715,13 @@ describe("The Graph Component", function() {
expect(injectableCytoscape.elements().size()).toEqual(3);
});

it('should remove previously removed elements from the results', function() {
graph.setRemovedElements([{id: function(){return "\"foo\""}}]);
injectableCytoscape.elements().restore();
ctrl.update(elements);
expect(injectableCytoscape.elements().size()).toEqual(1);
});

it('should not error when vertex type is unknown', function() {
entityVertexType = undefined;

Expand Down
Loading

0 comments on commit 71a3e46

Please sign in to comment.