Update VSTP package to use processing from CIF package
This commit is contained in:
@@ -10,10 +10,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const timetableCollection string = "timetable"
|
||||
|
||||
// Pushes the current version of this application to the data base 'versions' collection.
|
||||
// Currently uses the old name of mq-client
|
||||
func PushVersionToDb() {
|
||||
version := database.Version{
|
||||
Target: "timetable-mgr",
|
||||
@@ -33,30 +30,3 @@ func PushVersionToDb() {
|
||||
log.Debug("Version up to date in Database")
|
||||
}
|
||||
}
|
||||
|
||||
// Puts one item of the type `database.Service` to the database, used by the VSTP package which receives services one at a time
|
||||
func PutOneService(data database.Service) bool {
|
||||
coll := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
_, err := coll.InsertOne(context.TODO(), data)
|
||||
if err != nil {
|
||||
log.Error("Unable to insert to database: " + err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Deletes one service from the database.
|
||||
func DeleteOneService(data database.DeleteQuery) bool {
|
||||
coll := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
var filter = bson.D{
|
||||
{Key: "trainUid", Value: data.TrainUid},
|
||||
{Key: "stpIndicator", Value: data.StpIndicator},
|
||||
{Key: "scheduleStartDate", Value: data.ScheduleStartDate},
|
||||
}
|
||||
_, err := coll.DeleteOne(context.TODO(), filter)
|
||||
if err != nil {
|
||||
log.Error("Unable to delete service: " + err.Error())
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ type CifMetadata struct {
|
||||
|
||||
// Fetches the CifMetadata from the database, returns nil if no metadata exists - before first initialisation for example.
|
||||
func GetCifMetadata() (*CifMetadata, error) {
|
||||
database := MongoClient.Database(databaseName)
|
||||
collection := database.Collection(metaCollection)
|
||||
database := MongoClient.Database(DatabaseName)
|
||||
collection := database.Collection(MetaCollection)
|
||||
filter := bson.M{"type": Doctype}
|
||||
var result CifMetadata
|
||||
err := collection.FindOne(context.Background(), filter).Decode(&result)
|
||||
@@ -46,8 +46,8 @@ func GetCifMetadata() (*CifMetadata, error) {
|
||||
|
||||
// Uses upsert to Insert/Update the CifMetadata in the database
|
||||
func PutCifMetadata(metadata *CifMetadata, lastUpdateType string) bool {
|
||||
database := MongoClient.Database(databaseName)
|
||||
collection := database.Collection(metaCollection)
|
||||
database := MongoClient.Database(DatabaseName)
|
||||
collection := database.Collection(MetaCollection)
|
||||
options := options.Update().SetUpsert(true)
|
||||
filter := bson.M{"type": Doctype}
|
||||
update := bson.M{
|
||||
@@ -86,7 +86,7 @@ func DeleteCifEntries(deletions []database.DeleteQuery) error {
|
||||
log.Debug("Running deletions against database", zap.Int("count", len(deletions)))
|
||||
|
||||
// Prepare deletion tasks
|
||||
collection := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
collection := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
|
||||
bulkDeletions := make([]mongo.WriteModel, 0, len(deletions))
|
||||
|
||||
for _, deleteQuery := range deletions {
|
||||
@@ -117,7 +117,7 @@ func CreateCifEntries(schedules []database.Service) error {
|
||||
}
|
||||
log.Debug("Running creations against database", zap.Int("count", len(schedules)))
|
||||
|
||||
collection := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
collection := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
|
||||
|
||||
models := make([]mongo.WriteModel, 0, len(schedules))
|
||||
|
||||
@@ -141,7 +141,7 @@ func RemoveOutdatedServices(cutoff time.Time) (count int64, err error) {
|
||||
// Define filter
|
||||
filter := bson.M{"scheduleEndDate": bson.M{"$lt": cutoff}}
|
||||
|
||||
collection := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
collection := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
|
||||
|
||||
res, err := collection.DeleteMany(context.Background(), filter)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// CAUTION: Drops the collection named in collectionName
|
||||
func DropCollection(collectionName string) error {
|
||||
log.Info("Dropping collection", zap.String("Collection Name", collectionName))
|
||||
database := MongoClient.Database(databaseName)
|
||||
database := MongoClient.Database(DatabaseName)
|
||||
collection := database.Collection(collectionName)
|
||||
|
||||
err := collection.Drop(context.Background())
|
||||
@@ -27,8 +27,8 @@ func DropCollection(collectionName string) error {
|
||||
|
||||
// Checks the update time (unix timestamp) of the collection named in collectionName, uses 'type: collection' entries in the meta collection
|
||||
func CheckUpdateTime(collectionName string) (int64, error) {
|
||||
database := MongoClient.Database(databaseName)
|
||||
collection := database.Collection(metaCollection)
|
||||
database := MongoClient.Database(DatabaseName)
|
||||
collection := database.Collection(MetaCollection)
|
||||
filter := bson.D{
|
||||
{Key: "target", Value: collectionName},
|
||||
{Key: "type", Value: "collection"},
|
||||
@@ -46,7 +46,7 @@ func CheckUpdateTime(collectionName string) (int64, error) {
|
||||
// Sets a new update time (unix timestamp) of the collection named in collectionName. The update time is calculated within the function.
|
||||
func SetUpdateTime(collectionName string) error {
|
||||
log.Info("Setting update time", zap.String("collection", collectionName))
|
||||
database := MongoClient.Database(databaseName)
|
||||
database := MongoClient.Database(DatabaseName)
|
||||
collection := database.Collection("meta")
|
||||
options := options.Update().SetUpsert(true)
|
||||
updateTime := time.Now().Unix()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dbAccess
|
||||
|
||||
const databaseName string = "owlboard"
|
||||
const DatabaseName string = "owlboard"
|
||||
const CorpusCollection string = "corpus"
|
||||
const StationsCollection string = "stations"
|
||||
const metaCollection string = "meta"
|
||||
const MetaCollection string = "meta"
|
||||
const TimetableCollection string = "timetable"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// Puts an array of Corpus Documents into the database
|
||||
func PutManyCorpus(corpusData *[]database.CorpusEntry) error {
|
||||
collection := MongoClient.Database(databaseName).Collection(CorpusCollection)
|
||||
collection := MongoClient.Database(DatabaseName).Collection(CorpusCollection)
|
||||
|
||||
documents := convertCorpusToInterfaceSlice(corpusData)
|
||||
|
||||
@@ -23,7 +23,7 @@ func PutManyCorpus(corpusData *[]database.CorpusEntry) error {
|
||||
|
||||
// Puts an array of Stations documents into the database
|
||||
func PutManyStations(stationsData *[]database.StationEntry) error {
|
||||
collection := MongoClient.Database(databaseName).Collection(StationsCollection)
|
||||
collection := MongoClient.Database(DatabaseName).Collection(StationsCollection)
|
||||
|
||||
documents := convertStationsToInterfaceSlice(stationsData)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user