github.com/cs3org/reva/v2@v2.27.7/pkg/mentix/exchangers/importers/importers.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package importers 20 21 import ( 22 "github.com/rs/zerolog" 23 24 "github.com/cs3org/reva/v2/pkg/mentix/config" 25 "github.com/cs3org/reva/v2/pkg/mentix/entity" 26 "github.com/cs3org/reva/v2/pkg/mentix/exchangers" 27 ) 28 29 // Collection represents a collection of importers. 30 type Collection struct { 31 Importers []Importer 32 } 33 34 var ( 35 registeredImporters = entity.NewRegistry() 36 ) 37 38 // Entities returns a vector of entities within the collection. 39 func (collection *Collection) Entities() []entity.Entity { 40 return exchangers.AsEntityCollection(collection).Entities() 41 } 42 43 // Exchangers returns a vector of exchangers within the collection. 44 func (collection *Collection) Exchangers() []exchangers.Exchanger { 45 exchngrs := make([]exchangers.Exchanger, 0, len(collection.Importers)) 46 for _, connector := range collection.Importers { 47 exchngrs = append(exchngrs, connector) 48 } 49 return exchngrs 50 } 51 52 // ActivateAll activates all importers. 53 func (collection *Collection) ActivateAll(conf *config.Configuration, log *zerolog.Logger) error { 54 return entity.ActivateEntities(collection, conf, log) 55 } 56 57 // StartAll starts all importers. 58 func (collection *Collection) StartAll() error { 59 return exchangers.StartExchangers(collection) 60 } 61 62 // StopAll stops all importers. 63 func (collection *Collection) StopAll() { 64 exchangers.StopExchangers(collection) 65 } 66 67 // GetRequestImporters returns all importers that implement the RequestExchanger interface. 68 func (collection *Collection) GetRequestImporters() []exchangers.RequestExchanger { 69 return exchangers.GetRequestExchangers(collection) 70 } 71 72 // AvailableImporters returns a collection of all importers that are enabled in the configuration. 73 func AvailableImporters(conf *config.Configuration) (*Collection, error) { 74 // Try to add all importers configured in the environment 75 entities, err := registeredImporters.FindEntities(conf.EnabledImporters, true, false) 76 if err != nil { 77 return nil, err 78 } 79 80 importers := make([]Importer, 0, len(entities)) 81 for _, entry := range entities { 82 importers = append(importers, entry.(Importer)) 83 } 84 85 return &Collection{Importers: importers}, nil 86 } 87 88 // TODO: Uncomment once an importer is actually implemented 89 /* 90 func registerImporter(importer Importer) { 91 registeredImporters.Register(importer) 92 } 93 */