protected FL_Link buildResultFromDocument(SolrDocument sd) { FL_Link.Builder linkBuilder = FL_Link.newBuilder(); FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors(); FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors(); final String type = getTypeFromDocument(sd, linkDescriptors); Boolean isMultitype = (entityDescriptors.getTypes().size() > 1); String uid = sd.getFieldValue( PropertyDescriptorHelper.mapKey( FL_RequiredPropertyKey.ID.name(), linkDescriptors.getProperties(), type)) .toString(); Object oSource = sd.getFieldValue( PropertyDescriptorHelper.mapKey( FL_RequiredPropertyKey.FROM.name(), linkDescriptors.getProperties(), type)); String sSource = oSource instanceof String ? (String) oSource : oSource instanceof Integer ? Integer.toString((Integer) oSource) : null; linkBuilder.setProvenance(null); linkBuilder.setUncertainty(null); linkBuilder.setType(type); List<FL_Property> props = getPropertiesFromDocument(sd, type, linkDescriptors.getProperties()); linkBuilder.setProperties(props); linkBuilder.setLinkTypes(null); linkBuilder.setUid(_namespaceHandler.globalFromLocalEntityId(InfluentId.LINK, type, uid)); String sourceUID = null; if (sSource != null) { InfluentId infId; if (isMultitype) { infId = InfluentId.fromTypedId(InfluentId.ACCOUNT, sSource); } else { infId = InfluentId.fromNativeId( InfluentId.ACCOUNT, entityDescriptors.getTypes().get(0).getKey(), sSource); } sourceUID = infId.toString(); } linkBuilder.setSource(sourceUID); linkBuilder.setTarget(getTarget(sd)); return linkBuilder.build(); }
private String getTarget(SolrDocument sd) { FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors(); FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors(); final String type = getTypeFromDocument(sd, linkDescriptors); Object oTarget = sd.getFieldValue( PropertyDescriptorHelper.mapKey( FL_RequiredPropertyKey.TO.name(), linkDescriptors.getProperties(), type)); String sTarget = oTarget instanceof String ? (String) oTarget : oTarget instanceof Integer ? Integer.toString((Integer) oTarget) : null; Boolean isMultitype = (entityDescriptors.getTypes().size() > 1); String targetUID = ""; for (String individualTarget : sTarget.split("\\s*,\\s*")) { String individualTargetUID = null; if (individualTarget != null) { char toClass = InfluentId.ACCOUNT; String toType; if (isMultitype) { InfluentId infId = InfluentId.fromTypedId(toClass, individualTarget); toType = infId.getIdType(); individualTarget = infId.getNativeId(); } else { toType = entityDescriptors.getTypes().get(0).getKey(); } individualTargetUID = _namespaceHandler.globalFromLocalEntityId(toClass, toType, individualTarget); } if (individualTargetUID != null) { targetUID += individualTargetUID + ","; } } targetUID = targetUID.substring(0, targetUID.length() - 1); return targetUID; }