Search in sources :

Example 96 with XmEntity

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

the class XmEntityServiceImpl method saveXmEntity.

/**
 * Save a xmEntity.
 * When you call this method will be run general save LEP
 *
 * @param xmEntity the entity to save
 * @return the persisted entity
 */
@LogicExtensionPoint("Save")
public XmEntity saveXmEntity(XmEntity xmEntity) {
    log.debug("Request to save XmEntity : {}", xmEntity);
    Optional<XmEntity> oldEntity = startUpdateDateGenerationStrategy.preProcessStartUpdateDates(xmEntity, xmEntity.getId(), xmEntityRepository, XmEntity::setStartDate, XmEntity::getStartDate, XmEntity::setUpdateDate);
    if (oldEntity.isPresent()) {
        preventRenameTenant(xmEntity, oldEntity.get());
    } else if (xmEntity.getCreatedBy() == null) {
        xmEntity.setCreatedBy(authContextHolder.getContext().getUserKey().orElse(null));
    }
    // FIXME It is hack to link each tag with entity before persisting. may be there is more elegant solution.
    xmEntity.updateXmEntityReference(xmEntity.getAttachments(), Attachment::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getCalendars(), Calendar::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getLocations(), Location::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getRatings(), Rating::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getTags(), Tag::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getComments(), Comment::setXmEntity);
    xmEntity.updateXmEntityReference(xmEntity.getTargets(), Link::setSource);
    xmEntity.updateXmEntityReference(xmEntity.getSources(), Link::setTarget);
    xmEntity.updateXmEntityReference(xmEntity.getVotes(), Vote::setXmEntity);
    XmEntity result = xmEntityRepository.save(xmEntity);
    xmEntitySearchRepository.save(result);
    return result;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Link(com.icthh.xm.ms.entity.domain.Link) Location(com.icthh.xm.ms.entity.domain.Location) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 97 with XmEntity

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

the class XmEntityServiceImpl method deleteNewLink.

private void deleteNewLink(Link linkToDelete) {
    XmEntity entity = linkToDelete.getTarget();
    entity.getSources().remove(linkToDelete);
    for (Link sourceLink : nullSafe(entity.getSources())) {
        if (!sourceLink.linkFromSameEntity(linkToDelete)) {
            log.warn("Entity {} has links from other entity(ies), so deletion of this entity will be ignored in cascade deletion.", entity);
            return;
        }
    }
    deleteXmEntity(entity);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Example 98 with XmEntity

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

the class XmEntityServiceImpl method updateAvatar.

@Override
public URI updateAvatar(IdOrKey idOrKey, HttpEntity<Resource> avatarHttpEntity) {
    XmEntity source = toSourceXmEntity(idOrKey);
    String avatarUrl = storageService.store(avatarHttpEntity, null);
    log.info("Avatar {} stored for entity {}", avatarUrl, idOrKey);
    source.setAvatarUrl(avatarUrl);
    save(source);
    return URI.create(avatarUrl);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 99 with XmEntity

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

the class XmEntityServiceImpl method selectAndUpdate.

@Override
@Transactional
public XmEntity selectAndUpdate(IdOrKey idOrKey, Consumer<XmEntity> consumer) {
    log.debug("Request to get XmEntity : {}", idOrKey);
    Long xmEntityId;
    if (idOrKey.isKey()) {
        XmEntityIdKeyTypeKey projection = getXmEntityIdKeyTypeKey(idOrKey);
        xmEntityId = projection.getId();
    } else {
        xmEntityId = idOrKey.getId();
    }
    XmEntity entity = xmEntityRepository.findOneByIdForUpdate(xmEntityId);
    consumer.accept(entity);
    return save(entity);
}
Also used : XmEntityIdKeyTypeKey(com.icthh.xm.ms.entity.projection.XmEntityIdKeyTypeKey) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with XmEntity

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

the class XmEntityServiceImpl method toSourceXmEntity.

private XmEntity toSourceXmEntity(IdOrKey idOrKey) {
    XmEntity source;
    if (idOrKey.isSelf()) {
        source = profile();
        log.debug("Self resolved entity id = {}, typeKet = {}", source.getId(), source.getTypeKey());
    } else {
        source = findOne(idOrKey);
        log.debug("Resolved entity id = {}, typeKet = {}", source.getId(), source.getTypeKey());
    }
    return source;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

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