Map<String, String> dirtyFieldsOrigVals = new HashMap<String, String>();
List<String> dirtyFields = new ArrayList<String>();
Map<String, StructuredContentField> structuredContentFieldMap = structuredContent.getStructuredContentFields();
for (Property property : persistencePackage.getEntity().getProperties()) {
if (templateFieldNames.contains(property.getName())) {
StructuredContentField structuredContentField = structuredContentFieldMap.get(property.getName());
if (structuredContentField != null) {
boolean isDirty = (structuredContentField.getValue() == null && property.getValue() != null) ||
(structuredContentField.getValue() != null && property.getValue() == null);
if (isDirty || (structuredContentField.getValue() != null && property.getValue() != null &&
!structuredContentField.getValue().trim().equals(property.getValue().trim()))) {
dirtyFields.add(property.getName());
dirtyFieldsOrigVals.put(property.getName(), structuredContentField.getValue());
}
structuredContentField.setValue(property.getValue());
} else {
structuredContentField = new StructuredContentFieldImpl();
structuredContentField.setFieldKey(property.getName());
structuredContentField.setValue(property.getValue());
dynamicEntityDao.persist(structuredContentField);
structuredContentFieldMap.put(property.getName(), structuredContentField);
dirtyFields.add(property.getName());
}
}