From 676e04bdc898e0819499a44600454c6d96c1f988 Mon Sep 17 00:00:00 2001 From: Ryan Stonebraker Date: Mon, 25 Sep 2023 16:24:28 -0700 Subject: [PATCH] Adds option to delete mist rois with regular roi deletion --- .gitignore | 2 +- api/ws/handlers/roi.go | 47 ++++++++++++++++++++++++-- data-formats | 2 +- generated-protos/roi-msgs.pb.go | 60 ++++++++++++++++++++++----------- 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index e8e79bfa..b38ab4c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -__debug_bin +__debug_bin* __debug_bin.exe .idea/ diff --git a/api/ws/handlers/roi.go b/api/ws/handlers/roi.go index 921062a2..98b71fce 100644 --- a/api/ws/handlers/roi.go +++ b/api/ws/handlers/roi.go @@ -45,6 +45,14 @@ func HandleRegionOfInterestGetReq(req *protos.RegionOfInterestGetReq, hctx wsHel } func HandleRegionOfInterestDeleteReq(req *protos.RegionOfInterestDeleteReq, hctx wsHelpers.HandlerContext) (*protos.RegionOfInterestDeleteResp, error) { + if req.IsMIST { + // Delete from MIST table + _, err := hctx.Svcs.MongoDB.Collection(dbCollections.MistROIsName).DeleteOne(context.TODO(), bson.D{{"_id", req.Id}}) + if err != nil { + return nil, err + } + } + return wsHelpers.DeleteUserObject[protos.RegionOfInterestDeleteResp](req.Id, protos.ObjectType_OT_ROI, dbCollections.RegionsOfInterestName, hctx) } @@ -358,8 +366,9 @@ func HandleRegionOfInterestBulkWriteReq(req *protos.RegionOfInterestBulkWriteReq } } - writtenROIs := []*protos.ROIItem{} + needMistEntry := false + writtenROIs := []*protos.ROIItem{} for _, item := range req.RegionsOfInterest { item.Owner = nil item.IsMIST = req.IsMIST @@ -371,15 +380,49 @@ func HandleRegionOfInterestBulkWriteReq(req *protos.RegionOfInterestBulkWriteReq if err != nil { return nil, err } + } else if req.SkipDuplicates { + // If id is not empty, but we're not overwriting, so skip this ROI + // If id is empty and this is a MIST ROI, we need to check if this ROI already exists + if req.IsMIST && len(item.MistROIItem.ClassificationTrail) > 0 { + // Skip ROIs with same classification trail for the same scan + filter := bson.M{"scanid": item.ScanId, "classificationtrail": item.MistROIItem.ClassificationTrail} + opts := options.Find().SetProjection(bson.M{"_id": true}) + cursor, err := hctx.Svcs.MongoDB.Collection(dbCollections.MistROIsName).Find(context.Background(), filter, opts) + if err != nil { + return nil, err + } + + ids := []*IdOnly{} + err = cursor.All(context.Background(), &ids) + if err != nil { + return nil, err + } + + // If we found an ROI with the same classification trail, then don't create a new one + if len(ids) > 0 { + continue + } else { + // Create new ROI + item, err = createROI(item, hctx) + if err != nil { + return nil, err + } + + needMistEntry = true + } + } + } else { // Create new ROI item, err = createROI(item, hctx) if err != nil { return nil, err } + + needMistEntry = req.IsMIST } - if req.IsMIST { + if needMistEntry { mistROIItem := &protos.MistROIItem{ Id: item.Id, ScanId: item.ScanId, diff --git a/data-formats b/data-formats index ed33d6b1..d8ae00d7 160000 --- a/data-formats +++ b/data-formats @@ -1 +1 @@ -Subproject commit ed33d6b1b408d276aea5cb24e890eddeafe65140 +Subproject commit d8ae00d7bbfc33ccd9744f49b9a4e8cdde3a45cf diff --git a/generated-protos/roi-msgs.pb.go b/generated-protos/roi-msgs.pb.go index 626dd9c5..8d1f8c98 100644 --- a/generated-protos/roi-msgs.pb.go +++ b/generated-protos/roi-msgs.pb.go @@ -345,9 +345,10 @@ type RegionOfInterestBulkWriteReq struct { unknownFields protoimpl.UnknownFields RegionsOfInterest []*ROIItem `protobuf:"bytes,1,rep,name=regionsOfInterest,proto3" json:"regionsOfInterest,omitempty"` - Overwrite bool `protobuf:"varint,5,opt,name=overwrite,proto3" json:"overwrite,omitempty"` // if true, then overwrite existing ROIs with same ID - IsMIST bool `protobuf:"varint,2,opt,name=isMIST,proto3" json:"isMIST,omitempty"` - MistROIScanIdsToDelete []string `protobuf:"bytes,3,rep,name=mistROIScanIdsToDelete,proto3" json:"mistROIScanIdsToDelete,omitempty"` // List of scan ids to delete all MIST ROIs for + Overwrite bool `protobuf:"varint,2,opt,name=overwrite,proto3" json:"overwrite,omitempty"` // if true, then overwrite existing ROIs with same ID + SkipDuplicates bool `protobuf:"varint,3,opt,name=skipDuplicates,proto3" json:"skipDuplicates,omitempty"` // if true, then skip ROIs with same ID + IsMIST bool `protobuf:"varint,4,opt,name=isMIST,proto3" json:"isMIST,omitempty"` + MistROIScanIdsToDelete []string `protobuf:"bytes,5,rep,name=mistROIScanIdsToDelete,proto3" json:"mistROIScanIdsToDelete,omitempty"` // List of scan ids to delete all MIST ROIs for } func (x *RegionOfInterestBulkWriteReq) Reset() { @@ -396,6 +397,13 @@ func (x *RegionOfInterestBulkWriteReq) GetOverwrite() bool { return false } +func (x *RegionOfInterestBulkWriteReq) GetSkipDuplicates() bool { + if x != nil { + return x.SkipDuplicates + } + return false +} + func (x *RegionOfInterestBulkWriteReq) GetIsMIST() bool { if x != nil { return x.IsMIST @@ -463,7 +471,8 @@ type RegionOfInterestDeleteReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + IsMIST bool `protobuf:"varint,2,opt,name=isMIST,proto3" json:"isMIST,omitempty"` } func (x *RegionOfInterestDeleteReq) Reset() { @@ -505,6 +514,13 @@ func (x *RegionOfInterestDeleteReq) GetId() string { return "" } +func (x *RegionOfInterestDeleteReq) GetIsMIST() bool { + if x != nil { + return x.IsMIST + } + return false +} + type RegionOfInterestDeleteResp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -591,27 +607,31 @@ var file_roi_msgs_proto_rawDesc = []byte{ 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x52, 0x4f, 0x49, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x10, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, - 0x73, 0x74, 0x22, 0xc4, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, + 0x73, 0x74, 0x22, 0xec, 0x01, 0x0a, 0x1c, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x42, 0x75, 0x6c, 0x6b, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x36, 0x0a, 0x11, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x52, 0x4f, 0x49, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x11, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6f, - 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, - 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x4d, - 0x49, 0x53, 0x54, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x4d, 0x49, 0x53, - 0x54, 0x12, 0x36, 0x0a, 0x16, 0x6d, 0x69, 0x73, 0x74, 0x52, 0x4f, 0x49, 0x53, 0x63, 0x61, 0x6e, - 0x49, 0x64, 0x73, 0x54, 0x6f, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x16, 0x6d, 0x69, 0x73, 0x74, 0x52, 0x4f, 0x49, 0x53, 0x63, 0x61, 0x6e, 0x49, 0x64, - 0x73, 0x54, 0x6f, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x22, 0x57, 0x0a, 0x1d, 0x52, 0x65, 0x67, - 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x42, 0x75, 0x6c, - 0x6b, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x36, 0x0a, 0x11, 0x72, 0x65, - 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x52, 0x4f, 0x49, 0x49, 0x74, 0x65, 0x6d, 0x52, - 0x11, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, - 0x73, 0x74, 0x22, 0x2b, 0x0a, 0x19, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, - 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, + 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, + 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x6b, 0x69, + 0x70, 0x44, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x0e, 0x73, 0x6b, 0x69, 0x70, 0x44, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x65, + 0x73, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x4d, 0x49, 0x53, 0x54, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x06, 0x69, 0x73, 0x4d, 0x49, 0x53, 0x54, 0x12, 0x36, 0x0a, 0x16, 0x6d, 0x69, 0x73, + 0x74, 0x52, 0x4f, 0x49, 0x53, 0x63, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x54, 0x6f, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x16, 0x6d, 0x69, 0x73, 0x74, 0x52, + 0x4f, 0x49, 0x53, 0x63, 0x61, 0x6e, 0x49, 0x64, 0x73, 0x54, 0x6f, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x22, 0x57, 0x0a, 0x1d, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, + 0x65, 0x72, 0x65, 0x73, 0x74, 0x42, 0x75, 0x6c, 0x6b, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x36, 0x0a, 0x11, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x4f, 0x66, 0x49, + 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, + 0x52, 0x4f, 0x49, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x11, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, + 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x22, 0x43, 0x0a, 0x19, 0x52, 0x65, + 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x4d, 0x49, 0x53, + 0x54, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x4d, 0x49, 0x53, 0x54, 0x22, 0x1c, 0x0a, 0x1a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x4f, 0x66, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,