Add new AlfrescoContentService in ng2-alfresco-core

- Returns v1 public API endpoints for content and thumbnails
- Refactor getHost(), basePath and similar props into settings
- Use AlfrescoAuthenticationService to get alf_ticket value
This commit is contained in:
Will Abson
2016-06-07 14:02:09 +01:00
parent b8f129ed82
commit e39439b68c
8 changed files with 102 additions and 74 deletions

View File

@@ -20,6 +20,7 @@ import { AlfrescoTranslationLoader } from './src/services/AlfrescoTranslationLoa
import { AlfrescoTranslationService } from './src/services/AlfrescoTranslationService.service'; import { AlfrescoTranslationService } from './src/services/AlfrescoTranslationService.service';
import { AlfrescoPipeTranslate } from './src/services/AlfrescoPipeTranslate.service'; import { AlfrescoPipeTranslate } from './src/services/AlfrescoPipeTranslate.service';
import { AlfrescoAuthenticationService } from './src/services/AlfrescoAuthenticationService.service'; import { AlfrescoAuthenticationService } from './src/services/AlfrescoAuthenticationService.service';
import { AlfrescoContentService } from './src/services/AlfrescoContentService.service';
export * from './src/services/AlfrescoSettingsService.service'; export * from './src/services/AlfrescoSettingsService.service';
export * from './src/services/AlfrescoTranslationLoader.service'; export * from './src/services/AlfrescoTranslationLoader.service';
@@ -27,9 +28,11 @@ export * from './src/services/AlfrescoTranslationService.service';
export * from './src/services/AlfrescoPipeTranslate.service'; export * from './src/services/AlfrescoPipeTranslate.service';
export * from './src/material/MaterialDesignLiteUpgradeElement'; export * from './src/material/MaterialDesignLiteUpgradeElement';
export * from './src/services/AlfrescoAuthenticationService.service'; export * from './src/services/AlfrescoAuthenticationService.service';
export * from './src/services/AlfrescoContentService.service';
export const ALFRESCO_CORE_PROVIDERS: [any] = [ export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoTranslationLoader, AlfrescoTranslationLoader,
AlfrescoTranslationService, AlfrescoTranslationService,

View File

@@ -0,0 +1,51 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from 'angular2/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
@Injectable()
export class AlfrescoContentService {
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService
) {
}
/**
* Get thumbnail URL for the given document node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/renditions/doclib/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
}

View File

@@ -19,7 +19,10 @@ import { Injectable } from 'angular2/core';
@Injectable() @Injectable()
export class AlfrescoSettingsService { export class AlfrescoSettingsService {
private _host: string = 'http://127.0.0.1:8080'; private _host: string = 'http://127.0.0.1:8080';
private _contextPath = '/alfresco';
private _apiBasePath: string = '/api/-default-/public/alfresco/versions/1';
public get host(): string { public get host(): string {
return this._host; return this._host;
@@ -29,6 +32,10 @@ export class AlfrescoSettingsService {
this._host = value; this._host = value;
} }
getApiBaseUrl(): string {
return this._host + this._contextPath + this._apiBasePath;
}
getAuthToken(): string { getAuthToken(): string {
// todo: get proper token value // todo: get proper token value
return 'Basic ' + btoa('admin:admin'); return 'Basic ' + btoa('admin:admin');

View File

@@ -17,16 +17,22 @@
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {AlfrescoService} from '../../src/services/alfresco.service'; import {AlfrescoService} from '../../src/services/alfresco.service';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core'; import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
export class AlfrescoServiceMock extends AlfrescoService { export class AlfrescoServiceMock extends AlfrescoService {
_folderToReturn: any = {}; _folderToReturn: any = {};
constructor( constructor(
settings: AlfrescoSettingsService = null settings: AlfrescoSettingsService = null,
authService: AlfrescoAuthenticationService = null,
contentService: AlfrescoContentService = null
) { ) {
super(settings); super(settings, authService, contentService);
} }
getFolder(folder: string) { getFolder(folder: string) {

View File

@@ -19,7 +19,11 @@ import { Injectable } from 'angular2/core';
import { Response } from 'angular2/http'; import { Response } from 'angular2/http';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model'; import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any; declare let AlfrescoApi: any;
@@ -62,23 +66,14 @@ export class AlfrescoService {
}; };
constructor( constructor(
private settings: AlfrescoSettingsService) { private settings: AlfrescoSettingsService,
} private authService: AlfrescoAuthenticationService,
private contentService: AlfrescoContentService
public getHost(): string { ) {
return this.settings.host;
}
private getBaseUrl(): string {
return this.getHost() + this._baseUrlPath;
}
private getAlfrescoTicket() {
return localStorage.getItem('token');
} }
private getAlfrescoClient() { private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket()); return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
} }
private getNodesPromise(folder: string) { private getNodesPromise(folder: string) {
@@ -117,18 +112,7 @@ export class AlfrescoService {
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(document: MinimalNodeEntity) { getDocumentThumbnailUrl(document: MinimalNodeEntity) {
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket(); return this.contentService.getDocumentThumbnailUrl(document);
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: MinimalNodeEntity) {
return this.getHost() +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
} }
getMimeTypeIcon(mimeType: string): string { getMimeTypeIcon(mimeType: string): string {

View File

@@ -18,7 +18,11 @@
import {Http} from 'angular2/http'; import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core'; import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {AlfrescoService} from './../../src/services/alfresco.service'; import {AlfrescoService} from './../../src/services/alfresco.service';
export class AlfrescoServiceMock extends AlfrescoService { export class AlfrescoServiceMock extends AlfrescoService {
@@ -26,9 +30,11 @@ export class AlfrescoServiceMock extends AlfrescoService {
_folderToReturn: any = {}; _folderToReturn: any = {};
constructor( constructor(
settings: AlfrescoSettingsService = null settings: AlfrescoSettingsService = null,
authService: AlfrescoAuthenticationService = null,
contentService: AlfrescoContentService = null
) { ) {
super(settings); super(settings, authService, contentService);
} }
getFolder(folder: string) { getFolder(folder: string) {

View File

@@ -64,18 +64,6 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
this.displaySearchResults(this.searchTerm); this.displaySearchResults(this.searchTerm);
} }
/**
* Gets content URL for the given node.
* @param node Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(node: any): string {
if (this._alfrescoService) {
return this._alfrescoService.getContentUrl(node);
}
return null;
}
/** /**
* Gets thumbnail URL for the given document node. * Gets thumbnail URL for the given document node.
* @param node Node to get URL for. * @param node Node to get URL for.

View File

@@ -18,7 +18,11 @@
import { Injectable } from 'angular2/core'; import { Injectable } from 'angular2/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any; declare let AlfrescoApi: any;
@@ -28,25 +32,15 @@ declare let AlfrescoApi: any;
@Injectable() @Injectable()
export class AlfrescoService { export class AlfrescoService {
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1'; constructor(
private settings: AlfrescoSettingsService,
constructor(private settings: AlfrescoSettingsService) { private authService: AlfrescoAuthenticationService,
} private contentService: AlfrescoContentService
) {
public getHost(): string {
return this.settings.host;
}
private getBaseUrl(): string {
return this.getHost() + this._baseUrlPath;
}
private getAlfrescoTicket() {
return localStorage.getItem('token');
} }
private getAlfrescoClient() { private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket()); return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
} }
private getSearchNodesPromise(term: string) { private getSearchNodesPromise(term: string) {
@@ -78,18 +72,7 @@ export class AlfrescoService {
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(document: any) { getDocumentThumbnailUrl(document: any) {
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket(); return this.contentService.getDocumentThumbnailUrl(document);
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.getHost() +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
} }
private handleError(error: any) { private handleError(error: any) {