@@ -129,33 +129,42 @@ public void removeProperty(String propertyName) {
129
129
public void removePropertyValue (String propertyName , Object propertyValue ) {
130
130
RequestContext context = RequestContext .get ();
131
131
Iterator <? extends Property <Object >> it = getWrappedElement ().properties (propertyName );
132
- // we create a map of properties that are only internal
133
- fillInternalPropertiesIfApplicable ( propertyName , propertyValue , it , context ) ;
134
- it = getWrappedElement (). properties ( propertyName );
132
+ List < Object > finalValues = new ArrayList <>();
133
+ boolean removedFirst = false ;
134
+
135
135
while (it .hasNext ()) {
136
136
Property currentProperty = it .next ();
137
137
Object currentPropertyValue = currentProperty .value ();
138
138
139
- if (Objects .equals (currentPropertyValue , propertyValue )) {
139
+ if (Objects .equals (currentPropertyValue , propertyValue ) && ! removedFirst ) {
140
140
currentProperty .remove ();
141
- break ;
141
+ removedFirst = true ;
142
+ } else {
143
+ finalValues .add (currentPropertyValue );
142
144
}
143
145
}
146
+
147
+ recordInternalAttribute (propertyName , finalValues );
144
148
}
145
149
146
150
@ Override
147
151
public void removeAllPropertyValue (String propertyName , Object propertyValue ) {
148
152
Iterator <? extends Property <Object >> it = getWrappedElement ().properties (propertyName );
149
- RequestContext context = RequestContext .get ();
150
- fillInternalPropertiesIfApplicable (propertyName , propertyValue , it , context );
153
+ List <Object > finalValues = new ArrayList <>();
154
+
155
+
151
156
while (it .hasNext ()) {
152
157
Property currentProperty = it .next ();
153
158
Object currentPropertyValue = currentProperty .value ();
154
159
155
160
if (Objects .equals (currentPropertyValue , propertyValue )) {
156
161
currentProperty .remove ();
162
+ } else {
163
+ finalValues .add (currentPropertyValue );
157
164
}
158
165
}
166
+
167
+ recordInternalAttribute (propertyName , finalValues );
159
168
}
160
169
161
170
@ Override
@@ -169,19 +178,7 @@ public void setProperty(String propertyName, Object value) {
169
178
}
170
179
} else {
171
180
getWrappedElement ().property (propertyName , value );
172
- //fill all internal properties for the entityGuid
173
- if (propertyName .startsWith (INTERNAL_PROPERTY_KEY_PREFIX )) {
174
- String entityGuid = this .getProperty (GUID_PROPERTY_KEY , String .class );
175
- if (StringUtils .isNotEmpty (entityGuid )) {
176
- if (context .getAllInternalAttributesMap ().get (entityGuid ) != null ) {
177
- context .getAllInternalAttributesMap ().get (entityGuid ).put (propertyName , value );
178
- } else {
179
- Map <String , Object > map = new HashMap <>();
180
- map .put (propertyName , value );
181
- context .getAllInternalAttributesMap ().put (entityGuid , map );
182
- }
183
- }
184
- }
181
+ recordInternalAttribute (propertyName , value );
185
182
}
186
183
} catch (SchemaViolationException e ) {
187
184
throw new AtlasSchemaViolationException (e );
@@ -348,29 +345,18 @@ public boolean isIdAssigned() {
348
345
return true ;
349
346
}
350
347
351
-
352
- private void fillInternalPropertiesIfApplicable (String propertyName , Object propertyValue , Iterator <? extends Property <Object >> it , RequestContext context ) {
353
- while (it .hasNext ()) {
354
- Property currentProperty = it .next ();
355
- Object currentPropertyValue = currentProperty .value ();
356
-
357
- if (!Objects .equals (currentPropertyValue , propertyValue )) {
358
- //fill the map with all iterartor values for the entityGuid
359
- if (propertyName .startsWith (INTERNAL_PROPERTY_KEY_PREFIX )) {
360
- String entityGuid = this .getProperty (GUID_PROPERTY_KEY , String .class );
361
- if (StringUtils .isNotEmpty (entityGuid )) {
362
- if (context .getAllInternalAttributesMap ().get (entityGuid ) != null ) {
363
- Object value = context .getAllInternalAttributesMap ().get (entityGuid );
364
- List <Object > values = new ArrayList <>();
365
- values .add (value );
366
- values .add (currentPropertyValue );
367
- context .getAllInternalAttributesMap ().get (entityGuid ).put (propertyName , values );
368
- } else {
369
- Map <String , Object > map = new HashMap <>();
370
- map .put (propertyName , currentPropertyValue );
371
- context .getAllInternalAttributesMap ().put (entityGuid , map );
372
- }
373
- }
348
+ private void recordInternalAttribute (String propertyName , Object finalValue ) {
349
+ if (propertyName .startsWith (INTERNAL_PROPERTY_KEY_PREFIX )) {
350
+ RequestContext context = RequestContext .get ();
351
+ String entityGuid = this .getProperty (GUID_PROPERTY_KEY , String .class );
352
+
353
+ if (StringUtils .isNotEmpty (entityGuid )) {
354
+ if (context .getAllInternalAttributesMap ().get (entityGuid ) != null ) {
355
+ context .getAllInternalAttributesMap ().get (entityGuid ).put (propertyName , finalValue );
356
+ } else {
357
+ Map <String , Object > map = new HashMap <>();
358
+ map .put (propertyName , finalValue );
359
+ context .getAllInternalAttributesMap ().put (entityGuid , map );
374
360
}
375
361
}
376
362
}
0 commit comments