Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditions check #128

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"title": "omschrijving",
"summary": "zaaktypeomschrijving",
"description": "zaaktypeomschrijving",
"category": "{% if zaaktypecode|default %}{% set wooVerzoekenEnBesluiten = ['LP00000431', 'B1873', 'cherry'] %}{% set klachtoordelen = ['LP00000091', 'LP00001132', 'LP00000121', 'B0757', 'LP00000832', 'LP00001096'] %}{% if zaaktypecode in wooVerzoekenEnBesluiten %}{{ 'Woo-verzoeken en -besluiten' }}{% elseif zaaktypecode in klachtoordelen %}{{ 'Klachtoordelen' }}{% endif %}{% endif %}",
"category": "{% if zaaktypecode|default %}{% set wooVerzoekenEnBesluiten = ['LP00000431', 'B1873'] %}{% set klachtoordelen = ['LP00000091', 'LP00001132', 'LP00000121', 'B0757', 'LP00000832', 'LP00001096'] %}{% if zaaktypecode in wooVerzoekenEnBesluiten %}{{ 'Woo-verzoeken en -besluiten' }}{% elseif zaaktypecode in klachtoordelen %}{{ 'Klachtoordelen' }}{% endif %}{% endif %}",
"published": "startdatum",
"modified": "{{ 'now'|date('H:i:sTm-d-Y') }}",
"attachments": "[{% if files|default %}{% for file in files %} { {% if file['titel']|default %}\"title\": \"{{ file['titel'] }}\",{% endif %}\"labels\": [\"{{ 'Informatieverzoek' }}\"],{% if file['formaat']|default %}\"extension\": \"{{ file['formaat']|split('/')|last }}\",\"type\": \"{{ file['formaat'] }}\",{% endif %}{% if file['inhoud']|default and file['formaat']|default %}\"accessUrl\": \"data:{{ file['formaat'] }};base64,{{ file.inhoud }}\"{% endif %} }{{ loop.last ? '' : ',' }} {% endfor %}{% endif %}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"sourceId": "1",
"sourceType": "api",
"sourceHash": "",
"sourceHashMapping": "1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is added in a other pull request but adding it here is harmless

"sourceTargetMapping": "1",
"sourceConfig": {
"idPosition": "identificatie",
Expand All @@ -13,6 +14,7 @@
"headers": [],
"query.startdatum__gte": "2024-08-01",
"query.einddatum__lt": "2025-01-01",
"query.maximaleVertrouwelijkheidaanduiding": "openbaar",
Copy link
Contributor

@RalkeyOfficial RalkeyOfficial Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moet "aanduiding" niet met een hoofdletter?
ik ga ervan uit dat dit met een hoofdletter moet zijn want de andere woorden in deze string hebben ook hoofdletters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nee dit is een veld vanuit xxllnc suite, ik heb het niet verzonnen

"usesPagination": "false",
"extraDataConfigs.0.staticEndpoint": "/tlb/zaaksysteem/api/v1/zaken/{{ originId }}/informatieobjecten",
"extraDataConfigs.0.mergeExtraData": "true",
Expand All @@ -21,5 +23,17 @@
"extraDataConfigs.0.extraDataConfigPerResult.staticEndpoint": "/tlb/zaaksysteem/api/v1/informatieobjecten/{{ originId }}"
},
"targetId": "1/1",
"targetType": "register/schema"
"targetType": "register/schema",
"conditions": {
"if": [
{
"or": [
{ "in": [{ "var": "zaaktypecode" }, ["LP00000431", "B1873"]] },
{ "in": [{ "var": "zaaktypecode" }, ["LP00000091", "LP00001132", "LP00000121", "B0757", "LP00000832", "LP00001096"]] }
]
},
true,
false
]
}
}
16 changes: 10 additions & 6 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa
$objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest);

foreach ($objectList as $key => $object) {

// Check if object adheres to conditions.
// Take note, JsonLogic::apply() returns a range of return types, so checking it with '=== false' or '!== true' does not work properly.
if ($synchronization->getConditions() !== [] && !JsonLogic::apply($synchronization->getConditions(), $object)) {

// @todo log that this object is not valid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo, create a log

unset($objectList[$key]);
continue;
}

// If the source configuration contains a dot notation for the id position, we need to extract the id from the source object
$originId = $this->getOriginId($synchronization, $object);

Expand Down Expand Up @@ -340,12 +350,6 @@ public function synchronizeContract(SynchronizationContract $synchronizationCont
$synchronizationContract->setSourceLastChanged(new DateTime());
$synchronizationContract->setSourceLastChecked(new DateTime());

// Check if object adheres to conditions.
// Take note, JsonLogic::apply() returns a range of return types, so checking it with '=== false' or '!== true' does not work properly.
if ($synchronization->getConditions() !== [] && !JsonLogic::apply($synchronization->getConditions(), $object)) {
return $synchronizationContract;
}

// If no source target mapping is defined, use original object
if (empty($synchronization->getSourceTargetMapping()) === true) {
$targetObject = $object;
Expand Down
2 changes: 2 additions & 0 deletions src/entities/synchronization/synchronization.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const mockSynchronizationData = (): TSynchronization[] => [
id: 1,
name: 'Synchronization 1',
description: 'Synchronization 1',
conditions: '{"!!": { "var": "valid" }}',
sourceId: 'source1',
sourceType: 'api',
sourceHash: 'source1',
Expand All @@ -29,6 +30,7 @@ export const mockSynchronizationData = (): TSynchronization[] => [
id: 2,
name: 'Synchronization 2',
description: 'Synchronization 2',
conditions: '{"!!": { "var": "valid" }}',
sourceId: 'source2',
sourceType: 'api',
sourceHash: 'source2',
Expand Down
3 changes: 3 additions & 0 deletions src/entities/synchronization/synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
public id: number
public name: string
public description: string
public conditions: string
public sourceId: string
public sourceType: string
public sourceHash: string
Expand All @@ -32,6 +33,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
id: synchronization.id || null,
name: synchronization.name || '',
description: synchronization.description || '',
conditions: synchronization.conditions || '',
sourceId: synchronization.sourceId || '',
sourceType: synchronization.sourceType || '',
sourceHash: synchronization.sourceHash || '',
Expand Down Expand Up @@ -60,6 +62,7 @@ export class Synchronization extends ReadonlyBaseClass implements TSynchronizati
id: z.number().nullable(),
name: z.string(),
description: z.string(),
conditions: z.string(),
sourceId: z.string(),
sourceType: z.string(),
sourceHash: z.string(),
Expand Down
1 change: 1 addition & 0 deletions src/entities/synchronization/synchronization.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type TSynchronization = {
id: number
name: string
description: string
conditions: string
sourceId: string
sourceType: string
sourceHash: string
Expand Down
10 changes: 9 additions & 1 deletion src/modals/Synchronization/EditSynchronization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import { synchronizationStore, navigationStore, sourceStore, mappingStore } from
<NcTextArea :value.sync="synchronizationItem.description"
label="Description" />

<NcTextArea :value.sync="synchronizationItem.conditions"
label="Conditions (json logic)" />

<NcSelect v-bind="typeOptions"
v-model="typeOptions.value"
input-label="Source Type" />
Expand Down Expand Up @@ -199,6 +202,7 @@ export default {
synchronizationItem: { // Initialize with empty fields
name: '',
description: '',
conditions: '',
sourceId: '',
sourceType: '',
sourceConfig: {
Expand Down Expand Up @@ -274,7 +278,10 @@ export default {
mounted() {
if (this.IS_EDIT) {
// If there is a synchronization item in the store, use it
this.synchronizationItem = { ...synchronizationStore.synchronizationItem }
this.synchronizationItem = {
...synchronizationStore.synchronizationItem,
conditions: JSON.stringify(synchronizationStore.synchronizationItem.conditions),
}

// update targetTypeOptions with the synchronization item target type
this.targetTypeOptions.value = this.targetTypeOptions.options.find(option => option.id === this.synchronizationItem.targetType)
Expand Down Expand Up @@ -529,6 +536,7 @@ export default {
sourceId: this.sourceOptions.sourceValue?.id || null,
sourceType: this.typeOptions.value?.id || null,
sourceTargetMapping: this.sourceTargetMappingOptions.sourceValue?.id || null,
conditions: JSON.parse(this.synchronizationItem.conditions) || null,
targetType: this.targetTypeOptions.value?.id || null,
targetId: targetId || null,
targetSourceMapping: this.sourceTargetMappingOptions.targetValue?.id || null,
Expand Down
3 changes: 0 additions & 3 deletions src/views/Mapping/MappingDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ import { mappingStore, navigationStore } from '../../store/store.js'
disable-menu
:size="44" />
</template>
<template #subname>
{{ value }}
</template>
<template #actions>
<NcActionButton @click="mappingStore.setMappingUnsetKey(value); navigationStore.setModal('editMappingUnset')">
<template #icon>
Expand Down
Loading