labarchives.service.ts 3.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {Injectable, Inject} from '@angular/core';
import {Subject} from 'rxjs/Subject';
import {Http} from '@angular/http';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/delay';
import {Observable} from 'rxjs/Observable';

import {BaseService} from './shared/base-service';
import {ConfigService} from './shared/config-service';

@Injectable()
export class LabarchivesService extends BaseService {

  protected baseUrl: any;
  public recordURL: string = this.brandingAndPortalUrl + '/record/view';
  protected initSubject: any;

  constructor(@Inject(Http) http: Http,
              @Inject(ConfigService) protected configService: ConfigService) {
    super(http, configService);
    this.initSubject = new Subject();
    this.emitInit();
  }

  public waitForInit(handler: any) {
    const subs = this.initSubject.subscribe(handler);
    this.emitInit();
    return subs;
  }

  public emitInit() {
    if (this.brandingAndPortalUrl) {
      this.initSubject.next('');
    }
  }

37
38
39
40
41
42
43
44
45
46
47
48
49
  public async info() {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/info';
    try {
      const result = await this.http.get(
        wsUrl,
        this.options
      ).toPromise();
      return Promise.resolve(this.extractData(result));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

50
51
52
53
54
55
56
57
58
59
60
61
62
63
  public async login(username, password) {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/login';
    try {
      const result = await this.http.post(
        wsUrl,
        {username: username, password: password},
        this.options
      ).toPromise();
      return Promise.resolve(this.extractData(result));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

64
65
66
67
68
69
70
71
72
73
74
75
  public async list() {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/list';
    try {
      const result = await this.http.get(
        wsUrl,
        this.options
      ).toPromise();
      return Promise.resolve(this.extractData(result));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }
76

Moises Sacal's avatar
Moises Sacal committed
77
78
  public async link(workspace: any, rdmpId: string) {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/link';
79
80
81
    try {
      const result = await this.http.post(
        wsUrl,
Moises Sacal's avatar
Moises Sacal committed
82
        {rdmp: rdmpId, workspace: workspace},
83
84
85
86
87
88
89
90
        this.options
      ).toPromise();
      return Promise.resolve(this.extractData(result));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

Moises Sacal's avatar
Moises Sacal committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  public async checkLink(rdmpId: string, nbId: string) {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/checkLink';
    try {
      const result = await this.http.post(
        wsUrl,
        {rdmp: rdmpId, nbId: nbId},
        this.options
      ).toPromise();
      return Promise.resolve(this.extractData(result));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

105
106
107
108
109
110
111
112
113
114
115
116
117
  public async getUserInfo() {
    const wsUrl = this.brandingAndPortalUrl + '/user/info';
    try {
      const result = await this.http.get(
        wsUrl,
        this.options
      ).toPromise();
      return Promise.resolve((this.extractData(result)));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  public async createNotebook(rdmp: string, nbName: string, supervisorEmail: string, userEmail: string) {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/create';
    try {
      const result = await this.http.post(
        wsUrl,
        {name: nbName, supervisor: supervisorEmail, rdmp: rdmp, userEmail: userEmail},
        this.options
      ).toPromise();
      return Promise.resolve((this.extractData(result)));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

  public async rdmpInfo(rdmp: string) {
    const wsUrl = this.brandingAndPortalUrl + '/ws/labarchives/rdmp';
    try {
      const result = await this.http.post(
        wsUrl,
        {rdmp: rdmp},
        this.options
      ).toPromise();
      return Promise.resolve((this.extractData(result)));
    } catch (e) {
      return Promise.reject(new Error(e));
    }
  }

146
}