Skip to content

Commit

Permalink
feat: adds call for webshot service in blm-final-results process
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvalave committed Mar 31, 2022
1 parent d9263c5 commit 1e37aba
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
3 changes: 1 addition & 2 deletions api/apps/api/src/modules/scenarios/scenarios.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import {
} from '@marxan-api/modules/access-control/scenarios-acl/locks/dto/scenario.lock.dto';
import { mapAclDomainToHttpError } from '@marxan-api/utils/acl.utils';
import { BaseTilesOpenApi } from '@marxan/tiles';
import { WebshotConfig, WebshotService } from '@marxan/webshot';
import { WebshotConfig } from '@marxan/webshot';
import { AppSessionTokenCookie } from '@marxan-api/decorators/app-session-token-cookie.decorator';
import { setImagePngResponseHeadersForSuccessfulRequests } from '@marxan/utils';

Expand Down Expand Up @@ -131,7 +131,6 @@ export class ScenariosController {
private readonly zipFilesSerializer: ZipFilesSerializer,
private readonly planningUnitsSerializer: ScenarioPlanningUnitSerializer,
private readonly scenarioAclService: ScenarioAccessControl,
private readonly webshotService: WebshotService,
) {}

@ApiOperation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export class BlmFinalResultsRepository {
return Promise.resolve(undefined);
}

async findOneByScenarioId(
scenarioId: string,
): Promise<BlmFinalResultEntity | undefined> {
const result = await this.entityManager.findOne(BlmFinalResultEntity, {
where: { scenarioId },
});
async findOneByScenarioId(scenarioId: string): Promise<BlmFinalResultEntity> {
const result = await this.entityManager.findOneOrFail(
BlmFinalResultEntity,
{
where: { scenarioId },
},
);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Cancellable } from '@marxan-geoprocessing/marxan-sandboxed-runner/ports/cancellable';
import { geoprocessingConnections } from '@marxan-geoprocessing/ormconfig';
import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry';
import { JobData } from '@marxan/blm-calibration';
import { WebshotService } from '@marxan/webshot';
import { Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { EventBus } from '@nestjs/cqrs';
import { InjectEntityManager } from '@nestjs/typeorm';
import AbortController from 'abort-controller';
import { EntityManager, getManager } from 'typeorm';
import { v4 } from 'uuid';
import { SandboxRunner } from '../ports/sandbox-runner';
import { BlmFinalResultsRepository } from './blm-final-results.repository';
Expand All @@ -21,6 +26,9 @@ export class MarxanSandboxBlmRunnerService
private readonly finalResultsRepository: BlmFinalResultsRepository,
private readonly marxanRunnerFactory: MarxanRunnerFactory,
private readonly eventBus: EventBus,
private readonly webshotService: WebshotService,
@InjectEntityManager(geoprocessingConnections.apiDB)
private readonly apiEntityManager: EntityManager,
) {}

kill(ofScenarioId: string): void {
Expand Down Expand Up @@ -92,24 +100,37 @@ export class MarxanSandboxBlmRunnerService
calibrationId,
);

// This won't work because every run has same scenarioId
const createdFinalResult = await this.finalResultsRepository.findOneByScenarioId(
scenarioId,
);

const { blmValue } = createdFinalResult;

//array of uuid of project_pu table entities included in best solution
//need to be joined with scenario_pu_data and planning_units_geom
const puIds = createdFinalResult?.protected_pu_ids;

//-> I need to get the tiles for the APP(FE) to generate the maps.
// Once they are ready after the ¿proxy? request to API I need to
// request the webshot service png generation with those tiles.
// const proxyCall(puids)
// this.interruptIfKilled(scenarioId);
const projectId = await this.apiEntityManager
.createQueryBuilder()
.select(['project_id'])
.from('scenarios', 's')
.where('id = :scenarioId', { scenarioId })
.execute();

/*
Webshot call happens here with puIds.
This will return the PNG data, that needs to be inserted in next call to update finalResults.
await this.webshot.createScreenshot(puData, scenarioId, runId);
this.interruptIfKilled(scenarioId);
*/
// const pngStream = await this.webshotService.getBlmValuesImage(
// scenarioId,
// projectId,
// configForWebshot,
// blmValue,
// );
this.interruptIfKilled(scenarioId);

// When webshot call returns -> this.finalResultsRepository.updateFinalResults(scenarioId, pngData).

Expand Down
4 changes: 3 additions & 1 deletion api/apps/geoprocessing/test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"@marxan/files-repository/(.*)": "<rootDir>/../../libs/files-repository/src/$1",
"@marxan/files-repository": "<rootDir>/../../libs/files-repository/src",
"@marxan/cloning/(.*)": "<rootDir>/../../libs/cloning/src/$1",
"@marxan/cloning": "<rootDir>/../../libs/cloning/src"
"@marxan/cloning": "<rootDir>/../../libs/cloning/src",
"@marxan/webshot/(.*)": "<rootDir>../../libs/webshot/src/$1",
"@marxan/webshot": "<rootDir>../../libs/webshot/src"
}
}

0 comments on commit 1e37aba

Please sign in to comment.