@@ -13,6 +13,8 @@ import { VocabularyEntry } from '../../submission/vocabularies/models/vocabulary
1313import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model' ;
1414import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model' ;
1515import { CoreState } from '../../core-state.model' ;
16+ import { Metadata } from '../../shared/metadata.utils' ;
17+ import { ConfidenceType } from '../../shared/confidence-type' ;
1618
1719/**
1820 * Provides methods to dispatch JsonPatch Operations Actions
@@ -110,27 +112,25 @@ export class JsonPatchOperationsBuilder {
110112 operationValue = [ ] ;
111113 value . forEach ( ( entry ) => {
112114 if ( ( typeof entry === 'object' ) ) {
113- if ( securityLevel != null ) {
115+ if ( isNotEmpty ( securityLevel ) ) {
114116 operationValue . push ( this . prepareObjectValue ( entry , securityLevel ) ) ;
115117 } else {
116118 operationValue . push ( this . prepareObjectValue ( entry ) ) ;
117119 }
118-
119120 } else {
120121 operationValue . push ( new FormFieldMetadataValueObject ( entry , null , securityLevel ) ) ;
121122 }
122123 } ) ;
123124 } else if ( typeof value === 'object' ) {
124- if ( securityLevel != null ) {
125+ if ( isNotEmpty ( securityLevel ) ) {
125126 operationValue = this . prepareObjectValue ( value , securityLevel ) ;
126127 } else {
127128 operationValue = this . prepareObjectValue ( value ) ;
128129 }
129-
130130 } else {
131131 // add the possibility to add security level when value is string
132132 // in this case security level is set on metadata value
133- if ( securityLevel != null ) {
133+ if ( isNotEmpty ( securityLevel ) ) {
134134 operationValue = new FormFieldMetadataValueObject ( value , null , securityLevel ) ;
135135 } else {
136136 operationValue = new FormFieldMetadataValueObject ( value , null ) ;
@@ -143,21 +143,26 @@ export class JsonPatchOperationsBuilder {
143143 }
144144
145145 protected prepareObjectValue ( value : any , securityLevel = null ) {
146- let operationValue = Object . create ( { } ) ;
146+ let operationValue = Object . create ( { } ) ;
147147 if ( isEmpty ( value ) || value instanceof FormFieldMetadataValueObject ) {
148- if ( securityLevel != null ) {
149- operationValue = { ...value , securityLevel : securityLevel } ;
150- } else {
148+ if ( isNotEmpty ( securityLevel ) ) {
149+ operationValue = { ...value , securityLevel : securityLevel } ;
150+ } else {
151151 operationValue = value ;
152152 }
153+ //Update confidence if was added once the field was already created, value is set only in constructor of FormFieldMetadataValueObject
154+ if ( Metadata . hasValidAuthority ( operationValue . authority ) && ( isEmpty ( operationValue . confidence ) || operationValue . confidence === - 1 ) ) {
155+ operationValue . confidence = ConfidenceType . CF_ACCEPTED ;
156+ }
157+
153158 } else if ( value instanceof Date ) {
154159 if ( securityLevel != null ) {
155- operationValue = new FormFieldMetadataValueObject ( dateToISOFormat ( value ) , null , securityLevel ) ;
160+ operationValue = new FormFieldMetadataValueObject ( dateToISOFormat ( value ) , null , securityLevel ) ;
156161 } else {
157162 operationValue = new FormFieldMetadataValueObject ( dateToISOFormat ( value ) ) ;
158163 }
159164 } else if ( value instanceof VocabularyEntry ) {
160- operationValue = this . prepareAuthorityValue ( value ) ;
165+ operationValue = new FormFieldMetadataValueObject ( value . value , null , value . securityLevel , value . authority ) ;
161166 } else if ( value instanceof FormFieldLanguageValueObject ) {
162167 operationValue = new FormFieldMetadataValueObject ( value . value , value . language , securityLevel ) ;
163168 } else if ( value . hasOwnProperty ( 'authority' ) ) {
@@ -170,11 +175,10 @@ export class JsonPatchOperationsBuilder {
170175 Object . keys ( value )
171176 . forEach ( ( key ) => {
172177 if ( typeof value [ key ] === 'object' ) {
173- if ( securityLevel != null ) {
174- operationValue [ key ] = this . prepareObjectValue ( value [ key ] , securityLevel ) ;
178+ if ( isNotEmpty ( securityLevel ) ) {
179+ operationValue [ key ] = this . prepareObjectValue ( value [ key ] , securityLevel ) ;
175180 } else {
176- operationValue [ key ] = this . prepareObjectValue ( value [ key ] ) ;
177-
181+ operationValue [ key ] = this . prepareObjectValue ( value [ key ] ) ;
178182 }
179183 } else {
180184 operationValue [ key ] = value [ key ] ;
@@ -184,14 +188,4 @@ export class JsonPatchOperationsBuilder {
184188 return operationValue ;
185189 }
186190
187- protected prepareAuthorityValue ( value : any ) : FormFieldMetadataValueObject {
188- let operationValue : FormFieldMetadataValueObject ;
189- if ( isNotEmpty ( value . authority ) ) {
190- operationValue = new FormFieldMetadataValueObject ( value . value , value . language , value . securityLevel , value . authority ) ;
191- } else {
192- operationValue = new FormFieldMetadataValueObject ( value . value , value . language , value . securityLevel , ) ;
193- }
194- return operationValue ;
195- }
196-
197191}
0 commit comments