Search in sources :

Example 1 with LogicExtensionPoint

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;
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 2 with LogicExtensionPoint

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;
}
Also used : Attachment(com.icthh.xm.ms.entity.domain.Attachment) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 3 with LogicExtensionPoint

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));
    }
}
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 4 with LogicExtensionPoint

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;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 5 with LogicExtensionPoint

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);
}
Also used : XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)8 Link (com.icthh.xm.ms.entity.domain.Link)4 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)4 Attachment (com.icthh.xm.ms.entity.domain.Attachment)3 EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)2 Comment (com.icthh.xm.ms.entity.domain.Comment)2 Location (com.icthh.xm.ms.entity.domain.Location)2 Profile (com.icthh.xm.ms.entity.domain.Profile)2 Rating (com.icthh.xm.ms.entity.domain.Rating)2 Tag (com.icthh.xm.ms.entity.domain.Tag)2 Vote (com.icthh.xm.ms.entity.domain.Vote)2 XmEntityIdKeyTypeKey (com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)1 ErrorConstants (com.icthh.xm.commons.exceptions.ErrorConstants)1 LepService (com.icthh.xm.commons.lep.spring.LepService)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)1 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)1