void updateService(ExternalEvent event, Map<String, Object> serviceData) { Service svc = serviceDao.getServiceByExternalId(event.getAccountId(), event.getExternalId()); if (svc == null) { log.info( "Unable to find service while attempting to update. Returning. Service external id: [{}], account id: [{}]", event.getExternalId(), event.getAccountId()); return; } Map<String, Object> fields = DataUtils.getFields(svc); Map<String, Object> updates = new HashMap<String, Object>(); for (Map.Entry<String, Object> resourceField : serviceData.entrySet()) { String fieldName = resourceField.getKey(); Object newFieldValue = resourceField.getValue(); Object currentFieldValue = fields.get(fieldName); if (ObjectUtils.hasWritableProperty(svc, fieldName)) { Object property = ObjectUtils.getProperty(svc, fieldName); if (newFieldValue != null && !newFieldValue.equals(property) || property == null) { updates.put(fieldName, newFieldValue); } } else if ((newFieldValue != null && !newFieldValue.equals(currentFieldValue)) || currentFieldValue != null) { updates.put(fieldName, newFieldValue); } } if (!updates.isEmpty()) { objectManager.setFields(svc, updates); resourceDao.updateAndSchedule(svc); } }