Map<String, String> dirtyFieldsOrigVals = new HashMap<String, String>();
List<String> dirtyFields = new ArrayList<String>();
Map<String, PageField> pageFieldMap = page.getPageFields();
for (Property property : persistencePackage.getEntity().getProperties()) {
if (templateFieldNames.contains(property.getName())) {
PageField pageField = pageFieldMap.get(property.getName());
if (pageField != null) {
boolean isDirty = (pageField.getValue() == null && property.getValue() != null) ||
(pageField.getValue() != null && property.getValue() == null);
if (isDirty || (pageField.getValue() != null && property.getValue() != null &&
!pageField.getValue().trim().equals(property.getValue().trim()))) {
dirtyFields.add(property.getName());
dirtyFieldsOrigVals.put(property.getName(), pageField.getValue());
}
pageField.setValue(property.getValue());
} else {
pageField = new PageFieldImpl();
pageField.setFieldKey(property.getName());
pageField.setValue(property.getValue());
dynamicEntityDao.persist(pageField);
pageFieldMap.put(property.getName(), pageField);
dirtyFields.add(property.getName());
}
}