mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
fix api service bugs and remove workarounds
rebasing onto develop
This commit is contained in:
committed by
Anton Ramanovich
parent
f67a7d0721
commit
c4f7fdf093
@@ -15,16 +15,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
|
||||||
import { StorageService, AppConfigService } from '@alfresco/adf-core';
|
|
||||||
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||||
|
|
||||||
|
/** @deprecated use `AlfrescoApiService` instead */
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoApiNoAuthService extends AlfrescoApiService {
|
export class AlfrescoApiNoAuthService extends AlfrescoApiService {
|
||||||
constructor(storage: StorageService, appConfig: AppConfigService, private readonly adfHttpClient: AdfHttpClient) {
|
constructor() {
|
||||||
super(appConfig, storage);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
override createInstance(config: AlfrescoApiConfig) {
|
override createInstance(config: AlfrescoApiConfig) {
|
||||||
|
@@ -46,8 +46,6 @@ import { AlfrescoViewerComponent } from './viewer';
|
|||||||
import { ContentTypeDialogComponent } from './content-type';
|
import { ContentTypeDialogComponent } from './content-type';
|
||||||
import { MaterialModule } from './material.module';
|
import { MaterialModule } from './material.module';
|
||||||
import { AlfrescoIconComponent } from './alfresco-icon/alfresco-icon.component';
|
import { AlfrescoIconComponent } from './alfresco-icon/alfresco-icon.component';
|
||||||
import { AlfrescoApiService } from './services/alfresco-api.service';
|
|
||||||
import { AlfrescoApiNoAuthService } from './api-factories/alfresco-api-no-auth.service';
|
|
||||||
import { AlfrescoApiLoaderService, createAlfrescoApiInstance } from './api-factories/alfresco-api-v2-loader.service';
|
import { AlfrescoApiLoaderService, createAlfrescoApiInstance } from './api-factories/alfresco-api-v2-loader.service';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -114,7 +112,6 @@ export class ContentModule {
|
|||||||
providers: [
|
providers: [
|
||||||
provideTranslations('adf-content-services', 'assets/adf-content-services'),
|
provideTranslations('adf-content-services', 'assets/adf-content-services'),
|
||||||
ContentAuthLoaderService,
|
ContentAuthLoaderService,
|
||||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiNoAuthService },
|
|
||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
useFactory: versionCompatibilityFactory,
|
useFactory: versionCompatibilityFactory,
|
||||||
|
@@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||||
import { AppConfigService, StorageService } from '@alfresco/adf-core';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoApiServiceMock extends AlfrescoApiService {
|
export class AlfrescoApiServiceMock extends AlfrescoApiService {
|
||||||
constructor(protected appConfig: AppConfigService, protected storageService: StorageService) {
|
constructor() {
|
||||||
super(appConfig, storageService);
|
super();
|
||||||
|
|
||||||
if (!this.alfrescoApi) {
|
if (!this.alfrescoApi) {
|
||||||
this.initAlfrescoApi();
|
this.initAlfrescoApi();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 { AlfrescoApiService } from './alfresco-api.service';
|
||||||
|
import { AppConfigService, StorageService } from '@alfresco/adf-core';
|
||||||
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||||
|
|
||||||
|
describe('AlfrescoApiService', () => {
|
||||||
|
let service: AlfrescoApiService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const appConfigSpy = jasmine.createSpyObj('AppConfigService', ['get']);
|
||||||
|
const storageSpy = jasmine.createSpyObj('StorageService', ['']);
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [HttpClientTestingModule],
|
||||||
|
providers: [AlfrescoApiService, { provide: AppConfigService, useValue: appConfigSpy }, { provide: StorageService, useValue: storageSpy }]
|
||||||
|
});
|
||||||
|
|
||||||
|
service = TestBed.inject(AlfrescoApiService);
|
||||||
|
|
||||||
|
service['lastConfig'] = {
|
||||||
|
hostBpm: 'http://localhost:8080',
|
||||||
|
contextRootBpm: 'activiti-app'
|
||||||
|
} as any;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for excluded error URL', () => {
|
||||||
|
const currentFullPath = 'http://localhost:8080/activiti-app/api/enterprise/system/properties';
|
||||||
|
expect(service.isExcludedErrorListener(currentFullPath)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for non-excluded error URL', () => {
|
||||||
|
const currentFullPath = 'http://localhost:8080/activiti-app/api/enterprise/other';
|
||||||
|
expect(service.isExcludedErrorListener(currentFullPath)).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
@@ -15,11 +15,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
|
import { inject, Injectable, InjectionToken } from '@angular/core';
|
||||||
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||||
import { ReplaySubject } from 'rxjs';
|
import { ReplaySubject } from 'rxjs';
|
||||||
import { AlfrescoApiFactory } from './alfresco-api.interface';
|
import { AlfrescoApiFactory } from './alfresco-api.interface';
|
||||||
import { AppConfigService, AppConfigValues, OauthConfigModel, OpenidConfiguration, StorageService } from '@alfresco/adf-core';
|
import { AppConfigService, AppConfigValues, OauthConfigModel, OpenidConfiguration, StorageService } from '@alfresco/adf-core';
|
||||||
|
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||||
|
|
||||||
export const ALFRESCO_API_FACTORY = new InjectionToken('ALFRESCO_API_FACTORY');
|
export const ALFRESCO_API_FACTORY = new InjectionToken('ALFRESCO_API_FACTORY');
|
||||||
|
|
||||||
@@ -27,7 +28,12 @@ export const ALFRESCO_API_FACTORY = new InjectionToken('ALFRESCO_API_FACTORY');
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AlfrescoApiService {
|
export class AlfrescoApiService {
|
||||||
alfrescoApiInitialized = new ReplaySubject<boolean>(1);
|
protected appConfig = inject(AppConfigService);
|
||||||
|
protected storageService = inject(StorageService);
|
||||||
|
protected alfrescoApiFactory = inject<AlfrescoApiFactory>(ALFRESCO_API_FACTORY, { optional: true });
|
||||||
|
protected adfHttpClient = inject(AdfHttpClient);
|
||||||
|
|
||||||
|
alfrescoApiInitialized: ReplaySubject<boolean> = new ReplaySubject(1);
|
||||||
|
|
||||||
protected alfrescoApi: AlfrescoApi;
|
protected alfrescoApi: AlfrescoApi;
|
||||||
|
|
||||||
@@ -36,20 +42,12 @@ export class AlfrescoApiService {
|
|||||||
|
|
||||||
idpConfig: OpenidConfiguration;
|
idpConfig: OpenidConfiguration;
|
||||||
|
|
||||||
private excludedErrorUrl: string[] = ['api/enterprise/system/properties'];
|
private readonly excludedErrorUrl = ['/api/enterprise/system/properties'];
|
||||||
|
|
||||||
getInstance(): AlfrescoApi {
|
getInstance(): AlfrescoApi {
|
||||||
return this.alfrescoApi;
|
return this.alfrescoApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected appConfig: AppConfigService,
|
|
||||||
protected storageService: StorageService,
|
|
||||||
@Optional()
|
|
||||||
@Inject(ALFRESCO_API_FACTORY)
|
|
||||||
private alfrescoApiFactory?: AlfrescoApiFactory
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async load(config: AlfrescoApiConfig): Promise<void> {
|
async load(config: AlfrescoApiConfig): Promise<void> {
|
||||||
this.currentAppConfig = config;
|
this.currentAppConfig = config;
|
||||||
|
|
||||||
@@ -122,15 +120,26 @@ export class AlfrescoApiService {
|
|||||||
if (this.alfrescoApiFactory) {
|
if (this.alfrescoApiFactory) {
|
||||||
return this.alfrescoApiFactory.createAlfrescoApi(config);
|
return this.alfrescoApiFactory.createAlfrescoApi(config);
|
||||||
}
|
}
|
||||||
return new AlfrescoApi(config);
|
|
||||||
|
return new AlfrescoApi(
|
||||||
|
{
|
||||||
|
...config,
|
||||||
|
oauthInit: false
|
||||||
|
},
|
||||||
|
this.adfHttpClient
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDifferentConfig(lastConfig: AlfrescoApiConfig, newConfig: AlfrescoApiConfig) {
|
isDifferentConfig(lastConfig: AlfrescoApiConfig, newConfig: AlfrescoApiConfig) {
|
||||||
return JSON.stringify(lastConfig) !== JSON.stringify(newConfig);
|
return JSON.stringify(lastConfig) !== JSON.stringify(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private formatExcludedPath(path: string): string {
|
||||||
|
return path.replace(this.lastConfig.hostBpm + '/' + this.lastConfig.contextRootBpm, '');
|
||||||
|
}
|
||||||
|
|
||||||
isExcludedErrorListener(currentFullPath: string): boolean {
|
isExcludedErrorListener(currentFullPath: string): boolean {
|
||||||
const formattedPath = currentFullPath.replace(this.lastConfig.hostBpm + '/' + this.lastConfig.contextRootBpm, '');
|
const formattedPath = this.formatExcludedPath(currentFullPath);
|
||||||
return this.excludedErrorUrl.includes(formattedPath);
|
return this.excludedErrorUrl.includes(formattedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user