Search in sources :

Example 11 with Attachment

use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.

the class AttachmentResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Attachment.class);
    Attachment attachment1 = new Attachment();
    attachment1.setId(1L);
    Attachment attachment2 = new Attachment();
    attachment2.setId(attachment1.getId());
    assertThat(attachment1).isEqualTo(attachment2);
    attachment2.setId(2L);
    assertThat(attachment1).isNotEqualTo(attachment2);
    attachment1.setId(null);
    assertThat(attachment1).isNotEqualTo(attachment2);
}
Also used : Attachment(com.icthh.xm.ms.entity.domain.Attachment) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Attachment

use of com.icthh.xm.ms.entity.domain.Attachment 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 13 with Attachment

use of com.icthh.xm.ms.entity.domain.Attachment in project xm-ms-entity by xm-online.

the class EntityServiceImplIntTest method saveSelfLinkTarget.

@Test
@Transactional
@WithMockUser(authorities = "SUPER-ADMIN")
public void saveSelfLinkTarget() throws Exception {
    when(storageService.store(Mockito.any(MultipartFile.class), Mockito.any())).thenReturn("test.txt");
    int databaseSizeBeforeCreate = linkRepository.findAll().size();
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, TARGET_TYPE_KEY));
    Link link = createSelfLink(targetEntity);
    // Create link with attachment
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TEST".getBytes());
    xmEntityService.saveLinkTarget(IdOrKey.SELF, link, file);
    // Validate the link in the database
    List<Link> linkList = linkRepository.findAll();
    assertThat(linkList).hasSize(databaseSizeBeforeCreate + BigInteger.ONE.intValue());
    // validate attachment in database
    List<Attachment> attachments = attachmentService.findAll(null);
    assertThat(attachments).hasSize(BigInteger.ONE.intValue());
    Attachment attachment = attachments.stream().findFirst().get();
    assertThat(attachment.getContentUrl()).contains("test.txt");
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Link(com.icthh.xm.ms.entity.domain.Link) WithMockUser(org.springframework.security.test.context.support.WithMockUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Attachment

use of com.icthh.xm.ms.entity.domain.Attachment 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)

Aggregations

Attachment (com.icthh.xm.ms.entity.domain.Attachment)14 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Transactional (org.springframework.transaction.annotation.Transactional)8 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)6 Location (com.icthh.xm.ms.entity.domain.Location)4 Tag (com.icthh.xm.ms.entity.domain.Tag)4 Calendar (com.icthh.xm.ms.entity.domain.Calendar)3 Link (com.icthh.xm.ms.entity.domain.Link)3 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)2 Comment (com.icthh.xm.ms.entity.domain.Comment)2 Content (com.icthh.xm.ms.entity.domain.Content)2 Event (com.icthh.xm.ms.entity.domain.Event)2 Rating (com.icthh.xm.ms.entity.domain.Rating)2 Vote (com.icthh.xm.ms.entity.domain.Vote)2 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 PropertyAccessor (com.fasterxml.jackson.annotation.PropertyAccessor)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1