コード例 #1
0
ファイル: neo.go プロジェクト: buddhamagnet/gref_backends
// SourceInfo retrieves the source object including the canonical identifier.
func (n *NeoBackend) SourceInfo(mapping *models.Mapping) (string, int, error) {

	q := fmt.Sprintf(`match (o:%s)-[r:KNOWS {id:'%s'}]->(s:source {name:'%s'}) return o.canonical`, mapping.ObjectType, mapping.SourceID, mapping.Source)
	vals, err := graphExec([]string{q})
	if err != nil {
		return "", http.StatusInternalServerError, err
	}
	if len(vals) == 0 {
		return "resource not found", http.StatusNotFound, errors.New("resource not found")
	}
	v := vals[0]["o.canonical"]
	mapping.Canonical = v
	mapping.Object += "/" + v

	return mapping.Canonical, http.StatusOK, nil
}