mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-8991] Saved searches potential file conflict fix (#10393)
This commit is contained in:
@@ -59,7 +59,6 @@ describe('SavedSearchesService', () => {
|
||||
service = TestBed.inject(SavedSearchesService);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
spyOn(service.nodesApi, 'getNode').and.callFake(() => Promise.resolve({ entry: { id: testNodeId } } as NodeEntry));
|
||||
spyOn(service.searchApi, 'search').and.callFake(() => Promise.resolve({ list: { entries: [] } }));
|
||||
spyOn(service.nodesApi, 'createNode').and.callFake(() => Promise.resolve({ entry: { id: 'new-node-id' } }));
|
||||
spyOn(service.nodesApi, 'updateNodeContent').and.callFake(() => Promise.resolve({ entry: {} } as NodeEntry));
|
||||
getNodeContentSpy = spyOn(service.nodesApi, 'getNodeContent').and.callFake(() => createBlob());
|
||||
@@ -85,14 +84,15 @@ describe('SavedSearchesService', () => {
|
||||
});
|
||||
|
||||
it('should create config.json file if it does not exist', (done) => {
|
||||
const error: Error = { name: 'test', message: '{ "error": { "statusCode": 404 } }' };
|
||||
spyOn(authService, 'getUsername').and.callFake(() => testUserName);
|
||||
service.nodesApi.getNode = jasmine.createSpy().and.returnValue(Promise.reject(error));
|
||||
getNodeContentSpy.and.callFake(() => Promise.resolve(new Blob([''])));
|
||||
service.innit();
|
||||
|
||||
service.getSavedSearches().subscribe((searches) => {
|
||||
expect(service.nodesApi.getNode).toHaveBeenCalledWith('-my-');
|
||||
expect(service.searchApi.search).toHaveBeenCalled();
|
||||
expect(service.nodesApi.createNode).toHaveBeenCalledWith(testNodeId, jasmine.objectContaining({ name: 'config.json' }));
|
||||
expect(service.nodesApi.getNode).toHaveBeenCalledWith('-my-', { relativePath: 'config.json' });
|
||||
expect(service.nodesApi.createNode).toHaveBeenCalledWith('-my-', jasmine.objectContaining({ name: 'config.json' }));
|
||||
expect(searches.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NodesApi, NodeEntry, SearchApi, SEARCH_LANGUAGE, ResultSetPaging } from '@alfresco/js-api';
|
||||
import { NodesApi, NodeEntry } from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, of, from, ReplaySubject, throwError } from 'rxjs';
|
||||
import { catchError, concatMap, first, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
@@ -27,12 +27,6 @@ import { AuthenticationService } from '@alfresco/adf-core';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SavedSearchesService {
|
||||
private _searchApi: SearchApi;
|
||||
get searchApi(): SearchApi {
|
||||
this._searchApi = this._searchApi ?? new SearchApi(this.apiService.getInstance());
|
||||
return this._searchApi;
|
||||
}
|
||||
|
||||
private _nodesApi: NodesApi;
|
||||
get nodesApi(): NodesApi {
|
||||
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
|
||||
@@ -209,43 +203,35 @@ export class SavedSearchesService {
|
||||
this.currentUserLocalStorageKey = localStorageKey;
|
||||
let savedSearchesNodeId = localStorage.getItem(this.currentUserLocalStorageKey) ?? '';
|
||||
if (savedSearchesNodeId === '') {
|
||||
return from(this.nodesApi.getNode('-my-')).pipe(
|
||||
return from(this.nodesApi.getNode('-my-', { relativePath: 'config.json' })).pipe(
|
||||
first(),
|
||||
map((node) => node.entry.id),
|
||||
concatMap((parentNodeId) =>
|
||||
from(
|
||||
this.searchApi.search({
|
||||
query: {
|
||||
language: SEARCH_LANGUAGE.AFTS,
|
||||
query: `cm:name:"config.json" AND PARENT:"${parentNodeId}"`
|
||||
}
|
||||
})
|
||||
).pipe(
|
||||
first(),
|
||||
concatMap((searchResult: ResultSetPaging) => {
|
||||
if (searchResult.list.entries.length > 0) {
|
||||
savedSearchesNodeId = searchResult.list.entries[0].entry.id;
|
||||
localStorage.setItem(this.currentUserLocalStorageKey, savedSearchesNodeId);
|
||||
} else {
|
||||
return this.createSavedSearchesNode(parentNodeId).pipe(
|
||||
first(),
|
||||
map((node) => {
|
||||
localStorage.setItem(this.currentUserLocalStorageKey, node.entry.id);
|
||||
return node.entry.id;
|
||||
})
|
||||
);
|
||||
}
|
||||
this.savedSearchFileNodeId = savedSearchesNodeId;
|
||||
return savedSearchesNodeId;
|
||||
})
|
||||
)
|
||||
)
|
||||
concatMap((configNode) => {
|
||||
savedSearchesNodeId = configNode.entry.id;
|
||||
localStorage.setItem(this.currentUserLocalStorageKey, savedSearchesNodeId);
|
||||
this.savedSearchFileNodeId = savedSearchesNodeId;
|
||||
return savedSearchesNodeId;
|
||||
}),
|
||||
catchError((error) => {
|
||||
const errorStatusCode = JSON.parse(error.message).error.statusCode;
|
||||
if (errorStatusCode === 404) {
|
||||
return this.createSavedSearchesNode('-my-').pipe(
|
||||
first(),
|
||||
map((node) => {
|
||||
localStorage.setItem(this.currentUserLocalStorageKey, node.entry.id);
|
||||
return node.entry.id;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return throwError(() => error);
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
this.savedSearchFileNodeId = savedSearchesNodeId;
|
||||
return of(savedSearchesNodeId);
|
||||
}
|
||||
}
|
||||
|
||||
private createSavedSearchesNode(parentNodeId: string): Observable<NodeEntry> {
|
||||
return from(this.nodesApi.createNode(parentNodeId, { name: 'config.json', nodeType: 'cm:content' }));
|
||||
}
|
||||
|
@@ -596,7 +596,6 @@ export abstract class BaseQueryBuilderService {
|
||||
* @param searchUrl search url to navigate to
|
||||
*/
|
||||
async navigateToSearch(query: string, searchUrl: string) {
|
||||
this.update();
|
||||
this.userQuery = query;
|
||||
await this.execute();
|
||||
await this.router.navigate([searchUrl], {
|
||||
|
Reference in New Issue
Block a user