Update /internal/connector/sharepoint/collection.go
Logic for serialization of models.Pages completed.
This commit is contained in:
parent
1b4d3c2b08
commit
d2c5ad45bf
@ -7,9 +7,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
||||||
|
|
||||||
kw "github.com/microsoft/kiota-serialization-json-go"
|
kw "github.com/microsoft/kiota-serialization-json-go"
|
||||||
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
@ -207,10 +206,7 @@ func (sc *Collection) retrieveLists(
|
|||||||
|
|
||||||
lists, err := loadSiteLists(ctx, sc.service, sc.fullPath.ResourceOwner(), sc.jobs)
|
lists, err := loadSiteLists(ctx, sc.service, sc.fullPath.ResourceOwner(), sc.jobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = support.WrapAndAppend(sc.fullPath.ResourceOwner(), err, errs)
|
return metrics, errors.Wrap(err, sc.fullPath.ResourceOwner())
|
||||||
if sc.ctrl.FailFast {
|
|
||||||
return metrics, errs
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics.attempts += len(lists)
|
metrics.attempts += len(lists)
|
||||||
@ -220,6 +216,10 @@ func (sc *Collection) retrieveLists(
|
|||||||
byteArray, err := serializeContent(wtr, lst)
|
byteArray, err := serializeContent(wtr, lst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = support.WrapAndAppend(*lst.GetId(), err, errs)
|
errs = support.WrapAndAppend(*lst.GetId(), err, errs)
|
||||||
|
if sc.ctrl.FailFast {
|
||||||
|
return metrics, errs
|
||||||
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,32 +253,61 @@ func (sc *Collection) retrievePages(
|
|||||||
wtr *kw.JsonSerializationWriter,
|
wtr *kw.JsonSerializationWriter,
|
||||||
progress chan<- struct{},
|
progress chan<- struct{},
|
||||||
) (numMetrics, error) {
|
) (numMetrics, error) {
|
||||||
|
var (
|
||||||
|
errs error
|
||||||
|
metrics numMetrics
|
||||||
|
)
|
||||||
|
|
||||||
|
pages, err := GetSitePages(ctx, sc.service, sc.fullPath.ResourceOwner(), sc.jobs)
|
||||||
|
if err != nil {
|
||||||
|
return metrics, errors.Wrap(err, sc.fullPath.ResourceOwner())
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics.attempts = len(pages)
|
||||||
|
// For each models.Pageable, object is serialize and the metrics are collected and returned.
|
||||||
|
// Pageable objects are not supported in v1.0 of msgraph at this time.
|
||||||
|
// TODO: Verify Parsable interface supported with modified-Pageable
|
||||||
|
for _, pg := range pages {
|
||||||
|
byteArray, err := serializeContent(wtr, pg)
|
||||||
|
if err != nil {
|
||||||
|
errs = support.WrapAndAppend(*pg.GetId(), err, errs)
|
||||||
|
if sc.ctrl.FailFast {
|
||||||
|
return metrics, errs
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayLength := int64(len(byteArray))
|
||||||
|
|
||||||
|
if arrayLength > 0 {
|
||||||
|
t := time.Now()
|
||||||
|
if t1 := pg.GetLastModifiedDateTime(); t1 != nil {
|
||||||
|
t = *t1
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics.totalBytes += arrayLength
|
||||||
|
metrics.success++
|
||||||
|
sc.data <- &Item{
|
||||||
|
id: *pg.GetId(),
|
||||||
|
data: io.NopCloser(bytes.NewReader(byteArray)),
|
||||||
|
info: sharePointPageInfo(pg, arrayLength),
|
||||||
|
modTime: t,
|
||||||
|
}
|
||||||
|
|
||||||
|
progress <- struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return numMetrics{}, nil
|
return numMetrics{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func serializeListContent(writer *kw.JsonSerializationWriter, lst models.Listable) ([]byte, error) {
|
|
||||||
defer writer.Close()
|
|
||||||
|
|
||||||
err := writer.WriteObjectValue("", lst)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
byteArray, err := writer.GetSerializedContent()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return byteArray, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func serializeContent(writer *kw.JsonSerializationWriter, obj absser.Parsable) ([]byte, error) {
|
func serializeContent(writer *kw.JsonSerializationWriter, obj absser.Parsable) ([]byte, error) {
|
||||||
defer writer.Close()
|
defer writer.Close()
|
||||||
|
|
||||||
err := writer.WriteObjectValue("", obj)
|
err := writer.WriteObjectValue("", obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byteArray, err := writer.GetSerializedContent()
|
byteArray, err := writer.GetSerializedContent()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user