Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • ccd34dafe8b54f033ad89e59878644bccf509c05
  • development default
  • bugfix/EDELIVERY-14172-domismp-accepts-requests-with-wrong-domain-header-value
  • EDELIVERY-15372-upgrade-libraries-and-plugins-and-update-httpclient-to-httpclient5
  • EDELIVERY-15377-migrate-to-angular-20
  • feature/EDELIVERY-15382-rest-api-jwt-authentication-for-dynamic-discovery-client
  • bugfix/EDELIVERY-14196-select-domain-select-resource-dropdown-should-be-order-alphabetically
  • feature/EDELIVERY-12753-sml-integration-migration-to-different-smp
  • feature/EDELIVERY-13757-extend-session-dialog-should-have-an-active-counter
  • EDELIVERY-15144-sql-update
  • bugfix/EDELIVERY-14326-ui-edit-resource-filters
  • feature/EDELIVERY-15144-domismp-system-notification-generalize-time-expiration-alerts
  • bugfix/EDELIVERY-15102-alert-is-not-appearing-when-adding-duplicated-certificate
  • bugfix/EDELIVERY-15203-small-left-grid-shows-no-data-found-for-1-2-seconds-before-loading-the-data
  • EDELIVERY-15219-search-filter-with-understore-char-does-not-work
  • bugfix/EDELIVERY-15226-certificates-error-when-trying-to-delete-certificates
  • bugfix/EDELIVERY-15224-error-when-trying-to-update-info-from-profile-page
  • bugfix/EDELIVERY-15225-emails-are-not-sent-in-domismp
  • release/5.1.x
  • feature/EDELIVERY-12746-external-secret-sharing-services-as-vaults
  • EDELIVERY-15229-upgrade-libraries-and-plugins
  • 5.1.1
  • 5.1
  • 5.1-TEST
  • 5.1-RC1
  • 5.0.1
  • 5.0
  • 5.0-RC1
  • 4.2
  • 4.2-RC1
  • 4.1.2
  • 4.1.1
  • 4.1.0
  • 4.1.0-RC1
  • 4.0.0
  • 4.0.0-RC1
  • 3.0.2
  • 3.0.1
  • 3.0.0
39 results

service-group-metadata-dialog.component.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    service-group-metadata-dialog.component.ts 11.94 KiB
    import {Component, Inject, OnInit, ViewChild} from '@angular/core';
    import {MAT_DIALOG_DATA, MatDialog, MatDialogConfig, MatDialogRef} from '@angular/material';
    import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
    import {AlertService} from "../../alert/alert.service";
    import {SearchTableEntityStatus} from "../../common/search-table/search-table-entity-status.model";
    import {ServiceMetadataEditRo} from "../service-metadata-edit-ro.model";
    import {GlobalLookups} from "../../common/global-lookups";
    import {ServiceMetadataWizardDialogComponent} from "../service-metadata-wizard-dialog/service-metadata-wizard-dialog.component";
    import {ServiceGroupEditRo} from "../service-group-edit-ro.model";
    import {SmpConstants} from "../../smp.constants";
    import {Observable} from "rxjs/internal/Observable";
    import {HttpClient} from "@angular/common/http";
    import {ServiceGroupDomainEditRo} from "../service-group-domain-edit-ro.model";
    import {ServiceMetadataValidationEditRo} from "./service-metadata-validation-edit-ro.model";
    import {ServiceMetadataWizardRo} from "../service-metadata-wizard-dialog/service-metadata-wizard-edit-ro.model";
    
    @Component({
      selector: 'service-group-metadata-dialog',
      templateUrl: './service-group-metadata-dialog.component.html',
      styleUrls: ['./service-group-metadata-dialog.component.css']
    })
    export class ServiceGroupMetadataDialogComponent implements OnInit {
    
      static readonly NEW_MODE = 'New ServiceMetadata';
      static readonly EDIT_MODE = 'Edit ServiceMetadata';
    
      @ViewChild('domainList') domainList: any;
    
    
      editMode: boolean;
      formTitle: string;
      current: ServiceMetadataEditRo & { confirmation?: string };
      currentServiceGroup: ServiceGroupEditRo;
      dialogForm: FormGroup;
      metadataValidationMessage: string;
      xmlServiceMetadataObserver: Observable<ServiceMetadataEditRo>;
      isMetadataValid: boolean = true;
    
    
      constructor(public dialog: MatDialog,
                  protected http: HttpClient,
                  public lookups: GlobalLookups,
                  private dialogRef: MatDialogRef<ServiceGroupMetadataDialogComponent>,
                  private alertService: AlertService,
                  @Inject(MAT_DIALOG_DATA) public data: any,
                  private fb: FormBuilder) {
    
        this.editMode = data.edit;
        this.formTitle = this.editMode ? ServiceGroupMetadataDialogComponent.EDIT_MODE : ServiceGroupMetadataDialogComponent.NEW_MODE;
        this.currentServiceGroup = data.serviceGroup;
        this.current = this.editMode
          ? {
            ...data.metadata,
          }
          : {
            documentIdentifier: '',
            documentIdentifierScheme: '',
            smlSubdomain: this.currentServiceGroup.serviceGroupDomains[0].smlSubdomain,
            domainCode: this.currentServiceGroup.serviceGroupDomains[0].domainCode,
            domainId: null,
            status: SearchTableEntityStatus.NEW,
            xmlContentStatus: SearchTableEntityStatus.NEW,
          };
    
        this.dialogForm = fb.group({
          'participantIdentifier': new FormControl({value: this.currentServiceGroup.participantIdentifier, disabled: true}),
          'participantScheme': new FormControl({value: this.currentServiceGroup.participantScheme, disabled: true}),
          'domainCode': new FormControl({}, [Validators.required]),
    
          'documentIdentifier': new FormControl({value: this.current.documentIdentifier, disabled: this.editMode},
            [Validators.required]),
          'documentIdentifierScheme': new FormControl({
              value: this.current.documentIdentifierScheme,
              disabled: this.editMode
            },
            []),
          'xmlContent': new FormControl({value: ''}, [Validators.required]),
        });
    
        // update values
        this.dialogForm.controls['domainCode'].setValue(this.current.domainCode);
        this.dialogForm.controls['xmlContent'].setValue(this.current.xmlContent);
      }
    
      ngOnInit() {
    
        // retrieve xml extension for this service group
        if (this.current.status !== SearchTableEntityStatus.NEW && !this.current.xmlContent) {
          // init domains
          this.xmlServiceMetadataObserver = this.http.get<ServiceMetadataEditRo>(SmpConstants.REST_METADATA + '/' + this.current.id);
          this.xmlServiceMetadataObserver.subscribe((res: ServiceMetadataEditRo) => {
            this.dialogForm.get('xmlContent').setValue(res.xmlContent);
            // store init xml to current value for change validation
            this.current.xmlContent=res.xmlContent;
          });
        }
    
      }
    
      checkValidity(g: FormGroup) {
        Object.keys(g.controls).forEach(key => {
          g.get(key).markAsDirty();
        });
        Object.keys(g.controls).forEach(key => {
          g.get(key).markAsTouched();
        });
        //!!! updateValueAndValidity - else some filed did no update current / on blur never happened
        Object.keys(g.controls).forEach(key => {
          g.get(key).updateValueAndValidity();
        });
      }
    
      submitForm() {
        this.checkValidity(this.dialogForm);
    
        // before closing check the schema
        let request: ServiceMetadataValidationEditRo = {
          participantScheme: this.dialogForm.controls['participantScheme'].value,
          participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
          documentIdentifierScheme: !this.dialogForm.controls['documentIdentifierScheme'].value?null:
          this.dialogForm.controls['documentIdentifierScheme'].value,
          documentIdentifier: this.dialogForm.controls['documentIdentifier'].value,
          xmlContent: this.dialogForm.controls['xmlContent'].value,
          statusAction: this.editMode?SearchTableEntityStatus.UPDATED:SearchTableEntityStatus.NEW,
        }
        //
        let validationObservable = this.http.post<ServiceMetadataValidationEditRo>(SmpConstants.REST_METADATA_VALIDATE, request);
        validationObservable.subscribe((res: ServiceMetadataValidationEditRo) => {
          if (res.errorMessage) {
            this.metadataValidationMessage = res.errorMessage;
            this.isMetadataValid = false;
          } else {
            this.metadataValidationMessage = "ServiceMetada is valid!";
            this.isMetadataValid = true;
            // now we can close the dialog
            this.dialogRef.close(true);
          }
    
        });
      }
    
    
      onClearServiceMetadata() {
        this.dialogForm.controls['xmlContent'].setValue("");
      }
    
      onStartWizardDialog() {
    
        let serviceMetadataWizard: ServiceMetadataWizardRo = {
          isNewServiceMetadata: !this.editMode,
          participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
          participantScheme: this.dialogForm.controls['participantScheme'].value,
          documentIdentifier: this.dialogForm.controls['documentIdentifier'].value,
          documentIdentifierScheme: this.dialogForm.controls['documentIdentifierScheme'].value,
          processIdentifier: '',
          processScheme: '',
          transportProfile: 'bdxr-transport-ebms3-as4-v1p0', // default value for oasis AS4
    
          endpointUrl: '',
          endpointCertificate: '',
    
          serviceDescription: '',
          technicalContactUrl: '',
    
        }
    
        let wizardInit: MatDialogConfig = {
          data: serviceMetadataWizard
        }
    
    
    
        const formRef: MatDialogRef<any> = this.dialog.open(ServiceMetadataWizardDialogComponent,wizardInit);
        formRef.afterClosed().subscribe(result => {
          if (result) {
    
            let smw: ServiceMetadataWizardRo =  formRef.componentInstance.getCurrent();
            this.dialogForm.controls['xmlContent'].setValue(smw.contentXML);
            if(!this.editMode){
              this.dialogForm.controls['documentIdentifierScheme'].setValue(smw.documentIdentifierScheme);
              this.dialogForm.controls['documentIdentifier'].setValue(smw.documentIdentifier);
            }
          }
        });
      }
    
      onGenerateSimpleXML() {
        let exampleXML = '<ServiceMetadata xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05">' +
          '\n    <ServiceInformation>' +
          '\n        <ParticipantIdentifier scheme="' + this.xmlSpecialChars(this.dialogForm.controls['participantScheme'].value) + '">' + this.xmlSpecialChars(this.dialogForm.controls['participantIdentifier'].value) + '</ParticipantIdentifier>' +
          '\n        <DocumentIdentifier ' +
          ( !this.dialogForm.controls['documentIdentifierScheme'].value ?'': 'scheme="' + this.xmlSpecialChars(this.dialogForm.controls['documentIdentifierScheme'].value) +'"') + ' >' + this.xmlSpecialChars(this.dialogForm.controls['documentIdentifier'].value) + '</DocumentIdentifier>' +
          '\n        <ProcessList>' +
          '\n            <Process>' +
          '\n                <ProcessIdentifier scheme="[enterProcessType]">[enterProcessName]</ProcessIdentifier>' +
          '\n                <ServiceEndpointList>' +
          '\n                   <Endpoint transportProfile="bdxr-transport-ebms3-as4-v1p0">' +
          '\n                        <EndpointURI>https://mypage.eu</EndpointURI>' +
          '\n                        <Certificate>UGFzdGUgYmFzZTY0IGVuY29kZWQgY2VydGlmaWNhdGUgb2YgQVA=</Certificate>' +
          '\n                        <ServiceDescription>Service description for partners</ServiceDescription>' +
          '\n                        <TechnicalContactUrl>www.best-page.eu</TechnicalContactUrl>' +
          '\n                    </Endpoint>' +
          '\n                </ServiceEndpointList>' +
          '\n            </Process>' +
          '\n        </ProcessList>' +
          '\n    </ServiceInformation>' +
          '\n</ServiceMetadata>';
        this.dialogForm.controls['xmlContent'].setValue(exampleXML);
      }
    
      xmlSpecialChars(unsafe) {
        return !unsafe?'':unsafe
          .replace(/&/g, "&amp;")
          .replace(/</g, "&lt;")
          .replace(/>/g, "&gt;")
          .replace(/"/g, "&quot;");
      }
    
      onServiceMetadataValidate() {
    
        let request: ServiceMetadataValidationEditRo = {
    
          participantScheme: this.dialogForm.controls['participantScheme'].value,
          participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
          documentIdentifierScheme: !this.dialogForm.controls['documentIdentifierScheme'].value?null:
            this.dialogForm.controls['documentIdentifierScheme'].value,
          documentIdentifier: this.dialogForm.controls['documentIdentifier'].value,
          xmlContent: this.dialogForm.controls['xmlContent'].value,
          statusAction: this.editMode?SearchTableEntityStatus.UPDATED:SearchTableEntityStatus.NEW,
        }
        //
        let validationObservable = this.http.post<ServiceMetadataValidationEditRo>(SmpConstants.REST_METADATA_VALIDATE, request);
        validationObservable.subscribe((res: ServiceMetadataValidationEditRo) => {
          if (res.errorMessage) {
            this.metadataValidationMessage = res.errorMessage;
            this.isMetadataValid = false;
          } else {
            this.metadataValidationMessage = "Servicemetadata is valid!";
            this.isMetadataValid = true;
          }
    
        });
      }
    
      public getCurrent(): ServiceMetadataEditRo {
    
        this.current.domainCode = this.domainList.selected.value.domainCode;
        this.current.smlSubdomain = this.domainList.selected.value.smlSubdomain;
        this.current.domainId = this.domainList.selected.value.domainId;
    
        this.current.xmlContent = this.dialogForm.value['xmlContent'];
        // change this two properties only on new
        if (this.current.status === SearchTableEntityStatus.NEW) {
          this.current.documentIdentifier = this.dialogForm.value['documentIdentifier'];
          this.current.documentIdentifierScheme = this.dialogForm.value['documentIdentifierScheme'];
        } else if (this.current.status === SearchTableEntityStatus.PERSISTED) {
          this.current.status = SearchTableEntityStatus.UPDATED;
          this.current.xmlContentStatus = SearchTableEntityStatus.UPDATED;
        }
        return this.current;
      }
    
      //!! this two method must be called before getCurrent
      public isMetaDataXMLChanged():boolean{
         return  this.dialogForm.value['xmlContent'] !== this.current.xmlContent;
      }
      public isServiceMetaDataChanged():boolean{
        return  this.isMetaDataXMLChanged() || !this.isEqual(this.current.domainCode, this.domainList.selected.value.domainCode) ;
      }
    
      compareDomainCode(sgDomain: ServiceGroupDomainEditRo, domainCode: String): boolean {
        return sgDomain.domainCode === domainCode;
      }
    
      isEqual(val1, val2): boolean {
        return (this.isEmpty(val1) && this.isEmpty(val2)
          || val1 === val2);
      }
    
      isEmpty(str): boolean {
        return (!str || 0 === str.length);
      }
    }