-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(api): keep only current specification data in the table for proce… #493
Merged
Dyostiq
merged 2 commits into
develop
from
fix/MARXAN-687-keep-only-current-spec-data-for-processing
Aug 27, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 6 additions & 17 deletions
23
api/apps/api/src/modules/scenario-specification/adapters/specification-activated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...pi/src/modules/scenario-specification/adapters/specification-processing-finished.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IEvent } from '@nestjs/cqrs'; | ||
|
||
export class SpecificationProcessingFinishedEvent implements IEvent { | ||
constructor( | ||
public readonly scenarioId: string, | ||
public readonly specificationId: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { ScenarioSpecificationModule } from './scenario-specification.module'; | ||
export { SpecificationActivated } from './domain'; | ||
export { SpecificationProcessingFinishedEvent } from './adapters/specification-processing-finished.event'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Command } from '@nestjs-architects/typed-cqrs'; | ||
|
||
export class MoveDataFromPreparationCommand extends Command<void> { | ||
constructor( | ||
public readonly scenarioId: string, | ||
public readonly specificationId: string, | ||
) { | ||
super(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
CommandHandler, | ||
EventBus, | ||
IInferredCommandHandler, | ||
} from '@nestjs/cqrs'; | ||
import { EntityManager } from 'typeorm'; | ||
import { InjectEntityManager } from '@nestjs/typeorm'; | ||
import { | ||
ScenarioFeaturesPreparation, | ||
ScenarioFeaturesData, | ||
} from '@marxan/features'; | ||
import { DbConnections } from '@marxan-api/ormconfig.connections'; | ||
import { SpecificationProcessingFinishedEvent } from '@marxan-api/modules/scenario-specification'; | ||
import { MoveDataFromPreparationCommand } from './move-data-from-preparation.command'; | ||
|
||
@CommandHandler(MoveDataFromPreparationCommand) | ||
export class MoveDataFromPreparationHandler | ||
implements IInferredCommandHandler<MoveDataFromPreparationCommand> { | ||
constructor( | ||
@InjectEntityManager(DbConnections.geoprocessingDB) | ||
private readonly entityManager: EntityManager, | ||
private readonly eventBus: EventBus, | ||
) {} | ||
|
||
async execute(command: MoveDataFromPreparationCommand): Promise<void> { | ||
await this.entityManager.transaction(async (transactionalEntityManager) => { | ||
await transactionalEntityManager.delete(ScenarioFeaturesData, { | ||
scenarioId: command.scenarioId, | ||
}); | ||
await transactionalEntityManager.query( | ||
` | ||
insert into scenario_features_data as sfd (id, | ||
feature_class_id, | ||
scenario_id, | ||
total_area, | ||
current_pa, | ||
fpf, | ||
target, | ||
prop, | ||
target2, | ||
targetocc, | ||
sepnum, | ||
created_by, | ||
metadata, | ||
specification_id) | ||
select id, | ||
feature_class_id, | ||
scenario_id, | ||
total_area, | ||
current_pa, | ||
fpf, | ||
target, | ||
prop, | ||
target2, | ||
targetocc, | ||
sepnum, | ||
created_by, | ||
metadata, | ||
specification_id | ||
from scenario_features_preparation sfp | ||
where sfp.specification_id = $1 | ||
`, | ||
[command.specificationId], | ||
); | ||
await transactionalEntityManager.delete(ScenarioFeaturesPreparation, { | ||
specificationId: command.specificationId, | ||
}); | ||
}); | ||
|
||
this.eventBus.publish( | ||
new SpecificationProcessingFinishedEvent( | ||
command.scenarioId, | ||
command.specificationId, | ||
), | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.saga.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ICommand, ofType, Saga } from '@nestjs/cqrs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { SpecificationActivated } from '@marxan-api/modules/scenario-specification'; | ||
import { MoveDataFromPreparationCommand } from './move-data-from-preparation.command'; | ||
|
||
@Injectable() | ||
export class MoveDataFromPreparationSaga { | ||
@Saga() | ||
specificationActivated = (events$: Observable<any>): Observable<ICommand> => { | ||
return events$.pipe( | ||
ofType(SpecificationActivated), | ||
map( | ||
(event) => | ||
new MoveDataFromPreparationCommand( | ||
event.scenarioId, | ||
event.specificationId.value, | ||
), | ||
), | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this event a part of adapters really?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, but boundaries between two modules is artificial a bit, and I need to reflect the state of the specification by the event