Skip to content

Commit

Permalink
Set spring configs into app data.
Browse files Browse the repository at this point in the history
Signed-off-by: yichen88 <[email protected]>
  • Loading branch information
yichen88 committed Jan 25, 2021
1 parent fff77d8 commit c020b0d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,41 @@
import com.powsybl.afs.AppFileSystem;
import com.powsybl.afs.AppFileSystemProvider;
import com.powsybl.afs.AppFileSystemProviderContext;
import com.powsybl.afs.storage.EventsBus;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
@AutoService(AppFileSystemProvider.class)
public class PostgresAppFileSystemAppProvider implements AppFileSystemProvider {

private final List<PostgresAppFileSystemConfig> configs;

public PostgresAppFileSystemAppProvider() {
this(PostgresAppFileSystemConfig.load());
}

public PostgresAppFileSystemAppProvider(List<PostgresAppFileSystemConfig> configs) {
this.configs = Objects.requireNonNull(configs);
}

@Override
public List<AppFileSystem> getFileSystems(AppFileSystemProviderContext context) {
return Collections.emptyList();
// return Collections.singletonList(new PostgresAppFileSystem("test", true, new PostgresAppStorage()));
final PostgresAppFileSystemConfig postgresAppFileSystemConfig = configs.get(0);
AnnotationConfigApplicationContext springContext
= new AnnotationConfigApplicationContext();
springContext.getEnvironment().setActiveProfiles("production");
springContext.scan("com.powsybl.afs.postgres");
springContext.register(PostgresAppStorage.class);
springContext.getBeanFactory().registerSingleton(EventsBus.class.toString(), context.getEventsBus());
springContext.getBeanFactory().registerSingleton(String.class.toString(), postgresAppFileSystemConfig.getDriveName());
springContext.refresh();
final PostgresAppStorage bean = springContext.getBean(PostgresAppStorage.class);
return Collections.singletonList(new PostgresAppFileSystem(postgresAppFileSystemConfig.getDriveName(), true, bean));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ public class PostgresAppStorage extends AbstractAppStorage {
private final NodeDataRepository nodeDataRepository;
private final TimeSeriesService tsService;

private final String fileSystemName;

private static final int ROOT_NODE_VERSION = 0;

@Autowired
public PostgresAppStorage(NodeService nodeService,
public PostgresAppStorage(String fileSystemName,
NodeService nodeService,
NodeDataRepository nodeDataRepository,
TimeSeriesService tsService) {
// TODO here
this.eventsBus = new InMemoryEventsBus();
TimeSeriesService tsService,
EventsBus eventsBus) {
this.fileSystemName = Objects.requireNonNull(fileSystemName);
this.nodeService = Objects.requireNonNull(nodeService);
this.nodeDataRepository = Objects.requireNonNull(nodeDataRepository);
this.tsService = Objects.requireNonNull(tsService);
this.eventsBus = Objects.requireNonNull(eventsBus);
bindListener();
}

Expand All @@ -63,8 +67,7 @@ private void bindListener() {

@Override
public String getFileSystemName() {
// TODO here
return "postgres-test";
return fileSystemName;
}

@Override
Expand Down Expand Up @@ -100,7 +103,6 @@ public boolean isRemote() {
@Override
public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) {
final NodeInfo info = nodeService.createRootNodeIfNotExists(name, nodePseudoClass);
// pushEvent(new NodeCreated("test", null), "APPSTORAGE_NODE_TOPIC");
return info;
}

Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion afs-postgres/src/main/resources/persistence.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=update
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

import com.google.common.collect.Sets;
import com.powsybl.afs.postgres.jpa.NodeDataRepository;
import com.powsybl.afs.storage.AbstractAppStorageTest;
import com.powsybl.afs.storage.AppStorage;
import com.powsybl.afs.storage.NodeGenericMetadata;
import com.powsybl.afs.storage.NodeInfo;
import com.powsybl.afs.storage.*;
import com.powsybl.afs.storage.events.TimeSeriesCreated;
import com.powsybl.afs.storage.events.TimeSeriesDataUpdated;
import com.powsybl.timeseries.*;
Expand Down Expand Up @@ -44,10 +41,14 @@ public class PostgresAppStorageTest extends AbstractAppStorageTest {
private TimeSeriesService tsService;
@Autowired
private NodeDataRepository nodeDataRepository;
@Autowired
private EventsBus eventsBus;
@Autowired
private String fileSystemName;

@Override
protected AppStorage createStorage() {
return new PostgresAppStorage(nodeService, nodeDataRepository, tsService);
return new PostgresAppStorage(fileSystemName, nodeService, nodeDataRepository, tsService, eventsBus);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
package com.powsybl.afs.postgres;

import com.powsybl.afs.storage.EventsBus;
import com.powsybl.afs.storage.InMemoryEventsBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
Expand All @@ -15,6 +18,16 @@
*/
@Configuration
@PropertySource("classpath:application.properties")
@Profile({ "test" })
@Profile({"test"})
public class TestConfig {

@Bean
public EventsBus imMemory() {
return new InMemoryEventsBus();
}

@Bean(name = "fileSystemName")
public String getFileSystemName() {
return "postgres-afs";
}
}

0 comments on commit c020b0d

Please sign in to comment.