|
1 |
| -import fetch from "node-fetch"; |
2 |
| -import { app } from "../app"; |
3 |
| -import { Decorators } from "divaservices-utils"; |
4 |
| -import { |
5 |
| - SERVICES_API, |
6 |
| - WEBSERVICES_XML_FILEPATH, |
7 |
| - COLLECTIONS_API, |
8 |
| - WORKFLOWS_API |
9 |
| -} from "../../config"; |
| 1 | +import { Decorators, API } from "divaservices-utils"; |
| 2 | +import { WEBSERVICES_XML_FILEPATH } from "../../config"; |
| 3 | +import { webservices } from "../constants/globals"; |
10 | 4 |
|
11 |
| -export const getServicesAPI = async () => { |
12 |
| - let xml; |
| 5 | +export const getServices = async () => { |
13 | 6 | if (process.env.NODE_ENV === "production") {
|
14 |
| - const xmlApi = await fetch(SERVICES_API); |
15 |
| - xml = await xmlApi.text(); |
| 7 | + return await API.getServices(); |
16 | 8 | } else {
|
17 | 9 | const filepath = WEBSERVICES_XML_FILEPATH;
|
18 |
| - xml = (await import(`!!raw-loader!../../${filepath}`)).default; |
| 10 | + const xml = (await import(`!!raw-loader!../../${filepath}`)).default; |
| 11 | + return await Decorators.webservicesDecorator(xml); |
19 | 12 | }
|
20 |
| - return xml; |
21 | 13 | };
|
22 | 14 |
|
23 |
| -export const sendWorkflowSteps = async (xml, installation = false) => { |
24 |
| - // const xhr = new XMLHttpRequest(); |
25 |
| - // xhr.open( |
26 |
| - // "POST", |
27 |
| - // "http://diufvm17.unifr.ch:8080/exist/projects/diae/api/workflow/save?id=" + |
28 |
| - // app.workflowId, |
29 |
| - // true |
30 |
| - // ); |
31 |
| - // xhr.setRequestHeader("Content-Type", "text/xml"); |
32 |
| - // xhr.setRequestHeader("username", USERNAME); |
33 |
| - // xhr.setRequestHeader("password", PASSWORD); |
34 |
| - // xhr.send(xml); |
35 |
| - |
36 |
| - const install = installation ? "install=true&" : ""; |
37 |
| - |
38 |
| - return await fetch(`${WORKFLOWS_API}/save?${install}id=${app.workflowId}`, { |
39 |
| - method: "POST", |
40 |
| - body: xml, |
41 |
| - headers: { |
42 |
| - "Content-Type": "text/xml" |
43 |
| - } |
44 |
| - }); |
45 |
| -}; |
46 |
| - |
47 |
| -export const openWorkflowFromId = async id => { |
48 |
| - let xml; |
| 15 | +export const getWorkflowById = async (id, asXml = false) => { |
49 | 16 | if (process.env.NODE_ENV === "production") {
|
50 |
| - const workflow = await fetch(`${WORKFLOWS_API}?id=${id}`, { |
51 |
| - headers: { |
52 |
| - "Content-Type": "text/xml" |
53 |
| - } |
54 |
| - }); |
55 |
| - xml = await workflow.text(); |
| 17 | + if (asXml) { |
| 18 | + return await API.getWorkflowByIdJSON(id); |
| 19 | + } else { |
| 20 | + return await API.getWorkflowById(id); |
| 21 | + } |
56 | 22 | } else {
|
57 |
| - xml = `<Workflow> |
| 23 | + const xml = `<Workflow> |
58 | 24 | <Id>116</Id>
|
59 | 25 | <Information>
|
60 | 26 | <Name>new rofklow</Name>
|
@@ -94,19 +60,17 @@ export const openWorkflowFromId = async id => {
|
94 | 60 | </Step>
|
95 | 61 | </Steps>
|
96 | 62 | </Workflow>`;
|
| 63 | + return asXml ? xml : await Decorators.workflowDecorator(xml, webservices); |
97 | 64 | }
|
98 |
| - return xml; |
99 | 65 | };
|
100 | 66 |
|
101 |
| -export const getCollectionsAPI = async () => { |
102 |
| - let xml; |
| 67 | +export const getCollections = async () => { |
103 | 68 | if (process.env.NODE_ENV === "production") {
|
104 |
| - const xmlApi = await fetch(COLLECTIONS_API); |
105 |
| - xml = await xmlApi.text(); |
| 69 | + return await API.getCollections(); |
106 | 70 | } else {
|
107 | 71 | // const filepath = "collections.xml";
|
108 | 72 | // xml = (await import(`raw-loader!./${filepath}`)).default;
|
109 |
| - xml = `<Collections> |
| 73 | + const xml = `<Collections> |
110 | 74 | <Collection>
|
111 | 75 | <Id>134</Id>
|
112 | 76 | <Url>http://134.21.72.190:8080/collections/qwertz</Url>
|
@@ -335,7 +299,6 @@ export const getCollectionsAPI = async () => {
|
335 | 299 | </File>
|
336 | 300 | </Files>
|
337 | 301 | </Collection></Collections>`;
|
| 302 | + return await Decorators.collectionsDecorator(xml); |
338 | 303 | }
|
339 |
| - |
340 |
| - return await Decorators.collectionsDecorator(xml); |
341 | 304 | };
|
0 commit comments