mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
use people api and new js api where possible (#5888)
* use people api and new js api where possible * fix code and tests * cleanup tests
This commit is contained in:
@@ -76,7 +76,7 @@ export class PropertyGroupTranslatorService {
|
||||
}
|
||||
|
||||
private translate(property: Property, propertyValues: any, constraints: Constraint[]): CardViewItem {
|
||||
let propertyValue;
|
||||
let propertyValue: any;
|
||||
if (propertyValues && propertyValues[property.name]) {
|
||||
propertyValue = propertyValues[property.name];
|
||||
}
|
||||
@@ -94,7 +94,7 @@ export class PropertyGroupTranslatorService {
|
||||
constraints: constraints
|
||||
};
|
||||
|
||||
let cardViewItemProperty;
|
||||
let cardViewItemProperty: CardViewItem;
|
||||
|
||||
if (this.isListOfValues(propertyDefinition.constraints)) {
|
||||
const options = propertyDefinition.constraints[0].parameters.allowedValues.map((value) => ({ key: value, label: value }));
|
||||
@@ -154,7 +154,7 @@ export class PropertyGroupTranslatorService {
|
||||
return definition?.properties.find((item) => item.id === propertyName)?.constraints ?? [];
|
||||
}
|
||||
|
||||
private checkECMTypeValidity(ecmPropertyType) {
|
||||
private checkECMTypeValidity(ecmPropertyType: string) {
|
||||
if (PropertyGroupTranslatorService.RECOGNISED_ECM_TYPES.indexOf(ecmPropertyType) === -1) {
|
||||
this.logService.error(`Unknown type for mapping: ${ecmPropertyType}`);
|
||||
}
|
||||
|
@@ -74,14 +74,14 @@ describe('DocumentList', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
eventMock = {
|
||||
preventDefault: function () {
|
||||
}
|
||||
preventDefault: function () {}
|
||||
};
|
||||
|
||||
fixture = TestBed.createComponent(DocumentListComponent);
|
||||
|
||||
element = fixture.nativeElement;
|
||||
documentList = fixture.componentInstance;
|
||||
|
||||
documentListService = TestBed.inject(DocumentListService);
|
||||
apiService = TestBed.inject(AlfrescoApiService);
|
||||
customResourcesService = TestBed.inject(CustomResourcesService);
|
||||
@@ -101,8 +101,8 @@ describe('DocumentList', () => {
|
||||
documentList.ngOnInit();
|
||||
documentList.currentFolderId = 'no-node';
|
||||
|
||||
spyGetSites = spyOn(apiService.sitesApi, 'getSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer));
|
||||
spyFavorite = spyOn(apiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({ list: { entries: [] } }));
|
||||
spyGetSites = spyOn(customResourcesService.sitesApi, 'listSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer));
|
||||
spyFavorite = spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({ list: { entries: [] } }));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -1287,15 +1287,16 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should fetch trashcan', () => {
|
||||
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(null));
|
||||
const trashcanApi = customResourcesService.trashcanApi;
|
||||
spyOn(trashcanApi, 'listDeletedNodes').and.returnValue(Promise.resolve(null));
|
||||
|
||||
documentList.currentFolderId = '-trashcan-';
|
||||
documentList.loadFolder();
|
||||
expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled();
|
||||
expect(trashcanApi.listDeletedNodes).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit error when fetch trashcan fails', (done) => {
|
||||
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.reject('error'));
|
||||
spyOn(customResourcesService.trashcanApi, 'listDeletedNodes').and.returnValue(Promise.reject('error'));
|
||||
|
||||
const disposableError = documentList.error.subscribe((val) => {
|
||||
expect(val).toBe('error');
|
||||
@@ -1308,17 +1309,16 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should fetch shared links', () => {
|
||||
const sharedlinksApi = apiService.getInstance().core.sharedlinksApi;
|
||||
spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null));
|
||||
const sharedlinksApi = customResourcesService.sharedLinksApi;
|
||||
spyOn(sharedlinksApi, 'listSharedLinks').and.returnValue(Promise.resolve(null));
|
||||
|
||||
documentList.currentFolderId = '-sharedlinks-';
|
||||
documentList.loadFolder();
|
||||
expect(sharedlinksApi.findSharedLinks).toHaveBeenCalled();
|
||||
expect(sharedlinksApi.listSharedLinks).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit error when fetch shared links fails', (done) => {
|
||||
spyOn(apiService.getInstance().core.sharedlinksApi, 'findSharedLinks')
|
||||
.and.returnValue(Promise.reject('error'));
|
||||
spyOn(customResourcesService.sharedLinksApi, 'listSharedLinks').and.returnValue(Promise.reject('error'));
|
||||
|
||||
const disposableError = documentList.error.subscribe((val) => {
|
||||
expect(val).toBe('error');
|
||||
@@ -1331,11 +1331,11 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should fetch sites', () => {
|
||||
const sitesApi = apiService.getInstance().core.sitesApi;
|
||||
const sitesApi = customResourcesService.sitesApi;
|
||||
|
||||
documentList.currentFolderId = '-sites-';
|
||||
documentList.loadFolder();
|
||||
expect(sitesApi.getSites).toHaveBeenCalled();
|
||||
expect(sitesApi.listSites).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit error when fetch sites fails', (done) => {
|
||||
@@ -1352,17 +1352,16 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should fetch user membership sites', () => {
|
||||
const peopleApi = apiService.getInstance().core.peopleApi;
|
||||
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||
const sitesApi = customResourcesService.sitesApi;
|
||||
spyOn(sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||
|
||||
documentList.currentFolderId = '-mysites-';
|
||||
documentList.loadFolder();
|
||||
expect(peopleApi.listSiteMembershipsForPerson).toHaveBeenCalled();
|
||||
expect(sitesApi.listSiteMembershipsForPerson).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit error when fetch membership sites fails', (done) => {
|
||||
spyOn(apiService.getInstance().core.peopleApi, 'listSiteMembershipsForPerson')
|
||||
.and.returnValue(Promise.reject('error'));
|
||||
spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.reject('error'));
|
||||
|
||||
const disposableError = documentList.error.subscribe((val) => {
|
||||
expect(val).toBe('error');
|
||||
@@ -1375,11 +1374,11 @@ describe('DocumentList', () => {
|
||||
});
|
||||
|
||||
it('should fetch favorites', () => {
|
||||
const favoritesApi = apiService.getInstance().core.favoritesApi;
|
||||
const favoritesApi = customResourcesService.favoritesApi;
|
||||
|
||||
documentList.currentFolderId = '-favorites-';
|
||||
documentList.loadFolder();
|
||||
expect(favoritesApi.getFavorites).toHaveBeenCalled();
|
||||
expect(favoritesApi.listFavorites).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit error when fetch favorites fails', (done) => {
|
||||
@@ -1410,9 +1409,7 @@ describe('DocumentList', () => {
|
||||
|
||||
it('should have correct currentFolderId on loading folder by node id', () => {
|
||||
documentList.currentFolderId = '12345-some-id-6789';
|
||||
|
||||
const peopleApi = apiService.getInstance().core.peopleApi;
|
||||
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||
spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||
|
||||
documentList.currentFolderId = '-mysites-';
|
||||
documentList.loadFolder();
|
||||
|
@@ -19,19 +19,18 @@ import { CustomResourcesService } from './custom-resources.service';
|
||||
import { PaginationModel, AlfrescoApiServiceMock, AppConfigService, LogService, AppConfigServiceMock, StorageService } from '@alfresco/adf-core';
|
||||
|
||||
describe('CustomResourcesService', () => {
|
||||
let customActionService: CustomResourcesService;
|
||||
let alfrescoApiService: AlfrescoApiServiceMock;
|
||||
let customResourcesService: CustomResourcesService;
|
||||
|
||||
beforeEach(() => {
|
||||
const logService = new LogService(new AppConfigServiceMock(null));
|
||||
const alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||
|
||||
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||
customActionService = new CustomResourcesService(alfrescoApiService, logService);
|
||||
customResourcesService = new CustomResourcesService(alfrescoApiService, logService);
|
||||
});
|
||||
|
||||
describe('loadFavorites', () => {
|
||||
it('should return a list of items with default properties when target properties does not exist', (done) => {
|
||||
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
||||
spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
@@ -52,7 +51,7 @@ describe('CustomResourcesService', () => {
|
||||
skipCount: 0
|
||||
};
|
||||
|
||||
customActionService.loadFavorites(pagination).subscribe((result) => {
|
||||
customResourcesService.loadFavorites(pagination).subscribe((result) => {
|
||||
expect(result.list.entries).toEqual([
|
||||
{
|
||||
entry: {
|
||||
@@ -70,7 +69,7 @@ describe('CustomResourcesService', () => {
|
||||
});
|
||||
|
||||
it('should return a list of items with merged properties when target properties exist', (done) => {
|
||||
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
||||
spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({
|
||||
list: {
|
||||
entries: [
|
||||
{
|
||||
@@ -94,7 +93,7 @@ describe('CustomResourcesService', () => {
|
||||
skipCount: 0
|
||||
};
|
||||
|
||||
customActionService.loadFavorites(pagination).subscribe((result) => {
|
||||
customResourcesService.loadFavorites(pagination).subscribe((result) => {
|
||||
expect(result.list.entries).toEqual([
|
||||
{
|
||||
entry: {
|
||||
|
@@ -15,36 +15,72 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
LogService,
|
||||
PaginationModel
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core';
|
||||
import {
|
||||
NodePaging,
|
||||
PersonEntry,
|
||||
SitePaging,
|
||||
DeletedNodesPaging,
|
||||
SearchRequest,
|
||||
SharedLinkPaging,
|
||||
FavoritePaging,
|
||||
SiteMemberPaging,
|
||||
SiteRolePaging
|
||||
SiteRolePaging,
|
||||
PeopleApi,
|
||||
SitesApi,
|
||||
SearchApi,
|
||||
FavoritesApi,
|
||||
SharedlinksApi,
|
||||
TrashcanApi,
|
||||
NodesApi
|
||||
} from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, of, throwError } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CustomResourcesService {
|
||||
|
||||
private CREATE_PERMISSION = 'create';
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
private _peopleApi: PeopleApi;
|
||||
private _sitesApi: SitesApi;
|
||||
private _trashcanApi: TrashcanApi;
|
||||
private _searchApi: SearchApi;
|
||||
private _sharedLinksApi: SharedlinksApi;
|
||||
private _favoritesApi: FavoritesApi;
|
||||
private _nodesApi: NodesApi;
|
||||
|
||||
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
|
||||
|
||||
private get api() {
|
||||
return this.apiService.getInstance();
|
||||
}
|
||||
|
||||
get peopleApi(): PeopleApi {
|
||||
return this._peopleApi || (this._peopleApi = new PeopleApi(this.api));
|
||||
}
|
||||
|
||||
get sitesApi(): SitesApi {
|
||||
return this._sitesApi || (this._sitesApi = new SitesApi(this.api));
|
||||
}
|
||||
|
||||
get searchApi(): SearchApi {
|
||||
return this._searchApi || (this._searchApi = new SearchApi(this.api));
|
||||
}
|
||||
|
||||
get favoritesApi(): FavoritesApi {
|
||||
return this._favoritesApi || (this._favoritesApi = new FavoritesApi(this.api));
|
||||
}
|
||||
|
||||
get sharedLinksApi(): SharedlinksApi {
|
||||
return this._sharedLinksApi || (this._sharedLinksApi = new SharedlinksApi(this.api));
|
||||
}
|
||||
|
||||
get trashcanApi(): TrashcanApi {
|
||||
return this._trashcanApi || (this._trashcanApi = new TrashcanApi(this.api));
|
||||
}
|
||||
|
||||
get nodesApi(): NodesApi {
|
||||
return this._nodesApi || (this._nodesApi = new NodesApi(this.api));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,8 +115,8 @@ export class CustomResourcesService {
|
||||
];
|
||||
|
||||
return new Observable((observer) => {
|
||||
this.apiService.peopleApi.getPerson(personId)
|
||||
.then((person: PersonEntry) => {
|
||||
this.peopleApi.getPerson(personId)
|
||||
.then((person) => {
|
||||
const username = person.entry.id;
|
||||
const filterQueries = [
|
||||
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
||||
@@ -94,7 +130,7 @@ export class CustomResourcesService {
|
||||
});
|
||||
}
|
||||
|
||||
const query: SearchRequest = new SearchRequest({
|
||||
const query = new SearchRequest({
|
||||
query: {
|
||||
query: '*',
|
||||
language: 'afts'
|
||||
@@ -111,7 +147,7 @@ export class CustomResourcesService {
|
||||
skipCount: pagination.skipCount
|
||||
}
|
||||
});
|
||||
return this.apiService.searchApi.search(query)
|
||||
return this.searchApi.search(query)
|
||||
.then((searchResult) => {
|
||||
observer.next(searchResult);
|
||||
observer.complete();
|
||||
@@ -147,7 +183,7 @@ export class CustomResourcesService {
|
||||
};
|
||||
|
||||
return new Observable((observer) => {
|
||||
this.apiService.favoritesApi.getFavorites('-me-', options)
|
||||
this.favoritesApi.listFavorites('-me-', options)
|
||||
.then((result: FavoritePaging) => {
|
||||
const page: FavoritePaging = {
|
||||
list: {
|
||||
@@ -195,7 +231,7 @@ export class CustomResourcesService {
|
||||
};
|
||||
|
||||
return new Observable((observer) => {
|
||||
this.apiService.peopleApi.listSiteMembershipsForPerson('-me-', options)
|
||||
this.sitesApi.listSiteMembershipsForPerson('-me-', options)
|
||||
.then((result: SiteRolePaging) => {
|
||||
const page: SiteMemberPaging = new SiteMemberPaging( {
|
||||
list: {
|
||||
@@ -236,8 +272,10 @@ export class CustomResourcesService {
|
||||
};
|
||||
|
||||
return new Observable((observer) => {
|
||||
this.apiService.sitesApi.getSites(options)
|
||||
.then((page: SitePaging) => {
|
||||
this.sitesApi
|
||||
.listSites(options)
|
||||
.then(
|
||||
(page) => {
|
||||
page.list.entries.map(
|
||||
({ entry }: any) => {
|
||||
entry.name = entry.name || entry.title;
|
||||
@@ -269,7 +307,7 @@ export class CustomResourcesService {
|
||||
skipCount: pagination.skipCount
|
||||
};
|
||||
|
||||
return from(this.apiService.nodesApi.getDeletedNodes(options))
|
||||
return from(this.trashcanApi.listDeletedNodes(options))
|
||||
.pipe(catchError((err) => this.handleError(err)));
|
||||
|
||||
}
|
||||
@@ -291,7 +329,7 @@ export class CustomResourcesService {
|
||||
where
|
||||
};
|
||||
|
||||
return from(this.apiService.sharedLinksApi.findSharedLinks(options))
|
||||
return from(this.sharedLinksApi.listSharedLinks(options))
|
||||
.pipe(catchError((err) => this.handleError(err)));
|
||||
}
|
||||
|
||||
@@ -369,7 +407,7 @@ export class CustomResourcesService {
|
||||
|
||||
} else if (nodeId) {
|
||||
// cases when nodeId is '-my-', '-root-' or '-shared-'
|
||||
return from(this.apiService.nodesApi.getNode(nodeId)
|
||||
return from(this.nodesApi.getNode(nodeId)
|
||||
.then((node) => [node.entry.id]));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user