Search in sources :

Example 1 with LinkProjection

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);
}
Also used : LinkSpec(com.icthh.xm.ms.entity.domain.spec.LinkSpec) LinkProjection(com.icthh.xm.ms.entity.projection.LinkProjection) FindWithPermission(com.icthh.xm.commons.permission.annotation.FindWithPermission) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 PrivilegeDescription (com.icthh.xm.commons.permission.annotation.PrivilegeDescription)1 LinkSpec (com.icthh.xm.ms.entity.domain.spec.LinkSpec)1 LinkProjection (com.icthh.xm.ms.entity.projection.LinkProjection)1 Transactional (org.springframework.transaction.annotation.Transactional)1