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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations