Extends DeDup capabilities
Support modifier for value search and allow ability to select matching criteria for multi value field - Removed name from rule for now - Value modifier to search with are ignore-case, case-sensitive, fuzzy-search, sounds-like - Multi value matching criteria are one-of, equal - Migrate RecordDeDup config for module, by adding upgrade fix for module.config.recordDeDup to migrate as per to the latest DeDupRule struct.
This commit is contained in:
@@ -571,6 +571,12 @@ func (svc record) Bulk(ctx context.Context, oo ...*types.RecordBulkOperation) (r
|
||||
// before we start storing any changes
|
||||
rves = &types.RecordValueErrorSet{}
|
||||
|
||||
// duplication errors
|
||||
ddes = &types.RecordValueErrorSet{}
|
||||
|
||||
// merge of record value errors and duplication errors
|
||||
ee = &types.RecordValueErrorSet{}
|
||||
|
||||
action func(props ...*recordActionProps) *recordAction
|
||||
r *types.Record
|
||||
|
||||
@@ -599,11 +605,11 @@ func (svc record) Bulk(ctx context.Context, oo ...*types.RecordBulkOperation) (r
|
||||
switch p.Operation {
|
||||
case types.OperationTypeCreate:
|
||||
action = RecordActionCreate
|
||||
r, dd, err = svc.create(ctx, r)
|
||||
r, ddes, err = svc.create(ctx, r)
|
||||
|
||||
case types.OperationTypeUpdate:
|
||||
action = RecordActionUpdate
|
||||
r, dd, err = svc.update(ctx, r)
|
||||
r, ddes, err = svc.update(ctx, r)
|
||||
|
||||
case types.OperationTypeDelete:
|
||||
action = RecordActionDelete
|
||||
@@ -613,8 +619,13 @@ func (svc record) Bulk(ctx context.Context, oo ...*types.RecordBulkOperation) (r
|
||||
aProp.setChanged(r)
|
||||
|
||||
// Attach meta ID to each value error for FE identification
|
||||
if !dd.HasStrictErrors() && r != nil {
|
||||
dd.SetMetaID(r.ID)
|
||||
if !ddes.HasStrictErrors() && r != nil {
|
||||
ddes.SetMetaID(r.ID)
|
||||
}
|
||||
if !ddes.IsValid() && dd == nil {
|
||||
dd = ddes
|
||||
} else {
|
||||
dd.Merge(ddes)
|
||||
}
|
||||
|
||||
if rve := types.IsRecordValueErrorSet(err); rve != nil {
|
||||
@@ -644,9 +655,14 @@ func (svc record) Bulk(ctx context.Context, oo ...*types.RecordBulkOperation) (r
|
||||
}
|
||||
}
|
||||
|
||||
if !rves.IsValid() {
|
||||
// merge record value errors and strict duplication errors
|
||||
if dd.HasStrictErrors() {
|
||||
ee.Merge(rves, dd)
|
||||
}
|
||||
|
||||
if !ee.IsValid() {
|
||||
// Any errors gathered?
|
||||
return RecordErrValueInput().Wrap(rves)
|
||||
return RecordErrValueInput().Wrap(ee)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -701,10 +717,19 @@ func (svc record) create(ctx context.Context, new *types.Record) (rec *types.Rec
|
||||
new.SetModule(m)
|
||||
|
||||
{
|
||||
// handle deDup error/warnings
|
||||
dd, err = svc.DupDetection(ctx, m, new)
|
||||
|
||||
// handle input payload errors
|
||||
if rve = svc.procCreate(ctx, invokerID, m, new); !rve.IsValid() {
|
||||
return nil, dd, RecordErrValueInput().Wrap(rve)
|
||||
}
|
||||
|
||||
// record value errors from dup detection
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = svc.eventbus.WaitFor(ctx, event.RecordBeforeCreate(new, nil, m, ns, rve, nil)); err != nil {
|
||||
return
|
||||
} else if !rve.IsValid() {
|
||||
@@ -714,11 +739,6 @@ func (svc record) create(ctx context.Context, new *types.Record) (rec *types.Rec
|
||||
|
||||
new.Values = RecordValueDefaults(m, new.Values)
|
||||
|
||||
dd, err = svc.DupDetection(ctx, m, new)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Handle payload from automation scripts
|
||||
if rve = svc.procCreate(ctx, invokerID, m, new); !rve.IsValid() {
|
||||
return nil, dd, RecordErrValueInput().Wrap(rve)
|
||||
@@ -996,17 +1016,20 @@ func (svc record) update(ctx context.Context, upd *types.Record) (rec *types.Rec
|
||||
upd.SetModule(m)
|
||||
old.SetModule(m)
|
||||
|
||||
dd, err = svc.DupDetection(ctx, m, upd)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
// Handle input payload
|
||||
// handle deDup error/warnings
|
||||
dd, err = svc.DupDetection(ctx, m, upd)
|
||||
|
||||
// handle input payload errors
|
||||
if rve = svc.procUpdate(ctx, invokerID, m, upd, old); !rve.IsValid() {
|
||||
return nil, dd, RecordErrValueInput().Wrap(rve)
|
||||
}
|
||||
|
||||
// record value errors from dup detection
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Scripts can (besides simple error value) return complex record value error set
|
||||
// that is passed back to the UI or any other API consumer
|
||||
//
|
||||
@@ -1833,7 +1856,6 @@ func (svc record) DupDetection(ctx context.Context, m *types.Module, rec *types.
|
||||
return
|
||||
}
|
||||
|
||||
// @todo: improve error string with details
|
||||
rProps.setValueErrors(out)
|
||||
|
||||
// Error out if duplicate record exist
|
||||
@@ -2036,7 +2058,7 @@ fields:
|
||||
val.Value = pickRandomID(recRefs[refModID])
|
||||
|
||||
case "select":
|
||||
//val.Value = src.Select(f.Options)
|
||||
// val.Value = src.Select(f.Options)
|
||||
continue fields
|
||||
|
||||
case "url":
|
||||
|
||||
Reference in New Issue
Block a user