Skip to content

Commit

Permalink
Added conflict property in Entity Odata (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja authored Oct 12, 2023
1 parent 8bcbbea commit 5833dc2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12609,6 +12609,7 @@ paths:
| Entity Creator Actor ID | `__system/creatorId` |
| Entity Timestamp | `__system/createdAt` |
| Entity Update Timestamp | `__system/updatedAt` |
| Entity Conflict | `__system/conflict` |

Note that `createdAt` and `updatedAt` are time components. This means that any comparisons you make need to account for the full time of the entity. It might seem like `$filter=__system/createdAt le 2020-01-31` would return all results on or before 31 Jan 2020, but in fact only entities made before midnight of that day would be accepted. To include all of the month of January, you need to filter by either `$filter=__system/createdAt le 2020-01-31T23:59:59.999Z` or `$filter=__system/createdAt lt 2020-02-01`. Remember also that you can [query by a specific timezone](https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC).

Expand Down Expand Up @@ -12691,6 +12692,7 @@ paths:
updates: 1,
updatedAt: '2023-04-31T19:41:16.478Z'
version: 1
conflict: null
- __id: aeebd746-3b1e-4a24-ba9d-ed6547bd5ff1
label: 345cm mora
__system:
Expand All @@ -12700,6 +12702,7 @@ paths:
updates: 1,
updatedAt: '2023-04-31T19:41:16.478Z'
version: 2
conflict: null
geometry: 47.722581 18.562111 0 0,
species: mora,
circumference_cm: 345
Expand Down
6 changes: 4 additions & 2 deletions lib/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const { sanitizeOdataIdentifier } = require('../util/util');
const odataToColumnMap = new Map([
['__system/createdAt', 'entities.createdAt'],
['__system/updatedAt', 'entities.updatedAt'],
['__system/creatorId', 'entities.creatorId']
['__system/creatorId', 'entities.creatorId'],
['__system/conflict', 'entities.conflict']
]);

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -231,7 +232,8 @@ const selectFields = (entity, properties, selectedProperties) => {
creatorName: entity.aux.creator.displayName,
updates: entity.aux.stats.updates,
updatedAt: entity.updatedAt,
version: entity.def.version
version: entity.def.version,
conflict: entity.conflict
};

if (!selectedProperties || selectedProperties.has('__system')) {
Expand Down
52 changes: 47 additions & 5 deletions test/integration/api/odata-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,37 @@ describe('api: /datasets/:name.svc', () => {
.replace('uuid:12345678-1234-4123-8234-123456789abc', uuid()))
.set('Content-Type', 'application/xml')
.expect(200);

await user.patch(`/v1/projects/1/forms/simpleEntity/submissions/submission${i+skip}`)
.send({ reviewState: 'approved' })
.expect(200);

}
await exhaust(container);
};
/* eslint-enable no-await-in-loop*/

const createConflict = async (user, container) => {
await user.post('/v1/projects/1/forms/simpleEntity/submissions')
.send(testData.instances.simpleEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);

await user.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc?force=true')
.send({ data: { age: '99' } })
.expect(200);

await user.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.updateEntity)
.set('Content-Type', 'application/xml')
.expect(200);

// all properties changed
await user.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);
};

it('should return all entities', testService(async (service, container) => {
const asAlice = await service.login('alice');

Expand Down Expand Up @@ -239,6 +260,27 @@ describe('api: /datasets/:name.svc', () => {
});
}));

it('should filter by conflict status', testService(async (service, container) => {
const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/forms?publish=true')
.set('Content-Type', 'application/xml')
.send(testData.forms.simpleEntity)
.expect(200);

await createSubmissions(asAlice, container, 2);

await createConflict(asAlice, container);

await asAlice.get('/v1/projects/1/datasets/people.svc/Entities?$filter=__system/conflict eq \'hard\'')
.expect(200)
.then(({ body }) => {
body.value.length.should.be.eql(1);

body.value[0].__system.conflict.should.be.eql('hard');
});
}));

it('should return filtered entities with pagination', testService(async (service, container) => {
const asAlice = await service.login('alice');
const asBob = await service.login('bob');
Expand Down
14 changes: 10 additions & 4 deletions test/unit/data/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ describe('extracting and validating entities', () => {
uuid: 'uuid',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
conflict: 'hard',
def: {
label: 'label',
version: 1,
Expand Down Expand Up @@ -503,7 +504,8 @@ describe('extracting and validating entities', () => {
creatorName: 'displayName',
updatedAt: 'updatedAt',
updates: 0,
version: 1
version: 1,
conflict: 'hard'
},
firstName: entity.def.data.firstName,
lastName: entity.def.data.lastName
Expand Down Expand Up @@ -544,7 +546,8 @@ describe('extracting and validating entities', () => {
creatorName: 'displayName',
updatedAt: 'updatedAt',
updates: 0,
version: 1
version: 1,
conflict: 'hard'
}
});
});
Expand All @@ -554,6 +557,7 @@ describe('extracting and validating entities', () => {
uuid: 'uuid',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
conflict: 'hard',
def: {
label: 'label',
version: 1,
Expand All @@ -580,7 +584,8 @@ describe('extracting and validating entities', () => {
creatorName: 'displayName',
updatedAt: 'updatedAt',
updates: 0,
version: 1
version: 1,
conflict: 'hard'
},
firstName: '',
lastName: ''
Expand All @@ -601,7 +606,8 @@ describe('extracting and validating entities', () => {
creatorName: 'displayName',
updatedAt: 'updatedAt',
updates: 0,
version: 1
version: 1,
conflict: 'hard'
},
firstName: entity.def.data.firstName,
lastName: entity.def.data.lastName,
Expand Down

0 comments on commit 5833dc2

Please sign in to comment.