cancel
Showing results for 
Search instead for 
Did you mean: 

Why does copyContents() method of documentModelImpl class ignore a metaData change if its value has been removed from the source document.

Swaminathan_Jay
Champ in-the-making
Champ in-the-making

Why does copyContents ignore a metaData change if its value has been removed from the source document.

https://github.com/nuxeo/nuxeo/blob/master/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/cor...

I see that while calling the copyContents method, if the dataModel encounters a empty or null value, it moves ahead without replacing the destination field with the NULL value.

Was there any specific reason for doing like this? I thought of modifying the underlying logic. But i m not able to build and replace the NUXEO_CORE_API jar in my local bundles folder.

Changed copyContents() method can be found below

public static DataModel cloneDataModel(Schema schema, DataModel data) {


DataModel dm = new DataModelImpl(schema.getName());


for (Field field : schema.getFields()) {


String key = field.getName().getLocalName();


Object value;


try {


value = data.getData(key);


} catch (PropertyException e1) {


continue;


}


Object clone =null;


  


if (value != null) {


clone = cloneField(field, key, value);


}


try {


dm.setData(key, clone);


} catch (PropertyException e) {


throw new ClientRuntimeException(e);


}


}


return dm;


}


2 REPLIES 2

Florent_Guillau
World-Class Innovator
World-Class Innovator

Hi. Could you provide a unit test that demonstrates why in your opinion the current behavior is wrong? We use copyContent to copy data from an existing DocumentModel into a newly-created empty one, so the current behavior is correct in my opinion.

Swaminathan_Jay
Champ in-the-making
Champ in-the-making

I don't have a unit test handy. You are correct. As per the Current behavior, the data gets copied over without any issues into a new empty document.