Search in sources :

Example 16 with XmEntity

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

Example 17 with XmEntity

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

the class XmEntityGeneratorService method generateXmEntity.

public XmEntity generateXmEntity(String rootTypeKey) {
    TypeSpec typeSpec = getRandomTypeSpec(rootTypeKey);
    String name = typeSpec.getName().entrySet().iterator().next().getValue();
    if (!Constants.TENANT_TYPE_KEY.equals(rootTypeKey)) {
        name = name.concat(" name");
    } else {
        name = name.concat(String.valueOf(System.currentTimeMillis()));
    }
    XmEntity xmEntity = new XmEntity().key(UUID.randomUUID().toString()).typeKey(typeSpec.getKey()).stateKey(generateXmEntityState(xmEntitySpecService, typeSpec)).name(name).startDate(generateXmEntityStartDate()).updateDate(Instant.now()).endDate(generateXmEntityEndDate()).description(String.format("Generated [%s] Generator version [%s]", typeSpec.getName().entrySet().iterator().next().getValue(), GENERATOR_VERSION)).avatarUrl(generateXmEntityAvatarUrl()).data(generateXmEntityData(typeSpec)).locations(generateLocations(typeSpec.getLocations())).tags(generateTags(typeSpec)).createdBy(authContextHolder.getContext().getRequiredUserKey());
    return xmEntityService.save(xmEntity);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec)

Example 18 with XmEntity

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

the class XmEntityServiceImpl method exportEntities.

@LogicExtensionPoint("Export")
@Override
public byte[] exportEntities(String fileFormat, String typeKey) {
    Set<String> typeKeys = xmEntitySpecService.findNonAbstractTypesByPrefix(typeKey).stream().map(TypeSpec::getKey).collect(Collectors.toSet());
    List<XmEntity> xmEntities = xmEntityRepository.findAllByTypeKeyIn(new PageRequest(0, Integer.MAX_VALUE), typeKeys).getContent();
    ModelMapper modelMapper = new ModelMapper();
    List<SimpleExportXmEntityDto> simpleEntities = xmEntities.stream().map(entity -> modelMapper.map(entity, SimpleExportXmEntityDto.class)).collect(Collectors.toList());
    switch(FileFormatEnum.valueOf(fileFormat.toUpperCase())) {
        case CSV:
            return EntityToCsvConverterUtils.toCsv(simpleEntities, SimpleExportXmEntityDto.class);
        case XLSX:
            return EntityToExcelConverterUtils.toExcel(simpleEntities, typeKey);
        default:
            throw new BusinessException(ErrorConstants.ERR_VALIDATION, String.format("Converter doesn't support '%s' file format", fileFormat));
    }
}
Also used : XmEntityService(com.icthh.xm.ms.entity.service.XmEntityService) StorageService(com.icthh.xm.ms.entity.service.StorageService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) XmEntityPermittedRepository(com.icthh.xm.ms.entity.repository.XmEntityPermittedRepository) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Collectors.toMap(java.util.stream.Collectors.toMap) Vote(com.icthh.xm.ms.entity.domain.Vote) Arrays.asList(java.util.Arrays.asList) FileFormatEnum(com.icthh.xm.ms.entity.domain.FileFormatEnum) EntityToCsvConverterUtils(com.icthh.xm.ms.entity.domain.converter.EntityToCsvConverterUtils) Map(java.util.Map) EntityToExcelConverterUtils(com.icthh.xm.ms.entity.domain.converter.EntityToExcelConverterUtils) Pageable(org.springframework.data.domain.Pageable) FindWithPermission(com.icthh.xm.commons.permission.annotation.FindWithPermission) URI(java.net.URI) Resource(org.springframework.core.io.Resource) Link(com.icthh.xm.ms.entity.domain.Link) LifecycleLepStrategy(com.icthh.xm.ms.entity.service.LifecycleLepStrategy) BusinessException(com.icthh.xm.commons.exceptions.BusinessException) Collections.emptyList(java.util.Collections.emptyList) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) LinkService(com.icthh.xm.ms.entity.service.LinkService) XmEntitySearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntitySearchRepository) Page(org.springframework.data.domain.Page) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) HttpEntity(org.springframework.http.HttpEntity) List(java.util.List) ProfileService(com.icthh.xm.ms.entity.service.ProfileService) XmEntitySpecService(com.icthh.xm.ms.entity.service.XmEntitySpecService) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Specification(org.springframework.data.jpa.domain.Specification) Comment(com.icthh.xm.ms.entity.domain.Comment) Optional(java.util.Optional) XmAuthenticationContextHolder(com.icthh.xm.commons.security.XmAuthenticationContextHolder) CustomCollectionUtils.nullSafe(com.icthh.xm.ms.entity.util.CustomCollectionUtils.nullSafe) Constants(com.icthh.xm.ms.entity.config.Constants) XmEntityTypeKeyResolver(com.icthh.xm.ms.entity.lep.keyresolver.XmEntityTypeKeyResolver) XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) Callable(java.util.concurrent.Callable) LepService(com.icthh.xm.commons.lep.spring.LepService) ModelMapper(org.modelmapper.ModelMapper) XmEntityStateProjection(com.icthh.xm.ms.entity.projection.XmEntityStateProjection) Propagation(org.springframework.transaction.annotation.Propagation) SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) IdOrKey(com.icthh.xm.ms.entity.domain.ext.IdOrKey) AttachmentService(com.icthh.xm.ms.entity.service.AttachmentService) SEARCH_BUILDER_TYPE(com.icthh.xm.ms.entity.domain.spec.LinkSpec.SEARCH_BUILDER_TYPE) Rating(com.icthh.xm.ms.entity.domain.Rating) Iterator(java.util.Iterator) Optional.ofNullable(java.util.Optional.ofNullable) ErrorConstants(com.icthh.xm.commons.exceptions.ErrorConstants) LifecycleLepStrategyFactory(com.icthh.xm.ms.entity.service.LifecycleLepStrategyFactory) ObjectUtils(org.springframework.util.ObjectUtils) LinkSpec(com.icthh.xm.ms.entity.domain.spec.LinkSpec) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Location(com.icthh.xm.ms.entity.domain.Location) Consumer(java.util.function.Consumer) StateSpec(com.icthh.xm.ms.entity.domain.spec.StateSpec) XmEntityPermittedSearchRepository(com.icthh.xm.ms.entity.repository.search.XmEntityPermittedSearchRepository) XmEntityRepository(com.icthh.xm.ms.entity.repository.XmEntityRepository) Calendar(com.icthh.xm.ms.entity.domain.Calendar) MultipartFile(org.springframework.web.multipart.MultipartFile) NEW_BUILDER_TYPE(com.icthh.xm.ms.entity.domain.spec.LinkSpec.NEW_BUILDER_TYPE) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) PageRequest(org.springframework.data.domain.PageRequest) BusinessException(com.icthh.xm.commons.exceptions.BusinessException) SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) ModelMapper(org.modelmapper.ModelMapper) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 19 with XmEntity

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

the class XmEntityServiceImpl method delete.

/**
 * Delete the  xmEntity by id.
 *
 * @param id the id of the entity
 */
@Override
public void delete(Long id) {
    log.debug("Request to delete XmEntity : {}", id);
    XmEntity xmEntity = xmEntityRepository.findOne(id, asList("targets"));
    self.deleteXmEntityByTypeKeyLep(xmEntity);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 20 with XmEntity

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

the class XmEntityServiceImpl method deleteLinkTarget.

@Override
public void deleteLinkTarget(IdOrKey idOrKey, String linkId) {
    XmEntity source = toSourceXmEntity(idOrKey);
    Long longLinkId = Long.parseLong(linkId);
    Link foundLink = linkService.findOne(longLinkId);
    if (foundLink == null) {
        throw new IllegalArgumentException("Link not found by id " + linkId);
    }
    Long foundSourceId = foundLink.getSource().getId();
    if (!foundSourceId.equals(source.getId())) {
        throw new BusinessException("Wrong source id. Expected " + source.getId() + " found " + foundSourceId);
    }
    log.debug("Delete link by id " + linkId);
    linkService.delete(longLinkId);
}
Also used : BusinessException(com.icthh.xm.commons.exceptions.BusinessException) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Aggregations

XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)102 Test (org.junit.Test)60 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)46 Transactional (org.springframework.transaction.annotation.Transactional)32 Link (com.icthh.xm.ms.entity.domain.Link)22 Tag (com.icthh.xm.ms.entity.domain.Tag)10 ConstraintViolation (javax.validation.ConstraintViolation)9 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SneakyThrows (lombok.SneakyThrows)8 Attachment (com.icthh.xm.ms.entity.domain.Attachment)7 Location (com.icthh.xm.ms.entity.domain.Location)7 lombok.val (lombok.val)7 Calendar (com.icthh.xm.ms.entity.domain.Calendar)6 Profile (com.icthh.xm.ms.entity.domain.Profile)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Rating (com.icthh.xm.ms.entity.domain.Rating)5 Timed (com.codahale.metrics.annotation.Timed)4