Skip to content

Commit

Permalink
feat(connection-service): Create ConnectionService to manage shared c…
Browse files Browse the repository at this point in the history
…onnections and implement it for OPCUA
  • Loading branch information
nagyszabi authored and burgerni10 committed Jan 6, 2025
1 parent 8176ec8 commit 5bc61d7
Show file tree
Hide file tree
Showing 14 changed files with 899 additions and 65 deletions.
4 changes: 3 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import HomeMetricsService from './service/home-metrics.service';
import CommandService from './service/oia/command.service';
import RegistrationService from './service/oia/registration.service';
import ProxyServer from './web-server/proxy-server';
import ConnectionService from './service/connection.service';
import OIAnalyticsMessageService from './service/oia/message.service';

const CONFIG_DATABASE = 'oibus.db';
Expand Down Expand Up @@ -88,8 +89,9 @@ const LOG_DB_NAME = 'logs.db';
repositoryService.registrationRepository.getRegistrationSettings()
);

const connectionService = new ConnectionService(loggerService.logger!);
const northService = new NorthService(encryptionService, repositoryService);
const southService = new SouthService(encryptionService, repositoryService);
const southService = new SouthService(encryptionService, repositoryService, connectionService);
const historyQueryService = new HistoryQueryService(repositoryService);

const engineMetricsService = new EngineMetricsService(loggerService.logger!, oibusSettings.id, repositoryService.engineMetricsRepository);
Expand Down
6 changes: 3 additions & 3 deletions backend/src/repository/south-connector.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('South connector repository', () => {
]);
const southConnectors = repository.getSouthConnectors();
expect(database.prepare).toHaveBeenCalledWith(
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, ' +
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, shared_connection as sharedConnection, ' +
'history_max_read_interval AS maxReadInterval, history_read_delay AS readDelay, history_read_overlap AS overlap, settings FROM south_connectors;'
);
expect(southConnectors).toEqual(expectedValue);
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('South connector repository', () => {
});
const southConnector = repository.getSouthConnector('id1');
expect(database.prepare).toHaveBeenCalledWith(
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, ' +
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, shared_connection as sharedConnection, ' +
'history_max_read_interval AS maxReadInterval, history_read_delay AS readDelay, history_read_overlap AS overlap, settings FROM south_connectors WHERE id = ?;'
);
expect(get).toHaveBeenCalledWith('id1');
Expand All @@ -128,7 +128,7 @@ describe('South connector repository', () => {
get.mockReturnValueOnce(null);
const southConnector = repository.getSouthConnector('id1');
expect(database.prepare).toHaveBeenCalledWith(
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, ' +
'SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, shared_connection as sharedConnection, ' +
'history_max_read_interval AS maxReadInterval, history_read_delay AS readDelay, history_read_overlap AS overlap, settings FROM south_connectors WHERE id = ?;'
);
expect(get).toHaveBeenCalledWith('id1');
Expand Down
6 changes: 4 additions & 2 deletions backend/src/repository/south-connector.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class SouthConnectorRepository {
*/
getSouthConnectors(): Array<SouthConnectorDTO> {
const query =
`SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, ` +
`SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, shared_connection as sharedConnection, ` +
`history_max_read_interval AS maxReadInterval, history_read_delay AS readDelay, history_read_overlap AS overlap, ` +
`settings FROM ${SOUTH_CONNECTORS_TABLE};`;
return this.database
Expand All @@ -27,6 +27,7 @@ export default class SouthConnectorRepository {
type: result.type,
description: result.description,
enabled: Boolean(result.enabled),
sharedConnection: result.sharedConnection,
history: {
maxInstantPerItem: Boolean(result.maxInstantPerItem),
maxReadInterval: result.maxReadInterval,
Expand All @@ -42,7 +43,7 @@ export default class SouthConnectorRepository {
*/
getSouthConnector(id: string): SouthConnectorDTO | null {
const query =
`SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, ` +
`SELECT id, name, type, description, enabled, history_max_instant_per_item AS maxInstantPerItem, shared_connection as sharedConnection, ` +
`history_max_read_interval AS maxReadInterval, history_read_delay AS readDelay, history_read_overlap AS overlap, ` +
`settings FROM ${SOUTH_CONNECTORS_TABLE} WHERE id = ?;`;
const result: any = this.database.prepare(query).get(id);
Expand All @@ -57,6 +58,7 @@ export default class SouthConnectorRepository {
type: result.type,
description: result.description,
enabled: Boolean(result.enabled),
sharedConnection: result.sharedConnection,
history: {
maxInstantPerItem: Boolean(result.maxInstantPerItem),
maxReadInterval: result.maxReadInterval,
Expand Down
Loading

0 comments on commit 5bc61d7

Please sign in to comment.