Skip to content

Commit 26a9960

Browse files
authored
113 feature configue exclusion of building amenities (#114)
* Implement known features configuration * Updated changelog * update secrets baseline
1 parent 191d3b2 commit 26a9960

11 files changed

+148
-25
lines changed

.secrets.baseline

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"filename": "driven/uiucadapters/wayfindingadapter.go",
137137
"hashed_secret": "abd4b25cafb785cdf391edc04f82d8af45e1405c",
138138
"is_verified": false,
139-
"line_number": 41
139+
"line_number": 42
140140
}
141141
],
142142
"driver/web/adapter.go": [
@@ -172,5 +172,5 @@
172172
}
173173
]
174174
},
175-
"generated_at": "2024-06-26T14:32:05Z"
175+
"generated_at": "2024-11-04T17:23:04Z"
176176
}

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## UnReleased - 2024-11-04
8+
### Changed
9+
- Pull a list of all known building features from the database. Use this to filter out any that we do not want to display in the app on the building details panel as well as merge groups of some feature codes into a single feature.
10+
711
## [2.11.0] - 2024-09-24
812
### Changed
913
- Building feature list is now a compact list of feature names paired with floors they exist on to make is easier to use for display and floorplan linking in the app

core/apis_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func newAppClient(app *Application) appClient {
252252
client.ContactAdapter = uiucadapters.NewUIUCContactAdapter()
253253
client.LaundryAdapter = uiucadapters.NewCSCLaundryAdapter(laundryAssets)
254254
client.Courseadapter = uiucadapters.NewCourseAdapter()
255-
client.LocationAdapter = uiucadapters.NewUIUCWayFinding()
255+
client.LocationAdapter = uiucadapters.NewUIUCWayFinding(&app.AppBLdgFeatures)
256256
client.SuccessTeamAdapter = uiucadapters.NewSuccessTeamAdapter()
257257
return client
258258
}

core/apis_shared.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ func (a appShared) getExample(orgID string, appID string, id string) (*model.Exa
3232
func newAppShared(app *Application) appShared {
3333
return appShared{app: app}
3434
}
35+
36+
// getBuildingFeatures returns all building features
37+
func (a appShared) getBuildingFeatures() ([]model.AppBuildingFeature, error) {
38+
return a.app.storage.LoadAppBuildingFeatures()
39+
}

core/application.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ type Application struct {
4949
System System // expose to the drivers adapters
5050
shared Shared
5151

52-
CampusBuildings model.CachedBuildings //caches a list of all campus building data
52+
CampusBuildings model.CachedBuildings //caches a list of all campus building data
53+
AppBLdgFeatures map[string]model.AppBuildingFeature //caches the configured set of building features
5354

5455
AppointmentAdapters map[string]Appointments //expose to the different vendor specific appointment adapters
5556

@@ -113,6 +114,15 @@ func NewApplication(version string, build string,
113114
application.shared = newAppShared(&application)
114115
application.eventsLogic = newAppEventsLogic(&application, eventsBBAdapter, geoBBAdapter, *logger)
115116

117+
bldfeatures, blderr := application.shared.getBuildingFeatures()
118+
if blderr != nil {
119+
120+
}
121+
application.AppBLdgFeatures = make(map[string]model.AppBuildingFeature)
122+
for _, bf := range bldfeatures {
123+
application.AppBLdgFeatures[bf.CampusCode] = bf
124+
}
125+
116126
_, err := application.Client.GetBuildings()
117127
if err != nil {
118128
//set to one day ago to force a retry and refresh

core/interfaces.go

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type System interface {
9494
// Shared exposes shared APIs for other interface implementations
9595
type Shared interface {
9696
getExample(orgID string, appID string, id string) (*model.Example, error)
97+
getBuildingFeatures() ([]model.AppBuildingFeature, error)
9798
}
9899

99100
// EventsBBAdapter is used by core to communicate with the events BB
@@ -153,6 +154,8 @@ type Storage interface {
153154

154155
FindLegacyLocationItems() ([]model.LegacyLocation, error)
155156
InsertLegacyLocationItem(items model.LegacyLocation) error
157+
158+
LoadAppBuildingFeatures() ([]model.AppBuildingFeature, error)
156159
}
157160

158161
// StorageListener represents storage listener

core/model/appbuildingfeatures.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2022 Board of Trustees of the University of Illinois.
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+
package model
16+
17+
import (
18+
"github.com/rokwire/logging-library-go/v2/logutils"
19+
)
20+
21+
const (
22+
//TypeAppBuildingFeature type
23+
TypeAppBuildingFeature logutils.MessageDataType = "application building feature"
24+
)
25+
26+
// AppBuildingFeature represents the configured features for campus buildings
27+
type AppBuildingFeature struct {
28+
CampusName string `json:"campus_name" bson:"campus_name"`
29+
CampusCode string `json:"campus_code" bson:"campus_code"`
30+
AppName string `json:"app_name" bson:"app_name"`
31+
AppCode string `json:"app_code" bson:"app_code"`
32+
ShowInApp bool `json:"show_in_app" bson:"show_in_app"`
33+
}

core/model/uiuc/buildingdata.go

+37-13
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func NewFloorPlan(fp CampusFloorPlan) *model.FloorPlan {
143143

144144
// NewBuilding creates a wayfinding.Building instance from a campusBuilding,
145145
// including all active entrances for the building
146-
func NewBuilding(bldg CampusBuilding) *model.Building {
146+
func NewBuilding(bldg CampusBuilding, knownFeatures *map[string]model.AppBuildingFeature) *model.Building {
147147
newBldg := model.Building{ID: bldg.UUID, Name: bldg.Name, ImageURL: bldg.ImageURL, Address1: bldg.Address1, Address2: bldg.Address2,
148148
FullAddress: bldg.FullAddress, City: bldg.City, ZipCode: bldg.ZipCode, State: bldg.State, Latitude: bldg.Latitude, Longitude: bldg.Longitude, Number: bldg.Number}
149149
newBldg.Entrances = make([]model.Entrance, 0)
@@ -158,21 +158,27 @@ func NewBuilding(bldg CampusBuilding) *model.Building {
158158

159159
for _, n := range bldg.Features {
160160

161-
val, ok := featuredata[n.EQIndicator]
161+
//is this feature a known feature
162+
kf := *knownFeatures
163+
knownFeature, ok := kf[n.EQIndicator]
162164
if ok {
163-
if !slices.Contains(val.Floors, n.FoundOnFloor) {
164-
val.Floors = append(val.Floors, n.FoundOnFloor)
165-
featuredata[n.EQIndicator] = val
166-
}
165+
if knownFeature.ShowInApp {
166+
//does featuredata already contain an element with the current EQIndicator as a key
167+
newKey := knownFeature.AppCode
168+
newName := knownFeature.AppName
169+
addFeatureToList(newKey, newName, n.FoundOnFloor, &featuredata)
167170

171+
}
168172
} else {
169-
var floors = make([]string, 1)
170-
floors[0] = n.FoundOnFloor
171-
fme := model.FeatureMapEntry{Name: n.Name, Floors: floors}
172-
featuredata[n.EQIndicator] = fme
173+
//feature is not in the list of supported features, so add it.
174+
//treat non-existent as supported
175+
//does featuredata already contain an element with the current EQIndicator as a keuy
176+
addFeatureToList(n.EQIndicator, n.Name, n.FoundOnFloor, &featuredata)
177+
173178
}
174-
//newBldg.Features = append(newBldg.Features, *NewFeature(n))
179+
175180
}
181+
176182
for key, value := range featuredata {
177183
var feature = model.BuildingFeatureLocation{Key: key, Value: value}
178184
newBldg.Features = append(newBldg.Features, feature)
@@ -181,12 +187,30 @@ func NewBuilding(bldg CampusBuilding) *model.Building {
181187
return &newBldg
182188
}
183189

190+
func addFeatureToList(featureKey string, featureName string, foundOnFloor string, featuredata *map[string]model.FeatureMapEntry) {
191+
fd := *featuredata
192+
val, ok := fd[featureKey]
193+
if ok {
194+
//if so, does the value of that element (slice of strings) already contain the floor number
195+
//if not add it
196+
if !slices.Contains(val.Floors, foundOnFloor) {
197+
val.Floors = append(val.Floors, foundOnFloor)
198+
fd[featureKey] = val
199+
}
200+
} else { //feature data does not contain an element for this key
201+
var floors = make([]string, 1)
202+
floors[0] = foundOnFloor
203+
fme := model.FeatureMapEntry{Name: featureName, Floors: floors}
204+
fd[featureKey] = fme
205+
}
206+
}
207+
184208
// NewBuildingList returns a list of wayfinding buildings created frmo a list of campus building objects.
185-
func NewBuildingList(bldgList *[]CampusBuilding) *[]model.Building {
209+
func NewBuildingList(bldgList *[]CampusBuilding, knownBuildings *map[string]model.AppBuildingFeature) *[]model.Building {
186210
retList := make([]model.Building, len(*bldgList))
187211
for i := 0; i < len(*bldgList); i++ {
188212
cmpsBldg := (*bldgList)[i]
189-
crntBldng := NewBuilding(cmpsBldg)
213+
crntBldng := NewBuilding(cmpsBldg, knownBuildings)
190214
retList[i] = *crntBldng
191215
}
192216
return &retList
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2022 Board of Trustees of the University of Illinois.
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+
package storage
16+
17+
import (
18+
"application/core/model"
19+
"time"
20+
21+
"github.com/rokwire/logging-library-go/v2/errors"
22+
"github.com/rokwire/logging-library-go/v2/logutils"
23+
)
24+
25+
// LoadAppBuildingFeatures loads all of the configured building features
26+
func (a *Adapter) LoadAppBuildingFeatures() ([]model.AppBuildingFeature, error) {
27+
28+
var data []model.AppBuildingFeature
29+
//filter := bson.M{}
30+
timeout := 15 * time.Second //15 seconds timeout
31+
//err := a.db.legacyEvents.FindWithParams(context, filter, &data, nil, &timeout)
32+
err := a.db.appbuildingfeatures.FindWithParams(a.context, nil, &data, nil, &timeout)
33+
//err := a.db.appbuildingfeatures.FindWithContext(a.context, nil, &data, nil)
34+
if err != nil {
35+
return nil, errors.WrapErrorAction(logutils.ActionFind, model.TypeExample, filterArgs(nil), err)
36+
}
37+
38+
return data, nil
39+
}

driven/storage/database.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ type database struct {
3838
dbClient *mongo.Client
3939
logger *logs.Logger
4040

41-
globalConfigs *collectionWrapper
42-
configs *collectionWrapper
43-
examples *collectionWrapper
44-
unitcalendars *collectionWrapper
41+
globalConfigs *collectionWrapper
42+
configs *collectionWrapper
43+
examples *collectionWrapper
44+
unitcalendars *collectionWrapper
45+
appbuildingfeatures *collectionWrapper
4546

4647
legacyEvents *collectionWrapper
4748
legacyLocations *collectionWrapper
@@ -101,6 +102,8 @@ func (d *database) start() error {
101102

102103
unitcalendars := &collectionWrapper{database: d, coll: db.Collection("unitcalendars")}
103104

105+
appbuildingfeatures := &collectionWrapper{database: d, coll: db.Collection("building_features")}
106+
104107
legacyLocations := &collectionWrapper{database: d, coll: db.Collection("legacy_locations")}
105108
err = d.applyLegacyLocationsChecks(legacyEvents)
106109
if err != nil {
@@ -128,6 +131,7 @@ func (d *database) start() error {
128131
d.examples = examples
129132
d.legacyEvents = legacyEvents
130133
d.unitcalendars = unitcalendars
134+
d.appbuildingfeatures = appbuildingfeatures
131135
d.legacyLocations = legacyLocations
132136
d.webtoolsBlacklistItems = webtoolsBlacklistItems
133137
d.processedImages = processedImages

driven/uiucadapters/wayfindingadapter.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import (
2828

2929
// UIUCWayFinding is a vendor specific structure that implements the BuildingLocation interface
3030
type UIUCWayFinding struct {
31+
KnownBuildingFeatures *map[string]model.AppBuildingFeature
3132
}
3233

3334
// NewUIUCWayFinding returns a new instance of a UIUCWayFinding struct
34-
func NewUIUCWayFinding() *UIUCWayFinding {
35-
return &UIUCWayFinding{}
35+
func NewUIUCWayFinding(knownfeatures *map[string]model.AppBuildingFeature) *UIUCWayFinding {
36+
return &UIUCWayFinding{KnownBuildingFeatures: knownfeatures}
3637
}
3738

3839
// GetEntrance returns the active entrance closest to the user's position that meets the ADA Accessibility filter requirement
@@ -76,7 +77,7 @@ func (uwf *UIUCWayFinding) GetBuildings(conf *model.EnvConfigData) (*[]model.Bui
7677
if err != nil {
7778
return nil, err
7879
}
79-
returnList := uiuc.NewBuildingList(cmpBldgs)
80+
returnList := uiuc.NewBuildingList(cmpBldgs, uwf.KnownBuildingFeatures)
8081
return returnList, nil
8182
}
8283

@@ -107,7 +108,7 @@ func (uwf *UIUCWayFinding) GetBuilding(bldgID string, adaAccessibleOnly bool, la
107108
bldg := model.Building{}
108109
return &bldg, err
109110
}
110-
return uiuc.NewBuilding((*cmpBldg)[0]), nil
111+
return uiuc.NewBuilding((*cmpBldg)[0], uwf.KnownBuildingFeatures), nil
111112
}
112113

113114
// GetFloorPlan returns the requested floor plan

0 commit comments

Comments
 (0)