Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerd Wuetherich committed Jun 7, 2019
1 parent e5834f0 commit c3fc39d
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public IContentDefinitionProviderFactory<DirectoryBasedContentDefinitionProvider

@Override
public String toExternalRepresentation() {
return null;
return this._contentDefinitionProviderFactory.toExternalRepresentation(this);
}

/**
Expand Down Expand Up @@ -92,6 +92,14 @@ protected void onDisposeProjectContent() {
//
}

/**
*
* @return
*/
List<File> getDirectoriesWithBinaryArtifacts() {
return _directoriesWithBinaryArtifacts;
}

/**
* <p>
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
*/
package io.codekontor.slizaa.scanner.contentdefinition;

import java.io.File;
import java.util.stream.Collectors;

import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProviderFactory;
import io.codekontor.slizaa.scanner.spi.contentdefinition.InvalidContentDefinitionException;

public class DirectoryBasedContentDefinitionProviderFactory implements IContentDefinitionProviderFactory<DirectoryBasedContentDefinitionProvider> {

private final static String PATH_SEPARATOR = File.pathSeparator;

@Override
public String getFactoryId() {
return DirectoryBasedContentDefinitionProviderFactory.class.getName();
Expand All @@ -43,14 +49,29 @@ public DirectoryBasedContentDefinitionProvider emptyContentDefinitionProvider()

@Override
public String toExternalRepresentation(DirectoryBasedContentDefinitionProvider contentDefinitionProvider) {
// TODO Auto-generated method stub
return null;
return contentDefinitionProvider.getDirectoriesWithBinaryArtifacts().stream().map(file -> file.getAbsolutePath()).collect(Collectors.joining(PATH_SEPARATOR));
}

@Override
public DirectoryBasedContentDefinitionProvider fromExternalRepresentation(String externalRepresentation) {
// TODO Auto-generated method stub
return null;

//
if (externalRepresentation == null) {
throw new InvalidContentDefinitionException("Invalid content definition 'null'.");
}

//
String[] filePaths = externalRepresentation.split(PATH_SEPARATOR);

//
DirectoryBasedContentDefinitionProvider contentDefinitionProvider = new DirectoryBasedContentDefinitionProvider(this);
for (String filePath : filePaths) {
File file = new File(filePath);
contentDefinitionProvider.add(file);
}

//
return contentDefinitionProvider;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public interface IContentDefinitionProviderFactory<T extends IContentDefinitionP

String toExternalRepresentation(T contentDefinitionProvider);

T fromExternalRepresentation(String externalRepresentation);
T fromExternalRepresentation(String externalRepresentation) throws InvalidContentDefinitionException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* slizaa-scanner-spi-api - Slizaa Static Software Analysis Tools
* Copyright © 2019 Code-Kontor GmbH and others ([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/
package io.codekontor.slizaa.scanner.spi.contentdefinition;

public class InvalidContentDefinitionException extends RuntimeException {

private static final long serialVersionUID = 1L;

public InvalidContentDefinitionException() {
super();
}

public InvalidContentDefinitionException(String message, Throwable cause) {
super(message, cause);
}

public InvalidContentDefinitionException(String message) {
super(message);
}

public InvalidContentDefinitionException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.codekontor.slizaa.server.graphql;

public class ErrorMessages {

public static final String ERR_NON_EXISTING_DATABASE = "The specified database (id '%s') does not exist.";

public final static RuntimeException newException(String msg, Object... args) {
String message = args.length > 0 ? String.format(msg, args) : msg;
return new RuntimeException(message);
}

public final static RuntimeException newException(Exception cause, String msg, Object... args) {
String message = args.length > 0 ? String.format(msg, args) : msg;
return new RuntimeException(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package io.codekontor.slizaa.server.graphql.graphdatabase;

import io.codekontor.slizaa.server.graphql.ErrorMessages;
import io.codekontor.slizaa.server.graphql.SlizaaGraphQLError;
import io.codekontor.slizaa.server.service.slizaa.IGraphDatabase;
import io.codekontor.slizaa.server.service.slizaa.ISlizaaService;
Expand Down Expand Up @@ -51,16 +52,14 @@ protected GraphDatabase executeOnDatabase(DataFetchingEnvironment environment, S

// check exists
if (database == null) {
// TODO:
throw ErrorMessages.newException(ErrorMessages.ERR_NON_EXISTING_DATABASE, databaseId);
}

//
try {
consumer.accept(database);
} catch (Exception e) {
e.printStackTrace();
// TODO: ERROR HANDLING
// environment.addError(new SlizaaGraphQLError(e.getMessage(), null, null));
throw ErrorMessages.newException(e.getMessage());
}

// return the result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.slf4j.LoggerFactory;
import io.codekontor.slizaa.core.boltclient.IBoltClientFactory;
import io.codekontor.slizaa.hierarchicalgraph.graphdb.mapping.service.IMappingService;
import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProvider;
import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProviderFactory;
import io.codekontor.slizaa.server.service.backend.IBackendService;
import io.codekontor.slizaa.server.service.backend.IBackendServiceCallback;
Expand Down Expand Up @@ -136,9 +137,11 @@ public void initialize() throws Exception {
if (dbConfig.getContentDefinition() != null) {

// set the content definition...
graphDatabase.stateMachineContext().setContentDefinition(dbConfig.getContentDefinition().getFactoryId(),
IContentDefinitionProvider<?> contentDefinitionProvider = graphDatabase.stateMachineContext().createContentDefinitionProvider(dbConfig.getContentDefinition().getFactoryId(),
dbConfig.getContentDefinition().getContentDefinition());

graphDatabase.stateMachineContext().setContentDefinition(contentDefinitionProvider);

// ...and start the database
if (dbConfig.isRunning()) {
graphDatabase.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.statemachine.StateMachine;

import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProvider;
import io.codekontor.slizaa.scanner.spi.contentdefinition.InvalidContentDefinitionException;
import io.codekontor.slizaa.server.service.slizaa.GraphDatabaseState;
import io.codekontor.slizaa.server.service.slizaa.IGraphDatabase;
import io.codekontor.slizaa.server.service.slizaa.IHierarchicalGraph;
Expand All @@ -39,11 +40,9 @@
*/
public class GraphDatabaseImpl implements IGraphDatabase {

public static final String START_DATABASE_AFTER_PARSING = "START_DATABASE_AFTER_PARSING";
public static final String START_DATABASE_AFTER_PARSING = "START_DATABASE_AFTER_PARSING";

public static final String CONTENT_DEFINITION_FACTORY_ID = "CONTENT_DEFINITION_FACTORY_ID";

public static final String CONTENT_DEFINITION = "CONTENT_DEFINITION";
public static final String CONTENT_DEFINITION_PROVIDER = "CONTENT_DEFINITION_PROVIDER";

/** the state machine **/
private StateMachine<GraphDatabaseState, GraphDatabaseTrigger> _stateMachine;
Expand Down Expand Up @@ -78,11 +77,19 @@ public int getPort() {
@Override
public void setContentDefinition(String contentDefinitionFactoryId, String contentDefinition) {

//
IContentDefinitionProvider<?> contentDefinitionProvider = _stateMachineContext.createContentDefinitionProvider(contentDefinitionFactoryId, contentDefinition);

//
if (contentDefinitionProvider == null) {
throw new InvalidContentDefinitionException(String.format("Invalid content definition ('%s', '%s').", contentDefinitionFactoryId, contentDefinition));
}

//
Message<GraphDatabaseTrigger> triggerMessage = MessageBuilder
.withPayload(GraphDatabaseTrigger.SET_CONTENT_DEFINITION)
.setHeader(CONTENT_DEFINITION_FACTORY_ID, checkNotNull(contentDefinitionFactoryId))
.setHeader(CONTENT_DEFINITION, checkNotNull(contentDefinition)).build();
.setHeader(CONTENT_DEFINITION_PROVIDER, contentDefinitionProvider)
.build();

trigger(triggerMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.guard.Guard;

import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProvider;
import io.codekontor.slizaa.server.service.slizaa.GraphDatabaseState;

@EnableStateMachineFactory
Expand Down Expand Up @@ -158,10 +159,9 @@ public void configure(StateMachineTransitionConfigurer<GraphDatabaseState, Graph

private void setContentDefinition(StateContext<GraphDatabaseState, GraphDatabaseTrigger> stateCtx,
IGraphDatabaseStateMachineContext ctx) {
String contentDefinitionFactoryId = stateCtx.getMessageHeaders()
.get(GraphDatabaseImpl.CONTENT_DEFINITION_FACTORY_ID, String.class);
String contentDefinition = stateCtx.getMessageHeaders().get(GraphDatabaseImpl.CONTENT_DEFINITION, String.class);
ctx.setContentDefinition(contentDefinitionFactoryId, contentDefinition);

IContentDefinitionProvider<?> contentDefinitionProvider = stateCtx.getMessageHeaders().get(GraphDatabaseImpl.CONTENT_DEFINITION_PROVIDER, IContentDefinitionProvider.class);
ctx.setContentDefinition(contentDefinitionProvider);
}

private Action<GraphDatabaseState, GraphDatabaseTrigger> actionWithCtx(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
/**
* slizaa-server-service-slizaa - Slizaa Static Software Analysis Tools
* Copyright © 2019 Code-Kontor GmbH and others ([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/
package io.codekontor.slizaa.server.service.slizaa.internal.graphdatabase;

import java.util.List;

import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProvider;
import io.codekontor.slizaa.server.service.slizaa.IGraphDatabase;
import io.codekontor.slizaa.server.service.slizaa.IHierarchicalGraph;

/**
*
* @author Gerd W&uuml;therich ([email protected])
*/
public interface IGraphDatabaseStateMachineContext {

void setGraphDatabase(IGraphDatabase graphDatabase);

String getIdentifier();

int getPort();

boolean hasPopulatedDatabaseDirectory();

boolean hasContentDefinitionProvider();

void setContentDefinition(String factoryId, String contentDefinition);

IContentDefinitionProvider<?> getContentDefinitionProvider();

boolean isRunning();

boolean parse(boolean startDatabase);

void start();

void stop();

void terminate();

IHierarchicalGraph createHierarchicalGraph(String identifier);

IHierarchicalGraph getHierarchicalGraph(String identifier);

List<IHierarchicalGraph> getHierarchicalGraphs();

void disposeHierarchicalGraph(String identifier);

void storeConfiguration();
}
/**
* slizaa-server-service-slizaa - Slizaa Static Software Analysis Tools
* Copyright © 2019 Code-Kontor GmbH and others ([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/
package io.codekontor.slizaa.server.service.slizaa.internal.graphdatabase;

import java.util.List;

import io.codekontor.slizaa.scanner.spi.contentdefinition.IContentDefinitionProvider;
import io.codekontor.slizaa.server.service.slizaa.IGraphDatabase;
import io.codekontor.slizaa.server.service.slizaa.IHierarchicalGraph;

/**
*
* @author Gerd W&uuml;therich ([email protected])
*/
public interface IGraphDatabaseStateMachineContext {

void setGraphDatabase(IGraphDatabase graphDatabase);

String getIdentifier();

int getPort();

boolean hasPopulatedDatabaseDirectory();

IContentDefinitionProvider<?> createContentDefinitionProvider(String contentDefinitionFactoryId,
String contentDefinition);

boolean hasContentDefinitionProvider();

void setContentDefinition(IContentDefinitionProvider<?> contentDefinitionProvider);

IContentDefinitionProvider<?> getContentDefinitionProvider();

boolean isRunning();

boolean parse(boolean startDatabase);

void start();

void stop();

void terminate();

IHierarchicalGraph createHierarchicalGraph(String identifier);

IHierarchicalGraph getHierarchicalGraph(String identifier);

List<IHierarchicalGraph> getHierarchicalGraphs();

void disposeHierarchicalGraph(String identifier);

void storeConfiguration();
}
Loading

0 comments on commit c3fc39d

Please sign in to comment.