diff --git a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/AbstractGraphDatabaseCommandComponent.java b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/AbstractGraphDatabaseCommandComponent.java new file mode 100644 index 0000000..4c10cc2 --- /dev/null +++ b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/AbstractGraphDatabaseCommandComponent.java @@ -0,0 +1,149 @@ +/** + * slizaa-server-main - Slizaa Static Software Analysis Tools + * Copyright © 2019 Code-Kontor GmbH and others (slizaa@codekontor.io) + *
+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *
+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see true
if the backend is configured properly.
+ */
+ protected String checkBackendConfigured() {
+ if (!_slizaaService.getBackendService().hasInstalledExtensions()) {
+ return cannotExecuteCommand("The Slizaa Server has not been configured properly: There are not installed backend extensions.\n");
+ }
+ return null;
+ }
+
+ protected String checkDatabaseExists(String identifier) {
+ IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(identifier);
+ if (graphDatabase == null) {
+ return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", identifier));
+ }
+ return null;
+ }
+
+ protected String checkDatabaseDoesNotExist(String identifier) {
+ IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(identifier);
+ if (graphDatabase != null) {
+ return cannotExecuteCommand(String.format("The specified database '%s' already exists.\n", identifier));
+ }
+ return null;
+ }
+
+ protected String cannotExecuteCommand(String msg) {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append("Can not execute command.\n");
+ stringBuffer.append(msg + "\n");
+ return stringBuffer.toString();
+ }
+}
\ No newline at end of file
diff --git a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaBackendCommands.java b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaBackendCommands.java
index 1562903..a8bd5fa 100644
--- a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaBackendCommands.java
+++ b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaBackendCommands.java
@@ -17,12 +17,8 @@
*/
package io.codekontor.slizaa.server;
-import io.codekontor.slizaa.server.service.backend.IBackendService;
-import io.codekontor.slizaa.server.service.backend.IModifiableBackendService;
import io.codekontor.slizaa.server.service.extensions.IExtension;
import io.codekontor.slizaa.server.service.extensions.IExtensionIdentifier;
-import io.codekontor.slizaa.server.service.extensions.IExtensionService;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.*;
@@ -31,16 +27,7 @@
@ShellComponent
@ShellCommandGroup("Slizaa Backend Commands")
-public class SlizaaBackendCommands {
-
- @Autowired(required = false)
- private IModifiableBackendService _modifiableBackendService;
-
- @Autowired
- private IBackendService _backendService;
-
- @Autowired
- private IExtensionService _extensionService;
+public class SlizaaBackendCommands extends AbstractGraphDatabaseCommandComponent{
@ShellMethod(value = "List all available backend extensions.", key="listAvailableExtensions")
@ShellMethodAvailability("availabilityCheck")
@@ -49,8 +36,8 @@ public String listAvailableExtensions() {
//
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("Available Backend Extensions:\n");
- _extensionService.getExtensions().forEach(extension -> {
- stringBuffer.append(format(extension));
+ extensionService().getExtensions().forEach(extension -> {
+ stringBuffer.append(formatExtension(extension));
});
return stringBuffer.toString();
}
@@ -60,8 +47,8 @@ public String listInstalledExtensions() {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("Installed Backend Extensions:\n");
- _backendService.getInstalledExtensions().forEach(extension -> {
- stringBuffer.append(format(extension));
+ backendService().getInstalledExtensions().forEach(extension -> {
+ stringBuffer.append(formatExtension(extension));
});
@@ -73,7 +60,7 @@ public String listInstalledExtensions() {
public String installExtensions(String[] extensions) {
// fail fast
- if (_modifiableBackendService == null) {
+ if (!hasModifiableBackendService()) {
return cannotExecuteCommand("Backend is not modifiable.");
}
@@ -90,13 +77,13 @@ public String installExtensions(String[] extensions) {
}
//
- Listtrue
if the backend is configured properly.
- */
- private String checkBackendConfigured() {
- if (!_backendService.hasInstalledExtensions()) {
- return cannotExecuteCommand("The Slizaa Server has not been configured properly: There are not installed backend extensions.\n");
- }
- return null;
- }
-
- private String cannotExecuteCommand(String msg) {
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append("Can not execute command.\n");
- stringBuffer.append(msg + "\n");
- return stringBuffer.toString();
- }
-
- private String format(IExtension extension) {
+ private String formatExtension(IExtension extension) {
return String.format(" - %1$s_%2$s (Symbolic name: %1$s, version: %2$s)\n", extension.getSymbolicName(), extension.getVersion());
}
}
\ No newline at end of file
diff --git a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseCommands.java b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseCommands.java
index 8497837..43cd321 100644
--- a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseCommands.java
+++ b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseCommands.java
@@ -17,31 +17,18 @@
*/
package io.codekontor.slizaa.server;
-import io.codekontor.slizaa.server.descr.ContentDefinition;
-import io.codekontor.slizaa.server.descr.GraphDatabase;
-import io.codekontor.slizaa.server.service.backend.IModifiableBackendService;
import io.codekontor.slizaa.server.service.slizaa.IGraphDatabase;
import io.codekontor.slizaa.server.service.slizaa.IHierarchicalGraph;
-import io.codekontor.slizaa.server.service.slizaa.ISlizaaService;
-import org.jetbrains.annotations.NotNull;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import java.io.IOException;
-import java.util.Collections;
@ShellComponent
@ShellCommandGroup("Slizaa Graph Databases Commands")
-public class SlizaaGraphDatabaseCommands {
-
- @Autowired(required = false)
- private IModifiableBackendService _modifiableBackendService;
-
- @Autowired
- private ISlizaaService _slizaaService;
+public class SlizaaGraphDatabaseCommands extends AbstractGraphDatabaseCommandComponent {
@ShellMethod(value = "List all configured graph databases.", key = "listDBs")
public String listDBs() {
@@ -72,19 +59,14 @@ public String createDB(String identifier) {
}
//
- _slizaaService.newGraphDatabase(identifier);
+ slizaaService().newGraphDatabase(identifier);
// return the result
return dumpGraphDatabases();
}
- @ShellMethod(value = "List available content definition provider factories.", key = {"listContentDefinitionProviderFactories"}, group = "Slizaa Graph Databases Commands - Content Definition")
- public String listContentDefinitionProviderFactories() {
- return dumpContentDefinitionProviderFactories();
- }
-
- @ShellMethod(value = "Define the content that should be analyzed.", key = "setContentDefinitionProvider", group = "Slizaa Graph Databases Commands - Content Definition")
- public String setContentDefinitionProvider(@ShellOption({"-d", "--databaseId"}) String databaseIdentifier, @ShellOption({"-f", "--factoryId"}) String contentDefinitionProviderFactoryId, @ShellOption({"-c", "--contentDefinition"}) String contentDefinition) {
+ @ShellMethod(value = "Delete an existing graph database.", key = "deleteDB")
+ public String deleteDB(String identifier) {
// check the backend configuration
String checkBackendConfigured = checkBackendConfigured();
@@ -93,22 +75,23 @@ public String setContentDefinitionProvider(@ShellOption({"-d", "--databaseId"})
}
// check that the requested database exists
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(databaseIdentifier);
- if (graphDatabase == null) {
- return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", databaseIdentifier));
+ String checkDatabaseExists = checkDatabaseExists(identifier);
+ if (checkDatabaseExists != null) {
+ return checkDatabaseExists;
}
- // TODO:
- // _slizaaService.getContentDefinitionProviderFactories();
-
//
- graphDatabase.setContentDefinitionProvider(contentDefinitionProviderFactoryId, contentDefinition);
+ IGraphDatabase graphDatabase = slizaaService().getGraphDatabase(identifier);
+ graphDatabase.terminate();
// return the result
- return dumpGraphDatabases();
+ StringBuffer result = new StringBuffer();
+ result.append(String.format("Successfully deleted graph database '%s'.\n", identifier));
+ result.append(dumpGraphDatabases());
+ return result.toString();
}
- @ShellMethod(value = "Parse the definied content.", key = "parseDB", group = "Slizaa Graph Databases Commands - Lifecycle")
+ @ShellMethod(value = "Parse the definied content.", key = "parseDB")
public String parseDB(@ShellOption({"-d", "--databaseId"}) String databaseIdentifier) {
// check the backend configuration
@@ -118,13 +101,13 @@ public String parseDB(@ShellOption({"-d", "--databaseId"}) String databaseIdenti
}
// check that the requested database exists
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(databaseIdentifier);
+ IGraphDatabase graphDatabase = slizaaService().getGraphDatabase(databaseIdentifier);
if (graphDatabase == null) {
return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", databaseIdentifier));
}
// TODO:
- // _slizaaService.getContentDefinitionProviderFactories();
+ // slizaaService().getContentDefinitionProviderFactories();
//
try {
@@ -138,7 +121,7 @@ public String parseDB(@ShellOption({"-d", "--databaseId"}) String databaseIdenti
return dumpGraphDatabases();
}
- @ShellMethod(value = "Start the specified database.", key = "startDB", group = "Slizaa Graph Databases Commands - Lifecycle")
+ @ShellMethod(value = "Start the specified database.", key = "startDB")
public String startDB(@ShellOption({"-d", "--databaseId"}) String databaseIdentifier) {
// check the backend configuration
@@ -148,13 +131,13 @@ public String startDB(@ShellOption({"-d", "--databaseId"}) String databaseIdenti
}
// check that the requested database exists
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(databaseIdentifier);
+ IGraphDatabase graphDatabase = slizaaService().getGraphDatabase(databaseIdentifier);
if (graphDatabase == null) {
return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", databaseIdentifier));
}
// TODO:
- // _slizaaService.getContentDefinitionProviderFactories();
+ // slizaaService().getContentDefinitionProviderFactories();
//
graphDatabase.start();
@@ -163,7 +146,7 @@ public String startDB(@ShellOption({"-d", "--databaseId"}) String databaseIdenti
return dumpGraphDatabases();
}
- @ShellMethod(value = "Stop the specified database.", key = "stopDB", group = "Slizaa Graph Databases Commands - Lifecycle")
+ @ShellMethod(value = "Stop the specified database.", key = "stopDB")
public String stopDB(@ShellOption({"-d", "--databaseId"}) String databaseIdentifier) {
// check the backend configuration
@@ -173,13 +156,13 @@ public String stopDB(@ShellOption({"-d", "--databaseId"}) String databaseIdentif
}
// check that the requested database exists
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(databaseIdentifier);
+ IGraphDatabase graphDatabase = slizaaService().getGraphDatabase(databaseIdentifier);
if (graphDatabase == null) {
return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", databaseIdentifier));
}
// TODO:
- // _slizaaService.getContentDefinitionProviderFactories();
+ // slizaaService().getContentDefinitionProviderFactories();
//
graphDatabase.stop();
@@ -187,144 +170,4 @@ public String stopDB(@ShellOption({"-d", "--databaseId"}) String databaseIdentif
// return the result
return dumpGraphDatabases();
}
-
-
- @ShellMethod(value = "Create a new hierarchical graph.", key = "createHierarchicalGraph", group = "Slizaa Graph Databases Commands - Hierarchical Graphs")
- public String createHierarchicalGraph(@ShellOption({"-d", "--databaseId"}) String databaseIdentifier, @ShellOption({"-h", "--hierarchicalGraphId"}) String hierarchicalGraphIdentifier) {
-
- // check the backend configuration
- String checkBackendConfigured = checkBackendConfigured();
- if (checkBackendConfigured != null) {
- return checkBackendConfigured;
- }
-
- // check that the requested database exists
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(databaseIdentifier);
- if (graphDatabase == null) {
- return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", databaseIdentifier));
- }
-
- // check that the hierarchical graph does not exist
- IHierarchicalGraph hierarchicalGraph = graphDatabase.getHierarchicalGraph("hierarchicalGraphIdentifier");
- if (hierarchicalGraph != null) {
- return cannotExecuteCommand(String.format("The specified hierarchical graph '%s' already exists.\n", hierarchicalGraphIdentifier));
- }
-
- //
- graphDatabase.newHierarchicalGraph(hierarchicalGraphIdentifier);
-
- // return the result
- return dumpGraphDatabases();
- }
-
- @ShellMethod(value = "Delete an existing graph database.", key = "deleteDB")
- public String deleteDB(String identifier) {
-
- // check the backend configuration
- String checkBackendConfigured = checkBackendConfigured();
- if (checkBackendConfigured != null) {
- return checkBackendConfigured;
- }
-
- // check that the requested database exists
- String checkDatabaseExists = checkDatabaseExists(identifier);
- if (checkDatabaseExists != null) {
- return checkDatabaseExists;
- }
-
- //
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(identifier);
- graphDatabase.terminate();
-
- // return the result
- StringBuffer result = new StringBuffer();
- result.append(String.format("Successfully deleted graph database '%s'.\n", identifier));
- result.append(dumpGraphDatabases());
- return result.toString();
-
- }
-
- @NotNull
- private String dumpGraphDatabases() {
-
- StringBuffer stringBuffer = new StringBuffer("Graph Databases:\n");
-
- if (_slizaaService.hasGraphDatabases()) {
-
- _slizaaService.getGraphDatabases().forEach(db -> {
-
- ContentDefinition contentDefinition =
- db.getContentDefinition() != null ?
- new ContentDefinition(
- db.getContentDefinition().getContentDefinitionProviderFactory().getFactoryId(),
- db.getContentDefinition().toExternalRepresentation()) :
- null;
-
- GraphDatabase graphDatabase = new GraphDatabase(
- db.getIdentifier(),
- contentDefinition,
- Collections.emptyList(),
- db.getState().name(),
- db.getPort(),
- Collections.emptyList());
-
- stringBuffer.append(" - " + graphDatabase.toString() + "\n");
- });
- } else {
- stringBuffer.append("No database configured.\n");
- }
-
- return stringBuffer.toString();
- }
-
- @NotNull
- private String dumpContentDefinitionProviderFactories() {
-
- StringBuffer stringBuffer = new StringBuffer("Content Definition Provider Factories:\n");
-
- if (!_slizaaService.getContentDefinitionProviderFactories().isEmpty()) {
- _slizaaService.getContentDefinitionProviderFactories().forEach(factory -> {
- stringBuffer.append(" - " + factory.getFactoryId() + "\n");
- });
- } else {
- stringBuffer.append("No Content Definition Provider Factories available.\n");
- }
-
- return stringBuffer.toString();
- }
-
- /**
- * Checks if the backend is configured properly.
- *
- * @return true
if the backend is configured properly.
- */
- private String checkBackendConfigured() {
- if (!_slizaaService.getBackendService().hasInstalledExtensions()) {
- return cannotExecuteCommand("The Slizaa Server has not been configured properly: There are not installed backend extensions.\n");
- }
- return null;
- }
-
- private String checkDatabaseExists(String identifier) {
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(identifier);
- if (graphDatabase == null) {
- return cannotExecuteCommand(String.format("The specified database '%s' does not exist.\n", identifier));
- }
- return null;
- }
-
- private String checkDatabaseDoesNotExist(String identifier) {
- IGraphDatabase graphDatabase = _slizaaService.getGraphDatabase(identifier);
- if (graphDatabase != null) {
- return cannotExecuteCommand(String.format("The specified database '%s' already exists.\n", identifier));
- }
- return null;
- }
-
- private String cannotExecuteCommand(String msg) {
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append("Can not execute command.\n");
- stringBuffer.append(msg + "\n");
- return stringBuffer.toString();
- }
}
\ No newline at end of file
diff --git a/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseContentDefinitionCommands.java b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseContentDefinitionCommands.java
new file mode 100644
index 0000000..b9666c1
--- /dev/null
+++ b/slizaa-server/slizaa-server-main/src/main/java/io/codekontor/slizaa/server/SlizaaGraphDatabaseContentDefinitionCommands.java
@@ -0,0 +1,60 @@
+/**
+ * slizaa-server-main - Slizaa Static Software Analysis Tools
+ * Copyright © 2019 Code-Kontor GmbH and others (slizaa@codekontor.io)
+ *