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