@Override
public PolicyEntity update(PolicyEntity policyProto) {
Preconditions.checkNotNull(policyProto, "Entity should not be null");
Preconditions.checkNotNull(policyProto.getUuid(), "uuid should not be null");
PolicyEntity current = getByUUIDorName(policyProto.getUuid(), null);
if (policyProto.getName() != null) {
current.setName(policyProto.getName());
}
if (policyProto.getAlertPublishmentIds() != null) {
current.setAlertPublishmentIds(policyProto.getAlertPublishmentIds());
}
if (policyProto.getDefinition() != null) {
current.setDefinition(policyProto.getDefinition());
}
current.ensureDefault();
try {
if (!queryService.execute(updateSqlByUUID, current, policyEntityWriter)) {
throw new IllegalArgumentException("Failed to update policyProto");
}
} catch (SQLException e) {
LOGGER.error("Error to execute {}: {}", updateSqlByUUID, policyProto, e);
throw new IllegalArgumentException("SQL execution error: " + e.getMessage(), e);
}
return current;
}