예제 #1
0
func NewRepository(givenName string, repoConfig *config.RepositoryConfig, fullConfig *config.SerializedConfig) (*Repository, error) {
	r := &Repository{
		EventSet:         make(map[string]*transformation.Transformation),
		GivenName:        givenName,
		RepositoryConfig: *repoConfig,
	}

	// Create repository specific transformations.
	context := struct{ Repository transformation.RepositoryInfo }{Repository: r}
	transformations, err := transformation.TransformationsFromConfig(context, fullConfig.Transformations)
	if err != nil {
		return nil, err
	}
	r.Transformations = transformations

	// Extract the specified event set for this repository.
	evtSetName := repoConfig.EventSetName()
	evtSet, ok := fullConfig.EventSet[evtSetName]
	if !ok {
		return nil, fmt.Errorf("invalid event set %q for repository %q", evtSetName, givenName)
	}

	// Map the transformation to each of the configured events.
	for event, transfoName := range evtSet {
		r.EventSet[event] = r.Transformations[transfoName]
	}
	return r, nil
}
예제 #2
0
func NewRepository(givenName string, repoConfig *config.RepositoryConfig, fullConfig *config.SerializedConfig) (*Repository, error) {
	r := &Repository{
		EventSet:         make(map[string]transformation.Transformation),
		GivenName:        givenName,
		RepositoryConfig: *repoConfig,
	}

	// Initialize repository specific transformations.
	transfo := transformation.NewTransformations()
	initializeTemplateFunc(r, transfo, fullConfig)

	// Load transformations definitions from config.
	if err := transfo.Load(fullConfig.Transformations); err != nil {
		return nil, err
	}
	r.Transformations = transfo

	// Extract the specified event set for this repository.
	evtSetName := repoConfig.EventSetName()
	evtSet, ok := fullConfig.EventSet[evtSetName]
	if !ok {
		return nil, fmt.Errorf("invalid event set %q for repository %q", evtSetName, givenName)
	}

	// Map the transformation to each of the configured events.
	for event, transfoName := range evtSet {
		r.EventSet[event] = r.Transformations.Get(transfoName)
	}
	return r, nil
}