Added the connector to the external service provider
This commit is contained in:
parent
ff2eac1bc9
commit
7092e91918
|
@ -6,6 +6,7 @@ import { HttpModule } from '@angular/http';
|
|||
import { RouterModule, Routes, Router } from '@angular/router';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { RestBase } from './services/rest-base';
|
||||
import { DynamicFormComponent } from './form/dynamic-form.component';
|
||||
import { DynamicFormFieldComponent } from './form/fields/dynamic-form-field.component';
|
||||
import { ServerService } from './services/server.service';
|
||||
|
@ -21,6 +22,7 @@ import { PageNotFoundComponent } from './not-found.component';
|
|||
import { TocComponent } from './form/tableOfContents/toc.component';
|
||||
import { ProjectsModule } from './projects/project.module';
|
||||
import { PaginationService } from './services/pagination.service';
|
||||
import { EestoreService } from './services/eestore.service';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -43,7 +45,7 @@ import { PaginationService } from './services/pagination.service';
|
|||
AppRoutingModule
|
||||
|
||||
],
|
||||
providers: [ServerService, dataModelBuilder, AuthGuard, PaginationService, TokenService, LocalStorageService],
|
||||
providers: [ServerService, dataModelBuilder, AuthGuard, PaginationService, TokenService, LocalStorageService, RestBase, EestoreService],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import { Component, Input, OnInit, AfterViewChecked, ViewChild, Injectable } from '@angular/core';
|
||||
|
||||
import {RestBase} from './rest-base';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class EestoreService implements OnInit {
|
||||
|
||||
base: string = "https://eestore.paas2.uninett.no/api/";
|
||||
|
||||
datarepo: string = this.base+"datarepo/";
|
||||
projectrepo: string = this.base+"projectrepo/";
|
||||
organizationrepo: string = this.base+"organizationrepo/";
|
||||
metadataschemarepo: string = this.base+"metadataschemarepo/";
|
||||
servicerepo: string = this.base+"servicerepo/";
|
||||
personrepo: string = this.base+"personrepo/";
|
||||
config: string = this.base+"config/";
|
||||
configtags: string = this.base+"configtags/";
|
||||
|
||||
|
||||
constructor(public restBase: RestBase) {
|
||||
}
|
||||
|
||||
ngOnInit(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
getDataRepos(){
|
||||
return this.restBase.proxy_get(this.datarepo);
|
||||
}
|
||||
|
||||
getProjectRepos(){
|
||||
return this.restBase.proxy_get(this.projectrepo);
|
||||
}
|
||||
|
||||
getOrganizationRepos(){
|
||||
return this.restBase.proxy_get(this.organizationrepo);
|
||||
}
|
||||
|
||||
getMetadataSchemaRepos(){
|
||||
return this.restBase.proxy_get(this.metadataschemarepo);
|
||||
}
|
||||
|
||||
getServiceRepos(){
|
||||
return this.restBase.proxy_get(this.servicerepo);
|
||||
}
|
||||
|
||||
getPersonRepos(){
|
||||
return this.restBase.proxy_get(this.personrepo);
|
||||
}
|
||||
|
||||
getConfigs(){
|
||||
return this.restBase.proxy_get(this.config);
|
||||
}
|
||||
|
||||
getConfigTags(){
|
||||
return this.restBase.proxy_get(this.configtags);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
import { HttpClient , HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { TokenService, TokenProvider } from './token.service'
|
||||
import 'rxjs/Rx';
|
||||
|
||||
|
||||
declare var X2JS: any;
|
||||
|
||||
export class RestBase {
|
||||
|
||||
xml2jsonOBJ: any;
|
||||
|
||||
static get parameters() { return [HttpClient, TokenService] }
|
||||
|
||||
constructor(public http : HttpClient, public tokenService : TokenService) {
|
||||
this.xml2jsonOBJ = new X2JS();
|
||||
}
|
||||
|
||||
protocol: string = "http";
|
||||
hostname: string = "localhost";//"dl010.madgik.di.uoa.gr";//
|
||||
port: number = 7070;//8080;//
|
||||
webappname: string = "dmp-backend";//"dmp-backend-new";//
|
||||
|
||||
|
||||
proxyPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/proxy/";
|
||||
loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/login/";
|
||||
restPath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/rest/";
|
||||
|
||||
|
||||
public proxy_get(path : string){
|
||||
var options = this.createOptions();
|
||||
return this.http.get<any>(this.proxyPath +"proxy?url="+ path, options);
|
||||
}
|
||||
|
||||
public login(path : string, data : any){
|
||||
let options = { headers: new HttpHeaders().set('Content-Type', 'application/json') };
|
||||
return this.http.post<any>(this.loginPath + path, JSON.stringify(data), options);
|
||||
}
|
||||
|
||||
public get(path : string){
|
||||
var options = this.createOptions();
|
||||
return this.http.get<any>(this.restPath + path, options);
|
||||
}
|
||||
|
||||
|
||||
public post(path : string, data : any) {
|
||||
var options = this.createOptions();
|
||||
return this.http.post<any>(this.restPath + path, JSON.stringify(data), options);
|
||||
}
|
||||
|
||||
|
||||
private createOptions(){
|
||||
var token = this.tokenService.getToken();
|
||||
var provider: TokenProvider = this.tokenService.getProvider();
|
||||
//var csrfToken : string = this.tokenService.getCSRFToken();
|
||||
|
||||
const params = new HttpParams();
|
||||
var headers;
|
||||
if(provider == TokenProvider.google)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("google-token", token);
|
||||
if(provider == TokenProvider.native)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("native-token", token);
|
||||
let options = { params: params, headers: headers };
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -11,11 +11,11 @@ export class TokenService {
|
|||
|
||||
|
||||
constructor (private storage : LocalStorageService, @Inject(DOCUMENT) private document) {
|
||||
var csrfToken : string = jQuery(document).find('meta[name="csrf-token"]').attr('content');
|
||||
this.setCSRFToken(csrfToken);
|
||||
//var csrfToken : string = jQuery(document).find('meta[name="csrf-token"]').attr('content');
|
||||
//this.setCSRFToken(csrfToken);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
getCSRFToken() : string{
|
||||
return this.storage.retrieve('csrf-token');
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ export class TokenService {
|
|||
setCSRFToken(csrfToken : string){
|
||||
this.storage.store('csrf-token',csrfToken);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
getProvider() : TokenProvider {
|
||||
return this.storage.retrieve('provider');
|
||||
|
|
Loading…
Reference in New Issue