use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.
the class XmEntityGeneratorService method generateLocations.
private Set<Location> generateLocations(LocationSpec locationSpec) {
Set<Location> result = new HashSet<>();
List<Location> originalLocationStubs = getLocationStubs();
val locationStubs = originalLocationStubs.stream().filter(l -> RandomUtils.nextBoolean()).collect(toList());
if (isEmpty(locationStubs)) {
int randomLocationPosition = RandomUtils.nextInt(0, originalLocationStubs.size() - 1);
Location randomLocationStub = originalLocationStubs.get(randomLocationPosition);
locationStubs.add(randomLocationStub);
}
int locationsLimit = min(locationSpec.getMax(), locationStubs.size());
int countLocations = RandomUtils.nextInt(1, locationsLimit);
IntStream.range(0, countLocations).forEachOrdered(i -> {
Location locationStub = locationStubs.get(i);
updateLocationStubToLocation(locationSpec, locationStub);
result.add(locationStub);
});
return result;
}
use of com.icthh.xm.ms.entity.domain.Location 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;
}
Aggregations