Search in sources :

Example 1 with LinkSpec

use of com.icthh.xm.ms.entity.domain.spec.LinkSpec in project xm-ms-entity by xm-online.

the class XmEntitySpecService method getAllKeys.

/**
 * Transforms all XmEntity Specification keys into the thin structure based
 * in maps and sets.
 *
 * @return thin structure based in maps and sets
 */
@IgnoreLogginAspect
public Map<String, Map<String, Set<String>>> getAllKeys() {
    Map<String, Map<String, Set<String>>> result = Maps.newHashMap();
    for (TypeSpec typeSpec : findAllTypes()) {
        Map<String, Set<String>> subKeys = Maps.newHashMap();
        getKeys(subKeys, AttachmentSpec.class, typeSpec.getAttachments(), AttachmentSpec::getKey);
        getKeys(subKeys, CalendarSpec.class, typeSpec.getCalendars(), CalendarSpec::getKey);
        getKeys(subKeys, LinkSpec.class, typeSpec.getLinks(), LinkSpec::getKey);
        getKeys(subKeys, LocationSpec.class, typeSpec.getLocations(), LocationSpec::getKey);
        getKeys(subKeys, RatingSpec.class, typeSpec.getRatings(), RatingSpec::getKey);
        getKeys(subKeys, StateSpec.class, typeSpec.getStates(), StateSpec::getKey);
        getKeys(subKeys, TagSpec.class, typeSpec.getTags(), TagSpec::getKey);
        result.put(typeSpec.getKey(), subKeys);
    }
    return result;
}
Also used : AttachmentSpec(com.icthh.xm.ms.entity.domain.spec.AttachmentSpec) LocationSpec(com.icthh.xm.ms.entity.domain.spec.LocationSpec) Set(java.util.Set) RatingSpec(com.icthh.xm.ms.entity.domain.spec.RatingSpec) StateSpec(com.icthh.xm.ms.entity.domain.spec.StateSpec) TagSpec(com.icthh.xm.ms.entity.domain.spec.TagSpec) LinkSpec(com.icthh.xm.ms.entity.domain.spec.LinkSpec) CalendarSpec(com.icthh.xm.ms.entity.domain.spec.CalendarSpec) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) IgnoreLogginAspect(com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)

Example 2 with LinkSpec

use of com.icthh.xm.ms.entity.domain.spec.LinkSpec 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

LinkSpec (com.icthh.xm.ms.entity.domain.spec.LinkSpec)2 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 IgnoreLogginAspect (com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 PrivilegeDescription (com.icthh.xm.commons.permission.annotation.PrivilegeDescription)1 AttachmentSpec (com.icthh.xm.ms.entity.domain.spec.AttachmentSpec)1 CalendarSpec (com.icthh.xm.ms.entity.domain.spec.CalendarSpec)1 LocationSpec (com.icthh.xm.ms.entity.domain.spec.LocationSpec)1 RatingSpec (com.icthh.xm.ms.entity.domain.spec.RatingSpec)1 StateSpec (com.icthh.xm.ms.entity.domain.spec.StateSpec)1 TagSpec (com.icthh.xm.ms.entity.domain.spec.TagSpec)1 TypeSpec (com.icthh.xm.ms.entity.domain.spec.TypeSpec)1 LinkProjection (com.icthh.xm.ms.entity.projection.LinkProjection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Transactional (org.springframework.transaction.annotation.Transactional)1