Skip to content
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

GB3-1734: Add customParams for attributeFilters and TimeSlider values to print #87

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/app/shared/interfaces/print.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface PrintMapWms extends AbstractGb3Layer {
* Custom WMS params
* @example {"format":"image/png; mode=8bit","transparent":true}
*/
customParams?: object;
customParams?: CustomPrintParameters;
/**
* Layer opacity
* @min 0
Expand All @@ -120,3 +120,13 @@ export interface PrintCreationResponse {
/** print document retrieval endpoint URL */
reportUrl: string;
}

export interface DynamicStringParameters {
[key: string]: string;
}

export interface CustomPrintParameters {
transparent?: boolean;
format?: string;
dynamicStringParams: DynamicStringParameters;
}
104 changes: 97 additions & 7 deletions src/app/shared/services/apis/gb3/gb3-print.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import {UuidUtils} from '../../../utils/uuid.utils';
import {BasemapConfigService} from '../../../../map/services/basemap-config.service';
import {Basemap} from '../../../interfaces/basemap.interface';
import {PrintData} from '../../../../map/interfaces/print-data.interface';
import {TimeService} from '../../../interfaces/time-service.interface';
import {TIME_SERVICE} from '../../../../app.module';
import {TimeSliderConfiguration} from '../../../interfaces/topic.interface';

describe('Gb3PrintService', () => {
let service: Gb3PrintService;
let timeService: TimeService;
let httpClient: HttpClient;
let configService: ConfigService;

Expand All @@ -36,6 +40,7 @@ describe('Gb3PrintService', () => {
service = TestBed.inject(Gb3PrintService);
httpClient = TestBed.inject(HttpClient);
configService = TestBed.inject(ConfigService);
timeService = TestBed.inject(TIME_SERVICE);
});

it('should be created', () => {
Expand Down Expand Up @@ -64,7 +69,11 @@ describe('Gb3PrintService', () => {
type: 'WMS',
mapTitle: 'karte 1',
customParams: {
myCustomParamOne: 'myCustomValue',
format: 'image/png; mode=8bit',
transparent: true,
dynamicStringParams: {
myCustomParamOne: 'myCustomValue',
},
},
background: false,
layers: ['gott', 'würfelt', 'nicht'],
Expand Down Expand Up @@ -118,6 +127,8 @@ describe('Gb3PrintService', () => {
type: 'WMS',
map_title: 'karte 1',
custom_params: {
format: 'image/png; mode=8bit',
transparent: true,
myCustomParamOne: 'myCustomValue',
},
background: false,
Expand All @@ -128,7 +139,10 @@ describe('Gb3PrintService', () => {
{
type: 'WMS',
map_title: 'karte 2',
custom_params: undefined,
custom_params: {
format: undefined,
transparent: undefined,
},
background: false,
layers: ['holla', 'die', 'waldfee'],
url: 'url 2',
Expand All @@ -137,7 +151,10 @@ describe('Gb3PrintService', () => {
{
type: 'WMS',
map_title: 'karte 3',
custom_params: undefined,
custom_params: {
format: undefined,
transparent: undefined,
},
background: false,
layers: ['yolo'],
url: 'url 3',
Expand All @@ -146,7 +163,10 @@ describe('Gb3PrintService', () => {
{
type: 'WMS',
map_title: 'karte 4',
custom_params: undefined,
custom_params: {
format: undefined,
transparent: undefined,
},
background: true,
layers: [],
url: 'url 4',
Expand Down Expand Up @@ -233,6 +253,44 @@ describe('Gb3PrintService', () => {
layers: [{name: 'layer0_test-basemap'}, {name: 'layer1_test-basemap'}],
} as Basemap,
]);
const dateFormat = 'YYYY';
const minimumDate = timeService.createDateFromString('2000', dateFormat);
const maximumDate = timeService.createDateFromString('2020', dateFormat);
const minimumDateString = timeService.getDateAsFormattedString(minimumDate, dateFormat);
const maximumDateString = timeService.getDateAsFormattedString(maximumDate, dateFormat);
const alwaysMaxRange = false;
const range = 'P1Y';
const minimalRange = undefined;
const timeSliderConfiguration: TimeSliderConfiguration = {
name: 'mockTimeSlider',
dateFormat: dateFormat,
minimumDate: minimumDateString,
maximumDate: maximumDateString,
alwaysMaxRange: alwaysMaxRange,
range: range,
minimalRange: minimalRange,
sourceType: 'parameter',
source: {
startRangeParameter: 'filter_von',
endRangeParameter: 'filter_bis',
layerIdentifiers: [],
},
};

const mockItem = createGb2WmsMapItemMock(
'map with timeSlider',
1,
true,
1,
'uuid',
false,
{
start: minimumDate,
end: maximumDate,
},
[],
timeSliderConfiguration,
);

const printData: PrintData = {
reportType: 'standard',
Expand All @@ -252,6 +310,18 @@ describe('Gb3PrintService', () => {
createDrawingMapItemMock(UserDrawingLayer.Drawings),
createGb2WmsMapItemMock('visible map #3', 4),
createExternalWmsMapItemMock('https://www.example.com/wms', 'visible map #4', []),
createGb2WmsMapItemMock('map with filter', 1, true, 1, 'uuid', false, undefined, [
{
name: 'Test Filter',
parameter: 'test_filter',
description: 'A Filter',
filterValues: [
{name: 'first', isActive: false, values: ['some', 'value']},
{name: 'second', isActive: true, values: ['other', 'values']},
],
},
]),
mockItem,
],
mapCenter: {x: 900, y: 1},
drawings: [
Expand All @@ -272,7 +342,7 @@ describe('Gb3PrintService', () => {
reportLayout: printData.reportLayout,
reportOrientation: printData.reportOrientation,
attributes: {
reportTitle: 'visible map #3, visible map #1',
reportTitle: 'map with timeSlider, map with filter, visible map #3, visible map #1',
userTitle: printData.title,
userComment: printData.comment,
showLegend: printData.showLegend,
Expand All @@ -291,13 +361,33 @@ describe('Gb3PrintService', () => {
opacity: 1,
background: true,
},
{
type: 'WMS',
mapTitle: 'map with timeSlider',
layers: ['layer0_map with timeSlider'],
url: 'https://map with timeSlider.com',
opacity: 1,
customParams: {
format: 'image/png; mode=8bit',
transparent: true,
dynamicStringParams: {filter_von: '2000', filter_bis: '2020'},
},
},
{
type: 'WMS',
mapTitle: 'map with filter',
layers: ['layer0_map with filter'],
url: 'https://map with filter.com',
opacity: 1,
customParams: {format: 'image/png; mode=8bit', transparent: true, dynamicStringParams: {test_filter: "'some','value','',''"}},
},
{
type: 'WMS',
mapTitle: 'visible map #3',
layers: ['layer3_visible map #3', 'layer2_visible map #3', 'layer1_visible map #3', 'layer0_visible map #3'],
url: 'https://visible map #3.com',
opacity: 1,
customParams: {format: 'image/png; mode=8bit', transparent: true},
customParams: {format: 'image/png; mode=8bit', transparent: true, dynamicStringParams: {}},
},
{
type: 'Vector',
Expand All @@ -315,7 +405,7 @@ describe('Gb3PrintService', () => {
layers: ['layer1_visible map #1', 'layer0_visible map #1'],
url: 'https://visible map #1.com',
opacity: 1,
customParams: {format: 'image/png; mode=8bit', transparent: true},
customParams: {format: 'image/png; mode=8bit', transparent: true, dynamicStringParams: {}},
},
],
},
Expand Down
46 changes: 44 additions & 2 deletions src/app/shared/services/apis/gb3/gb3-print.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import {Inject, Injectable} from '@angular/core';
import {Gb3ApiService} from './gb3-api.service';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {PrintCreation, PrintCreationResponse, PrintMapItem, ReportOrientation} from '../../../interfaces/print.interface';
import {
DynamicStringParameters,
PrintCreation,
PrintCreationResponse,
PrintMapItem,
ReportOrientation,
} from '../../../interfaces/print.interface';
import {
PrintCreateData,
PrintFeatureInfoCreateData,
Expand All @@ -24,6 +30,8 @@ import {Gb2WmsSettings} from '../../../../map/models/implementations/gb2-wms.mod
import {DrawingLayerSettings} from '../../../../map/models/implementations/drawing.model';
import {TIME_SERVICE} from '../../../../app.module';
import {TimeService} from '../../../interfaces/time-service.interface';
import {Gb3TopicsService} from './gb3-topics.service';
import {TimeSliderParameterSource} from '../../../interfaces/topic.interface';

@Injectable({
providedIn: 'root',
Expand All @@ -36,6 +44,7 @@ export class Gb3PrintService extends Gb3ApiService {
@Inject(ConfigService) configService: ConfigService,
@Inject(TIME_SERVICE) timeService: TimeService,
private readonly basemapConfigService: BasemapConfigService,
private readonly gb3TopicsService: Gb3TopicsService,
) {
super(http, configService, timeService);
}
Expand Down Expand Up @@ -177,6 +186,34 @@ export class Gb3PrintService extends Gb3ApiService {
}

private createGb2WmsPrintItem(activeMapItem: ActiveMapItem, gb2WmsSettings: Gb2WmsSettings): PrintMapItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some unit tests for this; or extend existing ones to reach the coverage goal.

const dynamicStringParameters: DynamicStringParameters = {};
if (gb2WmsSettings.filterConfigurations) {
const attributeFilterParameters = this.gb3TopicsService.transformFilterConfigurationToParameters(gb2WmsSettings.filterConfigurations);
attributeFilterParameters.forEach((filterParameter) => {
dynamicStringParameters[filterParameter.name] = filterParameter.value;
});
}
if (gb2WmsSettings.timeSliderConfiguration && gb2WmsSettings.timeSliderExtent) {
switch (gb2WmsSettings.timeSliderConfiguration.sourceType) {
case 'parameter': {
const timeSliderParameterSource = gb2WmsSettings.timeSliderConfiguration.source as TimeSliderParameterSource;
TIL-EBP marked this conversation as resolved.
Show resolved Hide resolved
const dateFormat = gb2WmsSettings.timeSliderConfiguration.dateFormat;

dynamicStringParameters[timeSliderParameterSource.startRangeParameter] = this.timeService.getDateAsUTCString(
gb2WmsSettings.timeSliderExtent.start,
dateFormat,
);
dynamicStringParameters[timeSliderParameterSource.endRangeParameter] = this.timeService.getDateAsUTCString(
gb2WmsSettings.timeSliderExtent.end,
dateFormat,
);
break;
}
case 'layer':
// This already works as is as we are printing the visible layers already
break;
}
}
return {
// order matters: the lowest index has the highest visibility
layers: gb2WmsSettings.layers
Expand All @@ -190,6 +227,7 @@ export class Gb3PrintService extends Gb3ApiService {
customParams: {
TIL-EBP marked this conversation as resolved.
Show resolved Hide resolved
format: this.configService.gb2Config.wmsFormatMimeType,
transparent: true, // always true
dynamicStringParams: dynamicStringParameters,
},
};
}
Expand Down Expand Up @@ -225,7 +263,11 @@ export class Gb3PrintService extends Gb3ApiService {
type: 'WMS',
url: mapItem.url,
layers: mapItem.layers,
custom_params: mapItem.customParams,
custom_params: {
format: mapItem.customParams?.format,
transparent: mapItem.customParams?.transparent,
...mapItem.customParams?.dynamicStringParams,
},
opacity: mapItem.opacity,
map_title: mapItem.mapTitle,
background: mapItem.background,
Expand Down
6 changes: 5 additions & 1 deletion src/app/state/map/effects/print.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ describe('PrintEffects', () => {
type: 'WMS',
mapTitle: 'karte 1',
customParams: {
myCustomParamOne: 'myCustomValue',
format: 'image/png; mode=8bit',
transparent: true,
dynamicStringParams: {
myCustomParamOne: 'myCustomValue',
},
},
background: false,
layers: ['gott', 'würfelt', 'nicht'],
Expand Down
6 changes: 5 additions & 1 deletion src/app/state/map/reducers/print.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ describe('print reducer', () => {
type: 'WMS',
mapTitle: 'karte 1',
customParams: {
myCustomParamOne: 'myCustomValue',
format: 'image/png; mode=8bit',
transparent: true,
dynamicStringParams: {
myCustomParamOne: 'myCustomValue',
},
},
background: false,
layers: ['gott', 'würfelt', 'nicht'],
Expand Down
5 changes: 3 additions & 2 deletions src/app/testing/map-testing/active-map-item-test.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Gb2WmsActiveMapItem} from '../../map/models/implementations/gb2-wms.model';
import {FilterConfiguration, Map, MapLayer} from '../../shared/interfaces/topic.interface';
import {FilterConfiguration, Map, MapLayer, TimeSliderConfiguration} from '../../shared/interfaces/topic.interface';
import {ActiveMapItemFactory} from '../../shared/factories/active-map-item.factory';
import {DrawingLayerPrefix, UserDrawingLayer} from '../../shared/enums/drawing-layer.enum';
import {DrawingActiveMapItem} from '../../map/models/implementations/drawing.model';
Expand All @@ -18,8 +18,9 @@ export function createGb2WmsMapItemMock(
isTemporary: boolean = false,
timeExtent?: TimeExtent,
attributeFilters?: FilterConfiguration[],
timeSliderConfiguration?: TimeSliderConfiguration,
): Gb2WmsActiveMapItem {
const mapMock = {id, title: id, layers: [], uuid, wmsUrl: `https://${id}.com`} as Partial<Map>;
const mapMock = {id, title: id, layers: [], uuid, wmsUrl: `https://${id}.com`, timeSliderConfiguration} as Partial<Map>;
for (let layerNumber = 0; layerNumber < numberOfLayers; layerNumber++) {
const uniqueLayerName = `layer${layerNumber}_${id}`;
const layerMock = {layer: uniqueLayerName, title: uniqueLayerName, id: layerNumber, visible: true} as Partial<MapLayer>;
Expand Down
Loading