Spaces:
Paused
Paused
File size: 15,925 Bytes
5a81b95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | # JPA Entity to Database View Mapping for Risk Rules Framework
## π Overview
This document maps JPA entity classes to their corresponding database views and the risk rules they support. This mapping is essential for the complete 45-rule intelligence framework defined in RISK_RULES_INTOP_OSINT.md.
**Status**: Partially Implemented
**Date**: 2025-11-17
**Related Issue**: #[Current Issue Number]
---
## π Implementation Status Summary
| Category | Total Views | Implemented | Pending | Coverage |
|----------|-------------|-------------|---------|----------|
| V1.30 OSINT Performance Tracking | 4 | 3 | 1 | 75% |
| V1.29 Intelligence Operations | 6 | 0 | 6 | 0% |
| **TOTAL NEW VIEWS** | **10** | **3** | **7** | **30%** |
---
## β
Implemented Entities (v1.30)
### 1. ViewPoliticianBehavioralTrends
- **Package**: `com.hack23.cia.model.internal.application.data.politician.impl`
- **Database View**: `view_politician_behavioral_trends`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (person_id + period_start)
- **Columns**: 26 fields
- **Risk Rules Supported**: P-01 through P-24 (All politician behavioral rules)
- **Intelligence Purpose**: Time-series analysis of individual politician behavioral metrics (absence, effectiveness, rebellion) with automated classification
- **Status**: β
COMPLETE
- **Key Metrics**:
- Behavioral metrics: absence_rate, win_rate, rebel_rate
- Trend indicators: absence_trend, win_rate_trend, rebel_rate_trend
- Moving averages: 3-month MA for smoothed trend analysis
- Classifications: attendance_status, effectiveness_status, discipline_status, behavioral_assessment
### 2. ViewPartyEffectivenessTrends
- **Package**: `com.hack23.cia.model.internal.application.data.party.impl`
- **Database View**: `view_party_effectiveness_trends`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (party + period_start)
- **Columns**: 30 fields
- **Risk Rules Supported**: Pa-01 through Pa-10 (All party-level rules)
- **Intelligence Purpose**: Monitor party-level performance metrics over time, track win rates, productivity, and collaboration patterns
- **Status**: β
COMPLETE
- **Key Metrics**:
- Performance: avg_win_rate, avg_absence_rate, avg_rebel_rate, avg_yes_rate
- Productivity: documents_produced, motions_count, active_document_authors, votes_per_member
- Trend indicators: win_rate_trend, absence_trend, member_change
- Moving averages: ma_4quarter_win_rate, ma_4quarter_absence
- Classifications: performance_level, productivity_level, effectiveness_assessment
### 3. ViewRiskScoreEvolution
- **Package**: `com.hack23.cia.model.internal.application.data.rules.impl`
- **Database View**: `view_risk_score_evolution`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (person_id + assessment_period)
- **Columns**: 21 fields
- **Risk Rules Supported**: All 45 rules (cross-cutting risk assessment)
- **Intelligence Purpose**: Track temporal evolution of risk scores with severity classification and trend analysis
- **Status**: β
COMPLETE
- **Key Metrics**:
- Risk metrics: risk_score, prev_risk_score, risk_score_change
- Contributing factors: absence_rate, win_rate, rebel_rate, violation_count, violation_categories
- Classifications: risk_severity, risk_trend, severity_transition
- Assessment: risk_assessment (CRITICAL, HIGH, MODERATE, LOW, MINIMAL)
---
## πΆ Pending Entity Implementations
### v1.30 OSINT Performance Tracking Views (3 remaining)
#### 2. ViewPartyEffectivenessTrends
- **Package**: `com.hack23.cia.model.internal.application.data.party.impl`
- **Database View**: `view_party_effectiveness_trends`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (party + period_start)
- **Estimated Columns**: 30+
- **Risk Rules Supported**: Pa-01 through Pa-10 (All party-level rules)
- **Intelligence Purpose**: Monitor party-level performance metrics over time, track win rates, productivity, and collaboration patterns
- **Key Metrics**:
- Performance: avg_win_rate, avg_absence_rate, avg_rebel_rate
- Productivity: documents_produced, motions_count, votes_per_member
- Trend indicators: win_rate_trend, absence_trend, member_change
- Classifications: performance_level, productivity_level
- **Status**: πΆ PENDING - Entity class needs to be created
#### 3. ViewRiskScoreEvolution
- **Package**: `com.hack23.cia.model.internal.application.data.rules.impl`
- **Database View**: `view_risk_score_evolution`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (person_id + assessment_period)
- **Estimated Columns**: 22
- **Risk Rules Supported**: All 45 rules (cross-cutting risk assessment)
- **Intelligence Purpose**: Track temporal evolution of risk scores with severity classification and trend analysis
- **Key Metrics**:
- Risk metrics: risk_score, prev_risk_score, risk_score_change
- Contributing factors: absence_rate, win_rate, rebel_rate, violation_count
- Classifications: risk_severity, risk_trend, severity_transition
- Assessment: risk_assessment (CRITICAL, HIGH, MODERATE, LOW, MINIMAL)
- **Status**: πΆ PENDING - Entity class needs to be created
#### 4. ViewCommitteeProductivityMatrix
- **Package**: `com.hack23.cia.model.internal.application.data.committee.impl`
- **Database View**: `view_committee_productivity_matrix`
- **Liquibase Version**: v1.30
- **Primary Key**: Composite (committee_code + period_start)
- **Estimated Columns**: 28
- **Risk Rules Supported**: C-01 through C-04 (Committee performance rules)
- **Intelligence Purpose**: Quarterly committee productivity metrics with comparative analysis and benchmarking
- **Key Metrics**:
- Productivity: total_documents, committee_reports, documents_per_member
- Trend indicators: document_change, document_change_pct, ma_4quarter_documents
- Benchmarking: vs_average, vs_average_pct, period_median_documents
- Classifications: productivity_level, productivity_trend, productivity_assessment
- **Status**: πΆ IN PROGRESS - Entity class being created
---
### v1.29 Intelligence Operations Enhancement Views (6 remaining)
#### 5. ViewRiksdagenPartyMomentumAnalysis
- **Package**: `com.hack23.cia.model.internal.application.data.party.impl`
- **Database View**: `view_riksdagen_party_momentum_analysis`
- **Liquibase Version**: v1.29
- **Primary Key**: Composite (party + year + quarter)
- **Estimated Columns**: 14
- **Risk Rules Supported**: Pa-01, Pa-02, Pa-07 (Party momentum and stability)
- **Intelligence Purpose**: Detect momentum shifts in party support with acceleration/deceleration patterns
- **Key Metrics**:
- Momentum: momentum, acceleration, prev_quarter_rate
- Smoothing: moving_avg_4q, volatility
- Classifications: trend_direction, stability_classification, intelligence_assessment
- **Status**: πΆ PENDING - Entity class needs to be created
#### 6. ViewRiksdagenCoalitionAlignmentMatrix
- **Package**: `com.hack23.cia.model.internal.application.data.party.impl`
- **Database View**: `view_riksdagen_coalition_alignment_matrix`
- **Liquibase Version**: v1.29
- **Primary Key**: Composite (party_1 + party_2)
- **Estimated Columns**: 12
- **Risk Rules Supported**: Pa-03, Pa-08 (Coalition formation and stability)
- **Intelligence Purpose**: Measure voting alignment between party pairs for coalition formation prediction
- **Key Metrics**:
- Alignment: shared_votes, aligned_votes, opposed_votes, alignment_rate
- Analysis: coalition_likelihood, bloc_relationship
- Intelligence: intelligence_comment, years_observed
- **Status**: πΆ PENDING - Entity class needs to be created
#### 7. ViewRiksdagenVotingAnomalyDetection
- **Package**: `com.hack23.cia.model.internal.application.data.politician.impl`
- **Database View**: `view_riksdagen_voting_anomaly_detection`
- **Liquibase Version**: v1.29
- **Primary Key**: Composite (person_id + party)
- **Estimated Columns**: 13
- **Risk Rules Supported**: P-03, P-05, P-13 (Rebellion and discipline)
- **Intelligence Purpose**: Detect voting anomalies and party discipline deviations
- **Key Metrics**:
- Voting patterns: total_votes, aligned_votes, opposed_votes
- Discipline: party_discipline_score, rebellion_rate, unanimous_deviations
- Classifications: discipline_classification, defection_risk_assessment
- **Status**: πΆ PENDING - Entity class needs to be created
#### 8. ViewRiksdagenPoliticianInfluenceMetrics
- **Package**: `com.hack23.cia.model.internal.application.data.politician.impl`
- **Database View**: `view_riksdagen_politician_influence_metrics`
- **Liquibase Version**: v1.29
- **Primary Key**: person_id
- **Estimated Columns**: 10
- **Risk Rules Supported**: P-20, P-21 (Network influence and broker roles)
- **Intelligence Purpose**: Basic network centrality and influence scoring
- **Key Metrics**:
- Network: network_connections, cross_party_bridges
- Centrality: normalized_centrality, connectivity_level
- Classification: broker_classification, influence_score, influence_assessment
- **Status**: πΆ PENDING - Entity class needs to be created
#### 9. ViewRiksdagenCrisisResilienceIndicators
- **Package**: `com.hack23.cia.model.internal.application.data.politician.impl`
- **Database View**: `view_riksdagen_crisis_resilience_indicators`
- **Liquibase Version**: v1.29
- **Primary Key**: person_id
- **Estimated Columns**: 13
- **Risk Rules Supported**: P-08, P-22 (Performance under pressure)
- **Intelligence Purpose**: Assess politician performance during crisis periods vs normal periods
- **Key Metrics**:
- Crisis performance: crisis_period_votes, crisis_absence_rate, crisis_party_discipline
- Normal baseline: normal_period_votes, normal_absence_rate
- Analysis: absence_rate_change, resilience_score
- Classification: resilience_classification, pressure_performance_assessment
- **Status**: πΆ PENDING - Entity class needs to be created
#### 10. ViewRiksdagenIntelligenceDashboard
- **Package**: `com.hack23.cia.model.internal.application.data.impl`
- **Database View**: `view_riksdagen_intelligence_dashboard`
- **Liquibase Version**: v1.29
- **Primary Key**: None (single-row summary view, timestamp-based)
- **Estimated Columns**: 3
- **Risk Rules Supported**: All rules (summary dashboard)
- **Intelligence Purpose**: Executive summary dashboard with overall stability and coalition assessments
- **Key Metrics**:
- stability_assessment: Overall political stability indicator
- coalition_assessment: Coalition formation likelihood and status
- intelligence_report_timestamp: Report generation time
- **Status**: πΆ PENDING - Entity class needs to be created
---
## π Implementation Guidelines
### Entity Class Template
All view entities should follow this pattern:
```java
package com.hack23.cia.model.internal.application.data.[package].impl;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* JPA entity for [view_name] database view.
*
* Intelligence Purpose: [purpose description]
* Created by: Liquibase [version]
* Risk Rules Supported: [rule numbers]
*/
@Entity(name = "[ClassName]")
@Table(name = "[view_name]")
public class [ClassName] implements Serializable {
private static final long serialVersionUID = 1L;
// ID fields marked with @Id
// Other fields with @Column
// Dates with @Temporal
// BigDecimal for numeric fields with precision
// Default constructor
// Getters and setters
// equals(), hashCode(), toString() using Commons Lang builders
}
```
### Key Annotations
- `@Entity(name = "ClassName")`: JPA entity marker
- `@Table(name = "view_name")`: Database view name (lowercase with underscores)
- `@Id`: Primary key fields (may be composite)
- `@Column(name = "column_name")`: Column mapping
- `@Temporal(TemporalType.DATE|TIMESTAMP)`: For Date fields
- For BigDecimal: `@Column(name = "col", precision = X, scale = Y)`
### Composite Keys
For views with composite keys (multiple @Id fields), the combination of all @Id fields forms the primary key. No separate @IdClass is needed if using simple types.
---
## π Integration with Risk Rules Framework
### Rule-to-View Mapping
| Rule Category | Primary Views | Secondary Views |
|---------------|---------------|-----------------|
| **Politician Rules (P-01 to P-24)** | ViewPoliticianBehavioralTrends, ViewRiksdagenVotingAnomalyDetection | ViewRiksdagenPoliticianInfluenceMetrics, ViewRiksdagenCrisisResilienceIndicators |
| **Party Rules (Pa-01 to Pa-10)** | ViewPartyEffectivenessTrends, ViewRiksdagenPartyMomentumAnalysis | ViewRiksdagenCoalitionAlignmentMatrix |
| **Committee Rules (C-01 to C-04)** | ViewCommitteeProductivityMatrix | - |
| **Ministry Rules (M-01 to M-04)** | (v1.31 - not yet implemented) | - |
| **Cross-Cutting** | ViewRiskScoreEvolution, ViewRiksdagenIntelligenceDashboard | - |
---
## π Technical Specifications
### Data Types Mapping
| SQL Type | Java Type | Notes |
|----------|-----------|-------|
| VARCHAR | String | Use @Column(length = X) |
| INTEGER | Integer or Long | Use Long for counts |
| NUMERIC(p,s) | BigDecimal | Use @Column(precision = p, scale = s) |
| DATE | Date | Use @Temporal(TemporalType.DATE) |
| TIMESTAMP | Date | Use @Temporal(TemporalType.TIMESTAMP) |
| BOOLEAN | Boolean | - |
### Naming Conventions
- **Entity Class**: PascalCase, e.g., `ViewPoliticianBehavioralTrends`
- **Table Name**: snake_case, e.g., `view_politician_behavioral_trends`
- **Column Name**: snake_case, e.g., `avg_absence_rate`
- **Field Name**: camelCase, e.g., `avgAbsenceRate`
---
## π Next Steps
### Priority 1: Complete v1.30 Views (Required for Core Risk Assessment)
1. **ViewRiskScoreEvolution** - Critical for all 45 rules
2. **ViewCommitteeProductivityMatrix** - Committee rules (C-01 to C-04)
3. **ViewPartyEffectivenessTrends** - Party rules (Pa-01 to Pa-10)
### Priority 2: Complete v1.29 Intelligence Views (Enhanced Analytics)
4. **ViewRiksdagenVotingAnomalyDetection** - Critical for P-03, P-05, P-13
5. **ViewRiksdagenPartyMomentumAnalysis** - Party momentum analysis
6. **ViewRiksdagenCoalitionAlignmentMatrix** - Coalition formation
7. **ViewRiksdagenPoliticianInfluenceMetrics** - Network analysis
8. **ViewRiksdagenCrisisResilienceIndicators** - Crisis performance
9. **ViewRiksdagenIntelligenceDashboard** - Executive summary
### Priority 3: Verification and Testing
- Update persistence.xml with all new entity registrations
- Build and test entity mappings
- Verify query performance
- Test integration with rules engine
- Document usage examples
---
## π Related Documentation
- [RISK_RULES_INTOP_OSINT.md](RISK_RULES_INTOP_OSINT.md) - Complete 45-rule framework
- [DATABASE_VIEW_INTELLIGENCE_CATALOG.md](DATABASE_VIEW_INTELLIGENCE_CATALOG.md) - View catalog and usage patterns
- [LIQUIBASE_CHANGELOG_INTELLIGENCE_ANALYSIS.md](LIQUIBASE_CHANGELOG_INTELLIGENCE_ANALYSIS.md) - Changelog evolution
- [DATA_MODEL.md](DATA_MODEL.md) - Database schema and relationships
- [service.data.impl/README-SCHEMA-MAINTENANCE.md](service.data.impl/README-SCHEMA-MAINTENANCE.md) - Schema maintenance guidelines
---
## π Notes
- All views are READ-ONLY (database views, not tables)
- No @Immutable annotation needed (causes module dependency issues)
- Views are materialized or standard based on Liquibase definitions
- Composite keys use multiple @Id annotations on entity fields
- Use Apache Commons Lang builders for equals/hashCode/toString
**Last Updated**: 2025-11-17
**Maintainer**: CIA Intelligence Operations Team
|