mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AE-11486] move search service in alfresco content (#8086)
* [ci:force] move search service in alfresco content * fix * fix md * fix dep * fix demo shell * fix lint
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
import { Subject, BehaviorSubject } from 'rxjs';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SearchService, setupTestBed, DataTableComponent, DataSorting } from '@alfresco/adf-core';
|
||||
import { setupTestBed, DataTableComponent, DataSorting } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../../../search/services/search.service';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { SearchHeaderQueryBuilderService } from './../../../search/services/search-header-query-builder.service';
|
||||
|
@@ -18,10 +18,11 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AddPermissionPanelComponent } from './add-permission-panel.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { SearchService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { of } from 'rxjs';
|
||||
import { fakeAuthorityListResult, fakeNameListResult } from '../../../mock/add-permission.component.mock';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { SearchService } from '../../../search/services/search.service';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatIconTestingModule } from '@angular/material/icon/testing';
|
||||
|
@@ -15,7 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SearchConfigurationService, SearchService } from '@alfresco/adf-core';
|
||||
import { SearchConfigurationService } from '../../../search/services/search-configuration.service';
|
||||
import { SearchService } from '../../../search/services/search.service';
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
import { Component, EventEmitter, Output, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { UntypedFormControl } from '@angular/forms';
|
||||
|
@@ -15,11 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NodesApiService, SearchService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { SearchService } from '../../../search/services/search.service';
|
||||
import { PermissionListComponent } from './permission-list.component';
|
||||
import { NodePermissionService } from '../../services/node-permission.service';
|
||||
import {
|
||||
|
@@ -17,7 +17,8 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { NodePermissionService } from './node-permission.service';
|
||||
import { SearchService, NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../../search/services/search.service';
|
||||
import { Node, PermissionElement } from '@alfresco/js-api';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { fakeEmptyResponse, fakeNodeWithOnlyLocally, fakeSiteRoles, fakeSiteNodeResponse,
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
NodesApiService,
|
||||
SearchService,
|
||||
TranslationService,
|
||||
EcmUserModel
|
||||
} from '@alfresco/adf-core';
|
||||
@@ -31,6 +30,7 @@ import {
|
||||
PermissionElement,
|
||||
QueryBody
|
||||
} from '@alfresco/js-api';
|
||||
import { SearchService } from '../../search/services/search.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { forkJoin, from, Observable, of, throwError } from 'rxjs';
|
||||
import { catchError, map, switchMap } from 'rxjs/operators';
|
||||
|
@@ -20,13 +20,13 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import {
|
||||
AuthenticationService,
|
||||
SearchService,
|
||||
setupTestBed,
|
||||
UserPreferencesService,
|
||||
SearchTextInputComponent
|
||||
} from '@alfresco/adf-core';
|
||||
import { noResult, results } from '../../mock';
|
||||
import { SearchControlComponent } from './search-control.component';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { of } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
@@ -18,7 +18,8 @@
|
||||
import { Subject } from 'rxjs';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SearchService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../../services/search.service';
|
||||
import { SearchHeaderQueryBuilderService } from '../../services/search-header-query-builder.service';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { SEARCH_QUERY_SERVICE_TOKEN } from '../../search-query-service.token';
|
||||
|
@@ -17,7 +17,8 @@
|
||||
|
||||
import { SearchFilterComponent } from './search-filter.component';
|
||||
import { SearchQueryBuilderService } from '../../services/search-query-builder.service';
|
||||
import { AppConfigService, SearchService, TranslationService } from '@alfresco/adf-core';
|
||||
import { AppConfigService, TranslationService } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../../services/search.service';
|
||||
import { Subject } from 'rxjs';
|
||||
import { SearchFilterList } from '../../models/search-filter-list.model';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
@@ -16,7 +16,8 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SearchService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { differentResult, result, SimpleSearchTestComponent } from '../../mock';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
|
@@ -15,7 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SearchService, SearchComponentInterface } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { SearchComponentInterface } from '@alfresco/adf-core';
|
||||
import {
|
||||
AfterContentInit,
|
||||
Component,
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const fakeSearch = {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
totalItems: 1,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
createdByUser: {
|
||||
displayName: 'John Doe'
|
||||
},
|
||||
modifiedByUser: {
|
||||
displayName: 'John Doe'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
export const mockError = {
|
||||
error: {
|
||||
errorKey: 'Search failed',
|
||||
statusCode: 400,
|
||||
briefSummary: '08220082 search failed',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
};
|
||||
|
||||
export const searchMockApi: any = {
|
||||
|
||||
findNodes: () => Promise.resolve(fakeSearch)
|
||||
|
||||
};
|
@@ -30,6 +30,12 @@ export * from './models/search-form.interface';
|
||||
|
||||
export * from './search-query-service.token';
|
||||
export * from './services/search-header-query-builder.service';
|
||||
export * from './services/search-facet-filters.service';
|
||||
export * from './services/search-filter.service';
|
||||
export * from './services/search.service';
|
||||
export * from './services/search-configuration.service';
|
||||
|
||||
export * from './mocks/search.service.mock';
|
||||
|
||||
export * from './components/search.component';
|
||||
export * from './components/search-control.component';
|
||||
@@ -41,7 +47,6 @@ export * from './components/search-check-list/search-check-list.component';
|
||||
export * from './components/search-chip-list/search-chip-list.component';
|
||||
export * from './components/search-date-range/search-date-range.component';
|
||||
export * from './components/search-filter/search-filter.component';
|
||||
export * from './services/search-filter.service';
|
||||
export * from './components/search-filter-container/search-filter-container.component';
|
||||
export * from './components/search-number-range/search-number-range.component';
|
||||
export * from './components/search-radio/search-radio.component';
|
||||
@@ -52,7 +57,6 @@ export * from './components/search-text/search-text.component';
|
||||
export * from './components/search-widget-container/search-widget-container.component';
|
||||
export * from './components/search-datetime-range/search-datetime-range.component';
|
||||
export * from './components/search-form/search-form.component';
|
||||
export * from './services/search-facet-filters.service';
|
||||
export * from './components/search-filter-chips/search-filter-chips.component';
|
||||
export * from './components/search-filter-chips/search-filter-menu-card/search-filter-menu-card.component';
|
||||
export * from './components/search-facet-field/search-facet-field.component';
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { QueryBody } from '@alfresco/js-api';
|
||||
import { SearchConfigurationInterface } from '@alfresco/adf-core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SearchConfigurationService implements SearchConfigurationInterface {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a QueryBody object with custom search parameters.
|
||||
*
|
||||
* @param searchTerm Term text to search for
|
||||
* @param maxResults Maximum number of search results to show in a page
|
||||
* @param skipCount The offset of the start of the page within the results list
|
||||
* @returns Query body defined by the parameters
|
||||
*/
|
||||
generateQueryBody(searchTerm: string, maxResults: number, skipCount: number): QueryBody {
|
||||
const defaultQueryBody: QueryBody = {
|
||||
query: {
|
||||
query: searchTerm ? `'${searchTerm}*' OR name:'${searchTerm}*'` : searchTerm
|
||||
},
|
||||
include: ['path', 'allowableOperations'],
|
||||
paging: {
|
||||
maxItems: maxResults,
|
||||
skipCount
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `TYPE:'cm:folder' OR TYPE:'cm:content'` },
|
||||
{ query: 'NOT cm:creator:System' }]
|
||||
};
|
||||
|
||||
return defaultQueryBody;
|
||||
}
|
||||
}
|
@@ -20,7 +20,8 @@ import { FacetField } from '../models/facet-field.interface';
|
||||
import { Subject } from 'rxjs';
|
||||
import { SEARCH_QUERY_SERVICE_TOKEN } from '../search-query-service.token';
|
||||
import { SearchQueryBuilderService } from './search-query-builder.service';
|
||||
import { SearchService, TranslationService } from '@alfresco/adf-core';
|
||||
import { TranslationService } from '@alfresco/adf-core';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { GenericBucket, GenericFacetResponse, ResultSetContext, ResultSetPaging } from '@alfresco/js-api';
|
||||
import { SearchFilterList } from '../models/search-filter-list.model';
|
||||
|
@@ -0,0 +1,78 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { mockError, fakeSearch } from '../mocks/search.service.mock';
|
||||
import { SearchService } from './search.service';
|
||||
import { setupTestBed, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NodePaging } from '@alfresco/js-api';
|
||||
|
||||
describe('SearchService', () => {
|
||||
|
||||
let service: SearchService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(SearchService);
|
||||
});
|
||||
|
||||
it('should call search API with no additional options', (done) => {
|
||||
const searchTerm = 'searchTerm63688';
|
||||
spyOn(service.queriesApi, 'findNodes').and.returnValue(Promise.resolve(new NodePaging(fakeSearch)));
|
||||
service.getNodeQueryResults(searchTerm).subscribe(
|
||||
() => {
|
||||
expect(service.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should call search API with additional options', (done) => {
|
||||
const searchTerm = 'searchTerm63688';
|
||||
const options = {
|
||||
include: [ 'path' ],
|
||||
rootNodeId: '-root-',
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
spyOn(service.queriesApi, 'findNodes').and.returnValue(Promise.resolve(new NodePaging(fakeSearch)));
|
||||
service.getNodeQueryResults(searchTerm, options).subscribe(
|
||||
() => {
|
||||
expect(service.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, options);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should notify errors returned from the API', (done) => {
|
||||
spyOn(service.queriesApi, 'findNodes').and.returnValue(Promise.reject(mockError));
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
() => {},
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual(mockError);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
140
lib/content-services/src/lib/search/services/search.service.ts
Normal file
140
lib/content-services/src/lib/search/services/search.service.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NodePaging, QueriesApi, QueryBody, ResultSetPaging, SearchApi } from '@alfresco/js-api';
|
||||
import { Observable, Subject, from, throwError } from 'rxjs';
|
||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { SearchConfigurationService } from './search-configuration.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SearchService {
|
||||
|
||||
dataLoaded: Subject<ResultSetPaging> = new Subject();
|
||||
|
||||
private _queriesApi: QueriesApi;
|
||||
get queriesApi(): QueriesApi {
|
||||
this._queriesApi = this._queriesApi ?? new QueriesApi(this.apiService.getInstance());
|
||||
return this._queriesApi;
|
||||
}
|
||||
|
||||
private _searchApi: SearchApi;
|
||||
get searchApi(): SearchApi {
|
||||
this._searchApi = this._searchApi ?? new SearchApi(this.apiService.getInstance());
|
||||
return this._searchApi;
|
||||
}
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private searchConfigurationService: SearchConfigurationService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of nodes that match the given search criteria.
|
||||
*
|
||||
* @param term Term to search for
|
||||
* @param options Options for delivery of the search results
|
||||
* @returns List of nodes resulting from the search
|
||||
*/
|
||||
getNodeQueryResults(term: string, options?: SearchOptions): Observable<NodePaging> {
|
||||
const promise = this.queriesApi.findNodes(term, options);
|
||||
|
||||
promise.then((nodePaging: NodePaging) => {
|
||||
this.dataLoaded.next(nodePaging);
|
||||
}).catch((err) => this.handleError(err));
|
||||
|
||||
return from(promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a search.
|
||||
*
|
||||
* @param searchTerm Term to search for
|
||||
* @param maxResults Maximum number of items in the list of results
|
||||
* @param skipCount Number of higher-ranked items to skip over in the list
|
||||
* @returns List of search results
|
||||
*/
|
||||
search(searchTerm: string, maxResults: number, skipCount: number): Observable<ResultSetPaging> {
|
||||
const searchQuery = Object.assign(this.searchConfigurationService.generateQueryBody(searchTerm, maxResults, skipCount));
|
||||
const promise = this.searchApi.search(searchQuery);
|
||||
|
||||
promise.then((nodePaging: NodePaging) => {
|
||||
this.dataLoaded.next(nodePaging);
|
||||
}).catch((err) => this.handleError(err));
|
||||
|
||||
return from(promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a search with its parameters supplied by a QueryBody object.
|
||||
*
|
||||
* @param queryBody Object containing the search parameters
|
||||
* @returns List of search results
|
||||
*/
|
||||
searchByQueryBody(queryBody: QueryBody): Observable<ResultSetPaging> {
|
||||
const promise = this.searchApi.search(queryBody);
|
||||
|
||||
promise.then((nodePaging: NodePaging) => {
|
||||
this.dataLoaded.next(nodePaging);
|
||||
}).catch((err) => this.handleError(err));
|
||||
|
||||
return from(promise);
|
||||
}
|
||||
|
||||
private handleError(error: any): Observable<any> {
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
||||
export interface SearchOptions {
|
||||
/** The number of entities that exist in the collection before those included in this list. */
|
||||
skipCount?: number;
|
||||
|
||||
/** The maximum number of items to return in the list. */
|
||||
maxItems?: number;
|
||||
|
||||
/** The id of the node to start the search from. Supports the aliases -my-, -root- and -shared-. */
|
||||
rootNodeId?: string;
|
||||
|
||||
/** Restrict the returned results to only those of the given node type and its sub-types. */
|
||||
nodeType?: string;
|
||||
|
||||
/**
|
||||
* Return additional information about the node. The available optional fields are:
|
||||
* `allowableOperations`, `aspectNames`, `isLink`, `isLocked`, `path` and `properties`.
|
||||
*/
|
||||
include?: string[];
|
||||
|
||||
/**
|
||||
* String to control the order of the entities returned in a list. You can use this
|
||||
* parameter to sort the list by one or more fields. Each field has a default sort order,
|
||||
* which is normally ascending order (but see the JS-API docs to check if any fields used
|
||||
* in a method have a descending default search order). To sort the entities in a specific
|
||||
* order, you can use the "ASC" and "DESC" keywords for any field.
|
||||
*/
|
||||
orderBy?: string;
|
||||
|
||||
/**
|
||||
* List of field names. You can use this parameter to restrict the fields returned within
|
||||
* a response if, for example, you want to save on overall bandwidth. The list applies to a
|
||||
* returned individual entity or entries within a collection. If the API method also supports
|
||||
* the `include` parameter, then the fields specified in the include parameter are returned in
|
||||
* addition to those specified in the fields parameter.
|
||||
*/
|
||||
fields?: string[];
|
||||
}
|
Reference in New Issue
Block a user