Search in sources :

Example 6 with LogicExtensionPoint

use of com.icthh.xm.commons.lep.LogicExtensionPoint 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 7 with LogicExtensionPoint

use of com.icthh.xm.commons.lep.LogicExtensionPoint in project xm-ms-entity by xm-online.

the class ProfileService method updateProfile.

@LogicExtensionPoint("UpdateProfile")
public XmEntity updateProfile(XmEntity entity) {
    Profile profile = getSelfProfile();
    XmEntity profileEntity = profile.getXmentity();
    // update profile data
    profileEntity.setData(entity.getData());
    save(profile);
    return profileEntity;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Profile(com.icthh.xm.ms.entity.domain.Profile) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Example 8 with LogicExtensionPoint

use of com.icthh.xm.commons.lep.LogicExtensionPoint in project xm-ms-entity by xm-online.

the class ProfileService method getSelfProfile.

@LogicExtensionPoint("GetSelfProfile")
@Transactional(readOnly = true)
public Profile getSelfProfile() {
    XmAuthenticationContext context = authContextHolder.getContext();
    if (!context.isFullyAuthenticated()) {
        throw new EntityNotFoundException("Can't get profile for not fully authenticated user");
    }
    String userKey = context.getRequiredUserKey();
    log.debug("Get profile for user key {}", userKey);
    Profile profile = getProfile(userKey);
    if (profile == null) {
        throw new IllegalArgumentException("Profile not found for user key " + userKey);
    }
    return profile;
}
Also used : XmAuthenticationContext(com.icthh.xm.commons.security.XmAuthenticationContext) EntityNotFoundException(com.icthh.xm.commons.exceptions.EntityNotFoundException) Profile(com.icthh.xm.ms.entity.domain.Profile) 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