public JObject GetMenuItems() { try { Logger.Debug("Enter to GetMenuItems"); // TODO need to do the session user filter; var data = DBProxy.Get(ModuleAppConsts.Collection.BACKEND_UI_ROUTES, CommonConst.Filters.IS_OVERRIDE_FILTER); List <string> userAccess = new List <string>() { "*" }; var sessionUser = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (sessionUser != null) { userAccess.AddRange(sessionUser.groups); } JArray menuData = new JArray(); foreach (var item in data) { if (item["auth_users"].Where(f => userAccess.Contains(f.ToString())).Any()) { menuData.Add(item); } } Logger.Debug("Got GetMenuItems"); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, menuData)); } catch (Exception ex) { Logger.Error(string.Format("Error in GetMenuItems: {0}", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject GetBlocks() { try { JObject filter = new JObject(); filter[CommonConst.CommonField.IS_ENABLED] = true; string filterPage = string.Empty; var page = _paramContainer.GetKey(PAGE); if (page != null) { filterPage = page.ToString(); } var data = DBProxy.Get(ZBLOCK_COLLECTION, filter.ToString(), new List <string>() { CommonConst.CommonField.DATA_KEY, PAGES, INDEX, BLOCK_PATH, DISPLAY_AREA }); data = new JArray(data.Where(f => f[PAGES] != null && (f[PAGES] as JArray).Where(f1 => f1.ToString() == filterPage).Count() != 0).OrderBy(f => (int)f[INDEX])); Logger.Debug("Enter to Get Blocks"); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject MyPhotoUsers() { try { JObject filter = new JObject(); var data = DBProxy.Get(CommonConst.Collection.USERS, filter.ToString(), new List <string> { CommonConst.CommonField.USER_ID, CommonConst.CommonField.NAME, CommonConst.CommonField.USER_TYPE }); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
protected JObject GetPagedData(string collection, string query, List <string> fields = null, Dictionary <string, int> sortColumns = null, int pageSize = 10, int currentPage = 1) { int?top = null; int?skip = null; top = pageSize; skip = (pageSize * (currentPage - 1)); Logger.Debug(string.Format("GetPageData. Top:{0} Skip:{1} Query:{2}", top, skip, query)); var dbArrData = DBProxy.Get(collection, query, fields, sortColumns, top, skip); JObject extraData = new JObject(); long count = DBProxy.GetCount(collection, query); extraData[CommonConst.CommonField.TOTAL_RECORD_COUNT_KEY] = count; extraData[CommonConst.CommonField.TOTAL_PAGES_KEY] = Math.Ceiling(((double)count / pageSize)); extraData[CommonConst.CommonField.PAGE_SIZE_KEY] = pageSize; extraData[CommonConst.CommonField.CURRENT_PAGE_KEY] = currentPage; return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, dbArrData, extraData)); }
public JObject GetModules() { var data = DBProxy.Get(CommonConst.Collection.MODULES, "{}"); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data)); }
public byte[] GetImage() { try { var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var type = HttpProxy.GetQueryString("t"); if (string.IsNullOrEmpty(fileHash)) { HttpProxy.SetResponse(400); } if (string.IsNullOrEmpty(type)) { type = "s"; } var imageType = ImageProcessor.IMAGE_S_BASE64; switch (type.Trim().ToLower()) { case "l": imageType = ImageProcessor.IMAGE_L_BASE64; break; case "m": imageType = ImageProcessor.IMAGE_M_BASE64; break; } JObject filter = new JObject(); filter[ImageProcessor.FILE_HASH] = fileHash; var data = DBProxy.Get(ImageProcessor.MYPHOTO_COLLECTION, filter.ToString(), new List <string> { imageType }); if (data.Count == 0) { Logger.Error("Data not found"); HttpProxy.SetResponse(404); return(null); } else { var base64 = string.Empty; if (data[0][imageType] != null) { base64 = data[0][imageType].ToString(); } else { try { base64 = KeyValueStorage.Get <string>(ImageProcessor.IMAGE_KEY_VALUE_BUCKET, ImageProcessor.GetFileKey(imageType, fileHash)); } catch (KeyNotFoundException ex) { Logger.Error(ex.Message, ex); } } if (string.IsNullOrEmpty(base64)) { HttpProxy.SetResponse(404); return(null); } HttpProxy.ResponseHeaders["Cache-Control"] = "public, max-age=172800"; return(System.Convert.FromBase64String(base64)); } } catch (Exception ex) { HttpProxy.SetResponse(500); Logger.Error(ex.Message, ex); return(null); } }
public byte[] Get() { try { Logger.Debug("Calling Get JS "); var path = HttpProxy.GetQueryString("path"); if (string.IsNullOrEmpty(path)) { Logger.Error("Path is missing in the query string"); return(null); } var filterQuery = "{" + CommonConst.CommonField.FILE_PATH + ":/.js$/i}"; var data = DBProxy.Get(CommonConst.Collection.STATIC_CONTECT, filterQuery, new List <string> { CommonConst.CommonField.FILE_PATH }); Logger.Debug("Fetch value from Get JS"); var listOfArrays = new List <byte[]>(); var queryRecords = data.Select(l => new { length = l[CommonConst.CommonField.FILE_PATH].ToString().Length, file_path = l[CommonConst.CommonField.FILE_PATH].ToString() }).OrderBy(o => o.length).ToList(); Logger.Debug("Apply by Order by Get JS"); foreach (var item in queryRecords) { if (!string.IsNullOrEmpty(item.file_path) && item.file_path.IndexOf(path) == 0) { string jspath = item.file_path; if (jspath.IndexOf(CommonConst.CommonValue.APP_BACKEND_FOLDERPATH) == 1) { jspath = jspath.Replace(string.Format("/{0}", CommonConst.CommonValue.APP_BACKEND_FOLDERPATH), ApplicationConfig.AppBackendPath); } else if (jspath.IndexOf(CommonConst.CommonValue.APP_FRONTEND_FOLDERPATH) == 1) { jspath = jspath.Replace(string.Format("/{0}", CommonConst.CommonValue.APP_FRONTEND_FOLDERPATH), "/"); } var content = ContentHandler.GetContent(jspath); if (content != null) { if (ApplicationConfig.GetApplicationMode != ApplicationMode.Live) { listOfArrays.Add(Encoding.UTF8.GetBytes(string.Format("\n/*File: {0}*/\n", item.file_path))); } listOfArrays.Add(content); listOfArrays.Add(Encoding.UTF8.GetBytes("\n")); } } } return(listOfArrays .SelectMany(a => a) .ToArray()); } catch (Exception ex) { Logger.Error(string.Format("Error in GetJs {0}", ex.Message), ex); throw; } }
private void DoJoins(JObject data, string sourceCollection, JArray joins) { if (joins != null) { Dictionary <string, List <string> > collectionIds = new Dictionary <string, List <string> >(); // get the join keys foreach (JObject join in joins) { collectionIds.Add(join[CommonConst.CommonField.DB_JOIN_SOURCE_FIELD].ToString(), new List <string>()); } // get the join ids if (data[CommonConst.CommonField.DATA] == null) { return; } foreach (JObject item in data[CommonConst.CommonField.DATA] as JArray) { foreach (var joinColumn in collectionIds) { if (item[joinColumn.Key] != null) { joinColumn.Value.Add(item[joinColumn.Key].ToString()); } } } // gte data from IDs foreach (var joinCoumnId in collectionIds) { var join = joins.FirstOrDefault(f => f[CommonConst.CommonField.DB_JOIN_SOURCE_FIELD].ToString() == joinCoumnId.Key); if (join != null) { List <string> fields = new List <string>(); if (join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELDS] != null) { fields.Add(join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELD].ToString()); foreach (var field in join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELDS] as JArray) { fields.Add(field.ToString()); } } else { fields = null; } List <string> filter = new List <string>(); foreach (var item in joinCoumnId.Value) { filter.Add("{ " + join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELD].ToString() + ": \"" + item + "\" }"); } string filterQuery = "{ $or: [ " + string.Join(",", filter) + "] }"; JArray joinCollectionData = DBProxy.Get(join[CommonConst.CommonField.DB_JOIN_DESTINATION_COLELCTION].ToString(), filterQuery, fields); foreach (JObject joinData in joinCollectionData) { if (joinData[join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELD].ToString()] != null) { var joinid = joinData[join[CommonConst.CommonField.DB_JOIN_DESTINATION_FIELD].ToString()].ToString(); var dataJoin = (data[CommonConst.CommonField.DATA] as JArray).FirstOrDefault(f => f[join[CommonConst.CommonField.DB_JOIN_SOURCE_FIELD].ToString()].ToString() == joinid); if (dataJoin != null) { if (dataJoin[join[CommonConst.CommonField.DB_JOIN_VALUE].ToString()] == null) { dataJoin[join[CommonConst.CommonField.DB_JOIN_VALUE].ToString()] = new JArray(); } (dataJoin[join[CommonConst.CommonField.DB_JOIN_VALUE].ToString()] as JArray).Add(joinData); } } } } } } }