Skip to content

Commit

Permalink
Merge pull request #963 from EyeSeeTea/feature/efh-sync
Browse files Browse the repository at this point in the history
Sync all orgunits toggle for metadata rules
  • Loading branch information
MiquelAdell authored Jul 23, 2024
2 parents 7ed6842 + 174ad52 commit 4763be5
Show file tree
Hide file tree
Showing 26 changed files with 482 additions and 172 deletions.
20 changes: 16 additions & 4 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-02-21T11:09:33.513Z\n"
"PO-Revision-Date: 2024-02-21T11:09:33.513Z\n"
"POT-Creation-Date: 2024-07-18T21:33:28.930Z\n"
"PO-Revision-Date: 2024-07-18T21:33:28.930Z\n"

msgid ""
"THIS NEW RELEASE INCLUDES SHARING SETTINGS PER INSTANCES. FOR THIS VERSION "
Expand Down Expand Up @@ -243,7 +243,7 @@ msgstr ""
msgid "Condition"
msgstr ""

msgid "String to match (*)"
msgid "String to match"
msgstr ""

msgid "Edit"
Expand Down Expand Up @@ -517,6 +517,12 @@ msgstr ""
msgid "Show all entries"
msgstr ""

msgid "Dynamic auto update"
msgstr ""

msgid "Sync all Organisation Units"
msgstr ""

msgid "Select with children subtree"
msgstr ""

Expand All @@ -529,7 +535,7 @@ msgstr ""
msgid "Custodian"
msgstr ""

msgid "Search by "
msgid "Search by name, code or id"
msgstr ""

msgid ""
Expand Down Expand Up @@ -2172,6 +2178,12 @@ msgid ""
"{{period}}..."
msgstr ""

msgid "Get configuration from HQ server"
msgstr ""

msgid "Push data to HQ server"
msgstr ""

msgid "Output: "
msgstr ""

Expand Down
18 changes: 15 additions & 3 deletions i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-02-20T05:48:46.170Z\n"
"POT-Creation-Date: 2024-07-17T07:09:52.268Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -243,7 +243,7 @@ msgstr ""
msgid "Condition"
msgstr ""

msgid "String to match (*)"
msgid "String to match"
msgstr ""

msgid "Edit"
Expand Down Expand Up @@ -518,6 +518,12 @@ msgstr ""
msgid "Show all entries"
msgstr ""

msgid "Dynamic auto update"
msgstr ""

msgid "Sync all Organisation Units"
msgstr ""

msgid "Select with children subtree"
msgstr ""

Expand All @@ -530,7 +536,7 @@ msgstr ""
msgid "Custodian"
msgstr ""

msgid "Search by "
msgid "Search by name, code or id"
msgstr ""

msgid ""
Expand Down Expand Up @@ -2176,6 +2182,12 @@ msgid ""
"{{period}}..."
msgstr ""

msgid "Get configuration from HQ server"
msgstr ""

msgid "Push data to HQ server"
msgstr ""

msgid "Output: "
msgstr ""

Expand Down
18 changes: 15 additions & 3 deletions i18n/fr.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-02-20T05:48:46.170Z\n"
"POT-Creation-Date: 2024-07-17T07:09:52.268Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -243,7 +243,7 @@ msgstr ""
msgid "Condition"
msgstr ""

msgid "String to match (*)"
msgid "String to match"
msgstr ""

msgid "Edit"
Expand Down Expand Up @@ -518,6 +518,12 @@ msgstr ""
msgid "Show all entries"
msgstr ""

msgid "Dynamic auto update"
msgstr ""

msgid "Sync all Organisation Units"
msgstr ""

msgid "Select with children subtree"
msgstr ""

Expand All @@ -530,7 +536,7 @@ msgstr ""
msgid "Custodian"
msgstr ""

msgid "Search by "
msgid "Search by name, code or id"
msgstr ""

msgid ""
Expand Down Expand Up @@ -2175,6 +2181,12 @@ msgid ""
"{{period}}..."
msgstr ""

msgid "Get configuration from HQ server"
msgstr ""

msgid "Push data to HQ server"
msgstr ""

msgid "Output: "
msgstr ""

Expand Down
18 changes: 15 additions & 3 deletions i18n/pt.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-02-20T05:48:46.170Z\n"
"POT-Creation-Date: 2024-07-17T07:09:52.268Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -243,7 +243,7 @@ msgstr ""
msgid "Condition"
msgstr ""

msgid "String to match (*)"
msgid "String to match"
msgstr ""

msgid "Edit"
Expand Down Expand Up @@ -518,6 +518,12 @@ msgstr ""
msgid "Show all entries"
msgstr ""

msgid "Dynamic auto update"
msgstr ""

msgid "Sync all Organisation Units"
msgstr ""

msgid "Select with children subtree"
msgstr ""

Expand All @@ -530,7 +536,7 @@ msgstr ""
msgid "Custodian"
msgstr ""

msgid "Search by "
msgid "Search by name, code or id"
msgstr ""

msgid ""
Expand Down Expand Up @@ -2175,6 +2181,12 @@ msgid ""
"{{period}}..."
msgstr ""

msgid "Get configuration from HQ server"
msgstr ""

msgid "Push data to HQ server"
msgstr ""

msgid "Output: "
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "metadata-synchronization",
"description": "Advanced metadata & data synchronization utility",
"version": "2.18.2",
"version": "2.19.0",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export const MetadataSynchronizationParamsModel: Codec<MetadataSynchronizationPa
removeOrgUnitObjects: Schema.optional(Schema.boolean),
useDefaultIncludeExclude: Schema.optionalSafe(Schema.boolean, true),
metadataIncludeExcludeRules: Schema.optional(MetadataIncludeExcludeRulesModel),
metadataModelsSyncAll: Schema.optionalSafe(Schema.array(Schema.string), []),
})
);
72 changes: 72 additions & 0 deletions src/data/migrations/tasks/12.metadata-models-sync-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { MigrationParams } from ".";
import { MetadataIncludeExcludeRules } from "../../../domain/metadata/entities/MetadataExcludeIncludeRules";
import { MetadataImportParams } from "../../../domain/metadata/entities/MetadataSynchronizationParams";
import { Debug } from "../../../domain/migrations/entities/Debug";
import { SynchronizationType } from "../../../domain/synchronization/entities/SynchronizationType";
import { promiseMap } from "../../../utils/common";
import { AppStorage, Migration } from "../client/types";

export interface OldSynchronizationRuleData {
id: string;
type: SynchronizationType;
}

export interface OldSynchronizationBuilder {
syncParams?: OldMetadataSynchronizationParams;
}

export interface OldMetadataSynchronizationParams extends MetadataImportParams {
enableMapping: boolean;
includeSharingSettings: boolean;
removeOrgUnitReferences: boolean;
removeUserObjects?: boolean;
removeUserObjectsAndReferences?: boolean;
removeOrgUnitObjects?: boolean;
useDefaultIncludeExclude: boolean;
metadataIncludeExcludeRules?: MetadataIncludeExcludeRules;
}

export interface OldSynchronizationRuleDetails {
builder: OldSynchronizationBuilder;
}

export interface NewSynchronizationRuleDetails {
builder: NewSynchronizationBuilder;
}

export interface NewSynchronizationBuilder {
syncParams?: NewMetadataSynchronizationParams;
}

export interface NewMetadataSynchronizationParams extends OldMetadataSynchronizationParams {
metadataModelsSyncAll: string[]; //TODO: keyof MetadataEntities 963#discussion_r1682370900
}

export async function migrate(storage: AppStorage, _debug: Debug, _params: MigrationParams): Promise<void> {
const oldRules = (await storage.get<OldSynchronizationRuleData[]>("rules")) ?? [];
const oldEventRules = oldRules.filter(rule => rule.type === "metadata");

await promiseMap(oldEventRules, async oldRule => {
const oldRuleDetails = await storage.get<OldSynchronizationRuleDetails>("rules-" + oldRule.id);

if (oldRuleDetails) {
const oldSyncParams = oldRuleDetails.builder.syncParams;
if (!oldSyncParams) return;

const newSyncParams: NewMetadataSynchronizationParams = { ...oldSyncParams, metadataModelsSyncAll: [] };

const newRuleDatails: NewSynchronizationRuleDetails = {
builder: { ...oldRuleDetails?.builder, syncParams: newSyncParams },
};

await storage.save("rules-" + oldRule.id, newRuleDatails);
}
});
}

const migration: Migration<MigrationParams> = {
name: "Create in existed metadata rules a new field metadataModelsSyncAll to []",
migrate,
};

export default migration;
1 change: 1 addition & 0 deletions src/data/migrations/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function getMigrationTasks(): MigrationTasks<MigrationParams> {
[9, import("./09.mapping-instances")],
[10, import("./10.sync-all-teis")],
[11, import("./11.rename-run-analytics")],
[12, import("./12.metadata-models-sync-all")],
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/domain/entities/EmergencyResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ export type EmergencyType = "efh" | "ebola";

export interface EmergencyResponseConfig {
program: Code;
syncRules: { metadata: Code; data: Code };
syncRules: { metadata: Code[]; data: Code[] };
}

type Code = string;

const emergencyResponseConfig: Record<EmergencyType, EmergencyResponseConfig> = {
efh: {
program: "EFH_GENERAL_INTAKE_FORM",
syncRules: { metadata: "EFH_METADATA", data: "EFH_DATA" },
syncRules: { metadata: ["EFH_METADATA", "EFH_METADATA_ORGUNITS"], data: ["EFH_DATA"] },
},
ebola: {
program: "EBOLA_GENERAL_INTAKE_FORM",
syncRules: { metadata: "EBOLA_METADATA", data: "EBOLA_DATA" },
syncRules: { metadata: ["EBOLA_METADATA"], data: ["EBOLA_DATA"] },
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ export class UpdateEmergencyResponseSyncRuleUseCase {
if (!program) throw new Error(i18n.t("Program not found"));

const orgUnitPaths = program.organisationUnits.map(ou => ou.path);
const teiIds: string[] = await this.getTeis(program, orgUnitPaths);

return rule.updateDataSyncOrgUnitPaths(orgUnitPaths).updateDataSyncTEIs(teiIds);
return rule.updateDataSyncOrgUnitPaths(orgUnitPaths);
}

private async getProgram(emergencyType: EmergencyType) {
Expand All @@ -35,23 +34,6 @@ export class UpdateEmergencyResponseSyncRuleUseCase {
const form = res.objects[0] as unknown as Program | undefined;
return form;
}

private async getTeis(form: Program, orgUnitPaths: string[]) {
const teiIds: string[] = [];
let page = 1;
let done = false;

while (!done) {
const { trackedEntityInstances } = await this.teiRepository.getTEIs({ orgUnitPaths }, form.id, page, 1000);
const teiIdsInPage = trackedEntityInstances.map(tei => tei.trackedEntityInstance);
teiIds.push(...teiIdsInPage);

page++;
done = trackedEntityInstances.length === 0;
}

return teiIds;
}
}

interface Program {
Expand Down
2 changes: 2 additions & 0 deletions src/domain/metadata/entities/MetadataFriendlyNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export const includeExcludeRulesFriendlyNames: Dictionary<string> = {
"trackedEntityAttributes.legendSets": "Legends of tracked entity attributes",
"users.userRoles": "User roles of users",
"users.userGroups": "User groups of users",
"users.avatar": "Avatar of users",
avatar: "Avatar",
options: "Options",
"options.attributes": "Attributes of options",
"optionSets.attributes": "Attributes of option sets",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export interface MetadataSynchronizationParams extends MetadataImportParams {
removeOrgUnitObjects?: boolean;
useDefaultIncludeExclude: boolean;
metadataIncludeExcludeRules?: MetadataIncludeExcludeRules;
metadataModelsSyncAll: string[]; //TODO: keyof MetadataEntities 963#discussion_r1682370900
}
Loading

0 comments on commit 4763be5

Please sign in to comment.