Search in sources :

Example 1 with SolrFieldExtractor

use of com.odysseusinc.arachne.portal.api.v1.dto.converters.SolrFieldExtractor in project ArachneCentralAPI by OHDSI.

the class BaseSolrServiceImpl method getValuesByEntity.

@Override
public Map<T, Object> getValuesByEntity(final SolrEntity entity) {
    final Map<T, Object> values = new HashMap<>();
    final FieldList<T> fieldList = getFieldsOfClass(entity.getClass());
    for (final T solrField : fieldList) {
        final Object fieldValue;
        final Field field = solrField.getField();
        final SolrFieldExtractor extractor = solrField.getExtractor();
        if (extractor != null) {
            fieldValue = extractor.extract(entity);
        } else if (field != null) {
            field.setAccessible(true);
            fieldValue = getFieldValue(entity, field);
        } else {
            throw new NullPointerException("FieldValue cannot be null");
        }
        values.put(solrField, fieldValue);
    }
    if (entity.getId() != null) {
        final T idField = newSolrField(ID);
        idField.setDataType(Long.class);
        idField.setPostfixNeeded(false);
        values.put(idField, entity.getId());
    }
    addBreadcrumbsIfNeeded(entity, values);
    return values;
}
Also used : SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) SolrFieldExtractor(com.odysseusinc.arachne.portal.api.v1.dto.converters.SolrFieldExtractor)

Aggregations

SolrFieldExtractor (com.odysseusinc.arachne.portal.api.v1.dto.converters.SolrFieldExtractor)1 SolrField (com.odysseusinc.arachne.portal.service.impl.solr.SolrField)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1