Search in sources :

Example 6 with Comment

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);
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Comment

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;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Event(com.icthh.xm.ms.entity.domain.Event) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Location(com.icthh.xm.ms.entity.domain.Location)

Example 8 with Comment

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;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Link(com.icthh.xm.ms.entity.domain.Link) Location(com.icthh.xm.ms.entity.domain.Location) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 9 with Comment

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;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment)

Aggregations

Comment (com.icthh.xm.ms.entity.domain.Comment)9 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Timed (com.codahale.metrics.annotation.Timed)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)2 Location (com.icthh.xm.ms.entity.domain.Location)2 Rating (com.icthh.xm.ms.entity.domain.Rating)2 Tag (com.icthh.xm.ms.entity.domain.Tag)2 Vote (com.icthh.xm.ms.entity.domain.Vote)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 Event (com.icthh.xm.ms.entity.domain.Event)1 FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)1 Link (com.icthh.xm.ms.entity.domain.Link)1