github.com/cs3org/reva/v2@v2.27.7/pkg/mentix/entity/entities.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 entity
    20  
    21  import (
    22  	"fmt"
    23  
    24  	"github.com/cs3org/reva/v2/pkg/mentix/config"
    25  
    26  	"github.com/rs/zerolog"
    27  )
    28  
    29  // Collection is an interface for entity collections.
    30  type Collection interface {
    31  	// Entities returns a vector of entities within the collection.
    32  	Entities() []Entity
    33  }
    34  
    35  // ActivateEntities activates the given entities.
    36  func ActivateEntities(collection Collection, conf *config.Configuration, log *zerolog.Logger) error {
    37  	for _, exchanger := range collection.Entities() {
    38  		if err := exchanger.Activate(conf, log); err != nil {
    39  			return fmt.Errorf("unable to activate entity '%v': %v", exchanger.GetName(), err)
    40  		}
    41  	}
    42  
    43  	return nil
    44  }
    45  
    46  // GetIDs gets a list of entity IDs.
    47  func GetIDs(collection Collection) []string {
    48  	entities := collection.Entities()
    49  	ids := make([]string, 0, len(entities))
    50  	for _, entity := range entities {
    51  		ids = append(ids, entity.GetID())
    52  	}
    53  	return ids
    54  }
    55  
    56  // GetNames gets a list of entity names.
    57  func GetNames(collection Collection) []string {
    58  	entities := collection.Entities()
    59  	names := make([]string, 0, len(entities))
    60  	for _, entity := range entities {
    61  		names = append(names, entity.GetName())
    62  	}
    63  	return names
    64  }