diff --git a/src/Concept.js b/src/Concept.js index 3160dda..f769113 100644 --- a/src/Concept.js +++ b/src/Concept.js @@ -166,9 +166,6 @@ export default class Concept extends BaseEntity { concept.hiNormal = conceptResource.highNormal; concept.unit = conceptResource.unit; concept.voided = conceptResource.voided || false; //This change should be independently deployable irrespective of server - //remove orphan keyValues (because KeyValue doesn't have primary key - entityService && - entityService.deleteObjects(conceptResource["uuid"], Concept.schema.name, "keyValues"); concept.keyValues = _.map(conceptResource.keyValues, KeyValue.fromResource); return concept; } @@ -200,20 +197,17 @@ export default class Concept extends BaseEntity { concept.name = name; concept.datatype = dataType; concept.uuid = uuid; - concept.keyValues = keyValues; + concept.keyValues = _.map(keyValues, KeyValue.fromResource); return concept; } + /** + * This should never be cloned and used for reference as this is metadata which is not to be modified during transactional data operations + * + * @returns {Concept} + */ cloneForReference() { - const concept = Concept.create(this.name, this.datatype, this.keyValues); - concept.uuid = this.uuid; - concept.unit = this.unit; - concept.lowAbsolute = this.lowAbsolute; - concept.lowNormal = this.lowNormal; - concept.hiNormal = this.hiNormal; - concept.hiAbsolute = this.hiAbsolute; - concept.answers = this.answers || []; - return concept; + return this; } _valuePresent(value) { diff --git a/src/EntityMetaData.js b/src/EntityMetaData.js index 53e5151..099496e 100644 --- a/src/EntityMetaData.js +++ b/src/EntityMetaData.js @@ -502,7 +502,11 @@ class EntityMetaData { } static entitiesLoadedFromServer() { - return _.differenceBy(EntityMappingConfig.getInstance().getEntities(), [Settings, LocaleMapping], "schema.name"); + return _.differenceBy(EntityMappingConfig.getInstance().getEntities(), [Settings, LocaleMapping].concat(EntityMetaData.embeddedEntities()), "schema.name"); + } + + static embeddedEntities() { + return _.filter(EntityMappingConfig.getInstance().getEntities(), entity => entity.schema.embedded); } static findByName(entityName) { diff --git a/src/Observation.js b/src/Observation.js index 201acb9..48208b0 100644 --- a/src/Observation.js +++ b/src/Observation.js @@ -162,7 +162,7 @@ class Observation extends PersistedObject { } cloneForEdit() { - return clone(this.concept.cloneForReference(), this.getValueWrapper().cloneForEdit()); + return clone(this.concept, this.getValueWrapper().cloneForEdit()); } shallowClone() { diff --git a/src/application/FormElement.js b/src/application/FormElement.js index 47789d1..a11dbaa 100644 --- a/src/application/FormElement.js +++ b/src/application/FormElement.js @@ -155,8 +155,6 @@ class FormElement extends BaseEntity { ); formElement.concept = concept; - //remove orphan keyValues (because KeyValue doesn't have primary key - entityService.deleteObjects(resource["uuid"], FormElement.schema.name, "keyValues"); formElement.keyValues = _.map(resource.keyValues, KeyValue.fromResource); formElement.validFormat = Format.fromResource(resource["validFormat"]); return formElement; @@ -432,7 +430,7 @@ class FormElement extends BaseEntity { formElement.name = this.name; formElement.displayOrder = this.displayOrder; formElement.mandatory = this.mandatory; - formElement.keyValues = this.keyValues; + formElement.keyValues = _.map(this.keyValues, KeyValue.fromResource); formElement.concept = this.concept; formElement.type = this.type; formElement.formElementGroup = this.formElementGroup; diff --git a/src/application/KeyValue.js b/src/application/KeyValue.js index 1c87728..5c3ddea 100644 --- a/src/application/KeyValue.js +++ b/src/application/KeyValue.js @@ -18,7 +18,7 @@ class KeyValue extends PersistedObject { static fromResource(resource) { const keyValue = new KeyValue(); keyValue.key = resource.key; - keyValue.value = JSON.stringify(resource.value); + keyValue.value = typeof (resource.value) !== "string" ? JSON.stringify(resource.value): resource.value; return keyValue; } diff --git a/src/framework/RealmProxy.js b/src/framework/RealmProxy.js index 6268ba3..1b1be71 100644 --- a/src/framework/RealmProxy.js +++ b/src/framework/RealmProxy.js @@ -44,6 +44,13 @@ class RealmProxy { return this.realmDb.close(); } + /** + * + * @param schemaName + * @param properties + * @param updateMode , all === true, modified , never === false + * @returns {*} + */ create(schemaName, properties, updateMode = "never") { const underlyingObject = _.isNil(properties.that) ? properties : properties.that; const entityClass = this.entityMappingConfig.getEntityClass(schemaName); diff --git a/test/EntitiesMetaDataTest.js b/test/EntitiesMetaDataTest.js index 0959d7e..90c540e 100644 --- a/test/EntitiesMetaDataTest.js +++ b/test/EntitiesMetaDataTest.js @@ -7,6 +7,7 @@ describe('EntitiesMetaDataTest', () => { it('entitiesLoadedFromServer', () => { var entitiesLoadedFromServer = EntityMetaData.entitiesLoadedFromServer(); assert.notIncludeMembers(entitiesLoadedFromServer, [Settings, Individual]); + assert.notIncludeMembers(entitiesLoadedFromServer, EntityMetaData.embeddedEntities()); }); describe('model', function () {