return msgid;
}
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public boolean updateMessage(Topic oldMsg, Topic msg, User editor, List<String> newTags, String newText) {
EditHistoryDto editHistoryDto = new EditHistoryDto();
editHistoryDto.setMsgid(msg.getId());
editHistoryDto.setObjectType(EditHistoryObjectTypeEnum.TOPIC);
editHistoryDto.setEditor(editor.getId());
boolean modified = false;
String oldText = msgbaseDao.getMessageText(msg.getId()).getText();
if (!oldText.equals(newText)) {
editHistoryDto.setOldmessage(oldText);
modified = true;
msgbaseDao.updateMessage(msg.getId(), newText);
}
if (!oldMsg.getTitle().equals(msg.getTitle())) {
modified = true;
editHistoryDto.setOldtitle(oldMsg.getTitle());
namedJdbcTemplate.update(
"UPDATE topics SET title=:title WHERE id=:id",
ImmutableMap.of("title", msg.getTitle(), "id", msg.getId())
);
}
if (!equalStrings(oldMsg.getLinktext(), msg.getLinktext())) {
modified = true;
editHistoryDto.setOldlinktext(oldMsg.getLinktext());
namedJdbcTemplate.update(
"UPDATE topics SET linktext=:linktext WHERE id=:id",
ImmutableMap.of("linktext", msg.getLinktext(), "id", msg.getId())
);
}
if (!equalStrings(oldMsg.getUrl(), msg.getUrl())) {
modified = true;
editHistoryDto.setOldurl(oldMsg.getUrl());
namedJdbcTemplate.update(
"UPDATE topics SET url=:url WHERE id=:id",
ImmutableMap.of("url", msg.getUrl(), "id", msg.getId())
);
}
if (newTags != null) {
List<String> oldTags = topicTagService.getTags(msg);
boolean modifiedTags = topicTagService.updateTags(msg.getId(), oldTags, newTags);
if (modifiedTags) {
editHistoryDto.setOldtags(TagService.tagsToString(oldTags));
modified = true;
}
}
if (oldMsg.isMinor() != msg.isMinor()) {
namedJdbcTemplate.update("UPDATE topics SET minor=:minor WHERE id=:id",
ImmutableMap.of("minor", msg.isMinor(), "id", msg.getId()));
editHistoryDto.setOldminor(oldMsg.isMinor());
modified = true;
}
if (modified) {