use of com.icthh.xm.ms.entity.domain.Comment in project xm-ms-entity by xm-online.
the class CommentResourceIntTest method createComment.
@Test
@Transactional
public void createComment() throws Exception {
int databaseSizeBeforeCreate = commentRepository.findAll().size();
// Create the Comment
restCommentMockMvc.perform(post("/api/comments").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(comment))).andExpect(status().isCreated());
// Validate the Comment in the database
List<Comment> commentList = commentRepository.findAll();
assertThat(commentList).hasSize(databaseSizeBeforeCreate + 1);
Comment testComment = commentList.get(commentList.size() - 1);
assertThat(testComment.getUserKey()).isEqualTo(DEFAULT_USER_KEY);
assertThat(testComment.getMessage()).isEqualTo(DEFAULT_MESSAGE);
assertThat(testComment.getEntryDate()).isEqualTo(DEFAULT_ENTRY_DATE);
// Validate the Comment in Elasticsearch
Comment commentEs = commentSearchRepository.findOne(testComment.getId());
assertThat(commentEs).isEqualToComparingFieldByField(testComment);
}
use of com.icthh.xm.ms.entity.domain.Comment in project xm-ms-entity by xm-online.
the class DeleteEntityTest method createXmEntity.
private XmEntity createXmEntity() {
XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
return xmEntity;
}
use of com.icthh.xm.ms.entity.domain.Comment in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method saveXmEntity.
/**
* Save a xmEntity.
* When you call this method will be run general save LEP
*
* @param xmEntity the entity to save
* @return the persisted entity
*/
@LogicExtensionPoint("Save")
public XmEntity saveXmEntity(XmEntity xmEntity) {
log.debug("Request to save XmEntity : {}", xmEntity);
Optional<XmEntity> oldEntity = startUpdateDateGenerationStrategy.preProcessStartUpdateDates(xmEntity, xmEntity.getId(), xmEntityRepository, XmEntity::setStartDate, XmEntity::getStartDate, XmEntity::setUpdateDate);
if (oldEntity.isPresent()) {
preventRenameTenant(xmEntity, oldEntity.get());
} else if (xmEntity.getCreatedBy() == null) {
xmEntity.setCreatedBy(authContextHolder.getContext().getUserKey().orElse(null));
}
// FIXME It is hack to link each tag with entity before persisting. may be there is more elegant solution.
xmEntity.updateXmEntityReference(xmEntity.getAttachments(), Attachment::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getCalendars(), Calendar::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getLocations(), Location::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getRatings(), Rating::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getTags(), Tag::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getComments(), Comment::setXmEntity);
xmEntity.updateXmEntityReference(xmEntity.getTargets(), Link::setSource);
xmEntity.updateXmEntityReference(xmEntity.getSources(), Link::setTarget);
xmEntity.updateXmEntityReference(xmEntity.getVotes(), Vote::setXmEntity);
XmEntity result = xmEntityRepository.save(xmEntity);
xmEntitySearchRepository.save(result);
return result;
}
use of com.icthh.xm.ms.entity.domain.Comment in project xm-ms-entity by xm-online.
the class CommentService method save.
/**
* Save a comment.
*
* @param comment the entity to save
* @return the persisted entity
*/
public Comment save(Comment comment) {
comment.setUserKey(getUserKey());
Comment result = commentRepository.save(comment);
commentSearchRepository.save(result);
return result;
}
Aggregations