use of com.icthh.xm.commons.lep.LogicExtensionPoint 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.commons.lep.LogicExtensionPoint in project xm-ms-entity by xm-online.
the class AttachmentService method save.
/**
* Save a attachment.
*
* @param attachment the entity to save
* @return the persisted entity
*/
@LogicExtensionPoint("Save")
public Attachment save(Attachment attachment) {
startUpdateDateGenerationStrategy.preProcessStartDate(attachment, attachment.getId(), attachmentRepository, Attachment::setStartDate, Attachment::getStartDate);
Attachment result = attachmentRepository.save(attachment);
attachmentSearchRepository.save(result);
return result;
}
use of com.icthh.xm.commons.lep.LogicExtensionPoint 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.commons.lep.LogicExtensionPoint in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method saveLinkTarget.
@LogicExtensionPoint("SaveLinkTarget")
@Override
public Link saveLinkTarget(IdOrKey idOrKey, Link link, MultipartFile file) {
// resolve source entity by idOrKey
XmEntity source = toSourceXmEntity(idOrKey);
// resolve target entity by key
XmEntity target = findOne(toIdOrKey(link.getTarget()));
// save link
link.setSource(source);
link.setTarget(target);
link.setStartDate(Instant.now());
Link savedLink = linkService.save(link);
log.debug("Link saved with id {}", link.getId());
// save file to storage and attachment
if (file != null) {
addFileAttachment(savedLink.getTarget(), file);
}
return savedLink;
}
use of com.icthh.xm.commons.lep.LogicExtensionPoint in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method findOne.
/**
* Get one xmEntity by id or key.
*
* @param idOrKey the id or key of the entity
* @return the entity
*/
@LogicExtensionPoint("FindOne")
@Override
@Transactional(readOnly = true)
public XmEntity findOne(IdOrKey idOrKey) {
log.debug("Request to get XmEntity : {}", idOrKey);
Long xmEntityId;
if (idOrKey.isKey()) {
XmEntityIdKeyTypeKey projection = getXmEntityIdKeyTypeKey(idOrKey);
xmEntityId = projection.getId();
} else {
xmEntityId = idOrKey.getId();
}
return xmEntityRepository.findOneById(xmEntityId);
}
Aggregations