Compare commits

...
34 changed files with 666 additions and 64 deletions
+2
View File
@@ -30,3 +30,5 @@ out-tsc
e2e-result-*
licenses.txt
.DS_Store
.angular
nxcache
+4 -7
View File
@@ -20,7 +20,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FlexLayoutModule } from '@angular/flex-layout';
import { ChartsModule } from 'ng2-charts';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateModule } from '@ngx-translate/core';
import {
@@ -28,8 +28,7 @@ import {
TRANSLATION_PROVIDER,
DebugAppConfigService,
CoreModule,
CoreAutomationService,
AuthBearerInterceptor
CoreAutomationService
} from '@alfresco/adf-core';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { AppComponent } from './app.component';
@@ -115,6 +114,7 @@ import localeSv from '@angular/common/locales/sv';
import { setupAppNotifications } from './services/app-notifications-factory';
import { AppNotificationsService } from './services/app-notifications.service';
import { SearchFilterChipsComponent } from './components/search/search-filter-chips.component';
import { AlfrescoApiModule } from '@alfresco/adf-core/alfresco-api';
registerLocaleData(localeFr);
registerLocaleData(localeDe);
@@ -153,6 +153,7 @@ registerLocaleData(localeSv);
ThemePickerModule,
ChartsModule,
AppCloudSharedModule,
AlfrescoApiModule,
MonacoEditorModule.forRoot()
],
declarations: [
@@ -209,10 +210,6 @@ registerLocaleData(localeSv);
SearchFilterChipsComponent
],
providers: [
{
provide: HTTP_INTERCEPTORS, useClass:
AuthBearerInterceptor, multi: true
},
{ provide: AppConfigService, useClass: DebugAppConfigService }, // not use this service in production
{
provide: TRANSLATION_PROVIDER,
@@ -84,6 +84,7 @@ export class DataTableComponent {
}
resolver(row: DataRow, col: DataColumn): any {
debugger;
const value = row.getValue(col.key);
if (col.key === 'users') {
return (value || []).map(user => `${user.firstName} ${user.lastName}`).toString();
@@ -22,9 +22,10 @@ import { UploadService, AlfrescoApiService, AppConfigService, DiscoveryApiServic
import { PreviewService } from '../../services/preview.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '@alfresco/adf-core/alfresco-api';
export function processUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService, discoveryApiService: DiscoveryApiService) {
return new ProcessUploadService(api, config, discoveryApiService);
export function processUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService, discoveryApiService: DiscoveryApiService, alfrescoApiClientFactory: AlfrescoApiClientFactory) {
return new ProcessUploadService(api, config, discoveryApiService, alfrescoApiClientFactory);
}
@Component({
@@ -35,7 +36,7 @@ export function processUploadServiceFactory(api: AlfrescoApiService, config: App
{
provide: UploadService,
useFactory: (processUploadServiceFactory),
deps: [AlfrescoApiService, AppConfigService, DiscoveryApiService]
deps: [AlfrescoApiService, AppConfigService, DiscoveryApiService, AlfrescoApiClientFactory]
}
]
})
@@ -26,9 +26,10 @@ import { UploadService, AlfrescoApiService, AppConfigService, DiscoveryApiServic
import { PreviewService } from '../../services/preview.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '@alfresco/adf-core/alfresco-api';
export function taskUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService, discoveryApiService: DiscoveryApiService) {
return new TaskUploadService(api, config, discoveryApiService);
export function taskUploadServiceFactory(api: AlfrescoApiService, config: AppConfigService, discoveryApiService: DiscoveryApiService, alfrescoApiClientFactory: AlfrescoApiClientFactory) {
return new TaskUploadService(api, config, discoveryApiService, alfrescoApiClientFactory);
}
@Component({
@@ -39,7 +40,7 @@ export function taskUploadServiceFactory(api: AlfrescoApiService, config: AppCon
{
provide: UploadService,
useFactory: (taskUploadServiceFactory),
deps: [AlfrescoApiService, AppConfigService, DiscoveryApiService]
deps: [AlfrescoApiService, AppConfigService, DiscoveryApiService, AlfrescoApiClientFactory]
}
]
})
@@ -21,8 +21,8 @@ import { NodeEntry, NodesApi } from '@alfresco/js-api';
import { ShareDialogComponent } from './content-node-share.dialog';
import { Observable, from, Subject } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { takeUntil } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '../../../../core/alfresco-api';
@Directive({
selector: '[adf-share]',
@@ -46,15 +46,15 @@ export class NodeSharedDirective implements OnChanges, OnDestroy {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
constructor(
private dialog: MatDialog,
private zone: NgZone,
private alfrescoApiService: AlfrescoApiService) {
}
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {}
ngOnDestroy() {
this.onDestroy$.next(true);
@@ -17,12 +17,12 @@
import moment from 'moment-es6';
import { Component, Inject, OnInit, Optional, ViewEncapsulation } from '@angular/core';
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormBuilder, FormGroup } from '@angular/forms';
import { NodeBodyLock, Node, NodeEntry, NodesApi } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AlfrescoApiClientFactory } from '../../../../core/alfresco-api';
@Component({
selector: 'adf-node-lock',
@@ -37,15 +37,14 @@ export class NodeLockDialogComponent implements OnInit {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApi.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
constructor(
private formBuilder: FormBuilder,
public dialog: MatDialogRef<NodeLockDialogComponent>,
private alfrescoApi: AlfrescoApiService,
@Optional()
private alfrescoApiClientFactory: AlfrescoApiClientFactory,
@Inject(MAT_DIALOG_DATA)
public data: any
) {
@@ -43,7 +43,6 @@ import {
CustomNoPermissionTemplateDirective,
CustomEmptyContentTemplateDirective,
RequestPaginationModel,
AlfrescoApiService,
UserPreferenceValues,
LockService,
DataRow
@@ -63,6 +62,7 @@ import { RowFilter } from '../data/row-filter.model';
import { DocumentListService } from '../services/document-list.service';
import { DocumentLoaderNode } from '../models/document-folder.model';
import { takeUntil } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
@Component({
selector: 'adf-document-list',
@@ -347,7 +347,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -358,7 +358,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
private userPreferencesService: UserPreferencesService,
private contentService: ContentService,
private thumbnailService: ThumbnailService,
private alfrescoApiService: AlfrescoApiService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory,
private lockService: LockService) {
this.userPreferencesService
.select(UserPreferenceValues.PaginationSize)
@@ -33,6 +33,7 @@ import {
NodesApi
} from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
import { Observable, from, of, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
@@ -79,12 +80,15 @@ export class CustomResourcesService {
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {
}
constructor(
private apiService: AlfrescoApiService,
private logService: LogService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {}
/**
* Gets files recently accessed by a user.
@@ -16,7 +16,7 @@
*/
import {
AlfrescoApiService, ContentService, LogService, PaginationModel
ContentService, LogService, PaginationModel
} from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
@@ -26,6 +26,7 @@ import { Observable, from, throwError, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
const ROOT_ID = '-root-';
@@ -36,14 +37,14 @@ export class DocumentListService implements DocumentListLoader {
private _nodesApi: NodesApi;
get nodes(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
constructor(private contentService: ContentService,
private apiService: AlfrescoApiService,
private logService: LogService,
private customResourcesService: CustomResourcesService) {
private customResourcesService: CustomResourcesService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
}
/**
@@ -21,6 +21,7 @@ import { VersionsApi, Node, VersionEntry, VersionPaging, NodesApi, NodeEntry, Co
import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
import { ContentVersionService } from './content-version.service';
import { AlfrescoApiClientFactory } from '../../../../core/alfresco-api';
@Component({
selector: 'adf-version-list',
@@ -45,7 +46,7 @@ export class VersionListComponent implements OnChanges {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApi.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -87,8 +88,9 @@ export class VersionListComponent implements OnChanges {
constructor(private alfrescoApi: AlfrescoApiService,
private contentService: ContentService,
private contentVersionService: ContentVersionService,
private dialog: MatDialog) {
}
private dialog: MatDialog,
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {}
ngOnChanges() {
this.loadVersionHistory();
@@ -0,0 +1,53 @@
/*!
* @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.
*/
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { AlfrescoApiV2Service } from './services/alfresco-api-v2.service';
import { AlfrescoApiClientFactory } from './services/alfresco-api-client.factory';
import { AlfrescoApiV2LoaderService, createAlfrescoApiV2Service } from './services/alfresco-api-v2-loader.service';
import { AuthBearerInterceptor } from './services/auth-bearer.interceptor';
@NgModule({
imports: [
HttpClientModule,
HttpClientXsrfModule.withOptions({
cookieName: 'CSRF-TOKEN',
headerName: 'X-CSRF-TOKEN'
})
],
providers: [
AlfrescoApiV2Service,
AlfrescoApiV2LoaderService,
AlfrescoApiClientFactory,
{
provide: APP_INITIALIZER,
useFactory: createAlfrescoApiV2Service,
deps: [
AlfrescoApiV2LoaderService
],
multi: true
},
{
provide: HTTP_INTERCEPTORS, useClass:
AuthBearerInterceptor, multi: true
}
]
})
export class AlfrescoApiModule {}
+20
View File
@@ -0,0 +1,20 @@
/*!
* @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 * from './alfresco-api.module';
export * from './services/alfresco-api-v2.service';
export * from './services/alfresco-api-client.factory';
@@ -0,0 +1,58 @@
/*!
* @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 { RequestOptions } from '@alfresco/js-api';
export interface JsApiHttpClient {
basePath: string;
request<T = any>(options: RequestOptions): Promise<T>;
post<T = any>(options: RequestOptions): Promise<T>;
put<T = any>(options: RequestOptions): Promise<T>;
get<T = any>(options: RequestOptions): Promise<T>;
delete<T = void>(options: RequestOptions): Promise<T>;
/** @deprecated */
callApi(
path: string,
httpMethod: string,
pathParams?: any,
queryParams?: any,
headerParams?: any,
formParams?: any,
bodyParam?: any,
contentTypes?: string[],
accepts?: string[],
returnType?: any,
contextRoot?: string,
responseType?: string,
url?: string
): Promise<any>;
/** @deprecated */
callCustomApi(
path: string,
httpMethod: string,
pathParams?: any,
queryParams?: any,
headerParams?: any,
formParams?: any,
bodyParam?: any,
contentTypes?: string[],
accepts?: string[],
returnType?: any,
contextRoot?: string,
responseType?: string
): Promise<any>;
}
+18
View File
@@ -0,0 +1,18 @@
/*!
* @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.
*/
// Experimental module, nothing is published!
@@ -0,0 +1,51 @@
/*!
* @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.
*/
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
import { Injectable } from '@angular/core';
import { DiscoveryApi, NodesApi } from '@alfresco/js-api';
import { AlfrescoApiV2Service } from './alfresco-api-v2.service';
@Injectable()
export class AlfrescoApiClientFactory {
// Here we should all the APIs from js-api
private discoveryApi: DiscoveryApi = null;
private nodesApi: NodesApi = null;
constructor(
private angularAlfrescoApi?: AlfrescoApiV2Service) {
}
getDiscoveryApi() {
// DiscoveryApi needs to rely on a lot thinner interface: JsApiHttpClient; For now: "as any"
this.discoveryApi = this.discoveryApi ?? new DiscoveryApi(this.angularAlfrescoApi as any);
return this.discoveryApi;
}
getNodesApi () {
// NodesApi needs to rely on a lot thinner interface: JsApiHttpClient; For now: "as any"
this.nodesApi = this.nodesApi ?? new NodesApi(this.angularAlfrescoApi as any);
return this.nodesApi;
}
getSearchApi() {
// TODO
}
// etc...
}
@@ -0,0 +1,71 @@
/*!
* @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.
*/
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
import { Injectable } from '@angular/core';
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { OauthConfigModel } from '../../models/oauth-config.model';
import { StorageService } from '../../services/storage.service';
import { AlfrescoApiV2Service } from './alfresco-api-v2.service';
export function createAlfrescoApiV2Service(angularAlfrescoApiService: AlfrescoApiV2LoaderService) {
return () => angularAlfrescoApiService.load();
}
@Injectable()
export class AlfrescoApiV2LoaderService {
protected alfrescoApi: AlfrescoApi;
constructor(
protected appConfig: AppConfigService,
protected storageService: StorageService,
private alfrescoApiV2Service?: AlfrescoApiV2Service) {
}
load(): Promise<any> {
return this.appConfig.load().then(() => {
this.storageService.prefix = this.appConfig.get<string>(AppConfigValues.STORAGE_PREFIX, '');
this.initAngularAlfrescoApi();
});
}
protected initAngularAlfrescoApi() {
const oauth: OauthConfigModel = Object.assign({}, this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null));
if (oauth) {
oauth.redirectUri = window.location.origin + window.location.pathname;
oauth.redirectUriLogout = window.location.origin + window.location.pathname;
}
const config = new AlfrescoApiConfig({
provider: this.appConfig.get<string>(AppConfigValues.PROVIDERS),
hostEcm: this.appConfig.get<string>(AppConfigValues.ECMHOST),
hostBpm: this.appConfig.get<string>(AppConfigValues.BPMHOST),
authType: this.appConfig.get<string>(AppConfigValues.AUTHTYPE, 'BASIC'),
contextRootBpm: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM),
contextRoot: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM),
disableCsrf: this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF),
withCredentials: this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false),
domainPrefix : this.appConfig.get<string>(AppConfigValues.STORAGE_PREFIX),
oauth2: oauth
});
this.alfrescoApiV2Service.init(config);
}
}
@@ -0,0 +1,87 @@
/*!
* @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.
*/
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
import { AlfrescoApiConfig } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { JsApiHttpClient } from '../js-api/js-api-http-client';
import { JsApiAngularHttpClient } from './js-api-angular-http-client';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class AlfrescoApiV2Service {
public contentPrivateClient: JsApiHttpClient;
public contentClient: JsApiHttpClient;
public authClient: JsApiHttpClient;
public searchClient: JsApiHttpClient;
public discoveryClient: JsApiHttpClient;
public gsClient: JsApiHttpClient;
public processClient: JsApiHttpClient;
constructor(private httpClient: HttpClient) {}
init(config: AlfrescoApiConfig) {
this.contentPrivateClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api/${config.tenant}/private/alfresco/versions/1`,
this.httpClient
);
this.contentClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api/${config.tenant}/public/alfresco/versions/1`,
this.httpClient
);
this.authClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api/${config.tenant}/public/authentication/versions/1`,
this.httpClient
);
this.searchClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api/${config.tenant}/public/search/versions/1`,
this.httpClient
);
this.discoveryClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api`,
this.httpClient
);
this.gsClient = new JsApiAngularHttpClient(
config.hostEcm,
config.contextRoot,
`/api/${config.tenant}/public/gs/versions/1`,
this.httpClient
);
this.processClient = new JsApiAngularHttpClient(
config.hostBpm,
config.contextRootBpm,
'',
this.httpClient
);
}
}
@@ -21,7 +21,7 @@ import {
HttpHandler, HttpInterceptor, HttpRequest,
HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders
} from '@angular/common/http';
import { AuthenticationService } from './authentication.service';
import { AuthenticationService } from '../../services/authentication.service';
import { catchError, mergeMap } from 'rxjs/operators';
@Injectable()
@@ -0,0 +1,204 @@
/*!
* @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 {
paramToString,
RequestOptions
} from '@alfresco/js-api';
import { JsApiHttpClient } from '../js-api/js-api-http-client';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
/** tslint:disable-next line */
export class JsApiAngularHttpClient implements JsApiHttpClient {
public basePath: string;
constructor (
private host: string,
private contextRoot: string,
private servicePath: string,
private httpClient: HttpClient
) {
this.basePath = `${this.host}/${this.contextRoot}${this.servicePath}`;
}
request<T = any>(options: RequestOptions): Promise<T> {
const responseType = this.getResponseType(options);
const params = new HttpParams({ fromObject: this.removeUndefinedValues(options.queryParams) });
return this.httpClient.request(
options.httpMethod,
options.url,
{
...(options.bodyParam ? { body: options.bodyParam } : {}),
...(options.headerParams ? { headers: new HttpHeaders(options.headerParams) } : {}),
observe: 'body',
...(options.queryParams ? { params } : {}),
...(responseType ? { responseType } : {})
}).toPromise() as unknown as Promise<T>;
}
// Poor man's sanitizer
private removeUndefinedValues (obj: {[key: string]: any}) {
const newObj = {};
Object.keys(obj).forEach((key) => {
if (obj[key] === Object(obj[key])) {
newObj[key] = this.removeUndefinedValues(obj[key]);
} else if (obj[key] !== undefined && obj[key] !== null) {
newObj[key] = obj[key];
}
});
return newObj;
}
private getResponseType(options: RequestOptions): 'arraybuffer' | 'blob' | 'json' | 'text' {
let responseType = null;
if (options.returnType?.toString().toLowerCase() === 'blob' || options.responseType?.toString().toLowerCase() === 'blob') {
responseType = 'blob';
} else if (options.returnType === 'String') {
responseType = 'text';
}
return responseType;
}
post<T = any>(options: RequestOptions): Promise<T> {
return this.request<T>({
...options,
httpMethod: 'POST',
contentTypes: options.contentTypes || ['application/json'],
accepts: options.accepts || ['application/json']
});
}
put<T = any>(options: RequestOptions): Promise<T> {
return this.request<T>({
...options,
httpMethod: 'PUT',
contentTypes: options.contentTypes || ['application/json'],
accepts: options.accepts || ['application/json']
});
}
get<T = any>(options: RequestOptions): Promise<T> {
return this.request<T>({
...options,
httpMethod: 'GET',
contentTypes: options.contentTypes || ['application/json'],
accepts: options.accepts || ['application/json']
});
}
delete<T = void>(options: RequestOptions): Promise<T> {
return this.request<T>({
...options,
httpMethod: 'DELETE',
contentTypes: options.contentTypes || ['application/json'],
accepts: options.accepts || ['application/json']
});
}
/** @deprecated */
callApi(
path: string,
httpMethod: string,
pathParams?: any,
queryParams?: any,
headerParams?: any,
formParams?: any,
bodyParam?: any,
contentTypes?: string[],
accepts?: string[],
returnType?: any,
contextRoot?: string,
responseType?: string,
url?: string
): Promise<any> {
const basePath = contextRoot ? `${this.host}/${contextRoot}` : this.basePath;
url = url ?? this.buildUrl(basePath, path, pathParams);
return this.request({
path,
httpMethod,
pathParams,
queryParams,
headerParams,
formParams,
bodyParam,
contentTypes,
accepts,
returnType,
contextRoot,
responseType,
url
});
}
/** @deprecated */
callCustomApi(
fullPath: string,
httpMethod: string,
pathParams?: any,
queryParams?: any,
headerParams?: any,
formParams?: any,
bodyParam?: any,
contentTypes?: string[],
accepts?: string[],
returnType?: any,
contextRoot?: string,
responseType?: string
): Promise<any> {
const url = this.buildUrl(fullPath, '', pathParams);
return this.request({
path: fullPath,
httpMethod,
pathParams,
queryParams,
headerParams,
formParams,
bodyParam,
contentTypes,
accepts,
returnType,
contextRoot,
responseType,
url
});
}
private buildUrl(basePath: string, path: string, pathParams: any): string {
if (path && path !== '' && !path.match(/^\//)) {
path = '/' + path;
}
let url = basePath + path;
url = url.replace(/\{([\w-]+)\}/g, function (fullMatch, key) {
let value;
if (pathParams.hasOwnProperty(key)) {
value = paramToString(pathParams[key]);
} else {
value = fullMatch;
}
return encodeURIComponent(value);
});
return url;
}
}
+4 -2
View File
@@ -23,6 +23,7 @@ import { Observable, forkJoin, from, of } from 'rxjs';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { TranslationService } from '../services/translation.service';
import { map, catchError, retry } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '../alfresco-api';
interface ProcessedNodeData {
entry: Node | DeletedNode;
@@ -70,7 +71,7 @@ export class NodeDeleteDirective implements OnChanges {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -81,7 +82,8 @@ export class NodeDeleteDirective implements OnChanges {
constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
private elementRef: ElementRef) {
private elementRef: ElementRef,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
}
ngOnChanges() {
+4 -2
View File
@@ -28,6 +28,7 @@ import { PermissionsEnum } from '../models/permissions.enum';
import { AllowableOperationsEnum } from '../models/allowable-operations.enum';
import { DownloadService } from './download.service';
import { ThumbnailService } from './thumbnail.service';
import { AlfrescoApiClientFactory } from '../alfresco-api';
@Injectable({
providedIn: 'root'
@@ -46,7 +47,7 @@ export class ContentService {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -55,7 +56,8 @@ export class ContentService {
private logService: LogService,
private sanitizer: DomSanitizer,
private downloadService: DownloadService,
private thumbnailService: ThumbnailService) {
private thumbnailService: ThumbnailService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
}
/**
@@ -22,6 +22,7 @@ import { NodePaging, NodesApi, TrashcanApi } from '@alfresco/js-api';
import { AlfrescoApiService } from './alfresco-api.service';
import { UserPreferencesService } from './user-preferences.service';
import { catchError } from 'rxjs/operators';
import { AlfrescoApiClientFactory } from '../alfresco-api';
@Injectable({
providedIn: 'root'
@@ -30,7 +31,7 @@ export class DeletedNodesApiService {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -42,7 +43,8 @@ export class DeletedNodesApiService {
constructor(
private apiService: AlfrescoApiService,
private preferences: UserPreferencesService
private preferences: UserPreferencesService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {
}
+6 -3
View File
@@ -18,11 +18,12 @@
import { Injectable } from '@angular/core';
import { from, Observable, throwError, Subject } from 'rxjs';
import { catchError, map, switchMap, filter, take } from 'rxjs/operators';
import { AboutApi, DiscoveryApi, RepositoryInfo, SystemPropertiesApi, SystemPropertiesRepresentation } from '@alfresco/js-api';
import { AboutApi, RepositoryInfo, SystemPropertiesApi, SystemPropertiesRepresentation } from '@alfresco/js-api';
import { BpmProductVersionModel } from '../models/product-version.model';
import { AlfrescoApiService } from './alfresco-api.service';
import { AuthenticationService } from './authentication.service';
import { AlfrescoApiClientFactory } from '../alfresco-api';
@Injectable({
providedIn: 'root'
@@ -36,7 +37,8 @@ export class DiscoveryApiService {
constructor(
private apiService: AlfrescoApiService,
private authenticationService: AuthenticationService) {
private authenticationService: AuthenticationService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
this.authenticationService.onLogin
.pipe(
@@ -53,7 +55,8 @@ export class DiscoveryApiService {
* @returns ProductVersionModel containing product details
*/
getEcmProductInfo(): Observable<RepositoryInfo> {
const discoveryApi = new DiscoveryApi(this.apiService.getInstance());
// const discoveryApi = new DiscoveryApi(this.apiService.getInstance());
const discoveryApi = this.alfrescoApiClientFactory.getDiscoveryApi();
return from(discoveryApi.getRepositoryInformation())
.pipe(
@@ -22,6 +22,7 @@ import {
Node, NodesApi
} from '@alfresco/js-api';
import { ReplaySubject, Subject } from 'rxjs';
import { AlfrescoApiClientFactory } from '../alfresco-api';
@Injectable({
providedIn: 'root'
@@ -38,6 +39,10 @@ export class ExternalAlfrescoApiService {
protected alfrescoApi: AlfrescoApiCompatibility;
_nodesApi: NodesApi;
constructor(
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {}
getInstance(): AlfrescoApiCompatibility {
return this.alfrescoApi;
}
@@ -47,7 +52,7 @@ export class ExternalAlfrescoApiService {
}
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
+3 -1
View File
@@ -22,6 +22,7 @@ import { AlfrescoApiService } from './alfresco-api.service';
import { UserPreferencesService } from './user-preferences.service';
import { catchError, map } from 'rxjs/operators';
import { NodeMetadata } from '../models/node-metadata.model';
import { AlfrescoApiClientFactory } from '../alfresco-api';
@Injectable({
providedIn: 'root'
@@ -36,11 +37,12 @@ export class NodesApiService {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
constructor(private apiService: AlfrescoApiService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory,
private preferences: UserPreferencesService) {
}
+1 -1
View File
@@ -62,7 +62,7 @@ export * from './identity-user.service';
export * from './identity-group.service';
export * from './identity-role.service';
export * from './version-compatibility.service';
export * from './auth-bearer.interceptor';
export * from '../alfresco-api/services/auth-bearer.interceptor';
export * from './oauth2.service';
export * from './language.service';
export * from './identity-user.service.interface';
+4 -2
View File
@@ -30,6 +30,7 @@ import { AlfrescoApiService } from './alfresco-api.service';
import { DiscoveryApiService } from './discovery-api.service';
import { filter } from 'rxjs/operators';
import { NodesApi, UploadApi, VersionsApi } from '@alfresco/js-api';
import { AlfrescoApiClientFactory } from '../alfresco-api';
const MIN_CANCELLABLE_FILE_SIZE = 1000000;
const MAX_CANCELLABLE_FILE_PERCENTAGE = 50;
@@ -69,7 +70,7 @@ export class UploadService {
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -82,7 +83,8 @@ export class UploadService {
constructor(
protected apiService: AlfrescoApiService,
private appConfigService: AppConfigService,
private discoveryApiService: DiscoveryApiService) {
private discoveryApiService: DiscoveryApiService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
this.discoveryApiService.ecmProductInfo$.pipe(filter(info => !!info))
.subscribe(({ status }) => {
@@ -44,6 +44,7 @@ import { MatDialog } from '@angular/material/dialog';
import { ContentService } from '../../services/content.service';
import { UploadService } from '../../services/upload.service';
import { FileModel } from '../../models';
import { AlfrescoApiClientFactory } from '../../alfresco-api';
@Component({
selector: 'adf-viewer',
@@ -292,7 +293,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
@@ -310,7 +311,8 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
private uploadService: UploadService,
private el: ElementRef,
public dialog: MatDialog,
private cdr: ChangeDetectorRef) {
private cdr: ChangeDetectorRef,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
viewUtilService.maxRetries = this.maxRetries;
}
@@ -26,7 +26,6 @@ import {
FormValues,
ContentLinkModel,
AppConfigService,
AlfrescoApiService,
UploadWidgetContentLinkModel,
DestinationFolderPath
} from '@alfresco/adf-core';
@@ -36,6 +35,7 @@ import { ProcessCloudContentService } from '../../../services/process-cloud-cont
import { UploadCloudWidgetComponent } from './upload-cloud.widget';
import { DestinationFolderPathModel, DestinationFolderPathType } from '../../../models/form-cloud-representation.model';
import { ContentNodeSelectorPanelService } from '@alfresco/adf-content-services';
import { AlfrescoApiClientFactory } from '../../../../../../../core/alfresco-api';
export const RETRIEVE_METADATA_OPTION = 'retrieveMetadata';
export const ALIAS_ROOT_FOLDER = '-root-';
@@ -67,7 +67,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
_nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
displayedColumns = ['icon', 'fileName', 'action'];
@@ -80,8 +80,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
notificationService: NotificationService,
private contentNodeSelectorService: ContentCloudNodeSelectorService,
private appConfigService: AppConfigService,
private apiService: AlfrescoApiService,
private contentNodeSelectorPanelService: ContentNodeSelectorPanelService
private contentNodeSelectorPanelService: ContentNodeSelectorPanelService,
private alfrescoApiClientFactory: AlfrescoApiClientFactory
) {
super(formService, thumbnails, processCloudContentService, notificationService, logger);
}
@@ -16,7 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService, LogService, NotificationService } from '@alfresco/adf-core';
import { LogService, NotificationService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material/dialog';
import {
ContentNodeSelectorComponent,
@@ -27,6 +27,7 @@ import { Node, NodeEntry, NodesApi } from '@alfresco/js-api';
import { from, Observable, Subject, throwError } from 'rxjs';
import { catchError, map, mapTo } from 'rxjs/operators';
import { DestinationFolderPathModel } from '../models/form-cloud-representation.model';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
@Injectable({
providedIn: 'root'
@@ -35,17 +36,17 @@ export class ContentCloudNodeSelectorService {
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
this._nodesApi = this.alfrescoApiClientFactory.getNodesApi();
return this._nodesApi;
}
sourceNodeNotFound = false;
constructor(
private apiService: AlfrescoApiService,
private notificationService: NotificationService,
private logService: LogService,
private dialog: MatDialog) {
private dialog: MatDialog,
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
}
openUploadFileDialog(currentFolderId?: string, selectionMode?: string, isAllFileSources?: boolean, restrictRootToCurrentFolderId?: boolean): Observable<Node[]> {
@@ -18,6 +18,7 @@
import { AlfrescoApiService, AppConfigService, DiscoveryApiService, UploadService } from '@alfresco/adf-core';
import { ActivitiContentApi } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
import { throwError } from 'rxjs';
@Injectable({
@@ -31,8 +32,12 @@ export class ProcessUploadService extends UploadService {
return this._contentApi;
}
constructor(protected apiService: AlfrescoApiService, appConfigService: AppConfigService, discoveryApiService: DiscoveryApiService) {
super(apiService, appConfigService, discoveryApiService);
constructor(
protected apiService: AlfrescoApiService,
appConfigService: AppConfigService,
discoveryApiService: DiscoveryApiService,
alfrescoApiClientFactory: AlfrescoApiClientFactory) {
super(apiService, appConfigService, discoveryApiService, alfrescoApiClientFactory);
}
getUploadPromise(file: any): any {
@@ -19,6 +19,7 @@ import { AlfrescoApiService, AppConfigService, DiscoveryApiService, UploadServic
import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
import { ActivitiContentApi } from '@alfresco/js-api';
import { AlfrescoApiClientFactory } from '../../../../../core/alfresco-api';
@Injectable({
providedIn: 'root'
@@ -31,8 +32,12 @@ export class TaskUploadService extends UploadService {
return this._contentApi;
}
constructor(protected apiService: AlfrescoApiService, appConfigService: AppConfigService, discoveryApiService: DiscoveryApiService) {
super(apiService, appConfigService, discoveryApiService);
constructor(
protected apiService: AlfrescoApiService,
appConfigService: AppConfigService,
discoveryApiService: DiscoveryApiService,
alfrescoApiClientFactory: AlfrescoApiClientFactory) {
super(apiService, appConfigService, discoveryApiService, alfrescoApiClientFactory);
}
getUploadPromise(file: any): any {
+1
View File
@@ -32,6 +32,7 @@
"@alfresco/js-api": ["node_modules/@alfresco/js-api"],
"@alfresco/adf-extensions": ["lib/extensions"],
"@alfresco/adf-core": ["lib/core"],
"@alfresco/adf-core/*": ["lib/core/*"],
"@alfresco/adf-content-services": ["lib/content-services"],
"@alfresco/adf-process-services": ["lib/process-services"],
"@alfresco/adf-insights": ["lib/insights"],