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