• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FAIRsharing / fairsharing.github.io / 24769584990

22 Apr 2026 08:57AM UTC coverage: 95.892% (-4.1%) from 100.0%
24769584990

push

github

web-flow
Merge pull request #2746 from FAIRsharing/dev

Dev

3653 of 3813 branches covered (95.8%)

Branch coverage included in aggregate %.

17344 of 18229 new or added lines in 282 files covered. (95.15%)

766 existing lines in 50 files now uncovered.

38617 of 40268 relevant lines covered (95.9%)

5.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.62
/src/store/recordData.js
1
import { isEmpty, isEqual } from "lodash";
1✔
2
// import Vue from "vue";
1✔
3
import RESTClient from "@/lib/Client/RESTClient.js";
1✔
4

5
import Client from "../lib/GraphClient/GraphClient.js";
1✔
6
import recordDataAccessQuery from "../lib/GraphClient/queries/editor/getRecordDataAccess.json";
1✔
7
import recordRelationsQuery from "../lib/GraphClient/queries/editor/getRecordRelations.json";
1✔
8
import recordQuery from "../lib/GraphClient/queries/getRecord.json";
1✔
9
import recordHistory from "../lib/GraphClient/queries/getRecordHistory.json";
1✔
10
import recordOrganisationsQuery from "../lib/GraphClient/queries/getRecordOrganisations.json";
1✔
11
import { initEditorSections } from "./utils.js";
1✔
12

13
let client = new Client();
1✔
14
let restClient = new RESTClient();
1✔
15

16
/**
1✔
17
 * The record store handles the requests related to record (fairsharingRecord).
1✔
18
 * @type {Object}
1✔
19
 */
1✔
20
let recordStore = {
1✔
21
  namespaced: true,
1✔
22
  state: {
1✔
23
    currentRecord: {
1✔
24
      fairsharingRecord: {
1✔
25
        metadata: {
1✔
26
          citations: [],
1✔
27
        },
1✔
28
      },
1✔
29
    },
1✔
30
    currentRecordHistory: {},
1✔
31
    recordUpdate: {
1✔
32
      error: false,
1✔
33
      message: null,
1✔
34
      id: null,
1✔
35
    },
1✔
36
    sections: {
1✔
37
      generalInformation: initEditorSections(false, ["generalInformation"])
1✔
38
        .generalInformation,
1✔
39
    },
1✔
40
    editOrganisationLink: {
1✔
41
      showOverlay: false,
1✔
42
      data: {},
1✔
43
      id: null,
1✔
44
    },
1✔
45
    newRecord: false,
1✔
46
    currentID: null,
1✔
47
  },
1✔
48
  mutations: {
1✔
49
    setCurrentRecord(state, data) {
1✔
50
      state.currentRecord = data;
25✔
51
      let tags = ["subjects", "domains", "taxonomies", "userDefinedTags"];
25✔
52
      tags.forEach((tag) => {
25✔
53
        if (
100✔
54
          state.currentRecord["fairsharingRecord"][tag].length &&
100✔
55
          state.currentRecord["fairsharingRecord"][tag]
24✔
56
        ) {
100✔
57
          state.currentRecord["fairsharingRecord"][tag].forEach((item) => {
24✔
58
            item.type = tag;
24✔
59
          });
24✔
60
        }
24✔
61
      });
25✔
62
    },
1✔
63
    setRecordHistory(state, data) {
1✔
64
      state.currentRecordHistory = data;
2✔
65
    },
1✔
66
    resetCurrentRecordHistory(state) {
1✔
67
      state.currentRecordHistory = {};
36✔
68
    },
1✔
69
    setSections(state, data) {
1✔
70
      state.currentID = data["fairsharingRecord"].id;
18✔
71
      let sectionsNames = [
18✔
72
        "generalInformation",
18✔
73
        "support",
18✔
74
        "dataAccess",
18✔
75
        "publications",
18✔
76
        "organisations",
18✔
77
        "additionalInformation",
18✔
78
        "relations",
18✔
79
      ];
18✔
80
      state.sections = initEditorSections(
18✔
81
        data["fairsharingRecord"],
18✔
82
        sectionsNames,
18✔
83
      );
18✔
84
    },
1✔
85
    setGeneralInformation(state, data) {
1✔
86
      state.sections.generalInformation = initEditorSections(
9✔
87
        data["fairsharingRecord"],
9✔
88
        ["generalInformation"],
9✔
89
      ).generalInformation;
9✔
90
      if (data["fairsharingRecord"])
9✔
91
        state.sections.generalInformation.message =
9✔
92
          "Record successfully updated!";
3✔
93
    },
1✔
94
    resetMessage(state, sectionName) {
1✔
95
      state.sections[sectionName].message = null;
22✔
96
      state.sections[sectionName].message = false;
22✔
97
    },
1✔
98
    setSectionError(state, error) {
1✔
99
      state.sections[error.section].message = error.value;
8✔
100
      state.sections[error.section].error = true;
8✔
101
    },
1✔
102
    setChanges(state, diff) {
1✔
103
      state.sections[diff.section].changes = diff.value;
241✔
104
    },
1✔
105
    setContacts(state, contacts) {
1✔
106
      state.sections.generalInformation.data.metadata.contacts = contacts;
2✔
107
    },
1✔
108
    setTags(state, field) {
1✔
109
      state.sections.generalInformation.data[field.target] = field.value;
5✔
110
    },
1✔
111
    resetRegistry(state) {
1✔
112
      state.sections.generalInformation.data.type = "";
1✔
113
    },
1✔
114
    setPublications(state, publications) {
1✔
115
      state.sections.publications.data = publications;
2✔
116
    },
1✔
117
    setAdditionalInformation(state, additionalInformation) {
1✔
NEW
118
      if (!additionalInformation.subfieldName) {
×
NEW
119
        state.sections.additionalInformation.data[
×
NEW
120
          additionalInformation.fieldName
×
NEW
121
        ] = additionalInformation.fieldValue;
×
NEW
122
      } else {
×
NEW
123
        state.sections.additionalInformation.data[
×
NEW
124
          additionalInformation.fieldName
×
NEW
125
        ][additionalInformation.subfieldName] =
×
NEW
126
          additionalInformation.fieldValue;
×
NEW
127
      }
×
128
    },
1✔
129
    setAdditionalInformationSubField(state, additionalInformation) {
1✔
130
      if (additionalInformation.id !== null) {
3✔
131
        state.sections.additionalInformation.data[
1✔
132
          additionalInformation.fieldName
1✔
133
        ][additionalInformation.id] = additionalInformation.fieldValue;
1✔
134
      } else {
3✔
135
        if (
2✔
136
          !state.sections.additionalInformation.data[
2✔
137
            additionalInformation.fieldName
2✔
138
          ]
2✔
139
        ) {
2✔
140
          state.sections.additionalInformation.data[
1✔
141
            additionalInformation.fieldName
1✔
142
          ] = [];
1✔
143
        }
1✔
144
        try {
2✔
145
          state.sections.additionalInformation.data[
2✔
146
            additionalInformation.fieldName
2✔
147
          ][
2✔
148
            state.sections.additionalInformation.data[
2✔
149
              additionalInformation.fieldName
2✔
150
            ].length
2✔
151
          ] = additionalInformation.fieldValue;
2✔
152
          // eslint-disable-next-line no-empty
2✔
153
        } catch (e) {
2!
NEW
154
          // TODO: Investigate comments below.
×
NEW
155
          // Github has been failing tests (which are fine locally) here for reasons which
×
NEW
156
          // have not so far been determined.
×
NEW
157
          // TypeError: Cannot read property 'shallow' of undefined
×
NEW
158
          // ...on the Vue.set, above.
×
NEW
159
          // eslint-enable-next-line no-empty
×
NEW
160
        }
×
161
      }
2✔
162
    },
1✔
163
    removeAdditionalInformationSubField(state, additionalInformation) {
1✔
164
      state.sections.additionalInformation.data[
1✔
165
        additionalInformation.fieldName
1✔
166
      ].splice(additionalInformation.id, 1);
1✔
167
    },
1✔
168
    updateOrganisationsLinks(state, links) {
1✔
169
      state.sections.organisations.data = links;
3✔
170
      state.sections.organisations.initialData = JSON.parse(
3✔
171
        JSON.stringify(links),
3✔
172
      );
3✔
173
      state.sections.organisations.changes = 0;
3✔
174
      state.sections.organisations.message = "Record successfully updated!";
3✔
175
    },
1✔
176
    setEditOrganisationLink(state, newLink) {
1✔
177
      state.editOrganisationLink = newLink;
2✔
178
    },
1✔
179
    setEditOrganisationLinkOrganisation(state, organisation) {
1✔
180
      state.editOrganisationLink.data.organisation = organisation;
1✔
181
    },
1✔
182
    setEditOrganisationLinkGrant(state, grant) {
1✔
183
      state.editOrganisationLink.data.grant = grant;
1✔
184
    },
1✔
185
    setDataAccess(state, dataAccess) {
1✔
186
      let record = {
4✔
187
        exhaustiveLicences: dataAccess.exhaustiveLicences,
4✔
188
        licences: dataAccess["licenceLinks"],
4✔
189
        support_links: dataAccess.metadata.support_links,
4✔
190
      };
4✔
191
      state.sections.generalInformation.data.metadata.support_links =
4✔
192
        JSON.parse(JSON.stringify(record.support_links));
4✔
193
      state.sections.dataAccess.data.exhaustiveLicences =
4✔
194
        record.exhaustiveLicences;
4✔
195
      state.sections.generalInformation.initialData.metadata.support_links =
4✔
196
        JSON.parse(JSON.stringify(record.support_links));
4✔
197
      record.support_links.forEach((supportLink) => {
4✔
198
        if (supportLink.name)
8✔
199
          supportLink.url = { title: supportLink.name, url: supportLink.url };
8✔
200
      });
4✔
201
      state.sections.dataAccess.data = record;
4✔
202
      state.sections.dataAccess.initialData = JSON.parse(
4✔
203
        JSON.stringify(record),
4✔
204
      );
4✔
205
      state.sections.dataAccess.changes = 0;
4✔
206
      state.sections.dataAccess.message = "Record successfully updated!";
4✔
207
    },
1✔
208
    updateAdditionalInformation(state, additionalInformation) {
1✔
209
      let record = {};
2✔
210
      Object.keys(additionalInformation.record).forEach((field) => {
2✔
211
        if (additionalInformation.fields.includes(field)) {
38✔
212
          record[field] = additionalInformation.record[field];
26✔
213
          state.sections.generalInformation.data.metadata[field] = JSON.parse(
26✔
214
            JSON.stringify(record[field]),
26✔
215
          );
26✔
216
          state.sections.generalInformation.initialData.metadata[field] =
26✔
217
            JSON.parse(JSON.stringify(record[field]));
26✔
218
        }
26✔
219
      });
2✔
220
      state.sections.additionalInformation.data = record;
2✔
221
      state.sections.additionalInformation.initialData = JSON.parse(
2✔
222
        JSON.stringify(record),
2✔
223
      );
2✔
224
      state.sections.additionalInformation.changes = 0;
2✔
225
      state.sections.additionalInformation.message =
2✔
226
        "Record successfully updated!";
2✔
227
    },
1✔
228
    setCreatingNewRecord(state) {
1✔
229
      state.newRecord = true;
6✔
230
    },
1✔
231
    setEditingRecord(state) {
1✔
232
      state.newRecord = false;
6✔
233
    },
1✔
234
    setRelations(state, relations) {
1✔
NEW
235
      state.sections.relations.data.recordAssociations = relations;
×
NEW
236
      state.sections.relations.initialData.recordAssociations = JSON.parse(
×
NEW
237
        JSON.stringify(relations),
×
NEW
238
      );
×
NEW
239
      state.sections.relations.changes = 0;
×
NEW
240
      state.sections.relations.message = "Record successfully updated!";
×
NEW
241
      state.sections.relations.error = false;
×
242
    },
1✔
243
    setMessage(state, message) {
1✔
244
      state.sections[message.target].message = message.value;
7✔
245
    },
1✔
246
    setNewRecord(state, id) {
1✔
247
      state.recordUpdate = {
8✔
248
        error: false,
8✔
249
        message: "success",
8✔
250
        id: id,
8✔
251
      };
8✔
252
    },
1✔
253
    setError(state, error) {
1✔
254
      state.recordUpdate = {
12✔
255
        error: true,
12✔
256
        message: error,
12✔
257
        id: null,
12✔
258
      };
12✔
259
    },
1✔
260
    cleanRecordStore(state) {
1✔
261
      state.sections = null;
2✔
262
      state.sections = initEditorSections(false, [
2✔
263
        "generalInformation",
2✔
264
        "support",
2✔
265
        "dataAccess",
2✔
266
        "publications",
2✔
267
        "organisations",
2✔
268
        "additionalInformation",
2✔
269
      ]);
2✔
270
    },
1✔
271
  },
1✔
272
  actions: {
1✔
273
    async fetchRecord(state, options) {
1✔
274
      state.commit("resetCurrentRecordHistory");
35✔
275
      recordQuery.queryParam = {
35✔
276
        id: options.id,
35✔
277
      };
35✔
278
      if (options.token) {
35✔
279
        client.setHeader(options.token);
29✔
280
      }
29✔
281
      let data = await client.executeQuery(recordQuery);
35✔
282
      client.initalizeHeader();
34✔
283
      if (!data["fairsharingRecord"]["metadata"]["contacts"]) {
35✔
284
        data["fairsharingRecord"]["metadata"]["contacts"] = [];
1✔
285
      }
1✔
286
      // Citations should be created if empty.
18✔
287
      if (!data["fairsharingRecord"]["metadata"]["citations"]) {
35✔
288
        data["fairsharingRecord"]["metadata"]["citations"] = [];
1✔
289
      }
1✔
290
      state.commit("setCurrentRecord", JSON.parse(JSON.stringify(data)));
18✔
291
      state.commit("setSections", JSON.parse(JSON.stringify(data)));
18✔
292
    },
1✔
293
    async fetchPreviewRecord(state, id) {
1✔
294
      state.commit("resetCurrentRecordHistory");
1✔
295
      recordQuery.queryParam = {
1✔
296
        id: id,
1✔
297
      };
1✔
298
      let data = await client.executeQuery(recordQuery);
1✔
299
      state.commit("setCurrentRecord", data);
1✔
300
    },
1✔
301
    async fetchRecordHistory(state, options) {
1✔
302
      recordHistory.queryParam = { id: options.id };
2✔
303
      client.setHeader(options.token);
2✔
304
      let data = await client.executeQuery(recordHistory);
2✔
305
      state.commit("setRecordHistory", data["fairsharingRecord"]);
2✔
306
    },
1✔
307
    async updateGeneralInformation({ state, commit }, options) {
1✔
308
      commit("resetMessage", "generalInformation");
5✔
309
      let {
5✔
310
          type,
5✔
311
          countries,
5✔
312
          userDefinedTags,
5✔
313
          objectTypes,
5✔
314
          domains,
5✔
315
          subjects,
5✔
316
          taxonomies,
5✔
317
          status,
5✔
318
          curator_notes,
5✔
319
          isHidden,
5✔
320
          logo,
5✔
321
          maintainers,
5✔
322
          watchers,
5✔
323
          ...record
5✔
324
        } = JSON.parse(JSON.stringify(state.sections.generalInformation.data)),
5✔
325
        newTags = [],
5✔
326
        oldTags = [],
5✔
327
        tags = [];
5✔
328
      userDefinedTags.forEach((tag) => {
5✔
329
        if (Object.keys(tag).indexOf("id") === -1) {
10✔
330
          newTags.push(tag.label);
5✔
331
        } else {
5✔
332
          oldTags.push(tag.id);
5✔
333
        }
5✔
334
      });
5✔
335
      newTags = await Promise.all(
5✔
336
        newTags.map((tag) =>
5✔
337
          restClient.createNewUserDefinedTag(tag, options.token),
5✔
338
        ),
5✔
339
      );
5✔
340
      newTags.forEach((tag) => {
5✔
341
        if (!tag.error) {
5✔
342
          tags.push(tag.id);
4✔
343
        } else {
5✔
344
          commit("setSectionError", {
1✔
345
            section: "generalInformation",
1✔
346
            value: tag.error,
1✔
347
          });
1✔
348
          return tag.error;
1✔
349
        }
1✔
350
      });
5✔
351

352
      isEmpty(logo) ? delete record["logo"] : (record.logo = logo);
5✔
353
      record.country_ids = countries.map((obj) => obj.id);
5✔
354
      if (type.id) record.record_type_id = type.id;
5✔
355
      record.metadata.status = status;
5✔
356
      record.curator_notes = curator_notes;
5✔
357
      record.hidden = isHidden;
5✔
358
      record.object_type_ids = objectTypes.map((obj) => obj.id);
5✔
359
      record.domain_ids = domains.map((obj) => obj.id);
5✔
360
      record.subject_ids = subjects.map((obj) => obj.id);
5✔
361
      record.taxonomy_ids = taxonomies.map((obj) => obj.id);
5✔
362
      record.maintainer_ids = maintainers.map((obj) => obj.id);
5✔
363
      record.watcher_ids = watchers.map((obj) => obj.id);
5✔
364
      record.user_defined_tag_ids = tags.concat(
5✔
365
        oldTags.filter(function (el) {
5✔
366
          return el != null;
5✔
367
        }),
5✔
368
      );
5✔
369
      if (options.change) {
5✔
370
        record.remove_additional_properties = true;
2✔
371
      }
2✔
372
      let response = await restClient.updateRecord({
5✔
373
        record: record,
5✔
374
        token: options.token,
5✔
375
        id: options.id,
5✔
376
      });
5✔
377
      if (response.error) {
5✔
378
        commit("setSectionError", {
2✔
379
          section: "generalInformation",
2✔
380
          value: response.error,
2✔
381
        });
2✔
382
        return response.error;
2✔
383
      } else {
5✔
384
        let newRecord = JSON.parse(
3✔
385
          JSON.stringify(state.sections.generalInformation.data),
3✔
386
        );
3✔
387
        let userDefinedTags = [];
3✔
388
        newRecord.userDefinedTags.forEach((obj) => {
3✔
389
          if (Object.keys(obj).indexOf("id") === -1) {
6✔
390
            obj.id = newTags.filter((tag) => {
3✔
391
              tag.label = obj.label;
3✔
392
            })[0];
3✔
393
            userDefinedTags.push(obj);
3✔
394
          } else userDefinedTags.push(obj);
3✔
395
        });
3✔
396
        newRecord.userDefinedTags = userDefinedTags;
3✔
397
        commit("setGeneralInformation", { fairsharingRecord: newRecord });
3✔
398
      }
3✔
399
    },
1✔
400
    async updatePublications({ state, commit }, options) {
1✔
401
      commit("resetMessage", "publications");
7✔
402
      let publications = JSON.parse(
7✔
403
        JSON.stringify(state.sections.publications.data),
7✔
404
      );
7✔
405
      let record_data = {
7✔
406
        publication_ids: [],
7✔
407
        citation_ids: [],
7✔
408
      };
7✔
409
      publications.forEach(function (publication) {
7✔
410
        record_data.publication_ids.push(publication.id);
14✔
411
        if (publication.isCitation) {
14✔
412
          record_data.citation_ids.push(publication.id);
5✔
413
        }
5✔
414
        delete publication.isCitation;
14✔
415
      });
7✔
416
      const record = {
7✔
417
        record: record_data,
7✔
418
        token: options.token,
7✔
419
        id: options.id,
7✔
420
      };
7✔
421
      let response = await restClient.updateRecord(record);
7✔
422
      if (response.error) {
7✔
423
        commit("setSectionError", {
2✔
424
          section: "publications",
2✔
425
          value: response.error,
2✔
426
        });
2✔
427
        return response.error;
2✔
428
      } else {
7✔
429
        commit("setMessage", {
5✔
430
          target: "publications",
5✔
431
          value: "Record successfully updated!",
5✔
432
        });
5✔
433
      }
5✔
434
    },
1✔
435
    async updateOrganisations({ state, commit }, userToken) {
1✔
436
      commit("resetMessage", "organisations");
3✔
437
      let deleteItems = [],
3✔
438
        updateItems = [],
3✔
439
        createItems = [];
3✔
440
      state.sections.organisations.initialData.forEach((obj) => {
3✔
441
        let found = state.sections.organisations.data.filter(
3✔
442
          (org) => org.id === obj.id,
3✔
443
        )[0];
3✔
444
        if (!found) {
3✔
445
          deleteItems.push(obj);
1✔
446
        }
1✔
447
      });
3✔
448
      state.sections.organisations.data.forEach(function (obj) {
3✔
449
        let query = {
2✔
450
          fairsharing_record_id: state.currentRecord["fairsharingRecord"].id,
2✔
451
          organisation_id: obj.organisation.id,
2✔
452
          relation: obj.relation,
2✔
453
          grant_id: obj.grant ? obj.grant.id : null,
2✔
454
          is_lead: obj.isLead,
2✔
455
        };
2✔
456
        if (Object.prototype.hasOwnProperty.call(obj, "id"))
2✔
457
          updateItems.push({ query: query, id: obj.id });
2!
NEW
458
        else createItems.push(query);
×
459
      });
3✔
460
      let queries = await Promise.all([
3✔
461
        ...deleteItems.map((organisation) =>
3✔
462
          restClient.deleteOrganisationLink(organisation.id, userToken),
3✔
463
        ),
3✔
464
        ...createItems.map((organisation) =>
3✔
465
          restClient.createOrganisationLink(organisation, userToken),
3✔
466
        ),
3✔
467
        ...updateItems.map((organisation) =>
3✔
468
          restClient.updateOrganisationLink(
2✔
469
            organisation.query,
2✔
470
            organisation.id,
2✔
471
            userToken,
2✔
472
          ),
3✔
473
        ),
3✔
474
      ]);
3✔
475
      queries.forEach((org) => {
3✔
476
        if (org.error) {
3✔
477
          commit("setSectionError", {
1✔
478
            section: "organisations",
1✔
479
            value: org.error,
1✔
480
          });
1✔
481
        }
1✔
482
      });
3✔
483
      recordOrganisationsQuery.queryParam = {
3✔
484
        id: state.currentRecord.fairsharingRecord.id,
3✔
485
      };
3✔
486
      client.setHeader(userToken);
3✔
487
      let organisations = await client.executeQuery(recordOrganisationsQuery);
3✔
488
      commit(
3✔
489
        "updateOrganisationsLinks",
3✔
490
        organisations.fairsharingRecord.organisationLinks,
3✔
491
      );
3✔
492
    },
1✔
493
    async updateAdditionalInformation({ state, commit }, options) {
1✔
494
      commit("resetMessage", "additionalInformation");
3✔
495
      let newRecord = {
3✔
496
        metadata: state.sections.generalInformation.initialData.metadata,
3✔
497
      };
3✔
498
      options.fields.forEach((field) => {
3✔
499
        if (state.sections.additionalInformation.data[field]) {
45✔
500
          Object.keys(state.sections.additionalInformation.data[field]).forEach(
36✔
501
            (key) => {
36✔
502
              if (
86✔
503
                state.sections.additionalInformation.data[field][key] === ""
86✔
504
              ) {
86✔
505
                delete state.sections.additionalInformation.data[field][key];
2✔
506
              }
2✔
507
            },
36✔
508
          );
36✔
509
          newRecord.metadata[field] =
36✔
510
            state.sections.additionalInformation.data[field];
36✔
511
        } else if (state.sections.additionalInformation.data[field] === null) {
45✔
512
          // if its the case that there is a single string textInput only
2✔
513
          state.sections.additionalInformation.data[field] = "";
2✔
514
          newRecord.metadata[field] =
2✔
515
            state.sections.additionalInformation.data[field];
2✔
516
        }
2✔
517
      });
3✔
518
      let response = await restClient.updateRecord({
3✔
519
        record: newRecord,
3✔
520
        token: options.token,
3✔
521
        id: options.id,
3✔
522
      });
3✔
523
      if (response.error) {
3✔
524
        commit("setSectionError", {
1✔
525
          section: "additionalInformation",
1✔
526
          value: response.error,
1✔
527
        });
1✔
528
        return response.error;
1✔
529
      } else {
3✔
530
        commit("setMessage", {
2✔
531
          target: "additionalInformation",
2✔
532
          value: "Record successfully updated!",
2✔
533
        });
2✔
534
        commit("updateAdditionalInformation", {
2✔
535
          record: newRecord.metadata,
2✔
536
          fields: options.fields,
2✔
537
        });
2✔
538
      }
2✔
539
    },
1✔
540
    async updateDataAccess({ state, commit }, options) {
1✔
541
      commit("resetMessage", "dataAccess");
4✔
542
      let newRecord = {
4✔
543
        metadata: state.sections.generalInformation.initialData.metadata,
4✔
544
      };
4✔
545
      newRecord.metadata.support_links =
4✔
546
        state.sections.dataAccess.data.support_links;
4✔
547
      newRecord.metadata.support_links.forEach((supportLink) => {
4✔
548
        if (typeof supportLink.url !== "string") {
7✔
549
          supportLink.url = supportLink.url.url;
3✔
550
        }
3✔
551
      });
4✔
552

553
      let initialLicences = state.sections.dataAccess.initialData.licences,
4✔
554
        currentLicences = state.sections.dataAccess.data.licences,
4✔
555
        toDelete = [],
4✔
556
        toUpdate = [],
4✔
557
        toCreate = [];
4✔
558
      initialLicences.forEach((licence) => {
4✔
559
        let found = currentLicences.filter((obj) => obj.id === licence.id)[0];
7✔
560
        if (!found) toDelete.push(licence.id);
7✔
561
      });
4✔
562
      currentLicences.forEach((licence) => {
4✔
563
        let found = initialLicences.filter((obj) => obj.id === licence.id)[0],
9✔
564
          newLicence = prepareLicence(licence);
9✔
565
        if (!found) {
9✔
566
          toCreate.push(newLicence);
3✔
567
        } else if (found && !isEqual(licence, found)) {
9✔
568
          toUpdate.push(newLicence);
1✔
569
        }
1✔
570
      });
4✔
571
      newRecord.exhaustive_licences =
4✔
572
        state.sections.dataAccess.data.exhaustiveLicences;
4✔
573
      let responses = await Promise.all([
4✔
574
        restClient.updateRecord({
4✔
575
          record: newRecord,
4✔
576
          token: options.token,
4✔
577
          id: options.id,
4✔
578
        }),
4✔
579
        ...toCreate.map((licence) =>
4✔
580
          restClient.createLicenceLink(licence, options.token),
4✔
581
        ),
4✔
582
        ...toUpdate.map((licence) =>
4✔
583
          restClient.updateLicenceLink(licence, options.token),
4✔
584
        ),
4✔
585
        ...toDelete.map((licence) =>
4✔
586
          restClient.deleteLicenceLink(licence, options.token),
4✔
587
        ),
4✔
588
      ]);
4✔
589
      responses.forEach((response) => {
4✔
590
        if (response.error) {
9✔
591
          commit("setSectionError", {
1✔
592
            section: "dataAccess",
1✔
593
            value: response.error,
1✔
594
          });
1✔
595
          return response.error;
1✔
596
        }
1✔
597
      });
4✔
598

599
      recordDataAccessQuery.queryParam = {
4✔
600
        id: state.currentRecord.fairsharingRecord.id,
4✔
601
      };
4✔
602
      client.setHeader(options.token);
4✔
603
      let dataAccess = await client.executeQuery(recordDataAccessQuery);
4✔
604
      commit("setDataAccess", dataAccess.fairsharingRecord);
4✔
605
    },
1✔
606
    async updateRelations({ state, commit }, options) {
1✔
NEW
607
      commit("resetMessage", "relations");
×
NEW
608
      let newAssociations = [],
×
NEW
609
        deleteAssociations = [],
×
NEW
610
        oldAssociations = [];
×
NEW
611
      state.sections.relations.data.recordAssociations.forEach(
×
NEW
612
        (association) => {
×
NEW
613
          if (association.new) {
×
NEW
614
            const newAssociation = {
×
NEW
615
              fairsharing_record_id: options.source,
×
NEW
616
              linked_record_id: association.linkedRecord.id,
×
NEW
617
              record_assoc_label_id: association.recordAssocLabel.id,
×
NEW
618
            };
×
NEW
619
            newAssociations.push(newAssociation);
×
NEW
620
          } else {
×
NEW
621
            // Using a combination of record_id and label_id as this should be unique.
×
NEW
622
            // Using only record_id produced:
×
NEW
623
            // https://github.com/FAIRsharing/fairsharing.github.io/issues/1620
×
NEW
624
            let id =
×
NEW
625
              association.linkedRecord.id +
×
NEW
626
              "_" +
×
NEW
627
              association.recordAssocLabelId;
×
NEW
628
            oldAssociations.push(id);
×
NEW
629
          }
×
NEW
630
        },
×
NEW
631
      );
×
NEW
632
      state.sections.relations.initialData.recordAssociations.forEach(
×
NEW
633
        (oldAssociation) => {
×
NEW
634
          // Same unique ID as above.
×
NEW
635
          let id =
×
NEW
636
            oldAssociation.linkedRecord.id +
×
NEW
637
            "_" +
×
NEW
638
            oldAssociation.recordAssocLabelId;
×
NEW
639
          if (id && !oldAssociations.includes(id)) {
×
NEW
640
            deleteAssociations.push({
×
NEW
641
              id: oldAssociation.id,
×
NEW
642
              _destroy: 1,
×
UNCOV
643
            });
×
NEW
644
          }
×
NEW
645
        },
×
NEW
646
      );
×
NEW
647
      let responses = await Promise.all([
×
NEW
648
        restClient.saveRelations({
×
NEW
649
          token: options.token,
×
NEW
650
          relations: newAssociations,
×
NEW
651
          target: options.source,
×
NEW
652
        }),
×
NEW
653
        restClient.deleteRelations({
×
NEW
654
          token: options.token,
×
NEW
655
          relations: deleteAssociations,
×
NEW
656
          target: options.source,
×
NEW
657
        }),
×
NEW
658
      ]);
×
NEW
659
      let error = false;
×
NEW
660
      for (let response of responses) {
×
NEW
661
        if (response.error) {
×
NEW
662
          commit("setSectionError", {
×
NEW
663
            section: "relations",
×
NEW
664
            value: response.error,
×
NEW
665
          });
×
NEW
666
          error = true;
×
UNCOV
667
        }
×
NEW
668
      }
×
NEW
669
      if (!error) {
×
NEW
670
        recordRelationsQuery.queryParam = { id: options.source };
×
NEW
671
        client.setHeader(options.token);
×
NEW
672
        let relations = await client.executeQuery(recordRelationsQuery);
×
NEW
673
        commit(
×
NEW
674
          "setRelations",
×
NEW
675
          relations["fairsharingRecord"].recordAssociations,
×
NEW
676
        );
×
NEW
677
      }
×
678
    },
1✔
679
    resetRecord(state) {
1✔
680
      state.commit("setGeneralInformation", { fairsharingRecord: false });
6✔
681
    },
1✔
682
    async updateRecord(state, newRecord) {
1✔
683
      let response = await restClient.updateRecord(newRecord);
20✔
684
      if (response.error) {
20✔
685
        state.commit("setError", response.error.response);
12✔
686
      } else {
20✔
687
        state.commit("setNewRecord", response);
8✔
688
      }
8✔
689
    },
1✔
690
  },
1✔
691
  getters: {
1✔
692
    getField: (state) => (fieldName) => {
1✔
693
      return state.currentRecord["fairsharingRecord"][fieldName];
129✔
694
    },
1✔
695
    getSection: (state) => (sectionName) => {
1✔
696
      return state.sections[sectionName];
465✔
697
    },
1✔
698
    getChanges: (state) => {
1✔
699
      let changes = {};
3✔
700
      Object.keys(state.sections).forEach((section) => {
3✔
701
        changes[section] = state.sections[section].changes;
3✔
702
      });
3✔
703
      return changes;
3✔
704
    },
1✔
705
    getAllChanges: (state) => {
1✔
706
      let changes = 0;
1✔
707
      Object.keys(state.sections).forEach((section) => {
1✔
708
        changes += state.sections[section].changes;
7✔
709
      });
1✔
710
      return changes;
1✔
711
    },
1✔
712
    getCreatingNewRecord: (state) => {
1✔
713
      return state.newRecord;
3✔
714
    },
1✔
715
    getRecordType: (state) => {
1✔
716
      return state.sections["generalInformation"].initialData.type;
6✔
717
    },
1✔
718
  },
1✔
719
};
1✔
720

721
function prepareLicence(rawLicence) {
9✔
722
  let preparedLicence = { relation: rawLicence.relation };
9✔
723
  preparedLicence.fairsharing_record_id = rawLicence.fairsharingRecord
9✔
724
    ? rawLicence.fairsharingRecord.id
9✔
725
    : rawLicence.fairsharing_record_id;
9✔
726
  if (rawLicence.id) preparedLicence.id = rawLicence.id;
9✔
727

728
  if (rawLicence.licence.id) {
9✔
729
    preparedLicence.licence_id = rawLicence.licence.id;
8✔
730
  } else {
9✔
731
    preparedLicence.licence_attributes = rawLicence.licence;
1✔
732
  }
1✔
733
  return preparedLicence;
9✔
734
}
9✔
735

736
export default recordStore;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc