use of com.icthh.xm.ms.entity.projection.LinkProjection in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method searchXmEntitiesToLink.
@LogicExtensionPoint("SearchXmEntitiesToLink")
@Override
@Transactional(readOnly = true)
@FindWithPermission("XMENTITY.SEARCH")
@PrivilegeDescription("Privilege to search for the xmEntity corresponding to the query")
public Page<XmEntity> searchXmEntitiesToLink(IdOrKey idOrKey, String entityTypeKey, String linkTypeKey, String query, Pageable pageable, String privilegeKey) {
LinkSpec linkSpec = xmEntitySpecService.getLinkSpec(entityTypeKey, linkTypeKey).orElseThrow(() -> new IllegalArgumentException("Invalid entity typeKey ot link typeKey"));
if (!TRUE.equals(linkSpec.getIsUnique())) {
return self.search(query, pageable, privilegeKey);
}
Long id;
if (idOrKey.isId()) {
id = idOrKey.getId();
} else {
id = getXmEntityIdKeyTypeKey(idOrKey).getId();
}
List<LinkProjection> links = linkService.findLinkProjectionsBySourceIdAndTypeKey(id, linkTypeKey);
Set<Long> ids = links.stream().map(LinkProjection::getTarget).map(XmEntityId::getId).collect(toSet());
ids = new HashSet<>(ids);
ids.add(id);
return xmEntityPermittedSearchRepository.searchWithIdNotIn(query, ids, linkSpec.getTypeKey(), pageable, privilegeKey);
}
Aggregations