Search in sources :

Example 1 with Link

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

the class LinkService method save.

/**
 * Save a link.
 *
 * @param link the entity to save
 * @return the persisted entity
 */
@LogicExtensionPoint("Save")
public Link save(Link link) {
    startUpdateDateGenerationStrategy.preProcessStartDate(link, link.getId(), linkRepository, Link::setStartDate, Link::getStartDate);
    Link result = linkRepository.save(link);
    linkSearchRepository.save(result);
    return result;
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 2 with Link

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

the class DeleteEntityTest method testDeleteLink.

@Test
public void testDeleteLink() {
    XmEntity entity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE"));
    XmEntity breakLink = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_SEARCH"));
    XmEntity cascadeDeleteLink = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_NEW"));
    Link link = new Link();
    entity.addTargets(link);
    link.setTypeKey("breakLinks");
    link.setTarget(breakLink);
    link.setSource(entity);
    Link link2 = new Link();
    link2.setTypeKey("cascadeDeleteLinks");
    link2.setTarget(cascadeDeleteLink);
    entity.addTargets(link2);
    xmEntityService.save(entity);
    XmEntity cascadeBreakSubLinks = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_SEARCH"));
    XmEntity cascadeDeleteSubLinks = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_LIFECYCLE_LINK_NEW"));
    cascadeDeleteLink.addTargets(new Link().typeKey("cascadeBreakSubLinks").target(cascadeBreakSubLinks));
    cascadeDeleteLink.addTargets(new Link().typeKey("cascadeDeleteSubLinks").target(cascadeDeleteSubLinks));
    xmEntityService.save(cascadeDeleteLink);
    xmEntityService.delete(entity.getId());
    assertThat(xmEntityRepository.exists(entity.getId())).isFalse();
    assertThat(xmEntityRepository.exists(breakLink.getId())).isTrue();
    assertThat(xmEntityRepository.exists(cascadeDeleteLink.getId())).isFalse();
    assertThat(xmEntityRepository.exists(cascadeBreakSubLinks.getId())).isTrue();
    assertThat(xmEntityRepository.exists(cascadeDeleteSubLinks.getId())).isFalse();
    xmEntityService.delete(breakLink.getId());
    xmEntityService.delete(cascadeBreakSubLinks.getId());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Link

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

the class DeleteEntityTest method testDeleteLinkDifferentLinkTypes.

@Test
@SneakyThrows
public void testDeleteLinkDifferentLinkTypes() {
    XmEntity deletedEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE_NEW_LINK"));
    XmEntity otherEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE_SEARCH_LINK"));
    XmEntity sharedEntity = xmEntityService.save(new XmEntity().name(" ").key(randomUUID()).typeKey("TARGET_ENTITY"));
    Link newLink = new Link();
    newLink.setTypeKey("newLink");
    newLink.setTarget(sharedEntity);
    deletedEntity.addTargets(newLink);
    Link searchLink = new Link();
    searchLink.setTypeKey("cascadeDeleteLinks");
    searchLink.setTarget(sharedEntity);
    otherEntity.addTargets(searchLink);
    xmEntityService.save(deletedEntity);
    xmEntityService.save(otherEntity);
    xmEntityService.delete(deletedEntity.getId());
    assertThat(xmEntityRepository.exists(otherEntity.getId())).isTrue();
    assertThat(xmEntityRepository.exists(sharedEntity.getId())).isTrue();
    assertThat(xmEntityRepository.exists(deletedEntity.getId())).isFalse();
    xmEntityService.delete(sharedEntity.getId());
    xmEntityService.delete(otherEntity.getId());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 4 with Link

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

the class EntityServiceImplIntTest method testGetLinkSourcesSelfKey.

@Test
@Transactional
public void testGetLinkSourcesSelfKey() throws Exception {
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, "ACCOUNT.USER"));
    Link link = createSelfLink(targetEntity);
    linkRepository.save(link);
    List<Link> result = xmEntityService.getLinkSources(IdOrKey.of(targetEntity.getId()), TEST_LINK_KEY);
    assertThat(result).isNotNull();
    assertThat(result.size()).isEqualTo(BigInteger.ONE.intValue());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Link

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

the class EntityServiceImplIntTest method testGetLinkSourcesByEntityId.

@Test
@Transactional
public void testGetLinkSourcesByEntityId() throws Exception {
    XmEntity sourceEntity = xmEntityRepository.save(createEntity(null, "ACCOUNT"));
    XmEntity targetEntity = xmEntityRepository.save(createEntity(2l, "ACCOUNT.USER"));
    Link link = createLink(sourceEntity, targetEntity);
    linkRepository.save(link);
    List<Link> sourcesLinks = xmEntityService.getLinkSources(IdOrKey.of(targetEntity.getId()), TEST_LINK_KEY);
    assertThat(sourcesLinks).isNotNull();
    assertThat(sourcesLinks.size()).isEqualTo(BigInteger.ONE.intValue());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Link (com.icthh.xm.ms.entity.domain.Link)32 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)20 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 Transactional (org.springframework.transaction.annotation.Transactional)16 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 Timed (com.codahale.metrics.annotation.Timed)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 SneakyThrows (lombok.SneakyThrows)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 Location (com.icthh.xm.ms.entity.domain.Location)1 Rating (com.icthh.xm.ms.entity.domain.Rating)1 Tag (com.icthh.xm.ms.entity.domain.Tag)1