Skip to content

Commit 2df4625

Browse files
committed
Merge branch 'fix/dhis2-42-compatibility' into release/normal-release
* fix/dhis2-42-compatibility: use d2-api beta reference d2-api beta version clean up unused method use 2.42 schema update attribute filter to use attribute id as field update d2-api reference update attribute query update access fields remove userCredentials update sharing fields split metadata query
2 parents 7d753f7 + 68e5e8d commit 2df4625

File tree

8 files changed

+229
-133
lines changed

8 files changed

+229
-133
lines changed

src/data/repositories/D2ApiAppSettings.ts

Lines changed: 181 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -63,116 +63,189 @@ export class D2ApiAppSettings {
6363
const compactValues = (values: Maybe<string>[]) => _(values).compact().value();
6464

6565
return this.get().flatMap(appSettings => {
66-
return apiToFuture(
67-
this.api.metadata.get({
68-
attributes: {
69-
fields: { id: true, name: true, code: true },
70-
filter: {
71-
identifiable: {
72-
in: compactValues([
73-
appSettings.dataSetFilterField,
74-
appSettings.groupField,
75-
appSettings.inputDateField,
76-
appSettings.periodDateField,
77-
appSettings.indicatorHideField,
78-
// used for scripts to migrate data
79-
// not necessary to be configurable in the app through settings
80-
metadataCodes.attributes.outcomeDates,
81-
metadataCodes.attributes.outputDates,
82-
metadataCodes.attributes.project,
83-
metadataCodes.attributes.outputCompanionIndicator,
84-
metadataCodes.attributes.outcomeCompanionIndicator,
85-
metadataCodes.attributes.indicatorMatching,
86-
]),
87-
},
88-
},
89-
},
90-
categoryCombos: {
91-
fields: { id: true, name: true, code: true },
92-
filter: {
93-
identifiable: {
94-
in: compactValues([appSettings.categoryComboId]),
95-
},
96-
},
97-
},
98-
organisationUnitLevels: {
99-
fields: { id: true, name: true, code: true, level: true },
100-
filter: {
101-
identifiable: { in: compactValues([appSettings.countryLevelId]) },
102-
},
103-
},
104-
categories: {
105-
fields: { id: true, name: true, code: true },
106-
filter: {
107-
identifiable: {
108-
in: compactValues([appSettings.defaultProjectId]),
109-
},
110-
},
111-
},
112-
dataElementGroupSets: {
113-
fields: { id: true, name: true, code: true },
114-
filter: {
115-
identifiable: {
116-
in: compactValues([
117-
appSettings.coreCompetencyId,
118-
appSettings.dataElementThemeId,
119-
appSettings.originDataElementId,
120-
appSettings.statusDataElementId,
121-
metadataCodes.dataElementGroupSets.measure,
122-
]),
123-
},
124-
},
66+
return (
67+
Future.joinObj(
68+
{
69+
attributes: apiToFuture(
70+
this.api.models.attributes.get({
71+
fields: { id: true, name: true, code: true },
72+
filter: {
73+
id: {
74+
in: compactValues([
75+
appSettings.dataSetFilterField,
76+
appSettings.groupField,
77+
appSettings.inputDateField,
78+
appSettings.periodDateField,
79+
appSettings.indicatorHideField,
80+
]),
81+
},
82+
code: {
83+
in: compactValues([
84+
// used for scripts to migrate data
85+
// not necessary to be configurable in the app through settings
86+
metadataCodes.attributes.outcomeDates,
87+
metadataCodes.attributes.outputDates,
88+
metadataCodes.attributes.project,
89+
metadataCodes.attributes.outputCompanionIndicator,
90+
metadataCodes.attributes.outcomeCompanionIndicator,
91+
metadataCodes.attributes.indicatorMatching,
92+
]),
93+
},
94+
},
95+
rootJunction: "OR",
96+
paging: false,
97+
})
98+
),
99+
categoryCombos: apiToFuture(
100+
this.api.models.categoryCombos.get({
101+
fields: { id: true, name: true, code: true },
102+
filter: {
103+
id: {
104+
in: compactValues([appSettings.categoryComboId]),
105+
},
106+
},
107+
paging: false,
108+
})
109+
),
110+
organizationUnitLevels: apiToFuture(
111+
this.api.models.organisationUnitLevels.get({
112+
fields: { id: true, name: true, code: true, level: true },
113+
filter: {
114+
id: { in: compactValues([appSettings.countryLevelId]) },
115+
},
116+
paging: false,
117+
})
118+
),
119+
categories: apiToFuture(
120+
this.api.models.categories.get({
121+
fields: { id: true, name: true, code: true },
122+
filter: {
123+
id: {
124+
in: compactValues([appSettings.defaultProjectId]),
125+
},
126+
},
127+
paging: false,
128+
})
129+
),
130+
dataElementGroupSets: apiToFuture(
131+
this.api.models.dataElementGroupSets.get({
132+
fields: { id: true, name: true, code: true },
133+
filter: {
134+
id: {
135+
in: compactValues([
136+
appSettings.coreCompetencyId,
137+
appSettings.dataElementThemeId,
138+
appSettings.originDataElementId,
139+
appSettings.statusDataElementId,
140+
]),
141+
},
142+
code: {
143+
in: compactValues([
144+
metadataCodes.dataElementGroupSets.measure,
145+
]),
146+
},
147+
},
148+
rootJunction: "OR",
149+
paging: false,
150+
})
151+
),
152+
dataElementGroups: apiToFuture(
153+
this.api.models.dataElementGroups.get({
154+
fields: { id: true, name: true, code: true },
155+
filter: {
156+
id: {
157+
in: compactValues([
158+
appSettings.mandatoryDataElementId,
159+
appSettings.outputId,
160+
appSettings.dataElementThemeId,
161+
]),
162+
},
163+
code: {
164+
in: compactValues([
165+
metadataCodes.dataElementGroups.localIndicator,
166+
metadataCodes.dataElementGroups.donorIndicator,
167+
metadataCodes.dataElementGroups.individualsIndicator,
168+
metadataCodes.dataElementGroups.householdsIndicator,
169+
]),
170+
},
171+
},
172+
rootJunction: "OR",
173+
paging: false,
174+
})
175+
),
176+
indicatorGroupSets: apiToFuture(
177+
this.api.models.indicatorGroupSets.get({
178+
fields: { id: true, name: true, code: true },
179+
filter: {
180+
id: {
181+
in: compactValues([
182+
appSettings.indicatorThemeId,
183+
appSettings.originIndicatorId,
184+
appSettings.statusIndicatorId,
185+
]),
186+
},
187+
},
188+
paging: false,
189+
})
190+
),
191+
indicatorGroups: apiToFuture(
192+
this.api.models.indicatorGroups.get({
193+
fields: { id: true, name: true, code: true },
194+
filter: {
195+
id: {
196+
in: compactValues([appSettings.mandatoryIndicatorId]),
197+
},
198+
name: {
199+
in: compactValues([
200+
metadataCodes.indicatorGroup.donorIndicator,
201+
metadataCodes.indicatorGroup.localIndicator,
202+
]),
203+
},
204+
},
205+
rootJunction: "OR",
206+
paging: false,
207+
})
208+
),
209+
userGroups: apiToFuture(
210+
this.api.models.userGroups.get({
211+
fields: { id: true, name: true, code: true },
212+
filter: {
213+
code: { in: [metadataCodes.userGroups.adminNotification] },
214+
},
215+
paging: false,
216+
})
217+
),
125218
},
126-
dataElementGroups: {
127-
fields: { id: true, name: true, code: true },
128-
filter: {
129-
identifiable: {
130-
in: compactValues([
131-
appSettings.mandatoryDataElementId,
132-
appSettings.outputId,
133-
appSettings.dataElementThemeId,
134-
metadataCodes.dataElementGroups.localIndicator,
135-
metadataCodes.dataElementGroups.donorIndicator,
136-
metadataCodes.dataElementGroups.individualsIndicator,
137-
metadataCodes.dataElementGroups.householdsIndicator,
138-
]),
219+
{ concurrency: 10 }
220+
)
221+
// .map(metadata => ({ appSettings, metadata }));
222+
.map(
223+
({
224+
attributes,
225+
categoryCombos,
226+
organizationUnitLevels,
227+
categories,
228+
dataElementGroupSets,
229+
dataElementGroups,
230+
indicatorGroupSets,
231+
indicatorGroups,
232+
userGroups,
233+
}) => ({
234+
appSettings,
235+
metadata: {
236+
attributes: attributes.objects,
237+
categoryCombos: categoryCombos.objects,
238+
organisationUnitLevels: organizationUnitLevels.objects,
239+
categories: categories.objects,
240+
dataElementGroupSets: dataElementGroupSets.objects,
241+
dataElementGroups: dataElementGroups.objects,
242+
indicatorGroupSets: indicatorGroupSets.objects,
243+
indicatorGroups: indicatorGroups.objects,
244+
userGroups: userGroups.objects,
139245
},
140-
},
141-
},
142-
indicatorGroupSets: {
143-
fields: { id: true, name: true, code: true },
144-
filter: {
145-
identifiable: {
146-
in: compactValues([
147-
appSettings.indicatorThemeId,
148-
appSettings.originIndicatorId,
149-
appSettings.statusIndicatorId,
150-
]),
151-
},
152-
},
153-
},
154-
indicatorGroups: {
155-
fields: { id: true, name: true, code: true },
156-
filter: {
157-
identifiable: {
158-
in: compactValues([
159-
appSettings.mandatoryIndicatorId,
160-
metadataCodes.indicatorGroup.donorIndicator,
161-
metadataCodes.indicatorGroup.localIndicator,
162-
]),
163-
},
164-
},
165-
},
166-
userGroups: {
167-
fields: { id: true, name: true, code: true },
168-
filter: {
169-
identifiable: { in: [metadataCodes.userGroups.adminNotification] },
170-
},
171-
},
172-
})
173-
).map(metadata => {
174-
return { appSettings, metadata };
175-
});
246+
})
247+
)
248+
);
176249
});
177250
}
178251

src/data/repositories/D2ApiCategoryOption.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export class D2ApiCategoryOption {
2020
code: true,
2121
displayName: true,
2222
lastUpdated: true,
23-
sharing: true,
23+
sharing: {
24+
external: true,
25+
users: { id: true, displayName: true },
26+
userGroups: { id: true, displayName: true },
27+
public: true,
28+
},
2429
},
2530
paging: false,
2631
})

src/data/repositories/DataSetD2Api.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ export class DataSetD2Api {
4343
displayName: true,
4444
lastUpdated: true,
4545
sharing: { public: true },
46-
access: true,
46+
access: { update: true },
4747
},
4848
filter: {
4949
id: { in: options.filters.ids },
50-
"attributeValues.attribute.id": { eq: attributes.createdByApp.id },
51-
"attributeValues.value": { eq: "true" },
50+
[attributes.createdByApp.id]: { eq: "true" },
5251
identifiable: { token: options.filters.search },
5352
},
5453
page: options.paging.page,
@@ -116,8 +115,7 @@ export class DataSetD2Api {
116115
page: options.paging.page,
117116
filter: options.filters.projectsIds
118117
? {
119-
"attributeValues.attribute.id": { eq: attributes.project.id },
120-
"attributeValues.value": { in: options.filters.projectsIds },
118+
[attributes.project.id]: { in: options.filters.projectsIds },
121119
}
122120
: undefined,
123121
fields: dataSetFieldsWithOrgUnits,
@@ -445,7 +443,7 @@ export const categoryComboFields = {
445443
} as const;
446444

447445
export const dataSetFields = {
448-
access: true,
446+
access: { update: true },
449447
created: true,
450448
displayDescription: true,
451449
displayName: true,
@@ -454,7 +452,12 @@ export const dataSetFields = {
454452
notifyCompletingUser: true,
455453
id: true,
456454
lastUpdated: true,
457-
sharing: true,
455+
sharing: {
456+
external: true,
457+
users: { id: true, displayName: true },
458+
userGroups: { id: true, displayName: true },
459+
public: true,
460+
},
458461
displayShortName: true,
459462
sections: {
460463
id: true,

src/data/repositories/DataSetD2Repository.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import differenceBy from "lodash/differenceBy";
2-
import { D2AttributeValue, MetadataPick } from "@eyeseetea/d2-api/2.36";
3-
import { D2Api, MetadataResponse } from "$/types/d2-api";
2+
import { D2AttributeValue, MetadataPick, D2Api, MetadataResponse } from "$/types/d2-api";
43

54
import { apiToFuture } from "$/data/api-futures";
65
import { DataSet } from "$/domain/entities/DataSet";
@@ -89,8 +88,7 @@ export class DataSetD2Repository implements DataSetRepository {
8988
this.api.models.dataSets.get({
9089
paging: false,
9190
filter: {
92-
"attributeValues.attribute.id": { in: [attributes.createdByApp.id] },
93-
"attributeValues.value": { eq: "true" },
91+
[attributes.createdByApp.id]: { eq: "true" },
9492
id: { in: dataSetIds },
9593
},
9694
fields: dataSetFieldsWithOrgUnits,

src/data/repositories/DataSetPeriodDateD2Repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Maybe } from "$/utils/ts-utils";
99
import { Id } from "$/domain/entities/Ref";
1010
import _ from "$/domain/entities/generic/Collection";
1111
import { chunkRequest, getStatsFromD2Response } from "$/data/utils";
12-
import { D2AttributeValue } from "@eyeseetea/d2-api/2.36";
12+
import { D2AttributeValue } from "$/types/d2-api";
1313
import { Stats } from "$/domain/entities/Stats";
1414
import { convertAttributeValueToDate } from "$/data/utils";
1515
import { D2Attribute, D2DataSetOwner } from "$/data/repositories/DataSetD2Repository";
@@ -163,6 +163,7 @@ export class DataSetPeriodDateD2Repository implements DataSetPeriodDateRepositor
163163
attributeValues: { attribute: { id: true }, value: true },
164164
},
165165
filter: {
166+
[config.attributes.inputDates.id]: { like: "*" },
166167
"attributeValues.attribute.id": { eq: config.attributes.inputDates.id },
167168
},
168169
page: page,

0 commit comments

Comments
 (0)