Peer Manipulation
This commit is contained in:
@@ -57,24 +57,6 @@ func (m PeerRelation) EnumIndex() int {
|
||||
return int(m)
|
||||
}
|
||||
|
||||
func GetSelf() (utils.ShallowDBObject, string) {
|
||||
d, code, err := NewAccessor(nil).Search(nil, SELF.String(), false)
|
||||
if code != 200 || err != nil || len(d) == 0 {
|
||||
return nil, ""
|
||||
}
|
||||
id := d[0].GetID()
|
||||
return d[0], id
|
||||
}
|
||||
|
||||
func IsMySelf(peerID string) (bool, string) {
|
||||
d, code, err := NewAccessor(nil).Search(nil, SELF.String(), false)
|
||||
if code != 200 || err != nil || len(d) == 0 {
|
||||
return false, ""
|
||||
}
|
||||
id := d[0].GetID()
|
||||
return peerID == id, id
|
||||
}
|
||||
|
||||
// Peer is a struct that represents a peer
|
||||
type Peer struct {
|
||||
utils.AbstractObject
|
||||
@@ -120,16 +102,6 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
|
||||
ao.FailedExecution = new
|
||||
}
|
||||
|
||||
// IsMySelf checks if the peer is the local peer
|
||||
func (p *Peer) IsMySelf() (bool, string) {
|
||||
d, code, err := NewAccessor(nil).Search(nil, SELF.String(), p.IsDraft)
|
||||
if code != 200 || err != nil || len(d) == 0 {
|
||||
return false, ""
|
||||
}
|
||||
id := d[0].GetID()
|
||||
return p.UUID == id, id
|
||||
}
|
||||
|
||||
// LaunchPeerExecution launches an execution on a peer
|
||||
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (map[string]interface{}, error) {
|
||||
p.UUID = peerID
|
||||
|
||||
@@ -80,10 +80,14 @@ func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string, isDraf
|
||||
}
|
||||
func (a *peerMongoAccessor) GetDefaultFilter(search string) *dbs.Filters {
|
||||
if i, err := strconv.Atoi(search); err == nil {
|
||||
m := map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||
"relation": {{Operator: dbs.EQUAL.String(), Value: i}},
|
||||
}
|
||||
if i == PARTNER.EnumIndex() {
|
||||
m["verify"] = []dbs.Filter{{Operator: dbs.EQUAL.String(), Value: false}}
|
||||
}
|
||||
return &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||
"relation": {{Operator: dbs.EQUAL.String(), Value: i}},
|
||||
},
|
||||
Or: m,
|
||||
}
|
||||
} else {
|
||||
if search == "*" {
|
||||
|
||||
Reference in New Issue
Block a user