Files
geutebruck/geutebruck_app/lib/data/models/action_mapping_hive_model.dart
Administrator 14893e62a5 feat: Geutebruck GeViScope/GeViSoft Action Mapping System - MVP
This MVP release provides a complete full-stack solution for managing action mappings
in Geutebruck's GeViScope and GeViSoft video surveillance systems.

## Features

### Flutter Web Application (Port 8081)
- Modern, responsive UI for managing action mappings
- Action picker dialog with full parameter configuration
- Support for both GSC (GeViScope) and G-Core server actions
- Consistent UI for input and output actions with edit/delete capabilities
- Real-time action mapping creation, editing, and deletion
- Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers)

### FastAPI REST Backend (Port 8000)
- RESTful API for action mapping CRUD operations
- Action template service with comprehensive action catalog (247 actions)
- Server management (G-Core and GeViScope servers)
- Configuration tree reading and writing
- JWT authentication with role-based access control
- PostgreSQL database integration

### C# SDK Bridge (gRPC, Port 50051)
- Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll)
- Action mapping creation with correct binary format
- Support for GSC and G-Core action types
- Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug)
- Action ID lookup table with server-specific action IDs
- Configuration reading/writing via SetupClient

## Bug Fixes
- **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet
- Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)`
- Proper filter flags and VideoInput=0 for action mappings
- Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft)

## Technical Stack
- **Frontend**: Flutter Web, Dart, Dio HTTP client
- **Backend**: Python FastAPI, PostgreSQL, Redis
- **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK
- **Authentication**: JWT tokens
- **Configuration**: GeViSoft .set files (binary format)

## Credentials
- GeViSoft/GeViScope: username=sysadmin, password=masterkey
- Default admin: username=admin, password=admin123

## Deployment
All services run on localhost:
- Flutter Web: http://localhost:8081
- FastAPI: http://localhost:8000
- SDK Bridge gRPC: localhost:50051
- GeViServer: localhost (default port)

Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 18:10:54 +01:00

230 lines
6.8 KiB
Dart

import 'dart:convert';
import 'package:hive/hive.dart';
import '../../domain/entities/action_mapping.dart';
import 'action_mapping_model.dart';
import 'action_output.dart';
part 'action_mapping_hive_model.g.dart';
/// Hive model for local storage of action mappings with sync tracking
@HiveType(typeId: 1)
class ActionMappingHiveModel extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
final String name;
@HiveField(2)
final String? description;
@HiveField(3)
final String inputAction;
@HiveField(4)
final List<String> outputActions; // Deprecated - kept for compatibility
@HiveField(5)
final String? geviscopeInstanceScope;
@HiveField(6)
final bool enabled;
@HiveField(7)
final int executionCount;
@HiveField(8)
final DateTime? lastExecuted;
@HiveField(9)
final DateTime createdAt;
@HiveField(10)
final DateTime updatedAt;
@HiveField(11)
final String createdBy;
// Sync tracking fields
@HiveField(12)
final bool isDirty;
@HiveField(13)
final DateTime lastModified;
@HiveField(14)
final String? syncOperation; // 'create', 'update', 'delete'
// New fields for parameters (stored as JSON strings)
@HiveField(15)
final String? inputParametersJson; // JSON-encoded Map<String, dynamic>
@HiveField(16)
final String? outputActionsJson; // JSON-encoded List<ActionOutput>
ActionMappingHiveModel({
required this.id,
required this.name,
this.description,
required this.inputAction,
required this.outputActions,
this.geviscopeInstanceScope,
this.enabled = true,
this.executionCount = 0,
this.lastExecuted,
required this.createdAt,
required this.updatedAt,
required this.createdBy,
this.isDirty = false,
required this.lastModified,
this.syncOperation,
this.inputParametersJson,
this.outputActionsJson,
});
/// Create Hive model from domain entity
factory ActionMappingHiveModel.fromEntity(
ActionMapping mapping, {
bool isDirty = false,
String? syncOperation,
}) {
return ActionMappingHiveModel(
id: mapping.id,
name: mapping.name,
description: mapping.description,
inputAction: mapping.inputAction,
outputActions: mapping.outputActions.map((o) => o.action).toList(), // For compatibility
geviscopeInstanceScope: mapping.geviscopeInstanceScope,
enabled: mapping.enabled,
executionCount: mapping.executionCount,
lastExecuted: mapping.lastExecuted,
createdAt: mapping.createdAt,
updatedAt: mapping.updatedAt,
createdBy: mapping.createdBy,
isDirty: isDirty,
lastModified: DateTime.now(),
syncOperation: syncOperation,
inputParametersJson: jsonEncode(mapping.inputParameters),
outputActionsJson: jsonEncode(mapping.outputActions.map((o) => o.toJson()).toList()),
);
}
/// Create Hive model from API model
factory ActionMappingHiveModel.fromActionMappingModel(
ActionMappingModel model, {
bool isDirty = false,
String? syncOperation,
}) {
return ActionMappingHiveModel(
id: model.id,
name: model.name,
description: model.description,
inputAction: model.inputAction,
outputActions: model.outputActions.map((o) => o.action).toList(), // For compatibility
geviscopeInstanceScope: model.geviscopeInstanceScope,
enabled: model.enabled,
executionCount: model.executionCount,
lastExecuted: model.lastExecuted,
createdAt: model.createdAt,
updatedAt: model.updatedAt,
createdBy: model.createdBy,
isDirty: isDirty,
lastModified: DateTime.now(),
syncOperation: syncOperation,
inputParametersJson: jsonEncode(model.inputParameters),
outputActionsJson: jsonEncode(model.outputActions.map((o) => o.toJson()).toList()),
);
}
/// Convert to API model
ActionMappingModel toActionMappingModel() {
// Decode parameters from JSON
Map<String, dynamic> inputParams = {};
List<ActionOutput> outputs = [];
if (inputParametersJson != null && inputParametersJson!.isNotEmpty) {
try {
inputParams = Map<String, dynamic>.from(jsonDecode(inputParametersJson!));
} catch (e) {
print('Error decoding inputParametersJson: $e');
}
}
if (outputActionsJson != null && outputActionsJson!.isNotEmpty) {
try {
final decoded = jsonDecode(outputActionsJson!) as List<dynamic>;
outputs = decoded.map((e) => ActionOutput.fromJson(e as Map<String, dynamic>)).toList();
} catch (e) {
print('Error decoding outputActionsJson: $e');
// Fallback to legacy outputActions
outputs = outputActions.map((action) => ActionOutput(action: action, parameters: {})).toList();
}
} else {
// Fallback to legacy outputActions
outputs = outputActions.map((action) => ActionOutput(action: action, parameters: {})).toList();
}
return ActionMappingModel(
id: id,
name: name,
description: description,
inputAction: inputAction,
inputParameters: inputParams,
outputActions: outputs,
geviscopeInstanceScope: geviscopeInstanceScope,
enabled: enabled,
executionCount: executionCount,
lastExecuted: lastExecuted,
createdAt: createdAt,
updatedAt: updatedAt,
createdBy: createdBy,
);
}
/// Convert to domain entity
ActionMapping toEntity() {
return toActionMappingModel().toEntity();
}
/// Create a copy with modified fields
ActionMappingHiveModel copyWith({
String? id,
String? name,
String? description,
String? inputAction,
List<String>? outputActions,
String? geviscopeInstanceScope,
bool? enabled,
int? executionCount,
DateTime? lastExecuted,
DateTime? createdAt,
DateTime? updatedAt,
String? createdBy,
bool? isDirty,
DateTime? lastModified,
String? syncOperation,
String? inputParametersJson,
String? outputActionsJson,
}) {
return ActionMappingHiveModel(
id: id ?? this.id,
name: name ?? this.name,
description: description ?? this.description,
inputAction: inputAction ?? this.inputAction,
outputActions: outputActions ?? this.outputActions,
geviscopeInstanceScope: geviscopeInstanceScope ?? this.geviscopeInstanceScope,
enabled: enabled ?? this.enabled,
executionCount: executionCount ?? this.executionCount,
lastExecuted: lastExecuted ?? this.lastExecuted,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
createdBy: createdBy ?? this.createdBy,
isDirty: isDirty ?? this.isDirty,
lastModified: lastModified ?? this.lastModified,
syncOperation: syncOperation ?? this.syncOperation,
inputParametersJson: inputParametersJson ?? this.inputParametersJson,
outputActionsJson: outputActionsJson ?? this.outputActionsJson,
);
}
}