Skip to content

Commit

Permalink
Merged in CST-12867-ip-range-for-ldn-service (pull request #1239)
Browse files Browse the repository at this point in the history
CST-12867 ip range for ldn service

Approved-by: Stefano Maffei
  • Loading branch information
FrancescoMolinaro authored and steph-ieffam committed Jan 17, 2024
2 parents a878696 + 3a87044 commit ae8e9fb
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ <h2 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat
</div>
</div>

<!-- In the IP range section -->
<div class="mb-5 mt-5">
<label for="lowerIp" class="font-weight-bold">{{ 'ldn-new-service.form.label.ip-range' | translate }}</label>
<div class="d-flex">
<input [class.invalid-field]="formModel.get('lowerIp').invalid && formModel.get('lowerIp').touched"
[placeholder]="'ldn-new-service.form.placeholder.lowerIp' | translate" class="form-control mr-2"
formControlName="lowerIp"
id="lowerIp"
name="lowerIp"
type="text">
<input [class.invalid-field]="formModel.get('upperIp').invalid && formModel.get('upperIp').touched"
[placeholder]="'ldn-new-service.form.placeholder.upperIp' | translate" class="form-control"
formControlName="upperIp"
id="upperIp"
name="upperIp"
type="text">
</div>

<div *ngIf="(formModel.get('lowerIp').invalid && formModel.get('lowerIp').touched) || (formModel.get('upperIp').invalid && formModel.get('upperIp').touched)" class="error-text">
{{ 'ldn-new-service.form.error.ipRange' | translate }}
</div>
<div *ngIf="!(formModel.get('lowerIp').invalid && formModel.get('lowerIp').touched) || (formModel.get('upperIp').invalid && formModel.get('upperIp').touched)" class="text-muted">
{{ 'ldn-new-service.form.hint.ipRange' | translate }}
</div>
</div>

<!-- In the ldnUrl section -->
<div class="mb-5 mt-5">
<label for="ldnUrl" class="font-weight-bold">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
Expand Down Expand Up @@ -84,7 +110,7 @@ <h2 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat
<div class="col">
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
</div>
<ng-container *ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern)">
<ng-container *ngIf="formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern">
<div class="col">
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
</div>
Expand Down Expand Up @@ -145,7 +171,7 @@ <h2 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat

<div class="col">
<ng-container
*ngIf="!!(formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern)">
*ngIf="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern">
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown
placement="top-start">
<div class="position-relative right-addon" role="combobox">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
TemplateRef,
ViewChild
} from '@angular/core';
Expand All @@ -29,6 +26,7 @@ import {combineLatestWith, Observable, Subscription} from 'rxjs';
import {PaginationService} from '../../../core/pagination/pagination.service';
import {FindListOptions} from '../../../core/data/find-list-options.model';
import {NotifyServicePattern} from '../ldn-services-model/ldn-service-patterns.model';
import { IpV4Validator } from '../../../shared/utils/ipV4.validator';


/**
Expand All @@ -48,35 +46,26 @@ import {NotifyServicePattern} from '../ldn-services-model/ldn-service-patterns.m
})
export class LdnServiceFormComponent implements OnInit, OnDestroy {
formModel: FormGroup;

@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
@ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>;

public inboundPatterns: string[] = notifyPatterns;
public isNewService: boolean;
public areControlsInitialized: boolean;
itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
config: FindListOptions = Object.assign(new FindListOptions(), {
public itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
public config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20
});
public markedForDeletionInboundPattern: number[] = [];
public selectedInboundPatterns: string[];
public selectedInboundItemfilters: string[];

@Input() public name: string;
@Input() public description: string;
@Input() public url: string;
@Input() public ldnUrl: string;
@Input() public score: number;
@Input() public inboundPattern: string;
@Input() public constraint: string;
@Input() public automatic: boolean;
@Input() public headerKey: string;
@Output() submitForm: EventEmitter<any> = new EventEmitter();
@Output() cancelForm: EventEmitter<any> = new EventEmitter();
markedForDeletionInboundPattern: number[] = [];
selectedInboundPatterns: string[];
selectedInboundItemfilters: string[];
protected serviceId: string;

private deletedInboundPatterns: number[] = [];
private modalRef: any;
private service: LdnService;
private ldnService: LdnService;
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select';
private routeSubscription: Subscription;

Expand All @@ -99,6 +88,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
description: [''],
url: ['', Validators.required],
ldnUrl: ['', Validators.required],
lowerIp: ['', [Validators.required, new IpV4Validator()]],
upperIp: ['', [Validators.required, new IpV4Validator()]],
score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], inboundPattern: [''],
constraintPattern: [''],
enabled: [''],
Expand Down Expand Up @@ -139,15 +130,9 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
*/
createService() {
this.formModel.markAllAsTouched();

const name = this.formModel.get('name').value;
const url = this.formModel.get('url').value;
const score = this.formModel.get('score').value;
const ldnUrl = this.formModel.get('ldnUrl').value;

const hasInboundPattern = this.checkPatterns(this.formModel.get('notifyServiceInboundPatterns') as FormArray);

Check warning on line 133 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L132-L133

Added lines #L132 - L133 were not covered by tests

if (!name || !url || !ldnUrl || (!score && score !== 0) || this.formModel.get('score').invalid) {
if (this.formModel.invalid) {
this.closeModal();
return;

Check warning on line 137 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L136-L137

Added lines #L136 - L137 were not covered by tests
}
Expand Down Expand Up @@ -177,9 +162,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
if (rd.hasSucceeded) {
this.notificationService.success(this.translateService.get('ldn-service-notification.created.success.title'),

Check warning on line 163 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L163

Added line #L163 was not covered by tests
this.translateService.get('ldn-service-notification.created.success.body'));

this.sendBack();
this.closeModal();
this.sendBack();

Check warning on line 166 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L165-L166

Added lines #L165 - L166 were not covered by tests
} else {
this.notificationService.error(this.translateService.get('ldn-service-notification.created.failure.title'),

Check warning on line 168 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L168

Added line #L168 was not covered by tests
this.translateService.get('ldn-service-notification.created.failure.body'));
Expand Down Expand Up @@ -214,18 +198,21 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
).subscribe(
(data: RemoteData<LdnService>) => {
if (data.hasSucceeded) {
this.service = data.payload;
this.ldnService = data.payload;

Check warning on line 201 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L201

Added line #L201 was not covered by tests

this.formModel.patchValue({

Check warning on line 203 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L203

Added line #L203 was not covered by tests
id: this.service.id,
name: this.service.name,
description: this.service.description,
url: this.service.url,
score: this.service.score, ldnUrl: this.service.ldnUrl,
type: this.service.type,
enabled: this.service.enabled
id: this.ldnService.id,
name: this.ldnService.name,
description: this.ldnService.description,
url: this.ldnService.url,
score: this.ldnService.score,
ldnUrl: this.ldnService.ldnUrl,
type: this.ldnService.type,
enabled: this.ldnService.enabled,
lowerIp: this.ldnService.lowerIp,
upperIp: this.ldnService.upperIp,
});
this.filterPatternObjectsAndPickLabel('notifyServiceInboundPatterns');
this.filterPatternObjectsAndAssignLabel('notifyServiceInboundPatterns');

Check warning on line 215 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L215

Added line #L215 was not covered by tests
}
},
);
Expand All @@ -235,11 +222,11 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
* Filters pattern objects, initializes form groups, assigns labels, and adds them to the specified form array so the correct string is shown in the dropdown..
* @param formArrayName - The name of the form array to be populated
*/
filterPatternObjectsAndPickLabel(formArrayName: string) {
filterPatternObjectsAndAssignLabel(formArrayName: string) {
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
PatternsArray.clear();

Check warning on line 227 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L226-L227

Added lines #L226 - L227 were not covered by tests
let servicesToUse;
servicesToUse = this.service.notifyServiceInboundPatterns;

let servicesToUse = this.ldnService.notifyServiceInboundPatterns;

Check warning on line 229 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L229

Added line #L229 was not covered by tests

servicesToUse.forEach((patternObj: NotifyServicePattern) => {

Check warning on line 231 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L231

Added line #L231 was not covered by tests
let patternFormGroup;
Expand All @@ -253,8 +240,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
PatternsArray.push(patternFormGroup);
this.cdRef.detectChanges();

Check warning on line 241 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L240-L241

Added lines #L240 - L241 were not covered by tests
});


}

/**
Expand All @@ -269,6 +254,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
this.createReplaceOperation(patchOperations, 'url', '/url');
this.createReplaceOperation(patchOperations, 'score', '/score');
this.createReplaceOperation(patchOperations, 'lowerIp', '/lowerIp');
this.createReplaceOperation(patchOperations, 'upperIp', '/upperIp');

Check warning on line 258 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L252-L258

Added lines #L252 - L258 were not covered by tests

this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
this.deletedInboundPatterns.forEach(index => {
Expand Down Expand Up @@ -342,11 +329,10 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
value: newStatus,
};

this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
this.ldnServicesService.patch(this.ldnService, [patchOperation]).pipe(

Check warning on line 332 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L332

Added line #L332 was not covered by tests
getFirstCompletedRemoteData()
).subscribe(
() => {

this.formModel.get('enabled').setValue(newStatus);
this.cdRef.detectChanges();

Check warning on line 337 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L336-L337

Added lines #L336 - L337 were not covered by tests
}
Expand Down Expand Up @@ -402,7 +388,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
return;

Check warning on line 388 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L385-L388

Added lines #L385 - L388 were not covered by tests
}

this.ldnServicesService.patch(this.service, patchOperations).pipe(
this.ldnServicesService.patch(this.ldnService, patchOperations).pipe(

Check warning on line 391 in src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-ldn-services/ldn-service-form/ldn-service-form.component.ts#L391

Added line #L391 was not covered by tests
getFirstCompletedRemoteData()
).subscribe(
(rd: RemoteData<LdnService>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const mockLdnService: LdnService = {
enabled: false,
score: 0,
id: 1,
lowerIp: '192.0.2.146',
upperIp: '192.0.2.255',
name: 'Service Name',
description: 'Service Description',
url: 'Service URL',
Expand Down Expand Up @@ -45,6 +47,8 @@ export const mockLdnServices: LdnService[] = [{
enabled: false,
score: 0,
id: 1,
lowerIp: '192.0.2.146',
upperIp: '192.0.2.255',
name: 'Service Name',
description: 'Service Description',
url: 'Service URL',
Expand Down Expand Up @@ -75,6 +79,8 @@ export const mockLdnServices: LdnService[] = [{
enabled: false,
score: 0,
id: 2,
lowerIp: '192.0.2.146',
upperIp: '192.0.2.255',
name: 'Service Name',
description: 'Service Description',
url: 'Service URL',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { TestScheduler } from 'rxjs/testing';
import { LdnItemfiltersService } from './ldn-itemfilters-data.service';
import { RequestService } from '../../../core/data/request.service';
import { RemoteDataBuildService } from '../../../core/cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { RequestEntry } from '../../../core/data/request-entry.model';
import { RemoteData } from '../../../core/data/remote-data';
import { RequestEntryState } from '../../../core/data/request-entry-state.model';
import { cold, getTestScheduler } from 'jasmine-marbles';
import { RestResponse } from '../../../core/cache/response.models';
import { of } from 'rxjs';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { FindAllData } from '../../../core/data/base/find-all-data';
import { testFindAllDataImplementation } from '../../../core/data/base/find-all-data.spec';

describe('LdnItemfiltersService test', () => {
let scheduler: TestScheduler;
let service: LdnItemfiltersService;
let requestService: RequestService;
let rdbService: RemoteDataBuildService;
let objectCache: ObjectCacheService;
let halService: HALEndpointService;
let notificationsService: NotificationsService;
let responseCacheEntry: RequestEntry;

const endpointURL = `https://rest.api/rest/api/ldn/itemfilters`;
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';

const remoteDataMocks = {
Success: new RemoteData(null, null, null, RequestEntryState.Success, null, null, 200),
};

function initTestService() {
return new LdnItemfiltersService(
requestService,
rdbService,
objectCache,
halService,
notificationsService,
);
}

beforeEach(() => {
scheduler = getTestScheduler();

objectCache = {} as ObjectCacheService;
notificationsService = {} as NotificationsService;
responseCacheEntry = new RequestEntry();
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
responseCacheEntry.response = new RestResponse(true, 200, 'Success');

requestService = jasmine.createSpyObj('requestService', {
generateRequestId: requestUUID,
send: true,
removeByHrefSubstring: {},
getByHref: of(responseCacheEntry),
getByUUID: of(responseCacheEntry),
});

halService = jasmine.createSpyObj('halService', {
getEndpoint: of(endpointURL)
});

rdbService = jasmine.createSpyObj('rdbService', {
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
buildList: cold('a', { a: remoteDataMocks.Success })
});


service = initTestService();
});

describe('composition', () => {
const initFindAllService = () => new LdnItemfiltersService(null, null, null, null, null) as unknown as FindAllData<any>;
testFindAllDataImplementation(initFindAllService);
});

describe('get endpoint', () => {
it('should retrieve correct endpoint', (done) => {
service.getEndpoint().subscribe(() => {
expect(halService.getEndpoint).toHaveBeenCalledWith('itemfilters');
done();
});
});
});

});
Loading

0 comments on commit ae8e9fb

Please sign in to comment.