diff --git a/dmp-frontend/src/app/app.module.ts b/dmp-frontend/src/app/app.module.ts index b1d9312ff..a96ab1003 100644 --- a/dmp-frontend/src/app/app.module.ts +++ b/dmp-frontend/src/app/app.module.ts @@ -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 { diff --git a/dmp-frontend/src/app/services/eestore.service.ts b/dmp-frontend/src/app/services/eestore.service.ts new file mode 100644 index 000000000..904b8080c --- /dev/null +++ b/dmp-frontend/src/app/services/eestore.service.ts @@ -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); + } + +} \ No newline at end of file diff --git a/dmp-frontend/src/app/services/rest-base.ts b/dmp-frontend/src/app/services/rest-base.ts new file mode 100644 index 000000000..12efb01f4 --- /dev/null +++ b/dmp-frontend/src/app/services/rest-base.ts @@ -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(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(this.loginPath + path, JSON.stringify(data), options); + } + + public get(path : string){ + var options = this.createOptions(); + return this.http.get(this.restPath + path, options); + } + + + public post(path : string, data : any) { + var options = this.createOptions(); + return this.http.post(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; + } + + + +} + \ No newline at end of file diff --git a/dmp-frontend/src/app/services/token.service.ts b/dmp-frontend/src/app/services/token.service.ts index 5b2bd7897..0521179f6 100644 --- a/dmp-frontend/src/app/services/token.service.ts +++ b/dmp-frontend/src/app/services/token.service.ts @@ -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');