SubsetService.ts 11.5 KB
Newer Older
Matija Obreza's avatar
Subsets  
Matija Obreza committed
1
2
3

import * as UrlTemplate from 'url-template';
import * as QueryString from 'query-string';
4
import { axiosBackend } from 'utilities/requestUtils';
Matija Obreza's avatar
Subsets  
Matija Obreza committed
5
6

import FilteredPage, { IPageRequest } from 'model/FilteredPage';
7
import Page from 'model/Page';
8
import Subset from 'model/subset/Subset';
9
import SubsetCreator from 'model/subset/SubsetCreator';
10
import SubsetFilter from 'model/subset/SubsetFilter';
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

const URL_ADD_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/add-accessions/{UUID},{version}`);
const URL_APPROVE_SUBSET = `/api/v1/subset/approve`;
const URL_CREATE = `/api/v1/subset/create`;
const URL_REVIEW_SUBSET = `/api/v1/subset/for-review`;
const URL_LIST = `/api/v1/subset/list`;
const URL_MY_SUBSETS = `/api/v1/subset/list-mine`;
const URL_REJECT_SUBSET = `/api/v1/subset/reject`;
const URL_REMOVE_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/remove-accessions/{UUID},{version}`);
const URL_UPDATE = `/api/v1/subset/update`;
const URL_GET = UrlTemplate.parse(`/api/v1/subset/{UUID}`);
const URL_REMOVE = UrlTemplate.parse(`/api/v1/subset/{UUID},{version}`);
const URL_AUTOCOMPLETE = `/api/v1/subset/{UUID}/subsetcreator/autocomplete`;
const URL_CREATE_SUBSET_CREATOR = UrlTemplate.parse(`/api/v1/subset/{UUID}/subsetcreator/create`);
const URL_DELETE_SUBSET_CREATOR = UrlTemplate.parse(`/api/v1/subset/{UUID}/subsetcreator/delete`);
const URL_LIST_SUBSET_CREATORS = UrlTemplate.parse(`/api/v1/subset/{UUID}/subsetcreator/list`);
const URL_UPDATE_SUBSET_CREATOR = UrlTemplate.parse(`/api/v1/subset/{UUID}/subsetcreator/update`);
const URL_LOAD_BY_UUID = UrlTemplate.parse(`/api/v1/subset/{UUID}/subsetcreator/{creatorUuid}`);
Matija Obreza's avatar
Subsets  
Matija Obreza committed
29
30

/*
31
* Defined in Swagger as 'subset'
Matija Obreza's avatar
Subsets  
Matija Obreza committed
32
33
34
35
36
37
38
39
*/
class SubsetService {

  /**
   * addAccessions at /api/v1/subset/add-accessions/{UUID},{version}
   *
   * @param UUID UUID
   * @param version version
40
   * @param accessionIds accessionIds
Matija Obreza's avatar
Subsets  
Matija Obreza committed
41
   */
42
  public static addAccessions(UUID: string, version: number, accessionIds: string[]): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
43
44
45

    const apiUrl = URL_ADD_ACCESSIONS.expand({UUID, version});
    // console.log(`Fetching from ${apiUrl}`);
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    const content = { data: accessionIds };

    return axiosBackend.request({
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

  /**
   * approveSubset at /api/v1/subset/approve
   *
   * @param uuid uuid
   * @param version version
   */
  public static approveSubset(uuid: string, version: number): Promise<Subset> {

    const qs = QueryString.stringify({
      uuid: uuid || undefined,
      version: version || undefined,
    }, {});
    const apiUrl = URL_APPROVE_SUBSET + (qs ? `?${qs}` : '');
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };
Matija Obreza's avatar
Subsets  
Matija Obreza committed
70

71
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
72
73
74
75
76
77
78
79
80
81
82
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

  /**
   * create at /api/v1/subset/create
   *
   * @param subset subset
   */
83
  public static create(subset: Subset): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
84
85
86
87
88

    const apiUrl = URL_CREATE;
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: subset };

89
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
90
91
92
93
94
95
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /**
   * reviewSubset at /api/v1/subset/for-review
   *
   * @param uuid uuid
   * @param version version
   */
  public static reviewSubset(uuid: string, version: number): Promise<Subset> {

    const qs = QueryString.stringify({
      uuid: uuid || undefined,
      version: version || undefined,
    }, {});
    const apiUrl = URL_REVIEW_SUBSET + (qs ? `?${qs}` : '');
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };

    return axiosBackend.request({
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

Matija Obreza's avatar
Subsets  
Matija Obreza committed
119
120
121
122
  /**
   * list at /api/v1/subset/list
   *
   * @param filter filter
123
   * @param page undefined
Matija Obreza's avatar
Subsets  
Matija Obreza committed
124
   */
125
  public static list(filter: string | SubsetFilter, page?: IPageRequest): Promise<FilteredPage<Subset>> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
126
127
128
129
130

    const qs = QueryString.stringify({
      f: typeof filter === 'string' ? filter : undefined,
      p: page.page || undefined,
      l: page.size || undefined,
131
132
      d: page.direction && page.direction.length && page.direction || undefined,
      s: page.properties || undefined,
Matija Obreza's avatar
Subsets  
Matija Obreza committed
133
134
    }, {});
    const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
135
    console.log(`Fetching from ${apiUrl}`, page);
Matija Obreza's avatar
Subsets  
Matija Obreza committed
136
    const content = { data: typeof filter === 'string' ? null : { ...filter } };
Matija Obreza's avatar
Matija Obreza committed
137

138
    return axiosBackend.request({
Matija Obreza's avatar
Matija Obreza committed
139
140
141
142
143
144
145
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as FilteredPage<Subset>);
  }

  /**
146
   * mySubsets at /api/v1/subset/list-mine
Matija Obreza's avatar
Matija Obreza committed
147
148
   *
   * @param filter filter
149
   * @param page undefined
Matija Obreza's avatar
Matija Obreza committed
150
   */
151
  public static mySubsets(filter: string | SubsetFilter, page?: IPageRequest): Promise<FilteredPage<Subset>> {
Matija Obreza's avatar
Matija Obreza committed
152
153
154
155
156

    const qs = QueryString.stringify({
      f: typeof filter === 'string' ? filter : undefined,
      p: page.page || undefined,
      l: page.size || undefined,
157
158
      d: page.direction && page.direction.length && page.direction || undefined,
      s: page.properties || undefined,
Matija Obreza's avatar
Matija Obreza committed
159
    }, {});
160
    const apiUrl = URL_MY_SUBSETS + (qs ? `?${qs}` : '');
Matija Obreza's avatar
Matija Obreza committed
161
162
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: typeof filter === 'string' ? null : { ...filter } };
Matija Obreza's avatar
Subsets  
Matija Obreza committed
163

164
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
165
166
167
168
169
170
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as FilteredPage<Subset>);
  }

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
  /**
   * rejectSubset at /api/v1/subset/reject
   *
   * @param uuid uuid
   * @param version version
   */
  public static rejectSubset(uuid: string, version: number): Promise<Subset> {

    const qs = QueryString.stringify({
      uuid: uuid || undefined,
      version: version || undefined,
    }, {});
    const apiUrl = URL_REJECT_SUBSET + (qs ? `?${qs}` : '');
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };

    return axiosBackend.request({
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

Matija Obreza's avatar
Subsets  
Matija Obreza committed
194
195
196
197
198
199
200
  /**
   * removeAccessions at /api/v1/subset/remove-accessions/{UUID},{version}
   *
   * @param UUID UUID
   * @param version version
   * @param accessionsUuids accessionsUuids
   */
201
  public static removeAccessions(UUID: string, version: number, accessionsUuids: string[]): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
202
203
204
205
206

    const apiUrl = URL_REMOVE_ACCESSIONS.expand({UUID, version});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: accessionsUuids };

207
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
208
209
210
211
212
213
214
215
216
217
218
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

  /**
   * update at /api/v1/subset/update
   *
   * @param subset subset
   */
219
  public static update(subset: Subset): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
220
221
222
223
224

    const apiUrl = URL_UPDATE;
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: subset };

225
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
226
227
228
229
230
231
232
233
234
235
236
      url: apiUrl,
      method: 'POST',
      ...content,
    }).then(({ data }) => data as Subset);
  }

  /**
   * get at /api/v1/subset/{UUID}
   *
   * @param UUID UUID
   */
237
  public static get(UUID: string): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
238
239
240
241
242

    const apiUrl = URL_GET.expand({UUID});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };

243
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
244
245
246
247
248
249
250
      url: apiUrl,
      method: 'GET',
      ...content,
    }).then(({ data }) => data as Subset);
  }

  /**
251
   * remove at /api/v1/subset/{UUID},{version}
Matija Obreza's avatar
Subsets  
Matija Obreza committed
252
253
254
255
   *
   * @param UUID UUID
   * @param version version
   */
256
  public static remove(UUID: string, version: number): Promise<Subset> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
257

258
    const apiUrl = URL_REMOVE.expand({UUID, version});
Matija Obreza's avatar
Subsets  
Matija Obreza committed
259
260
261
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };

262
    return axiosBackend.request({
Matija Obreza's avatar
Subsets  
Matija Obreza committed
263
264
265
266
267
268
      url: apiUrl,
      method: 'DELETE',
      ...content,
    }).then(({ data }) => data as Subset);
  }

269
270
271
272
273
274
  /**
   * autocomplete at /api/v1/subset/{UUID}/subsetcreator/autocomplete
   *
   * @param c c
   */
  public static autocomplete(c: string): Promise<SubsetCreator[]> {
Matija Obreza's avatar
Subsets  
Matija Obreza committed
275

276
277
278
279
280
281
    const qs = QueryString.stringify({
      c: c || undefined,
    }, {});
    const apiUrl = URL_AUTOCOMPLETE + (qs ? `?${qs}` : '');
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
282

283
    return axiosBackend.request({
284
285
286
287
      url: apiUrl,
      method: 'GET',
      ...content,
    }).then(({ data }) => data as SubsetCreator[]);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
288
289
  }

290
291
292
293
294
295
296
297
298
299
300
  /**
   * createSubsetCreator at /api/v1/subset/{UUID}/subsetcreator/create
   *
   * @param UUID UUID
   * @param subsetCreator subsetCreator
   */
  public static createSubsetCreator(UUID: string, subsetCreator: SubsetCreator): Promise<SubsetCreator> {

    const apiUrl = URL_CREATE_SUBSET_CREATOR.expand({UUID});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: subsetCreator };
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
301

302
    return axiosBackend.request({
303
      url: apiUrl,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
304
      method: 'POST',
305
306
      ...content,
    }).then(({ data }) => data as SubsetCreator);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
307
308
  }

309
310
311
312
313
314
315
316
317
318
319
  /**
   * deleteSubsetCreator at /api/v1/subset/{UUID}/subsetcreator/delete
   *
   * @param UUID UUID
   * @param subsetCreator subsetCreator
   */
  public static deleteSubsetCreator(UUID: string, subsetCreator: SubsetCreator): Promise<SubsetCreator> {

    const apiUrl = URL_DELETE_SUBSET_CREATOR.expand({UUID});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: subsetCreator };
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
320

321
    return axiosBackend.request({
322
323
324
325
      url: apiUrl,
      method: 'DELETE',
      ...content,
    }).then(({ data }) => data as SubsetCreator);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
326
327
  }

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
  /**
   * listSubsetCreators at /api/v1/subset/{UUID}/subsetcreator/list
   *
   * @param UUID UUID
   * @param page undefined
   */
  public static listSubsetCreators(UUID: string, page?: IPageRequest): Promise<Page<SubsetCreator>> {

    const qs = QueryString.stringify({
      p: page.page || undefined,
      l: page.size || undefined,
      d: page.direction && page.direction.length && page.direction || undefined,
      s: page.properties || undefined,
    }, {});
    const apiUrl = URL_LIST_SUBSET_CREATORS.expand({UUID}) + (qs ? `?${qs}` : '');
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
345

346
    return axiosBackend.request({
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
      url: apiUrl,
      method: 'GET',
      ...content,
    }).then(({ data }) => data as Page<SubsetCreator>);
  }

  /**
   * updateSubsetCreator at /api/v1/subset/{UUID}/subsetcreator/update
   *
   * @param UUID UUID
   * @param subsetCreator subsetCreator
   */
  public static updateSubsetCreator(UUID: string, subsetCreator: SubsetCreator): Promise<SubsetCreator> {

    const apiUrl = URL_UPDATE_SUBSET_CREATOR.expand({UUID});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { data: subsetCreator };

    return axiosBackend.request({
      url: apiUrl,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
367
      method: 'POST',
368
369
      ...content,
    }).then(({ data }) => data as SubsetCreator);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
370
371
  }

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
  /**
   * loadByUuid at /api/v1/subset/{UUID}/subsetcreator/{creatorUuid}
   *
   * @param creatorUuid creatorUuid
   */
  public static loadByUuid(creatorUuid: string): Promise<SubsetCreator> {

    const apiUrl = URL_LOAD_BY_UUID.expand({creatorUuid});
    // console.log(`Fetching from ${apiUrl}`);
    const content = { /* No content in request body */ };

    return axiosBackend.request({
      url: apiUrl,
      method: 'GET',
      ...content,
    }).then(({ data }) => data as SubsetCreator);
  }


Matija Obreza's avatar
Subsets  
Matija Obreza committed
391
392
393
}

export default SubsetService;