Search in sources :

Example 1 with EntityRef

use of nl.knaw.huygens.timbuctoo.search.EntityRef in project timbuctoo by HuygensING.

the class SearchResponseV2_1RefAdderTest method addsASearchResponseRefToTheSearchResult.

@Test
public void addsASearchResponseRefToTheSearchResult() {
    SearchResponseV2_1RefAdder instance = new SearchResponseV2_1RefAdder();
    SearchResponseV2_1 searchResponse = new SearchResponseV2_1();
    EntityRef entityRef = new EntityRef("type", "id");
    entityRef.setDisplayName("displayName");
    instance.addRef(searchResponse, entityRef);
    assertThat(searchResponse.getRefs(), Matchers.contains(SearchResponseV2_1RefMatcher.likeSearchResponseRef().withId("id").withType("type").withDisplayName("displayName").withPath("domain/types/id")));
}
Also used : EntityRef(nl.knaw.huygens.timbuctoo.search.EntityRef) Test(org.junit.Test)

Example 2 with EntityRef

use of nl.knaw.huygens.timbuctoo.search.EntityRef in project timbuctoo by HuygensING.

the class AbstractSearchDescription method createRef.

public EntityRef createRef(Vertex vertex) {
    String id = getIdDescriptor().get(vertex);
    EntityRef ref = new EntityRef(getType(), id);
    String displayName = getDisplayNameDescriptor().get(vertex);
    ref.setDisplayName(displayName);
    Map<String, Object> data = Maps.newHashMap();
    getDataPropertyDescriptors().entrySet().forEach(entry -> data.put(entry.getKey(), entry.getValue().get(vertex)));
    ref.setData(data);
    return ref;
}
Also used : EntityRef(nl.knaw.huygens.timbuctoo.search.EntityRef)

Example 3 with EntityRef

use of nl.knaw.huygens.timbuctoo.search.EntityRef in project timbuctoo by HuygensING.

the class CnwPersonSearchDescription method createRef.

@Override
public EntityRef createRef(Vertex vertex) {
    final ObjectMapper objectMapper = new ObjectMapper();
    EntityRef entityRef = super.createRef(vertex);
    Map<String, Object> data = entityRef.getData();
    try {
        final TypeReference<List<String>> listTypeReference = new TypeReference<List<String>>() {
        };
        data.put("networkDomains", objectMapper.readValue((String) vertex.value("cnwperson_networkDomains"), listTypeReference));
        data.put("characteristics", objectMapper.readValue((String) vertex.value("cnwperson_characteristics"), listTypeReference));
        data.put("combinedDomains", objectMapper.readValue((String) vertex.value("cnwperson_combinedDomains"), listTypeReference));
        data.put("memberships", objectMapper.readValue((String) vertex.value("cnwperson_memberships"), listTypeReference));
        data.put("periodicals", objectMapper.readValue((String) vertex.value("cnwperson_periodicals"), listTypeReference));
    } catch (IOException e) {
        LOG.error("Cannot read value for cnwperson with tim_id: {}", vertex.value("tim_id"), e);
    }
    entityRef.setData(data);
    return entityRef;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) EntityRef(nl.knaw.huygens.timbuctoo.search.EntityRef) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with EntityRef

use of nl.knaw.huygens.timbuctoo.search.EntityRef in project timbuctoo by HuygensING.

the class ReceptionSearchDescription method createRef.

@Override
public EntityRef createRef(Vertex vertex) {
    Edge inEdge = vertex.edges(Direction.IN, getRelationNames()).next();
    Vertex otherVertex = inEdge.outVertex();
    EntityRef targetRef = super.createRef(vertex);
    EntityRef sourceRef = otherSearch.getSearchDescription().createRef(otherVertex);
    EntityRef ref = new EntityRef("wwrelation", (String) inEdge.property("tim_id").value());
    ref.setRelationName(inEdge.label());
    ref.setTargetData(targetRef.getData());
    ref.setTargetName(targetRef.getDisplayName());
    ref.setSourceData(sourceRef.getData());
    ref.setSourceName(sourceRef.getDisplayName());
    return ref;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) EntityRef(nl.knaw.huygens.timbuctoo.search.EntityRef)

Example 5 with EntityRef

use of nl.knaw.huygens.timbuctoo.search.EntityRef in project timbuctoo by HuygensING.

the class SearchResponseV2_1RefAdderTest method addsTheDataOfTheEntityRefToTheSearchResponseV2_1Ref.

@Test
public void addsTheDataOfTheEntityRefToTheSearchResponseV2_1Ref() {
    SearchResponseV2_1RefAdder instance = new SearchResponseV2_1RefAdder();
    SearchResponseV2_1 searchResponse = new SearchResponseV2_1();
    EntityRef entityRef = new EntityRef("type", "id");
    HashMap<String, Object> data = Maps.newHashMap();
    entityRef.setData(data);
    instance.addRef(searchResponse, entityRef);
    assertThat(searchResponse.getRefs(), Matchers.contains(SearchResponseV2_1RefMatcher.likeSearchResponseRef().withData(data)));
}
Also used : EntityRef(nl.knaw.huygens.timbuctoo.search.EntityRef) Test(org.junit.Test)

Aggregations

EntityRef (nl.knaw.huygens.timbuctoo.search.EntityRef)5 Test (org.junit.Test)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1