183 lines
5.9 KiB
TypeScript
183 lines
5.9 KiB
TypeScript
import {Injectable, ReflectiveInjector, Injector} from '@angular/core';
|
||
import { HttpClient , HttpHeaders, HttpParams} from '@angular/common/http';
|
||
import {FieldBase} from '../../app/form/fields/field-base';
|
||
import {JsonObjest} from '../../app/entities/JsonObject.class';
|
||
import {dataModelBuilder} from '../../app/services/dataModelBuilder.service';
|
||
import { DatasetProfile } from '../entities/datasetprofile';
|
||
import {DataModel} from '../entities/DataModel';
|
||
import {Project} from '../entities/model/project';
|
||
import {LoginComponent} from '../../app/login/login-page';
|
||
import { TokenService, TokenProvider } from './token.service';
|
||
import {RestBase} from './rest-base';
|
||
import 'rxjs/Rx';
|
||
|
||
import './../../assets/xml2json.min.js';
|
||
declare var X2JS: any;
|
||
|
||
@Injectable()
|
||
export class ServerService {
|
||
|
||
xml2jsonOBJ: any;
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9';
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';//include rules!
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/d597c26e-3d8b-416a-bc07-1734d68c79c9';//include sections! + 3groupfields
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/dmps/9a4a4a57-4d01-465e-9887-254534f31600'; με το security
|
||
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend-no-sec/rest/dmps/9a4a4a57-4d01-465e-9887-254534f31600';
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364';
|
||
|
||
/*
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9';
|
||
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';
|
||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364';
|
||
*/
|
||
|
||
//data: any;
|
||
|
||
constructor(private httpClient: HttpClient, private tokenService: TokenService, private restBase: RestBase) { //private http: Http
|
||
this.xml2jsonOBJ = new X2JS();
|
||
}
|
||
|
||
|
||
public listDatasetIDs(){
|
||
return this.restBase.get("dataset");
|
||
}
|
||
|
||
public getAllDatasets(){
|
||
return this.restBase.get("getAllDatasets");
|
||
}
|
||
|
||
public getAllDatasetIDs(datasetId: string){
|
||
return this.restBase.get("dataset/"+datasetId);
|
||
}
|
||
|
||
|
||
public getAllDmps(){
|
||
return this.restBase.get("dmp/getAll");
|
||
}
|
||
|
||
public listDmpsLabelID(){
|
||
return this.restBase.get("dmp/listDMPLabelID");
|
||
}
|
||
|
||
public getDmp(dmpid : string){
|
||
return this.restBase.get("dmps/"+dmpid);
|
||
}
|
||
|
||
public listDmpIDs(){
|
||
return this.restBase.get("dmps");
|
||
}
|
||
|
||
|
||
public listProjectIDs(){
|
||
return this.restBase.get("projects");
|
||
}
|
||
|
||
public getAllProjects(){
|
||
return this.restBase.get("project/getAll");
|
||
}
|
||
|
||
public getProject(projectID : string){
|
||
return this.restBase.get("projects/"+projectID);
|
||
}
|
||
|
||
public listProjectsLabelID(){
|
||
return this.restBase.get("project/listAllLabelIDs");
|
||
}
|
||
|
||
public listDmpsUser(){
|
||
return this.restBase.get("dmp/listDMPLabelID");
|
||
}
|
||
|
||
public getProjectOfUer(){
|
||
return this.restBase.get("project/getofuser");
|
||
}
|
||
|
||
public createProject(data:any){
|
||
return this.restBase.post("project/createofuser", data);
|
||
}
|
||
|
||
public getAllDataSet(){
|
||
return this.restBase.get("dataset/getAll");
|
||
}
|
||
|
||
public getDmpOfUser(){
|
||
return this.restBase.get("dmp/getofuser");
|
||
}
|
||
|
||
|
||
public createDmpForProject(data:any){
|
||
debugger;
|
||
return this.restBase.post("dmp/create", data);
|
||
}
|
||
|
||
|
||
logOut() {
|
||
|
||
var auth2 = gapi.auth2.getAuthInstance();
|
||
auth2.signOut().then(function () {
|
||
console.log('User signed out.');
|
||
localStorage.removeItem('currentUser');
|
||
});
|
||
this.tokenService.setToken(null); //kanonika prepei na mpei mesa sthn function.....
|
||
}
|
||
|
||
|
||
getData() {
|
||
|
||
//let headers = new HttpHeaders();
|
||
|
||
// let headers = new HttpHeaders().set("google-token", this.tokenService.getToken());
|
||
|
||
// console.log("google-token: "+ this.tokenService.getToken());
|
||
|
||
// return this.httpClient.get<any>(this.fetchURL);
|
||
return this.restBase.get("dmps/9a4a4a57-4d01-465e-9887-254534f31600");
|
||
|
||
/*
|
||
return this.http.get(this.fetchURL)
|
||
.map(
|
||
(response: Response) => {
|
||
console.log("response");
|
||
console.log(response);
|
||
const data = response.json();
|
||
|
||
//replace the xmls {model,view,rule} definitions with json -- https://github.com/abdmob/x2js library
|
||
data.dataset.profile.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.definition);
|
||
data.dataset.profile.ruleset.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.ruleset.definition);
|
||
data.dataset.profile.viewstyle.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.viewstyle.definition);
|
||
//can be converted back to xml (which shouldn't be needed) with this.xml2jsonOBJ.json2xml_str
|
||
|
||
this.data = data; //cache it for subsequent calls
|
||
return data;
|
||
}
|
||
);
|
||
*/
|
||
|
||
}
|
||
|
||
getProjects(){
|
||
|
||
let headers = new HttpHeaders().set("google-token", this.tokenService.getToken());
|
||
|
||
console.log("google-token: "+ this.tokenService.getToken());
|
||
|
||
return this.httpClient.get<any>("http://dl010.madgik.di.uoa.gr:8080/dmp-backend-no-sec/rest/project/getAll");
|
||
|
||
// let projects :Project[] =[];
|
||
|
||
// let project = new Project;
|
||
// project.name = "Project1";
|
||
// project.id = "Project1Id";
|
||
|
||
// projects.push(project);
|
||
|
||
// let project2 = new Project;
|
||
// project2.name = "Project2";
|
||
// project2.id = "Project2Id";
|
||
|
||
// projects.push(project2);
|
||
|
||
// return projects;
|
||
}
|
||
|
||
} |