[ADF-5429] Remove old compatibility layer ()

* Remove old compatibility layer
This commit is contained in:
Eugenio Romano 2021-08-10 16:55:18 +02:00 committed by GitHub
parent 1063f5e63e
commit 4c0e6b8861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 21711 additions and 197 deletions

@ -3,7 +3,7 @@ import:
- source: .travis/env.yml
mode: deep_merge_prepend
# =================
# merge anchor
# merge anchor
# =================
dist: bionic
@ -85,7 +85,7 @@ jobs:
name: 'Unit tests: ACA'
script:
- npm ci
- ng test app --code-coverage --watch=false
- ng test app --watch=false
cache: false
- stage: e2e

21504
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -24,9 +24,9 @@
},
"private": true,
"dependencies": {
"@alfresco/adf-content-services": "4.6.0-33193",
"@alfresco/adf-core": "4.6.0-33193",
"@alfresco/adf-extensions": "4.6.0-33193",
"@alfresco/adf-content-services": "4.6.0-33212",
"@alfresco/adf-core": "4.6.0-33212",
"@alfresco/adf-extensions": "4.6.0-33212",
"@alfresco/js-api": "4.6.0-3694",
"@angular/animations": "10.0.4",
"@angular/cdk": "^10.0.2",
@ -56,8 +56,8 @@
"zone.js": "~0.10.2"
},
"devDependencies": {
"@alfresco/adf-cli": "4.6.0-33193",
"@alfresco/adf-testing": "4.6.0-33193",
"@alfresco/adf-cli": "4.6.0-33212",
"@alfresco/adf-testing": "4.6.0-33212",
"@angular-custom-builders/lite-serve": "^0.2.3",
"@angular-devkit/build-angular": "^0.1002.0",
"@angular-devkit/build-ng-packagr": "^0.1002.0",

@ -25,7 +25,7 @@
import { AppService } from './app.service';
import { TestBed } from '@angular/core/testing';
import { AuthenticationService, AppConfigService } from '@alfresco/adf-core';
import { AuthenticationService, AppConfigService, AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import { HttpClientModule } from '@angular/common/http';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
@ -40,6 +40,7 @@ describe('AppService', () => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
SearchQueryBuilderService,
{
provide: AuthenticationService,

@ -41,7 +41,16 @@ import {
SiteBody,
SiteEntry,
FavoriteBody,
FavoriteEntry
FavoriteEntry,
NodesApi,
TrashcanApi,
SharedlinksApi,
DiscoveryApi,
FavoritesApi,
ContentApi,
SitesApi,
SearchApi,
PeopleApi
} from '@alfresco/js-api';
import { map } from 'rxjs/operators';
@ -49,7 +58,27 @@ import { map } from 'rxjs/operators';
providedIn: 'root'
})
export class ContentApiService {
constructor(private api: AlfrescoApiService, private preferences: UserPreferencesService) {}
private nodesApi: NodesApi;
private trashcanApi: TrashcanApi;
private sharedLinksApi: SharedlinksApi;
private discoveryApi: DiscoveryApi;
private favoritesApi: FavoritesApi;
private contentApi: ContentApi;
private sitesApi: SitesApi;
private searchApi: SearchApi;
private peopleApi: PeopleApi;
constructor(private api: AlfrescoApiService, private preferences: UserPreferencesService) {
this.nodesApi = new NodesApi(this.api.getInstance());
this.trashcanApi = new TrashcanApi(this.api.getInstance());
this.sharedLinksApi = new SharedlinksApi(this.api.getInstance());
this.discoveryApi = new DiscoveryApi(this.api.getInstance());
this.favoritesApi = new FavoritesApi(this.api.getInstance());
this.contentApi = new ContentApi(this.api.getInstance());
this.sitesApi = new SitesApi(this.api.getInstance());
this.searchApi = new SearchApi(this.api.getInstance());
this.peopleApi = new PeopleApi(this.api.getInstance());
}
/**
* Moves a node to the trashcan.
@ -58,7 +87,7 @@ export class ContentApiService {
* @returns Empty result that notifies when the deletion is complete
*/
deleteNode(nodeId: string, options: { permanent?: boolean } = {}): Observable<void> {
return from(this.api.nodesApi.deleteNode(nodeId, options));
return from(this.nodesApi.deleteNode(nodeId, options));
}
/**
@ -73,7 +102,7 @@ export class ContentApiService {
};
const queryOptions = Object.assign(defaults, options);
return from(this.api.nodesApi.getNode(nodeId, queryOptions));
return from(this.nodesApi.getNode(nodeId, queryOptions));
}
getNodeInfo(nodeId: string, options?: any): Observable<Node> {
@ -82,7 +111,19 @@ export class ContentApiService {
};
const queryOptions = Object.assign(defaults, options || {});
return from(this.api.nodesApi.getNodeInfo(nodeId, queryOptions));
// @ts-ignore
return from(
new Promise((resolve, reject) => {
this.nodesApi.getNode(nodeId, queryOptions).then(
(nodeEntry: NodeEntry) => {
resolve(nodeEntry.entry);
},
(error) => {
reject(error);
}
);
})
);
}
/**
@ -99,11 +140,11 @@ export class ContentApiService {
};
const queryOptions = Object.assign(defaults, options);
return from(this.api.nodesApi.getNodeChildren(nodeId, queryOptions));
return from(this.nodesApi.listNodeChildren(nodeId, queryOptions));
}
deleteSharedLink(linkId: string): Observable<any> {
return from(this.api.sharedLinksApi.deleteSharedLink(linkId));
return from(this.sharedLinksApi.deleteSharedLink(linkId));
}
getDeletedNodes(options: any = {}): Observable<DeletedNodesPaging> {
@ -112,15 +153,15 @@ export class ContentApiService {
};
const queryOptions = Object.assign(defaults, options);
return from(this.api.nodesApi.getDeletedNodes(queryOptions));
return from(this.trashcanApi.listDeletedNodes(queryOptions));
}
restoreNode(nodeId: string): Observable<MinimalNodeEntity> {
return from(this.api.nodesApi.restoreNode(nodeId));
return from(this.trashcanApi.restoreDeletedNode(nodeId));
}
purgeDeletedNode(nodeId: string): Observable<any> {
return from(this.api.nodesApi.purgeDeletedNode(nodeId));
return from(this.trashcanApi.deleteDeletedNode(nodeId));
}
/**
@ -130,7 +171,7 @@ export class ContentApiService {
* @returns User information
*/
getPerson(personId: string, options?: { fields?: Array<string> }): Observable<PersonEntry> {
return from(this.api.peopleApi.getPerson(personId, options));
return from(this.peopleApi.getPerson(personId, options));
}
/**
@ -142,7 +183,7 @@ export class ContentApiService {
* @param opts Api options
*/
copyNode(nodeId: string, targetParentId: string, name?: string, opts?: { include?: Array<string>; fields?: Array<string> }): Observable<NodeEntry> {
return from(this.api.nodesApi.copyNode(nodeId, { targetParentId, name }, opts));
return from(this.nodesApi.copyNode(nodeId, { targetParentId, name }, opts));
}
/**
@ -150,7 +191,7 @@ export class ContentApiService {
* @returns ProductVersionModel containing product details
*/
getRepositoryInformation(): Observable<DiscoveryEntry> {
return from(this.api.getInstance().discovery.discoveryApi.getRepositoryInformation());
return from(this.discoveryApi.getRepositoryInformation());
}
getFavorites(
@ -162,7 +203,7 @@ export class ContentApiService {
fields?: Array<string>;
}
): Observable<FavoritePaging> {
return from(this.api.favoritesApi.getFavorites(personId, opts));
return from(this.favoritesApi.listFavorites(personId, opts));
}
getFavoriteLibraries(personId: string = '-me-', opts?: any): Observable<FavoritePaging> {
@ -187,31 +228,31 @@ export class ContentApiService {
}
findSharedLinks(opts?: any): Observable<SharedLinkPaging> {
return from(this.api.sharedLinksApi.findSharedLinks(opts));
return from(this.sharedLinksApi.listSharedLinks(opts));
}
getSharedLinkContent(sharedId: string, attachment?: boolean): string {
return this.api.contentApi.getSharedLinkContentUrl(sharedId, attachment);
return this.contentApi.getSharedLinkContentUrl(sharedId, attachment);
}
search(request: SearchRequest): Observable<ResultSetPaging> {
return from(this.api.searchApi.search(request));
return from(this.searchApi.search(request));
}
getContentUrl(nodeId: string, attachment?: boolean): string {
return this.api.contentApi.getContentUrl(nodeId, attachment);
return this.contentApi.getContentUrl(nodeId, attachment);
}
getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean): string {
return this.api.contentApi.getVersionContentUrl(nodeId, versionId, attachment);
return this.contentApi.getVersionContentUrl(nodeId, versionId, attachment);
}
deleteSite(siteId?: string, opts?: { permanent?: boolean }): Observable<any> {
return from(this.api.sitesApi.deleteSite(siteId, opts));
return from(this.sitesApi.deleteSite(siteId, opts));
}
leaveSite(siteId?: string): Observable<any> {
return from(this.api.sitesApi.removeSiteMember(siteId, '-me-'));
return from(this.sitesApi.deleteSiteMembership(siteId, '-me-'));
}
createSite(
@ -222,15 +263,15 @@ export class ContentApiService {
skipAddToFavorites?: boolean;
}
): Observable<SiteEntry> {
return from(this.api.sitesApi.createSite(siteBody, opts));
return from(this.sitesApi.createSite(siteBody, opts));
}
getSite(siteId?: string, opts?: { relations?: Array<string>; fields?: Array<string> }): Observable<SiteEntry> {
return from(this.api.sitesApi.getSite(siteId, opts));
return from(this.sitesApi.getSite(siteId, opts));
}
updateLibrary(siteId: string, siteBody: SiteBody): Observable<SiteEntry> {
return from(this.api.sitesApi.updateSite(siteId, siteBody));
return from(this.sitesApi.updateSite(siteId, siteBody));
}
addFavorite(nodes: Array<MinimalNodeEntity>): Observable<FavoriteEntry> {
@ -249,7 +290,7 @@ export class ContentApiService {
};
});
return from(this.api.favoritesApi.addFavorite('-me-', payload as any));
return from(this.favoritesApi.createFavorite('-me-', payload as any));
}
removeFavorite(nodes: Array<MinimalNodeEntity>): Observable<any> {
@ -257,13 +298,13 @@ export class ContentApiService {
Promise.all(
nodes.map((node: any) => {
const id = node.entry.nodeId || node.entry.id;
return this.api.favoritesApi.removeFavoriteSite('-me-', id);
return this.favoritesApi.deleteFavorite('-me-', id);
})
)
);
}
unlockNode(nodeId: string, opts?: any) {
return this.api.nodesApi.unlockNode(nodeId, opts);
return this.nodesApi.unlockNode(nodeId, opts);
}
}

@ -29,12 +29,10 @@ import { UpdateLibraryAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Site, SitePaging } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
describe('LibraryMetadataFormComponent', () => {
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
let component: LibraryMetadataFormComponent;
let alfrescoApiService: AlfrescoApiService;
let store: Store<any>;
beforeEach(() => {
@ -53,7 +51,6 @@ describe('LibraryMetadataFormComponent', () => {
});
store = TestBed.inject(Store);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
fixture = TestBed.createComponent(LibraryMetadataFormComponent);
component = fixture.componentInstance;
@ -214,7 +211,7 @@ describe('LibraryMetadataFormComponent', () => {
it('should warn if library name input is used by another library', fakeAsync(() => {
const title = 'some-title';
spyOn(alfrescoApiService.getInstance().core.queriesApi, 'findSites').and.returnValue(
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { title } }] }
} as SitePaging)
@ -242,7 +239,7 @@ describe('LibraryMetadataFormComponent', () => {
}));
it('should not warn if library name input is the same with library node data', fakeAsync(() => {
spyOn(alfrescoApiService.getInstance().core.queriesApi, 'findSites').and.returnValue(
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { title: 'libraryTitle' } }] }
} as SitePaging)
@ -270,7 +267,7 @@ describe('LibraryMetadataFormComponent', () => {
}));
it('should not warn if library name is unique', fakeAsync(() => {
spyOn(alfrescoApiService.getInstance().core.queriesApi, 'findSites').and.returnValue(
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [] }
} as SitePaging)

@ -25,7 +25,7 @@
import { Component, Input, OnInit, OnChanges, OnDestroy } from '@angular/core';
import { FormGroup, FormControl, Validators, FormGroupDirective, NgForm } from '@angular/forms';
import { SiteEntry, SitePaging } from '@alfresco/js-api';
import { QueriesApi, SiteEntry, SitePaging } from '@alfresco/js-api';
import { Store } from '@ngrx/store';
import { AppStore, UpdateLibraryAction } from '@alfresco/aca-shared/store';
import { debounceTime, mergeMap, takeUntil } from 'rxjs/operators';
@ -45,6 +45,8 @@ export class InstantErrorStateMatcher implements ErrorStateMatcher {
templateUrl: './library-metadata-form.component.html'
})
export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestroy {
private queriesApi: QueriesApi;
@Input()
node: SiteEntry;
@ -68,7 +70,9 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro
onDestroy$: Subject<boolean> = new Subject<boolean>();
constructor(private alfrescoApiService: AlfrescoApiService, protected store: Store<AppStore>) {}
constructor(private alfrescoApiService: AlfrescoApiService, protected store: Store<AppStore>) {
this.queriesApi = new QueriesApi(this.alfrescoApiService.getInstance());
}
get canUpdateLibrary() {
return this.node && this.node.entry && this.node.entry.role === 'SiteManager';
@ -139,9 +143,8 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro
private findLibraryByTitle(libraryTitle: string): Observable<SitePaging | { list: { entries: any[] } }> {
return from(
this.alfrescoApiService
.getInstance()
.core.queriesApi.findSites(libraryTitle, {
this.queriesApi
.findSites(libraryTitle, {
maxItems: 1,
fields: ['title']
})

@ -32,11 +32,13 @@ import { LibrariesComponent } from './libraries.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { EffectsModule } from '@ngrx/effects';
import { LibraryEffects } from '../../store/effects';
import { ContentApiService } from '@alfresco/aca-shared';
describe('LibrariesComponent', () => {
let fixture: ComponentFixture<LibrariesComponent>;
let component: LibrariesComponent;
let alfrescoApi: AlfrescoApiService;
let contentApiService: ContentApiService;
let router: Router;
let page;
@ -60,11 +62,14 @@ describe('LibrariesComponent', () => {
component = fixture.componentInstance;
alfrescoApi = TestBed.inject(AlfrescoApiService);
contentApiService = TestBed.inject(ContentApiService);
alfrescoApi.reset();
router = TestBed.inject(Router);
spyOn(alfrescoApi.sitesApi, 'getSites').and.returnValue(Promise.resolve(page));
spyOn(alfrescoApi.peopleApi, 'getSiteMembership').and.returnValue(Promise.resolve({}));
const sitesApi: any = contentApiService['sitesApi'];
spyOn(sitesApi, 'listSites').and.returnValue(Promise.resolve(page));
spyOn(sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve({}));
});
describe('Node navigation', () => {

@ -41,8 +41,8 @@ describe('SearchLibrariesQueryBuilderService', () => {
apiService = TestBed.inject(AlfrescoApiService);
apiService.reset();
queriesApi = apiService.getInstance().core.queriesApi;
builder = new SearchLibrariesQueryBuilderService(apiService);
queriesApi = builder['queriesApi'];
});
it('should have empty user query by default', () => {

@ -25,7 +25,7 @@
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { SitePaging } from '@alfresco/js-api';
import { QueriesApi, SitePaging } from '@alfresco/js-api';
import { Subject } from 'rxjs';
export interface LibrarySearchQuery {
@ -41,6 +41,7 @@ export interface LibrarySearchQuery {
})
export class SearchLibrariesQueryBuilderService {
private _userQuery = '';
private queriesApi: QueriesApi;
updated: Subject<any> = new Subject();
executed: Subject<any> = new Subject();
@ -56,7 +57,9 @@ export class SearchLibrariesQueryBuilderService {
this._userQuery = value ? value.trim() : '';
}
constructor(private alfrescoApiService: AlfrescoApiService) {}
constructor(private alfrescoApiService: AlfrescoApiService) {
this.queriesApi = new QueriesApi(this.alfrescoApiService.getInstance());
}
update(): void {
const query = this.buildQuery();
@ -89,12 +92,9 @@ export class SearchLibrariesQueryBuilderService {
}
private findLibraries(libraryQuery: LibrarySearchQuery): Promise<SitePaging> {
return this.alfrescoApiService
.getInstance()
.core.queriesApi.findSites(libraryQuery.term, libraryQuery.opts)
.catch((err) => {
this.hadError.next(err);
return { list: { pagination: { totalItems: 0 }, entries: [] } };
});
return this.queriesApi.findSites(libraryQuery.term, libraryQuery.opts).catch((err) => {
this.hadError.next(err);
return { list: { pagination: { totalItems: 0 }, entries: [] } };
});
}
}

@ -27,7 +27,7 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
import { SearchResultsComponent } from './search-results.component';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppSearchResultsModule } from '../search-results.module';
import { AlfrescoApiService, AppConfigService, CoreModule, TranslationService } from '@alfresco/adf-core';
import { AppConfigService, CoreModule, TranslationService } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { NavigateToFolder, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { Pagination, SearchRequest } from '@alfresco/js-api';
@ -42,7 +42,6 @@ describe('SearchComponent', () => {
let config: AppConfigService;
let store: Store<any>;
let queryBuilder: SearchQueryBuilderService;
let alfrescoApi: AlfrescoApiService;
let translate: TranslationService;
let router: Router;
const searchRequest = {} as SearchRequest;
@ -70,7 +69,6 @@ describe('SearchComponent', () => {
config = TestBed.inject(AppConfigService);
store = TestBed.inject(Store);
queryBuilder = TestBed.inject(SearchQueryBuilderService);
alfrescoApi = TestBed.inject(AlfrescoApiService);
translate = TestBed.inject(TranslationService);
router = TestBed.inject(Router);
@ -91,7 +89,7 @@ describe('SearchComponent', () => {
});
it('should raise an error if search fails', fakeAsync(() => {
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 500 } } `
})
@ -114,7 +112,7 @@ describe('SearchComponent', () => {
return key;
});
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 401 } } `
})
@ -137,7 +135,7 @@ describe('SearchComponent', () => {
return key;
});
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
spyOn(queryBuilder['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 401 } } `
})

@ -30,14 +30,12 @@ import { AppTestingModule } from '../../testing/app-testing.module';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { AppExtensionService } from '@alfresco/aca-shared';
describe('SharedLinkViewComponent', () => {
let component: SharedLinkViewComponent;
let fixture: ComponentFixture<SharedLinkViewComponent>;
let alfrescoApiService: AlfrescoApiService;
let appExtensionService: AppExtensionService;
let spyGetSharedLink;
const storeMock = {
@ -52,14 +50,6 @@ describe('SharedLinkViewComponent', () => {
providers: [
AppExtensionService,
{ provide: Store, useValue: storeMock },
{
provide: AlfrescoApiService,
useValue: {
sharedLinksApi: {
getSharedLink: () => {}
}
}
},
{
provide: ActivatedRoute,
useValue: {
@ -73,10 +63,9 @@ describe('SharedLinkViewComponent', () => {
fixture = TestBed.createComponent(SharedLinkViewComponent);
component = fixture.componentInstance;
alfrescoApiService = TestBed.inject(AlfrescoApiService);
appExtensionService = TestBed.inject(AppExtensionService);
spyGetSharedLink = spyOn(alfrescoApiService.sharedLinksApi, 'getSharedLink');
spyGetSharedLink = spyOn(component['sharedLinksApi'], 'getSharedLink');
storeMock.dispatch.calls.reset();
});

@ -26,7 +26,7 @@
import { AppStore, SetSelectedNodesAction, getAppSelection } from '@alfresco/aca-shared/store';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { SharedLinkEntry } from '@alfresco/js-api';
import { SharedLinkEntry, SharedlinksApi } from '@alfresco/js-api';
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
@ -42,6 +42,7 @@ import { AppExtensionService } from '@alfresco/aca-shared';
host: { class: 'app-shared-link-view' }
})
export class SharedLinkViewComponent implements OnInit {
private sharedLinksApi: SharedlinksApi;
sharedLinkId: string = null;
viewerToolbarActions: Array<ContentActionRef> = [];
@ -50,15 +51,15 @@ export class SharedLinkViewComponent implements OnInit {
private store: Store<AppStore>,
private extensions: AppExtensionService,
private alfrescoApiService: AlfrescoApiService
) {}
) {
this.sharedLinksApi = new SharedlinksApi(this.alfrescoApiService.getInstance());
}
ngOnInit() {
this.route.params
.pipe(
mergeMap((params) =>
forkJoin([from(this.alfrescoApiService.sharedLinksApi.getSharedLink(params.id)), of(params.id)]).pipe(
catchError(() => of([null, params.id]))
)
forkJoin([from(this.sharedLinksApi.getSharedLink(params.id)), of(params.id)]).pipe(catchError(() => of([null, params.id])))
)
)
.subscribe(([sharedEntry, sharedId]: [SharedLinkEntry, string]) => {

@ -24,7 +24,7 @@
*/
import { AppStore, DownloadNodesAction, EditOfflineAction, SnackbarErrorAction, getAppSelection } from '@alfresco/aca-shared/store';
import { MinimalNodeEntity, NodeEntry, SharedLinkEntry, Node } from '@alfresco/js-api';
import { MinimalNodeEntity, NodeEntry, SharedLinkEntry, Node, NodesApi } from '@alfresco/js-api';
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Store } from '@ngrx/store';
import { isLocked } from '@alfresco/aca-shared';
@ -53,9 +53,12 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
host: { class: 'app-toggle-edit-offline' }
})
export class ToggleEditOfflineComponent implements OnInit {
private nodesApi: NodesApi;
selection: MinimalNodeEntity;
constructor(private store: Store<AppStore>, private alfrescoApiService: AlfrescoApiService) {}
constructor(private store: Store<AppStore>, private alfrescoApiService: AlfrescoApiService) {
this.nodesApi = new NodesApi(this.alfrescoApiService.getInstance());
}
ngOnInit() {
this.store.select(getAppSelection).subscribe(({ file }) => {
@ -113,14 +116,14 @@ export class ToggleEditOfflineComponent implements OnInit {
}
lockNode(nodeId: string) {
return this.alfrescoApiService.nodesApi.lockNode(nodeId, {
return this.nodesApi.lockNode(nodeId, {
type: 'ALLOW_OWNER_CHANGES',
lifetime: 'PERSISTENT'
});
}
unlockNode(nodeId: string) {
return this.alfrescoApiService.nodesApi.unlockNode(nodeId);
return this.nodesApi.unlockNode(nodeId);
}
private update(data: Node) {

@ -24,7 +24,7 @@
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AlfrescoApiService, CoreModule } from '@alfresco/adf-core';
import { CoreModule } from '@alfresco/adf-core';
import { ToggleFavoriteLibraryComponent } from './toggle-favorite-library.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Store } from '@ngrx/store';
@ -32,12 +32,13 @@ import { AppTestingModule } from '../../../testing/app-testing.module';
import { of } from 'rxjs';
import { Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { AppHookService } from '@alfresco/aca-shared';
import { AppHookService, ContentApiService } from '@alfresco/aca-shared';
describe('ToggleFavoriteLibraryComponent', () => {
let fixture: ComponentFixture<ToggleFavoriteLibraryComponent>;
let component: ToggleFavoriteLibraryComponent;
let appHookService: AppHookService;
let contentApiService: any;
const selection = { library: { entry: { id: 'libraryId' } } };
const mockRouter = {
@ -68,10 +69,10 @@ describe('ToggleFavoriteLibraryComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ToggleFavoriteLibraryComponent);
component = fixture.componentInstance;
contentApiService = TestBed.inject(ContentApiService);
appHookService = TestBed.inject(AppHookService);
const api = TestBed.inject(AlfrescoApiService);
spyOn(api.peopleApi, 'getFavoriteSite').and.returnValue(Promise.resolve(null));
spyOn(contentApiService['favoritesApi'], 'getFavoriteSite').and.returnValue(Promise.resolve(null));
});
it('should get library selection from Store', async () => {

@ -25,19 +25,19 @@
import { of } from 'rxjs';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AlfrescoApiService, DirectiveModule } from '@alfresco/adf-core';
import { DirectiveModule } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { SnackbarErrorAction, SnackbarInfoAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { ToggleJoinLibraryButtonComponent } from './toggle-join-library-button.component';
import { AppHookService } from '@alfresco/aca-shared';
import { AppHookService, ContentApiService } from '@alfresco/aca-shared';
describe('ToggleJoinLibraryComponent', () => {
let component: ToggleJoinLibraryButtonComponent;
let fixture: ComponentFixture<ToggleJoinLibraryButtonComponent>;
let alfrescoApi: AlfrescoApiService;
let appHookService: AppHookService;
let contentApiService: any;
let store: Store<any>;
let entry;
@ -65,13 +65,12 @@ describe('ToggleJoinLibraryComponent', () => {
});
store = TestBed.inject(Store);
alfrescoApi = TestBed.inject(AlfrescoApiService);
appHookService = TestBed.inject(AppHookService);
spyOn(alfrescoApi.peopleApi, 'getSiteMembershipRequest').and.stub();
contentApiService = TestBed.inject(ContentApiService);
fixture = TestBed.createComponent(ToggleJoinLibraryButtonComponent);
component = fixture.componentInstance;
spyOn(contentApiService['sitesApi'], 'getSiteMembershipRequestForPerson').and.stub();
});
afterEach(() => {

@ -64,6 +64,6 @@ describe('TrashcanComponent', () => {
});
beforeEach(() => {
spyOn(alfrescoApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(page));
spyOn(component['nodesApi'], 'getDeletedNodes').and.returnValue(Promise.resolve(page));
});
});

@ -37,7 +37,7 @@ import {
ViewNodeAction
} from '@alfresco/aca-shared/store';
import { ContentActionRef, SelectionState } from '@alfresco/adf-extensions';
import { MinimalNodeEntryEntity, SearchRequest, VersionEntry } from '@alfresco/js-api';
import { MinimalNodeEntryEntity, SearchRequest, VersionEntry, VersionsApi } from '@alfresco/js-api';
import { Component, HostListener, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, PRIMARY_OUTLET, Router } from '@angular/router';
import { AlfrescoApiService, ObjectUtils, UploadService, UserPreferencesService } from '@alfresco/adf-core';
@ -54,6 +54,8 @@ import { Actions, ofType } from '@ngrx/effects';
host: { class: 'app-viewer' }
})
export class AppViewerComponent implements OnInit, OnDestroy {
private versionsApi: VersionsApi;
onDestroy$ = new Subject<boolean>();
fileName: string;
@ -113,7 +115,9 @@ export class AppViewerComponent implements OnInit, OnDestroy {
private apiService: AlfrescoApiService,
private uploadService: UploadService,
private appHookService: AppHookService
) {}
) {
this.versionsApi = new VersionsApi(apiService.getInstance());
}
ngOnInit() {
this.infoDrawerOpened$ = this.store.select(isInfoDrawerOpened);
@ -144,7 +148,7 @@ export class AppViewerComponent implements OnInit, OnDestroy {
const { nodeId } = params;
this.versionId = params.versionId;
if (this.versionId) {
this.apiService.versionsApi.getVersion(nodeId, this.versionId).then((version: VersionEntry) => {
this.versionsApi.getVersion(nodeId, this.versionId).then((version: VersionEntry) => {
if (version) {
this.store.dispatch(new SetCurrentNodeVersionAction(version));
}

@ -61,9 +61,9 @@ describe('NodeActionsService', () => {
const permissionError = new Error(JSON.stringify({ error: { statusCode: 403 } }));
const badRequestError = new Error(JSON.stringify({ error: { statusCode: 400 } }));
const emptyChildrenList = { list: { entries: [] } };
let service: NodeActionsService;
let service: any;
let apiService: AlfrescoApiService;
let nodesApi;
let nodesApi: any;
let spyOnSuccess: jasmine.Spy;
let spyOnError: jasmine.Spy;
let contentApi: ContentApiService;
@ -112,7 +112,7 @@ describe('NodeActionsService', () => {
dialog = TestBed.inject(MatDialog);
apiService.reset();
nodesApi = apiService.getInstance().nodes;
nodesApi = service['nodesApi'];
});
describe('ContentNodeSelector configuration', () => {
@ -585,7 +585,7 @@ describe('NodeActionsService', () => {
nodeChildren: [existingFolder]
}
];
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(service, 'getChildByName').and.returnValue(of(existingFolder) as any);
copyObservable
@ -631,7 +631,7 @@ describe('NodeActionsService', () => {
nodeChildren: [existingFolder]
}
];
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(service, 'getChildByName').and.returnValue(of({}) as any);
copyObservable
@ -673,7 +673,7 @@ describe('NodeActionsService', () => {
nodeChildren: [existingFolder]
}
];
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(service, 'getChildByName').and.returnValue(of(existingFolder) as any);
copyObservable
@ -861,7 +861,7 @@ describe('NodeActionsService', () => {
const subject$ = new Subject<NodeChildAssociationEntry>();
spyOn(service, 'getChildByName').and.returnValue(subject$);
spyOn(service, 'getNodeChildren').and.returnValue(of(emptyChildrenList));
spyOn(nodesApi, 'listNodeChildren').and.returnValue(of(emptyChildrenList));
service.moveFolderAction(folderToMove.entry, folderDestinationId).subscribe(spyOnSuccess, spyOnError);
@ -885,7 +885,7 @@ describe('NodeActionsService', () => {
const subject$ = new Subject<NodeChildAssociationEntry>();
spyOn(service, 'getChildByName').and.returnValue(subject$);
const childrenNodes = [fileToMove, folderToMove];
spyOn(service, 'getNodeChildren').and.returnValue(of({ list: { entries: childrenNodes } }));
spyOn(nodesApi, 'listNodeChildren').and.returnValue(of({ list: { entries: childrenNodes } }));
service.moveFolderAction(parentFolderToMove.entry, folderDestinationId).subscribe(spyOnSuccess, spyOnError);
subject$.next(newDestination);
@ -1019,7 +1019,7 @@ describe('NodeActionsService', () => {
});
it('emits child node with specified name, when it exists in folder', (done) => {
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
service.getChildByName(testFamilyNodes[0].parentNodeId, childNode.entry.name).subscribe((value) => {
expect(value).toEqual(childNode);
@ -1028,7 +1028,7 @@ describe('NodeActionsService', () => {
});
it('emits null value when child with specified name is not found in folder', (done) => {
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes));
service.getChildByName(testFamilyNodes[0].parentNodeId, notChildNode.entry.name).subscribe((value) => {
expect(value).toEqual(null);
@ -1037,7 +1037,7 @@ describe('NodeActionsService', () => {
});
it('emits error when permission error occurs', (done) => {
spyOn(nodesApi, 'getNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes, actionIsForbidden));
spyOn(nodesApi, 'listNodeChildren').and.callFake(helper.fakeGetNodeChildren(testFamilyNodes, actionIsForbidden));
service.getChildByName(testFamilyNodes[0].parentNodeId, notChildNode.entry.name).subscribe(
() => {},

@ -35,7 +35,14 @@ import {
ShareDataRow,
NodeAction
} from '@alfresco/adf-content-services';
import { MinimalNodeEntity, MinimalNodeEntryEntity, SitePaging, NodeChildAssociationPaging, NodeChildAssociationEntry } from '@alfresco/js-api';
import {
MinimalNodeEntity,
MinimalNodeEntryEntity,
SitePaging,
NodeChildAssociationPaging,
NodeChildAssociationEntry,
NodesApi
} from '@alfresco/js-api';
import { ContentApiService } from '@alfresco/aca-shared';
import { catchError, map, mergeMap } from 'rxjs/operators';
@ -50,6 +57,8 @@ export class NodeActionsService {
moveDeletedEntries: any[] = [];
isSitesDestinationAvailable = false;
private nodesApi: NodesApi;
constructor(
private contentService: ContentService,
private contentApi: ContentApiService,
@ -58,7 +67,9 @@ export class NodeActionsService {
private apiService: AlfrescoApiService,
private translation: TranslationService,
private thumbnailService: ThumbnailService
) {}
) {
this.nodesApi = new NodesApi(this.apiService.getInstance());
}
/**
* Copy node list
@ -595,7 +606,7 @@ export class NodeActionsService {
* @param params optional parameters
*/
getNodeChildren(nodeId: string, params?: any): Observable<NodeChildAssociationPaging> {
return from(this.apiService.getInstance().nodes.getNodeChildren(nodeId, params));
return from(this.nodesApi.listNodeChildren(nodeId, params));
}
// Copied from ADF document-list.service, and added the name parameter
@ -607,7 +618,7 @@ export class NodeActionsService {
* @param name The new name for the copy that would be added on the destination folder
*/
copyNode(nodeId: string, targetParentId: string, name?: string) {
return from(this.apiService.getInstance().nodes.copyNode(nodeId, { targetParentId, name }));
return from(this.nodesApi.copyNode(nodeId, { targetParentId, name }));
}
public flatten(nDimArray: any[]) {

@ -30,14 +30,12 @@ import { TemplateEffects } from '../store/effects/template.effects';
import { AppTestingModule } from '../testing/app-testing.module';
import { Store } from '@ngrx/store';
import { MatDialog } from '@angular/material/dialog';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { NodeTemplateService } from './node-template.service';
import { ResultSetPaging } from '@alfresco/js-api';
describe('NodeTemplateService', () => {
let dialog: MatDialog;
let store: Store<AppStore>;
let alfrescoApiService: AlfrescoApiService;
let nodeTemplateService: NodeTemplateService;
const fileTemplateConfig = {
primaryPathName: 'parent-file-templates',
@ -55,13 +53,12 @@ describe('NodeTemplateService', () => {
});
store = TestBed.inject(Store);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
dialog = TestBed.inject(MatDialog);
nodeTemplateService = TestBed.inject(NodeTemplateService);
});
it('should open dialog with parent node `id` as data property', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'parent-node-id' } }] }
} as ResultSetPaging)
@ -75,7 +72,7 @@ describe('NodeTemplateService', () => {
}));
it('should remove parents path for templates breadcrumb', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [
@ -115,7 +112,7 @@ describe('NodeTemplateService', () => {
}));
it('should set template folder path as root for breadcrumb', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [
@ -156,7 +153,7 @@ describe('NodeTemplateService', () => {
}));
it('should raise an error when getNodeInfo fails', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.reject({
message: `{ "error": { "statusCode": 404 } } `
})
@ -170,7 +167,7 @@ describe('NodeTemplateService', () => {
}));
it('should return true if row is not a `link` nodeType', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [
@ -200,7 +197,7 @@ describe('NodeTemplateService', () => {
}));
it('should return false if row is a `filelink` nodeType', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [
@ -230,7 +227,7 @@ describe('NodeTemplateService', () => {
}));
it('should return false if row is a `folderlink` nodeType', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [
@ -261,7 +258,7 @@ describe('NodeTemplateService', () => {
describe('File templates', () => {
it('should return false if selected node is not a file', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)
@ -282,7 +279,7 @@ describe('NodeTemplateService', () => {
}));
it('should return true if selected node is a template file', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)
@ -303,7 +300,7 @@ describe('NodeTemplateService', () => {
}));
it('should set dialog title for file templates', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)
@ -321,7 +318,7 @@ describe('NodeTemplateService', () => {
describe('Folder templates', () => {
it('should return false if selected node is not a folder', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)
@ -342,7 +339,7 @@ describe('NodeTemplateService', () => {
}));
it('should return false if current node is the parent folder', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)
@ -363,7 +360,7 @@ describe('NodeTemplateService', () => {
}));
it('should return true if selected node is a folder template', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: {
entries: [{ entry: { id: 'templates-folder-id', path: { elements: [] } } }]
@ -386,7 +383,7 @@ describe('NodeTemplateService', () => {
}));
it('should set dialog title for folder templates', fakeAsync(() => {
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging)

@ -27,7 +27,7 @@ import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { CreateFromTemplateDialogComponent } from '../dialogs/node-template/create-from-template.dialog';
import { Subject, from, of } from 'rxjs';
import { Node, MinimalNode, MinimalNodeEntryEntity, ResultNode, PathElement } from '@alfresco/js-api';
import { Node, MinimalNode, MinimalNodeEntryEntity, ResultNode, PathElement, SearchApi } from '@alfresco/js-api';
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { switchMap, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store';
@ -45,13 +45,16 @@ export interface TemplateDialogConfig {
export class NodeTemplateService {
private currentTemplateConfig: TemplateDialogConfig = null;
private rootNode: ResultNode;
private searchApi: SearchApi;
constructor(
private store: Store<AppStore>,
private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
public dialog: MatDialog
) {}
) {
this.searchApi = new SearchApi(this.alfrescoApiService.getInstance());
}
selectTemplateDialog(config: TemplateDialogConfig): Subject<Node[]> {
this.currentTemplateConfig = config;
@ -84,7 +87,7 @@ export class NodeTemplateService {
include: ['path', 'properties', 'allowableOperations', 'permissions']
};
from(this.alfrescoApiService.searchApi.search(query))
from(this.searchApi.search(query))
.pipe(
switchMap((response) => {
const entry = response.list.entries[0].entry;

@ -44,6 +44,7 @@ import {
ContextMenuEffects
} from './effects';
import { INITIAL_STATE } from './initial-state';
import { provideBootstrapEffects } from './bootstrap-effect';
@NgModule({
imports: [
@ -62,7 +63,11 @@ import { INITIAL_STATE } from './initial-state';
stateKey: 'router'
}),
SharedStoreModule,
EffectsModule.forRoot([
EffectsModule.forRoot([]),
!environment.production ? StoreDevtoolsModule.instrument({ maxAge: 25 }) : []
],
providers: [
provideBootstrapEffects([
AppEffects,
NodeEffects,
DownloadEffects,
@ -73,8 +78,7 @@ import { INITIAL_STATE } from './initial-state';
FavoriteEffects,
TemplateEffects,
ContextMenuEffects
]),
!environment.production ? StoreDevtoolsModule.instrument({ maxAge: 25 }) : []
])
]
})
export class AppStoreModule {}

@ -0,0 +1,52 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { APP_BOOTSTRAP_LISTENER, InjectionToken, Inject, Type } from '@angular/core';
import { EffectSources } from '@ngrx/effects';
export const BOOTSTRAP_EFFECTS = new InjectionToken('Bootstrap Effects');
export function bootstrapEffects(effects: Type<any>[], sources: EffectSources) {
return () => {
effects.forEach((effect) => sources.addEffects(effect));
};
}
export function createInstances(...instances: any[]) {
return instances;
}
export function provideBootstrapEffects(effects: Type<any>[]) {
return [
effects,
{ provide: BOOTSTRAP_EFFECTS, deps: effects, useFactory: createInstances },
{
provide: APP_BOOTSTRAP_LISTENER,
multi: true,
useFactory: bootstrapEffects,
deps: [[new Inject(BOOTSTRAP_EFFECTS)], EffectSources]
}
];
}

@ -31,7 +31,6 @@ import { Store } from '@ngrx/store';
import { CreateFromTemplate, CreateFromTemplateSuccess, FileFromTemplate, FolderFromTemplate, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { NodeTemplateService } from '../../services/node-template.service';
import { of, Subject } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Node, NodeEntry } from '@alfresco/js-api';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { CreateFromTemplateDialogComponent } from '../../dialogs/node-template/create-from-template.dialog';
@ -40,8 +39,8 @@ import { AppHookService } from '@alfresco/aca-shared';
describe('TemplateEffects', () => {
let store: Store<any>;
let nodeTemplateService: NodeTemplateService;
let alfrescoApiService: AlfrescoApiService;
let appHookService: AppHookService;
let templateEffects: TemplateEffects;
let copyNodeSpy;
let updateNodeSpy;
let matDialog: MatDialog;
@ -88,7 +87,7 @@ describe('TemplateEffects', () => {
store = TestBed.inject(Store);
nodeTemplateService = TestBed.inject(NodeTemplateService);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
templateEffects = TestBed.inject(TemplateEffects);
appHookService = TestBed.inject(AppHookService);
matDialog = TestBed.inject(MatDialog);
subject = new Subject<Node[]>();
@ -98,8 +97,8 @@ describe('TemplateEffects', () => {
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(subject);
copyNodeSpy = spyOn(alfrescoApiService.getInstance().nodes, 'copyNode');
updateNodeSpy = spyOn(alfrescoApiService.getInstance().nodes, 'updateNode');
copyNodeSpy = spyOn(templateEffects['nodesApi'], 'copyNode');
updateNodeSpy = spyOn(templateEffects['nodesApi'], 'updateNode');
});
afterEach(() => {

@ -41,11 +41,13 @@ import { NodeTemplateService, TemplateDialogConfig } from '../../services/node-t
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AppHookService } from '@alfresco/aca-shared';
import { from, Observable, of } from 'rxjs';
import { NodeEntry, NodeBodyUpdate, Node } from '@alfresco/js-api';
import { NodeEntry, NodeBodyUpdate, Node, NodesApi } from '@alfresco/js-api';
import { MatDialog } from '@angular/material/dialog';
@Injectable()
export class TemplateEffects {
private nodesApi: NodesApi;
constructor(
private matDialog: MatDialog,
private appHookService: AppHookService,
@ -53,7 +55,9 @@ export class TemplateEffects {
private apiService: AlfrescoApiService,
private actions$: Actions,
private nodeTemplateService: NodeTemplateService
) {}
) {
this.nodesApi = new NodesApi(this.apiService.getInstance());
}
@Effect({ dispatch: false })
fileFromTemplate$ = this.actions$.pipe(
@ -115,7 +119,7 @@ export class TemplateEffects {
private copyNode(source: Node, parentId: string): Observable<NodeEntry> {
return from(
this.apiService.getInstance().nodes.copyNode(source.id, {
this.nodesApi.copyNode(source.id, {
targetParentId: parentId,
name: source.name
})
@ -135,7 +139,7 @@ export class TemplateEffects {
}
private updateNode(node: NodeEntry, update: NodeBodyUpdate): Observable<NodeEntry> {
return from(this.apiService.getInstance().nodes.updateNode(node.entry.id, update)).pipe(catchError(() => of(node)));
return from(this.nodesApi.updateNode(node.entry.id, update)).pipe(catchError(() => of(node)));
}
private handleError(error: Error): Observable<null> {