Skip to content
Snippets Groups Projects
Select Git revision
  • 2005e212544a7e7b7ff5ef7baf996d6e2925ccf0
  • main default protected
  • OZG-7856_schadcode_scanner
  • OZG-8314-Alfa-Vorgang-Bearbeiter-Zuweisung-entfernen
  • OZG-8305-Create-webpack-sbom
  • tooltip-improvements
  • release-info
  • release-administration
  • release
  • OZG-7714-UpgradeKeycloakDependencyTo25
  • OZG-8086-Admin-Datenanfrage-erstellen
  • OZG-8086-Datenanfrage-Umbenennung
  • mongodb-7-0-16-e2e
  • OZG-6220-Bescheid-speichern-ohne-Postfach
  • OZG-7922-KeycloakOperatorExceptions
  • OZG-8142-poc-cards
  • OZG-8086-E2E
  • OZG-8086-E2E2
  • OZG-8142-ProjectionStuff
  • OZG-8086-Statistik-Datenanfrage-erstellen
  • ovh-poc-add-image-pull-secret
  • 1.11.0-info
  • 1.11.0-administration
  • 2.26.0-alfa
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
  • 1.6.0-administration
  • 2.21.0-alfa
  • 1.5.0-info
  • 1.5.0-administration
41 results

heading.stories.ts

Blame
  • vorgang.service.ts 8.03 KiB
    /*
     * Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den
     * Ministerpräsidenten des Landes Schleswig-Holstein
     * Staatskanzlei
     * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
     *
     * Lizenziert unter der EUPL, Version 1.2 oder - sobald
     * diese von der Europäischen Kommission genehmigt wurden -
     * Folgeversionen der EUPL ("Lizenz");
     * Sie dürfen dieses Werk ausschließlich gemäß
     * dieser Lizenz nutzen.
     * Eine Kopie der Lizenz finden Sie hier:
     *
     * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
     *
     * Sofern nicht durch anwendbare Rechtsvorschriften
     * gefordert oder in schriftlicher Form vereinbart, wird
     * die unter der Lizenz verbreitete Software "so wie sie
     * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
     * ausdrücklich oder stillschweigend - verbreitet.
     * Die sprachspezifischen Genehmigungen und Beschränkungen
     * unter der Lizenz sind dem Lizenztext zu entnehmen.
     */
    import { ApiRootService } from '@alfa-client/api-root-shared';
    import { BinaryFileListResource } from '@alfa-client/binary-file-shared';
    import {
      CommandOrder,
      CommandResource,
      CommandService,
      CreateCommandProps,
    } from '@alfa-client/command-shared';
    import { ENVIRONMENT_CONFIG, Environment } from '@alfa-client/environment-shared';
    import { NavigationService } from '@alfa-client/navigation-shared';
    import {
      StateResource,
      createEmptyStateResource,
      doIfLoadingRequired,
      isNotNull,
    } from '@alfa-client/tech-shared';
    import { Inject, Injectable, isDevMode } from '@angular/core';
    import { ResourceUri, getUrl, hasLink } from '@ngxp/rest';
    import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel';
    import { Observable, combineLatest } from 'rxjs';
    import { filter, map, startWith, tap, withLatestFrom } from 'rxjs/operators';
    import { VorgangFacade } from './+state/vorgang.facade';
    import { buildLinkRelFromPathSegments } from './vorgang-navigation.util';
    import { VorgangWithEingangLinkRel } from './vorgang.linkrel';
    import { AdditionalActions, VorgangWithEingangResource } from './vorgang.model';
    import { createAssignUserCommand, createProcessVorgangCommand } from './vorgang.util';
    
    @Injectable({ providedIn: 'root' })
    export class VorgangService {
      public static readonly VORGANG_WITH_EINGANG_URL: string = 'vorgangWithEingangUrl';
    
      constructor(
        private navigationService: NavigationService,
        private facade: VorgangFacade,
        private apiRootService: ApiRootService,
        private commandService: CommandService,
        @Inject(ENVIRONMENT_CONFIG) private envConfig: Environment,
      ) {}
    
      public getVorgangWithEingang(): Observable<StateResource<VorgangWithEingangResource>> {
        return combineLatest([
          this.facade.getVorgangWithEingang(),
          this.apiRootService.getApiRoot(),
        ]).pipe(
          tap(([vorgangWithEingang, apiRoot]) => {
            if (isNotNull(apiRoot.resource))
              doIfLoadingRequired(vorgangWithEingang, () =>
                this.facade.loadVorgangWithEingang(this.getVorgangWithEingangUri()),
              );
          }),
          map(([vorgangWithEingang]) => vorgangWithEingang),
          startWith(createEmptyStateResource<VorgangWithEingangResource>(true)),
        );
      }
    
      public getAttachments(): Observable<StateResource<BinaryFileListResource>> {
        return this.facade.getAttachmentList().pipe(
          withLatestFrom(this.facade.getVorgangWithEingang()),
          tap(([attachmentList, vorgangWithEingang]) =>
            doIfLoadingRequired(attachmentList, () =>
              this.facade.loadAttachmentList(vorgangWithEingang.resource),
            ),
          ),
          map(([attachmentList]) => attachmentList),
          startWith(createEmptyStateResource<BinaryFileListResource>(true)),
        );
      }
    
      public getRepresentations(): Observable<StateResource<BinaryFileListResource>> {
        return this.facade.getRepresentationList().pipe(
          withLatestFrom(this.facade.getVorgangWithEingang()),
          tap(([representationList, vorgangWithEingang]) =>
            doIfLoadingRequired(representationList, () =>
              this.facade.loadRepresentationList(vorgangWithEingang.resource),
            ),
          ),
          map(([representationList]) => representationList),
          startWith(createEmptyStateResource<BinaryFileListResource>(true)),
        );
      }
    
      public clearVorgang(): void {
        this.facade.clearVorgangWithEingang();
      }
    
      public setPendingSendPostfachMailCommand(command: StateResource<CommandResource>) {
        this.facade.setPendingSendPostfachMailSingleCommand(command);
      }
      public setPendingSendPostfachMailSingleCommandLoading(): void {
        this.facade.setPendingSendPostfachMailSingleCommandLoading();
      }
      public getPendingSendPostfachMailCommand(): Observable<StateResource<CommandResource>> {
        return this.facade.getSendPostfachNachrichtPendingCommand();
      }
    
      public setPendingForwardSingleCommandLoading(): void {
        this.facade.setForwardSingleCommandLoading();
      }
      public getPendingForwardCommand(): Observable<StateResource<CommandResource>> {
        return this.facade.getForwardPendingCommand();
      }
      public setPendingForwardSingleCommand(command: StateResource<CommandResource>): void {
        this.facade.setForwardSingleCommand(command);
      }
    
      public reloadCurrentVorgang(): void {
        this.facade.loadVorgangWithEingang(this.getVorgangWithEingangUri());
      }
    
      public reloadCurrentVorgangWithAddtionalActions(additionalActions: AdditionalActions): void {
        this.facade.loadVorgangWithEingangWithAdditionalActions(
          this.getVorgangWithEingangUri(),
          additionalActions,
        );
      }
    
      getVorgangWithEingangUri(): ResourceUri {
        return this.navigationService.getDecodedParam(VorgangService.VORGANG_WITH_EINGANG_URL);
      }
    
      public assignUser(userUri: ResourceUri): Observable<StateResource<CommandResource>> {
        this.facade.initAssignUser();
    
        return this.getAssignUserCommand().pipe(
          withLatestFrom(this.facade.getVorgangWithEingang()),
          tap(([assignCommand, vorgangWithEingang]) => {
            if (assignCommand.reload && !assignCommand.loading) {
              this.facade.assignUser(vorgangWithEingang.resource, createAssignUserCommand(userUri));
            }
          }),
          map(([assignCommand]) => assignCommand),
        );
      }
    
      getAssignUserCommand(): Observable<StateResource<CommandResource>> {
        return this.facade.getAssignUserCommand();
      }
    
      public reloadVorgang(commandResource: CommandResource): void {
        this.facade.loadVorgangWithEingang(getUrl(commandResource, CommandLinkRel.EFFECTED_RESOURCE));
      }
    
      public getBackButtonUrl(): Observable<string> {
        return this.facade.getBackButtonUrl();
      }
    
      public canNavigateToPathSegements(path: string): Observable<boolean> {
        const pathSegments: string[] = path.substring(1).split('/');
        const linkRel: string = buildLinkRelFromPathSegments(pathSegments);
    
        return this.apiRootService.getApiRoot().pipe(
          filter((apiRoot) => isNotNull(apiRoot.resource)),
          map((apiRoot) => hasLink(apiRoot.resource, linkRel)),
        );
      }
    
      public getVorgangExport(): Observable<StateResource<boolean>> {
        return this.facade.getVorgangExport();
      }
    
      public export(vorgangWithEingang: VorgangWithEingangResource): void {
        this.facade.export(vorgangWithEingang);
      }
    
      public processVorgang(
        vorgangWithEingang: VorgangWithEingangResource,
      ): Observable<StateResource<CommandResource>> {
        return this.commandService.createCommandByProps(
          this.createProcessVorgangCommandProps(vorgangWithEingang),
        );
      }
    
      private createProcessVorgangCommandProps(
        vorgangWithEingang: VorgangWithEingangResource,
      ): CreateCommandProps {
        return {
          resource: vorgangWithEingang,
          linkRel: VorgangWithEingangLinkRel.PROCESS_VORGANG,
          command: createProcessVorgangCommand(this.envConfig.processorNames),
          snackBarMessage: 'Vorgang vorprüfen erfolgreich.',
        };
      }
    
      public setAktenzeichen(
        vorgang: VorgangWithEingangResource,
        aktenzeichen: string,
      ): Observable<StateResource<CommandResource>> {
        const createCommand = { order: CommandOrder.SET_AKTENZEICHEN, body: { aktenzeichen } };
        return this.commandService.createCommand(
          vorgang,
          VorgangWithEingangLinkRel.SET_AKTENZEICHEN,
          createCommand,
        );
      }
    }