func notifyProfileAssociates(dp models.DeviceProfile, dl device.DeviceLoader, action string) error {
	// Get the devices
	op := device.NewProfileIdExecutor(Configuration.Service, dl, LoggingClient, dp.Id)
	d, err := op.Execute()
	if err != nil {
		LoggingClient.Error(err.Error())
		return err
	}

	// Get the services for each device
	// Use map as a Set
	dsMap := map[string]models.DeviceService{}
	ds := []models.DeviceService{}
	for _, device := range d {
		// Only add if not there
		if _, ok := dsMap[device.Service.Id]; !ok {
			dsMap[device.Service.Id] = device.Service
			ds = append(ds, device.Service)
		}
	}

	if err := notifyAssociates(ds, dp.Id, action, models.PROFILE); err != nil {
		LoggingClient.Error(err.Error())
		return err
	}

	return nil
}
// Notify the associated device services for changes in the device profile
Notify the associated device services for changes in the device profile
// Notify the associated device services for changes in the device profile
func notifyProfileAssociates(dp models.DeviceProfile, dl device.DeviceLoader, action string) error {
	op := device.NewProfileIdExecutor(Configuration.Service, dl, LoggingClient, dp.Id)
	d, err := op.Execute()
	if err != nil {
		LoggingClient.Error(err.Error())
		return err
	}
	dsMap := map[string]models.DeviceService{}
	ds := []models.DeviceService{}
	for _, device := range d {
		if _, ok := dsMap[device.Service.Id]; !ok {
			dsMap[device.Service.Id] = device.Service
			ds = append(ds, device.Service)
		}
	}
	if err := notifyAssociates(ds, dp.Id, action, models.PROFILE); err != nil {
		LoggingClient.Error(err.Error())
		return err
	}
	return nil
}
func notifyProfileAssociates ( dp models . DeviceProfile , dl device . DeviceLoader , action string ) error { op := device . NewProfileIdExecutor ( Configuration . Service , dl , LoggingClient , dp . Id ) d , err := op . Execute ( ) if err != nil { LoggingClient . Error ( err . Error ( ) ) return err } dsMap := map [ string ] models . DeviceService { } ds := [ ] models . DeviceService { } for _ , device := range d { if _ , ok := dsMap [ device . Service . Id ] ; ! ok { dsMap [ device . Service . Id ] = device . Service ds = append ( ds , device . Service ) } } if err := notifyAssociates ( ds , dp . Id , action , models . PROFILE ) ; err != nil { LoggingClient . Error ( err . Error ( ) ) return err } return nil }
Notify the associated device services for changes in the device profile
Notify the associated device services for changes in the device profile
// Get the devices // Get the services for each device // Use map as a Set // Only add if not there