From f368da7a277fc5ed0de2bf9698de0de4ea67ce64 Mon Sep 17 00:00:00 2001
From: Art Lowel <art@atmire.com>
Date: Mon, 6 Apr 2020 16:40:45 +0200
Subject: [PATCH] fix issue where requestservice.getByUUID wouldn't work for
 requests that were never sent because there was already a copy in the cache

---
 src/app/core/data/request.service.ts | 30 +++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts
index 810b0721ae..c68bd751fd 100644
--- a/src/app/core/data/request.service.ts
+++ b/src/app/core/data/request.service.ts
@@ -3,9 +3,9 @@ import { HttpHeaders } from '@angular/common/http';
 
 import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
 import { Observable, race as observableRace } from 'rxjs';
-import { filter, map, mergeMap, take } from 'rxjs/operators';
+import { filter, map, mergeMap, take, switchMap } from 'rxjs/operators';
 import { cloneDeep, remove } from 'lodash';
-import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util';
+import { hasValue, isEmpty, isNotEmpty, hasValueOperator } from '../../shared/empty.util';
 import { CacheableObject } from '../cache/object-cache.reducer';
 import { ObjectCacheService } from '../cache/object-cache.service';
 import { CoreState } from '../core.reducers';
@@ -111,13 +111,22 @@ export class RequestService {
    */
   getByUUID(uuid: string): Observable<RequestEntry> {
     return observableRace(
-      this.store.pipe(select(entryFromUUIDSelector(uuid))),
+      this.store.pipe(
+        select(entryFromUUIDSelector(uuid)),
+        hasValueOperator()
+      ),
       this.store.pipe(
         select(originalRequestUUIDFromRequestUUIDSelector(uuid)),
-        mergeMap((originalUUID) => {
-            return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
+        switchMap((originalUUID) => {
+            if (hasValue(originalUUID)) {
+              return this.store.pipe(select(entryFromUUIDSelector(originalUUID)))
+            } else {
+              return []
+            }
           },
-        ))
+        ),
+        hasValueOperator()
+      )
     ).pipe(
       map((entry: RequestEntry) => {
         // Headers break after being retrieved from the store (because of lazy initialization)
@@ -137,7 +146,14 @@ export class RequestService {
   getByHref(href: string): Observable<RequestEntry> {
     return this.store.pipe(
       select(uuidFromHrefSelector(href)),
-      mergeMap((uuid: string) => this.getByUUID(uuid))
+      mergeMap((uuid: string) => {
+        if (isNotEmpty(uuid)) {
+          return this.getByUUID(uuid);
+        }
+        else {
+          return [undefined];
+        }
+      })
     );
   }
 
-- 
GitLab