argos/dmp-frontend/src/app/services/server.service.ts

194 lines
5.2 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 { TokenService, TokenProvider } from './login/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;
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 getDatasetByID(datasetId: string){
return this.restBase.get("datasets/"+datasetId);
}
public setDataset(dataset){
return this.restBase.post("dataset/update", dataset);
}
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 createDmpForCurrentUser(data:any){
return this.restBase.post("dmp/createofuser", data);
}
public updateDmp(data:any){
return this.restBase.post("dmp/update", data);
}
public getDatasetForDmp(data:any){
return this.restBase.post("dmp/getdatasets", data);
}
public createDatasetForDmp(data:any){
return this.restBase.post("dataset/create", data);
}
public getAllDatsetsProfile(){
return this.restBase.get("datasetprofile/getAll");
}
public getDatasetProfileByID(id){
return this.restBase.get("datasetprofiles/"+id);
}
public updateDatsetsProfile(data:any){
return this.restBase.post("dataset/update", data);
}
logOut() {
this.tokenService.logout();
}
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;
}
}