func setOneRedisExcel(request *messaging.ObjectRequest) RepositoryResponse { response := RepositoryResponse{} client, isError, errorMessage := getRedisExcelConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id value := getStringByObject(request, request.Body.Object) err := client.Set(key, value, 0, 0, false, false) if err != nil { response.IsSuccess = false request.Log("Error inserting/updating object in Redis : " + key + ", " + err.Error()) response.GetErrorResponse("Error inserting/updating one object in Redis" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully inserted/updated one object in Redis" request.Log(response.Message) } } return response }
func (repository CouchRepository) GetByKey(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-BY-KEY") response := RepositoryResponse{} bucket, errorMessage, isError := getCouchBucket(request) if isError == true { response.GetErrorResponse(errorMessage) } else { key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id rawBytes, err := bucket.GetRaw(key) var returnData map[string]interface{} returnData = make(map[string]interface{}) json.Unmarshal(rawBytes, &returnData) if request.Controls.SendMetaData == "false" { delete(returnData, "__osHeaders") } rawBytes, err = json.Marshal(returnData) if err != nil { response.GetErrorResponse("Error retrieving object from couchbase") } else { response.GetResponseWithBody(rawBytes) } } return response }
func (repository ElasticRepository) GetQuery(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-QUERY!") response := RepositoryResponse{} queryType := request.Body.Query.Type switch queryType { case "Query": if request.Body.Query.Parameters != "*" { fieldsInByte := executeElasticQuery(request) if fieldsInByte != nil { response.IsSuccess = true response.Message = "Successfully Retrieved Data For Custom Query" response.GetResponseWithBody(fieldsInByte) } else { response.IsSuccess = false response.Message = "Aborted! Unsuccessful Retrieving Data For Custom Query" errorMessage := response.Message response.GetErrorResponse(errorMessage) } } else { //Check if just STAR then execute GET-SEARCH method request.Log("Redirecting to GET-SEARCH!") return search(request, request.Body.Query.Parameters) } default: return search(request, request.Body.Query.Parameters) } return response }
func (repository PostgresRepository) GetQuery(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-QUERY") response := RepositoryResponse{} queryType := request.Body.Query.Type switch queryType { case "Query": if request.Body.Query.Parameters != "*" { fieldsInByte := executePostgresQuery(request) if fieldsInByte != nil { response.IsSuccess = true response.Message = "Successfully Retrieved Data For Custom Query" response.GetResponseWithBody(fieldsInByte) } else { response.IsSuccess = false response.Message = "Aborted! Unsuccessful Retrieving Data For Custom Query" errorMessage := response.Message response.GetErrorResponse(errorMessage) } } else { return repository.GetAll(request) } default: request.Log(queryType + " not implemented in Postgres_SQL Db repository") return getDefaultNotImplemented() } return response }
func setOneRedis(request *messaging.ObjectRequest) RepositoryResponse { response := RepositoryResponse{} client, isError, errorMessage := getRedisConnection(request) keyValue := getRedisRecordID(request, nil) if isError == true { response.GetErrorResponse(errorMessage) } else if keyValue != "" { key := request.Controls.Namespace + "." + request.Controls.Class + "." + keyValue request.Body.Object[request.Body.Parameters.KeyProperty] = keyValue value := getStringByObject(request.Body.Object) err := client.Set(key, value, 0, 0, false, false) if err != nil { response.IsSuccess = false request.Log("Error inserting/updating object in Redis : " + key + ", " + err.Error()) response.GetErrorResponse("Error inserting/updating one object in Redis" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully inserted/updated one object in Redis" request.Log(response.Message) } } //Update Response var Data []map[string]interface{} Data = make([]map[string]interface{}, 1) var actualData map[string]interface{} actualData = make(map[string]interface{}) actualData["ID"] = keyValue Data[0] = actualData response.Data = Data return response }
func (repository MongoRepository) InsertSingle(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting INSERT-SINGLE") response := RepositoryResponse{} collection, isError, errorMessage := getMongoConnection(request) key := getMongoDBRecordID(request, nil) if isError == true { response.GetErrorResponse(errorMessage) } else if key != "" { request.Body.Object[request.Body.Parameters.KeyProperty] = key request.Body.Object["_id"] = request.Controls.Namespace + "." + request.Controls.Class + "." + key err := collection.Insert(bson.M(request.Body.Object)) if err != nil { response.IsSuccess = false response.GetErrorResponse("Error inserting one object in mongo" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully inserted one object in Mongo" request.Log(response.Message) } } var Data []map[string]interface{} Data = make([]map[string]interface{}, 1) var actualData map[string]interface{} actualData = make(map[string]interface{}) actualData["ID"] = key Data[0] = actualData response.Data = Data return response }
func (repository CassandraRepository) GetByKey(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting Get-BY-KEY!") response := RepositoryResponse{} session, isError, errorMessage := getCassandraConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { isError = false //get primary key field name iter := session.Query("select type, column_name from system.schema_columns WHERE keyspace_name='" + getSQLnamespace(request) + "' AND columnfamily_name='" + request.Controls.Class + "'").Iter() my1, _ := iter.SliceMap() iter.Close() fieldName := "" for _, value := range my1 { if value["type"].(string) == "partition_key" { fieldName = value["column_name"].(string) break } } parameter := request.Controls.Id iter2 := session.Query("SELECT * FROM " + request.Controls.Class + " where " + fieldName + " = '" + parameter + "'").Iter() my, isErr := iter2.SliceMap() iter2.Close() if request.Controls.SendMetaData == "false" { for index, arrVal := range my { for key, _ := range arrVal { if key == "osheaders" { delete(my[index], key) } } } } byteValue, errMarshal := json.Marshal(my) if errMarshal != nil { response.IsSuccess = false response.GetErrorResponse("Error getting values for one object in Cassandra" + isErr.Error()) } else { response.IsSuccess = true response.GetResponseWithBody(byteValue) response.Message = "Successfully retrieved values for one object in Cassandra" request.Log(response.Message) } } return response }
func (repository CassandraRepository) GetAll(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-ALL!") response := RepositoryResponse{} session, isError, errorMessage := getCassandraConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { isError = false iter2 := session.Query("SELECT * FROM " + request.Controls.Class).Iter() my, isErr := iter2.SliceMap() iter2.Close() skip := 0 if request.Extras["skip"] != nil { skip, _ = strconv.Atoi(request.Extras["skip"].(string)) } take := len(my) if request.Extras["take"] != nil { take, _ = strconv.Atoi(request.Extras["take"].(string)) } fmt.Println(reflect.TypeOf(my)) if request.Controls.SendMetaData == "false" { for index, arrVal := range my { for key, _ := range arrVal { if key == "osheaders" { delete(my[index], key) } } } } byteValue, errMarshal := json.Marshal(my[skip:(skip + take)]) if errMarshal != nil { response.IsSuccess = false response.GetErrorResponse("Error getting values for all objects in Cassandra" + isErr.Error()) } else { response.IsSuccess = true response.GetResponseWithBody(byteValue) response.Message = "Successfully retrieved values for all objects in Cassandra" request.Log(response.Message) } } return response }
func (r QueuedStorageEngine) Store(request *messaging.ObjectRequest) (response repositories.RepositoryResponse) { conn, err := amqp.Dial("amqp://*****:*****@localhost:5672/") failOnError(err, "Failed to connect to RabbitMQ") defer conn.Close() ch, err := conn.Channel() failOnError(err, "Failed to open a channel") defer ch.Close() err = ch.ExchangeDeclare( "publisher_01", // name "direct", // type true, // durable false, // auto-deleted false, // internal false, // no-wait nil, // arguments ) failOnError(err, "Failed to declare an exchange") body, errMarshal := json.Marshal(request) if errMarshal != nil { response.Message = "Conversion to JSON failed!" request.Log(response.Message) } else { response.Message = "Conversion to JSON Success!" request.Log(response.Message) log.Printf(" [x] Sent %s", body) } err = ch.Publish( "publisher_01", // exchange "Queued", // routing key false, // mandatory false, // immediate amqp.Publishing{ // ContentType: "text/plain", ContentType: "*messaging.ObjectRequest", Body: body, }) failOnError(err, "Failed to publish a message") if err == nil { response.IsSuccess = true } //log.Printf(" [x] Sent %s", body) return response }
func getRedisConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) { isError = false client, err := goredis.DialURL("tcp://@" + request.Configuration.ServerConfiguration["REDIS"]["Host"] + ":" + request.Configuration.ServerConfiguration["REDIS"]["Port"] + "/0?timeout=10s&maxidle=1") if err != nil { isError = true errorMessage = err.Error() request.Log("Error! Can't connect to server!error") } request.Log("Reusing existing GoRedis connection") return }
func (repository ElasticRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting DELETE-MULTIPLE") response := RepositoryResponse{} conn := getConnection()(request) for _, object := range request.Body.Objects { key := getNoSqlKeyById(request, object) request.Log("Deleting single object from Elastic Search : " + key) _, err := conn.Delete(request.Controls.Namespace, request.Controls.Class, key, nil) _, err = conn.Delete(getKibanaElasticName(request), getKibanaElasticName(request), key, nil) if err != nil { errorMessage := "Elastic Search single delete error : " + err.Error() request.Log(errorMessage) response.GetErrorResponse(errorMessage) } else { response.IsSuccess = true response.Message = "Successfully deleted one in elastic search" request.Log(response.Message) } } return response }
func (repository CouchRepository) DeleteSingle(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting DELETE-SINGLE") response := RepositoryResponse{} bucket, errorMessage, isError := getCouchBucket(request) if isError == true { response.GetErrorResponse(errorMessage) } else { key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id request.Log("Deleting object from couchbase : " + key) err := bucket.Delete(key) if err != nil { response.IsSuccess = false request.Log("Error deleting object from couchbase : " + key + ", " + err.Error()) response.GetErrorResponse("Error deleting one object in Couchbase" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully deleted one object in Coucahbase" request.Log(response.Message) } } return response }
func (repository MysqlRepository) UpdateMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting UPDATE-MULTIPLE") response := RepositoryResponse{} session, isError, errorMessage := getMysqlConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { for i := 0; i < len(request.Body.Objects); i++ { noOfElements := len(request.Body.Objects[i]) - 1 var keyUpdate = make([]string, noOfElements) var valueUpdate = make([]string, noOfElements) var startIndex = 0 for key, value := range request.Body.Objects[i] { if key != request.Body.Parameters.KeyProperty { if key != "__osHeaders" { keyUpdate[startIndex] = key valueUpdate[startIndex] = value.(string) startIndex = startIndex + 1 } else { keyUpdate[startIndex] = "osHeaders" valueUpdate[startIndex] = ConvertOsheaders(value.(messaging.ControlHeaders)) startIndex = startIndex + 1 } } } var argValueList string //Build the query string for i := 0; i < noOfElements; i++ { if i != noOfElements-1 { argValueList = argValueList + keyUpdate[i] + " = " + "'" + valueUpdate[i] + "'" + ", " } else { argValueList = argValueList + keyUpdate[i] + " = " + "'" + valueUpdate[i] + "'" } } //DEBUG USE : Display Query information // fmt.Println("Table Name : " + request.Controls.Class) // fmt.Println("Value list : " + argValueList) request.Log("UPDATE " + getSQLnamespace(request) + "." + request.Controls.Class + " SET " + argValueList + " WHERE " + request.Body.Parameters.KeyProperty + " =" + "'" + request.Body.Objects[i][request.Body.Parameters.KeyProperty].(string) + "'") _, err := session.Query("UPDATE " + getSQLnamespace(request) + "." + request.Controls.Class + " SET " + argValueList + " WHERE " + request.Body.Parameters.KeyProperty + " =" + "'" + request.Body.Objects[i][request.Body.Parameters.KeyProperty].(string) + "'") if err != nil { response.IsSuccess = false request.Log("Error updating object in MySQL : " + getNoSqlKey(request) + ", " + err.Error()) response.GetErrorResponse("Error updating one object in MySQL because no match was found!" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully updating one object in MySQL " request.Log(response.Message) } } } return response }
func (repository CouchRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting DELETE_MULTIPLE") response := RepositoryResponse{} bucket, errorMessage, isError := getCouchBucket(request) if isError == true { response.GetErrorResponse(errorMessage) } else { for _, obj := range request.Body.Objects { key := getNoSqlKeyById(request, obj) request.Log("Deleting object from couchbase : " + key) err := bucket.Delete(key) if err != nil { response.IsSuccess = false request.Log("Error deleting object from couchbase : " + key + ", " + err.Error()) response.GetErrorResponse("Error deleting Multiple objects in Couchbase" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully deleted Multiple objects in Coucahbase" request.Log(response.Message) } } } return response }
func getRedisExcelConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) { isError = false client, err := goredis.DialURL("tcp://@127.0.0.1:6379/0?timeout=10s&maxidle=1") if err != nil { isError = true errorMessage = err.Error() request.Log("Error! Can't connect to server!error") } request.Log("Reusing existing GoRedis connection") return }
func (repository CouchRepository) GetAll(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-ALL") response := RepositoryResponse{} bucket, errorMessage, isError := getCouchBucket(request) if isError == true { response.GetErrorResponse(errorMessage) } else { //Get all IDs viewResult, err := bucket.View("dev_allkeytemp", "allkeystemp", nil) //Iterate check for pattern and choose only desired IDs pattern := request.Controls.Namespace + "." + request.Controls.Class + "." var idArray []string for _, row := range viewResult.Rows { if strings.Contains((row.Key).(string), pattern) { idArray = append(idArray, (row.Key).(string)) } } //read all data for fetched days and return var returnDataMap []map[string]interface{} data, err := bucket.GetBulkRaw(idArray) for key, _ := range data { var tempData map[string]interface{} tempData = make(map[string]interface{}) json.Unmarshal(data[key], &tempData) if request.Controls.SendMetaData == "false" { delete(tempData, "__osHeaders") } returnDataMap = append(returnDataMap, tempData) } rawBytes, err := json.Marshal(returnDataMap) if err != nil { fmt.Println(err.Error()) response.GetErrorResponse("Error retrieving object from couchbase : " + err.Error()) } else { response.GetResponseWithBody(rawBytes) } } return response }
func startAtomicOperation(request *messaging.ObjectRequest, repositoryList []repositories.AbstractRepository, successAction int, failAction int) (response repositories.RepositoryResponse) { canRollback := false if repositoryList == nil { fmt.Println("NIL REPOSITORIES") } else { fmt.Println("REPOSITORIES FOUND!") fmt.Print("Fetched Repositories : ") fmt.Println(repositoryList) } for _, repository := range repositoryList { if repository != nil { request.Log("Executing repository : " + repository.GetRepositoryName()) tmpResponse := repositories.Execute(request, repository) canBreak := false if tmpResponse.IsSuccess { request.Log("Executing repository : " + repository.GetRepositoryName() + " - Success") switch successAction { case 1: response = tmpResponse continue case 3: response = tmpResponse canBreak = true } } else { request.Log("Executing repository : " + repository.GetRepositoryName() + " - Failed") switch failAction { case 1: continue case 2: canRollback = true canBreak = true case 3: response = tmpResponse canBreak = true } if canBreak == true { break } //1 = COMMIT, 2 = ROLLBACK, 3 = BREAK } } else { fmt.Println("NIL REPOSITORY FOUND!") continue } } if canRollback { request.Log("Transaction failed Rollbacking!!!") } return }
func setManyRedis(request *messaging.ObjectRequest) RepositoryResponse { response := RepositoryResponse{} client, isError, errorMessage := getRedisConnection(request) var idData map[string]interface{} idData = make(map[string]interface{}) if isError == true { response.GetErrorResponse(errorMessage) } else { isError := false index := 0 for _, object := range request.Body.Objects { index++ keyValue := getRedisRecordID(request, object) if keyValue == "" { response.IsSuccess = false response.Message = "Failed inserting multiple object in Cassandra" request.Log(response.Message) request.Log("Inavalid ID request") return response } key := request.Controls.Namespace + "." + request.Controls.Class + "." + keyValue object[request.Body.Parameters.KeyProperty] = keyValue idData[strconv.Itoa(index)] = keyValue value := getStringByObject(object) err := client.Set(key, value, 0, 0, false, false) if err != nil { isError = true errorMessage = err.Error() break } } if isError == true { response.IsSuccess = false request.Log("Error inserting/updating multiple objects in Redis : " + errorMessage) response.GetErrorResponse("Error inserting/updating multiple objects in Redis" + errorMessage) } else { response.IsSuccess = true response.Message = "Successfully inserted/updated multiple objects in Redis" request.Log(response.Message) } } //Update Response var DataMap []map[string]interface{} DataMap = make([]map[string]interface{}, 1) var actualInput map[string]interface{} actualInput = make(map[string]interface{}) actualInput["ID"] = idData DataMap[0] = actualInput response.Data = DataMap return response }
func getMongoConnection(request *messaging.ObjectRequest) (client *mgo.Collection, isError bool, errorMessage string) { isError = false session, err := mgo.Dial(request.Configuration.ServerConfiguration["MONGO"]["Url"]) if err != nil { isError = false errorMessage = err.Error() request.Log("Mongo connection initilizing failed!") } namespace := getSQLnamespace(request) client = session.DB(namespace).C(request.Controls.Class) return }
func getPostgresReportingFieldOrder(request *messaging.ObjectRequest) []string { var returnArray []string //read fields byteValue := executePostgresReportingGetFields(request) err := json.Unmarshal(byteValue, &returnArray) if err != nil { request.Log("Converstion of Json Failed!") returnArray = make([]string, 1) returnArray[0] = "nil" return returnArray } return returnArray }
func getCustomMongoConnection(request *messaging.ObjectRequest, customNamespace string, customClass string) (client *mgo.Collection, isError bool, errorMessage string) { isError = false session, err := mgo.Dial(request.Configuration.ServerConfiguration["MONGO"]["Url"]) if err != nil { isError = false errorMessage = err.Error() request.Log("Mongo connection initilizing failed!") } //namespace := getSQLnamespace(request) client = session.DB(customNamespace).C(customClass) request.Log("Reusing existing Mongo connection") return }
func executeCassandraGetSelectedFields(request *messaging.ObjectRequest) (returnByte []byte) { session, isError, _ := getCassandraConnection(request) if isError == true { request.Log("Cassandra connection failed") returnByte = nil } else { isError = false var selectedItemsQuery string var requestedFields []string request.Log("Requested Field List : " + request.Body.Special.Parameters) if request.Body.Special.Parameters == "*" { request.Log("All fields requested") requestedFields = make([]string, 1) requestedFields[0] = "*" selectedItemsQuery = "*" } else { requestedFields = strings.Split(request.Body.Special.Parameters, " ") for key, value := range requestedFields { if key == len(requestedFields)-1 { selectedItemsQuery += value } else { selectedItemsQuery += (value + ",") } } } iter2 := session.Query("select " + selectedItemsQuery + " from " + request.Controls.Class).Iter() my, _ := iter2.SliceMap() iter2.Close() byteValue, errMarshal := json.Marshal(my) if errMarshal != nil { request.Log("Error getting values for all objects in Cassandra") returnByte = []byte("Error JSON marshalling to BYTE array") } else { request.Log("Successfully retrieved values for all objects in Cassandra") returnByte = byteValue } } return }
func (repository MongoRepository) GetAll(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-ALL") response := RepositoryResponse{} collection, isError, errorMessage := getMongoConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { isError = false var data []bson.M err := collection.Find(bson.M{}).All(&data) take := len(data) if request.Extras["take"] != nil { take, _ = strconv.Atoi(request.Extras["take"].(string)) } skip := 0 if request.Extras["skip"] != nil { skip, _ = strconv.Atoi(request.Extras["skip"].(string)) } for index, _ := range data { if request.Controls.SendMetaData == "false" { delete(data[index], "__osHeaders") } delete(data[index], "_id") } byteValue, errMarshal := json.Marshal(data[skip:(skip + take)]) if errMarshal != nil { response.IsSuccess = false response.GetErrorResponse("Error getting values for all objects in mongo" + err.Error()) } else { response.IsSuccess = true response.GetResponseWithBody(byteValue) response.Message = "Successfully retrieved values for all objects in mongo" request.Log(response.Message) } } return response }
func (repository RedisRepository) GetByKey(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting GET-BY-KEY") response := RepositoryResponse{} client, isError, errorMessage := getRedisConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { key := getNoSqlKey(request) value, err := client.Get(key) var tempMap map[string]interface{} tempMap = make(map[string]interface{}) err = json.Unmarshal(value, &tempMap) if err != nil { request.Log("Error converting Json to Map : " + err.Error()) } else { if request.Controls.SendMetaData == "false" { delete(tempMap, "__osHeaders") } } byteValue, _ := json.Marshal(tempMap) if err != nil { response.IsSuccess = false request.Log("Error getting value by key for object in Redis : " + key + ", " + err.Error()) response.GetErrorResponse("Error getting value by key for one object in Redis" + err.Error()) } if err != nil { response.IsSuccess = false request.Log("Error getting value by key for object in Redis : " + key + ", " + err.Error()) response.GetErrorResponse("Error getting value by key for one object in Redis" + err.Error()) } else { response.IsSuccess = true response.GetResponseWithBody(byteValue) response.Message = "Successfully retrieved one object in Redis" request.Log(response.Message) } } return response }
func (repository MongoRepository) InsertMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting INSERT-MULTIPLE") response := RepositoryResponse{} collection, isError, errorMessage := getMongoConnection(request) var idData map[string]interface{} idData = make(map[string]interface{}) if isError == true { response.GetErrorResponse(errorMessage) } else { isError = false if isError == true { response.IsSuccess = false request.Log("Error inserting multiple objects in Mongo : " + errorMessage) response.GetErrorResponse("Error inserting multiple objects in Mongo" + errorMessage) } else { response.IsSuccess = true response.Message = "Successfully inserted multiple objects in Mongo" request.Log(response.Message) } for i := 0; i < len(request.Body.Objects); i++ { key := getMongoDBRecordID(request, request.Body.Objects[i]) if key == "" { continue } request.Body.Objects[i]["_id"] = request.Controls.Namespace + "." + request.Controls.Class + "." + key request.Body.Objects[i][request.Body.Parameters.KeyProperty] = key idData[strconv.Itoa(i)] = key err := collection.Insert(bson.M(request.Body.Objects[i])) if err != nil { response.IsSuccess = false response.GetErrorResponse("Error inserting many object in mongo" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully inserted many object in Mongo" request.Log(response.Message) } } } var DataMap []map[string]interface{} DataMap = make([]map[string]interface{}, 1) var actualInput map[string]interface{} actualInput = make(map[string]interface{}) actualInput["ID"] = idData DataMap[0] = actualInput response.Data = DataMap return response }
func executeCouchbaseGetClasses(request *messaging.ObjectRequest) (returnByte []byte) { bucket, _, isError := getCouchBucket(request) if isError == true { returnByte = nil } else { //Get Classes Details key := request.Controls.Namespace + "#DomainClasses" rawBytes, err := bucket.GetRaw(key) if err != nil { request.Log("Error connection reset. Try again!") returnByte = nil } else { returnByte = rawBytes } } return }
func (repository RedisRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting DELETE-MULTIPLE") response := RepositoryResponse{} client, isError, errorMessage := getRedisConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { isError := false for _, object := range request.Body.Objects { key := getNoSqlKeyById(request, object) reply, err := client.ExecuteCommand("DEL", key) err2 := reply.OKValue() if err != nil { isError = true errorMessage = err.Error() response.IsSuccess = false request.Log("Error deleting object in Redis!" + err2.Error()) response.GetErrorResponse("Error deleting object in Redis!" + err2.Error()) break } else { response.IsSuccess = true response.Message = "Successfully deleted multiple objects in Redis" request.Log("Successfully deleted all objects in Redis!") } } if isError == true { response.IsSuccess = false request.Log("Error deleting multiple objects in Redis : " + errorMessage) response.GetErrorResponse("Error deleting multiple objects in Redis" + errorMessage) } else { response.IsSuccess = true response.Message = "Successfully deleted multiple objects in Redis" request.Log(response.Message) } } return response }
func getCassandraConnection(request *messaging.ObjectRequest) (session *gocql.Session, isError bool, errorMessage string) { keyspace := getSQLnamespace(request) isError = false cluster := gocql.NewCluster(request.Configuration.ServerConfiguration["CASSANDRA"]["Url"]) cluster.Keyspace = keyspace request.Log("Cassandra URL : " + request.Configuration.ServerConfiguration["CASSANDRA"]["Url"]) request.Log("KeySpace : " + keyspace) session, err := cluster.CreateSession() if err != nil { isError = false errorMessage = err.Error() request.Log("Cassandra connection initilizing failed!") session, _ = createNewCassandraKeyspace(request) } else { request.Log("Cassandra connection initilizing success!") } //defer session.Close() request.Log("Reusing existing Cassandra connection") return }
func executeCassandraGetNamespaces(request *messaging.ObjectRequest) (returnByte []byte) { session, isError, _ := getCassandraConnection(request) if isError == true { request.Log("Cassandra connection failed") returnByte = nil } else { isError = false iter2 := session.Query("select keyspace_name from system.schema_keyspaces").Iter() my, _ := iter2.SliceMap() iter2.Close() var fields []string fields = make([]string, len(my)) for key, value := range my { for _, fieldname := range value { fields[key] = fieldname.(string) } } byteValue, errMarshal := json.Marshal(fields) if errMarshal != nil { request.Log("Error getting values for all objects in Cassandra") returnByte = []byte("Error JSON marshalling to BYTE array") } else { request.Log("Successfully retrieved values for all objects in Cassandra") returnByte = byteValue } } return }
func (repository CassandraRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse { request.Log("Starting DELETE-MULTIPLE") response := RepositoryResponse{} session, isError, errorMessage := getCassandraConnection(request) if isError == true { response.GetErrorResponse(errorMessage) } else { for _, obj := range request.Body.Objects { err := session.Query("DELETE FROM " + request.Controls.Class + " WHERE " + request.Body.Parameters.KeyProperty + " = '" + obj[request.Body.Parameters.KeyProperty].(string) + "'").Exec() if err != nil { response.IsSuccess = false request.Log("Error deleting object in Cassandra : " + err.Error()) response.GetErrorResponse("Error deleting one object in Cassandra because no match was found!" + err.Error()) } else { response.IsSuccess = true response.Message = "Successfully deleted one object in Cassandra" request.Log(response.Message) } } } return response }