// QueryReferences returns the list of references of the given type according to the given query.
QueryReferences returns the list of references of the given type according to the given query.
// QueryReferences returns the list of references of the given type according to the given query .
func (s *Provider) QueryReferences(referenceType spi.ReferenceType, query *spi.Criteria,
	opts ...spi.QueryOpt) (spi.ReferenceIterator, error) {
	logger.Debugf("[%s] Querying references of type %s - Query: %+v", s.serviceName, referenceType, query)
	if query.ObjectIRI == nil {
		return nil, fmt.Errorf("object IRI is required")
	}
	options := storeutil.GetQueryOptions(opts...)
	if query.ReferenceIRI == nil {
		queryExpression, err := s.generateQueryExpression(referenceType, query)
		if err != nil {
			return nil, err
		}
		iterator, errQuery := s.referenceStore.Query(
			queryExpression,
			ariesstorage.WithSortOrder(&ariesstorage.SortOptions{
				Order:   ariesstorage.SortOrder(options.SortOrder),
				TagName: timeAddedTagName,
			}),
			ariesstorage.WithPageSize(options.PageSize),
			ariesstorage.WithInitialPageNum(options.PageNumber),
		)
		if errQuery != nil {
			return nil, orberrors.NewTransient(fmt.Errorf("failed to query store: %w", errQuery))
		}
		return &referenceIterator{ariesIterator: iterator}, nil
	}
	retrievedURLBytes, err := s.referenceStore.Get(getRefKey(referenceType, query.ObjectIRI, query.ReferenceIRI))
	if err != nil {
		if errors.Is(err, ariesstorage.ErrDataNotFound) {
			return memstore.NewReferenceIterator(nil, 0), nil
		}
		return nil, orberrors.NewTransient(fmt.Errorf("unexpected failure while getting reference: %w", err))
	}
	var urlStr string
	err = json.Unmarshal(retrievedURLBytes, &urlStr)
	if err != nil {
		return nil, fmt.Errorf("unmarshal URL: %w", err)
	}
	retrievedURL, err := url.Parse(urlStr)
	if err != nil {
		return nil, fmt.Errorf("failed to parse URL from storage: %w", err)
	}
	return memstore.NewReferenceIterator([]*url.URL{retrievedURL}, 1), nil
}
func ( s * Provider ) QueryReferences ( referenceType spi . ReferenceType , query * spi . Criteria , opts ... spi . QueryOpt ) ( spi . ReferenceIterator , error ) { logger . Debugf ( " " , s . serviceName , referenceType , query ) if query . ObjectIRI == nil { return nil , fmt . Errorf ( " " ) } options := storeutil . GetQueryOptions ( opts ... ) if query . ReferenceIRI == nil { queryExpression , err := s . generateQueryExpression ( referenceType , query ) if err != nil { return nil , err } iterator , errQuery := s . referenceStore . Query ( queryExpression , ariesstorage . WithSortOrder ( & ariesstorage . SortOptions { Order : ariesstorage . SortOrder ( options . SortOrder ) , TagName : timeAddedTagName , } ) , ariesstorage . WithPageSize ( options . PageSize ) , ariesstorage . WithInitialPageNum ( options . PageNumber ) , ) if errQuery != nil { return nil , orberrors . NewTransient ( fmt . Errorf ( " " , errQuery ) ) } return & referenceIterator { ariesIterator : iterator } , nil } retrievedURLBytes , err := s . referenceStore . Get ( getRefKey ( referenceType , query . ObjectIRI , query . ReferenceIRI ) ) if err != nil { if errors . Is ( err , ariesstorage . ErrDataNotFound ) { return memstore . NewReferenceIterator ( nil , 0 ) , nil } return nil , orberrors . NewTransient ( fmt . Errorf ( " " , err ) ) } var urlStr string err = json . Unmarshal ( retrievedURLBytes , & urlStr ) if err != nil { return nil , fmt . Errorf ( " " , err ) } retrievedURL , err := url . Parse ( urlStr ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return memstore . NewReferenceIterator ( [ ] * url . URL { retrievedURL } , 1 ) , nil }
QueryReferences returns the list of references of the given type according to the given query.
QueryReferences returns the list of references of the given type according to the given query .
// If no reference IRI is set, then grab all references associated with the object IRI. // Otherwise, if there is a reference IRI, // then we should only grab the reference associated with the object IRI and reference IRI.