Ejemplo n.º 1
0
        public IActionResult GetBbsModulesForProcedure(Guid procedureOid)
        {
            ModuleProcedureList model = new ModuleProcedureList();

            model.ModulesProcedureList = new List <Module>();
            ResponseResult result = new ResponseResult();

            result.Success = false;
            GetModulesForProcedureResponse response = new GetModulesForProcedureResponse();

            try
            {
                model.Rules = new List <string>();
                PandoraSession session = NetCoreUtility.GetSession(HttpContext);
                if (session == null)
                {
                    return(new StatusCodeResult(440));
                }

                #region Verifica Validità Access Token
                if (PandoraUtility.IsAccessTokenExpired(session.AccessToken))
                {
                    string            pandoraTokenPath = _appSettings.PANDORA_BASE_PATH + _appSettings.PANDORA_TOKEN_PATH;
                    AuthorizationData authData         = PandoraUtility.GetNewAccessToken(pandoraTokenPath, session.UserCode, session.Username, session.Refreshtoken);
                    session.AccessToken  = authData.Access_Token;
                    session.Refreshtoken = authData.Refresh_Token;
                    NetCoreUtility.SetSession(HttpContext, session);
                }
                #endregion

                #region Verifica Rules
                List <string> rulesList = new List <string> {
                    AppUtility.Rules.ACPReadProcedure
                };
                string pandoraRulePath = _appSettings.PANDORA_BASE_PATH + _appSettings.PANDORA_RULE_PATH + "/verifyrules";
                Dictionary <string, bool> rulesResult = VerifyRules(rulesList, session.RandomId, session.AccessToken, session.ScopeId, pandoraRulePath);

                #endregion

                #region Recupero le Relations

                if (PandoraUtility.IsVisibleRule(rulesResult, AppUtility.Rules.ACPReadProcedure))
                {
                    model.Rules.AddRange(rulesResult.Where(p => p.Value).Select(p => p.Key));
                    //need to be changed with the new request and passing the version oid
                    GetModulesForProcedureRequest request = new GetModulesForProcedureRequest
                    {
                        ProcedureOid = procedureOid
                    };
                    response = _bbsService.GetBbsModulesForProcedure(session.Username, request, _appSettings.APP_CODE, _appSettings.TS_ESB_MPR_APPCODE, _appSettings.TS_ESB_VERSION, _appSettings.TS_ESB_PLM_PASSWORD, _appSettings.TS_ESB_URL);
                    if (PandoraUtility.CheckEsbStatus(response))
                    {
                        result.Message = AppUtility.GetErrorDescription(Utility.Modules.ACP_Registries_Modules, Commands.GetBbsModulesByProcedure, response.Status.Code, null, response.Status.Description);
                    }
                    else
                    {
                        result.Success             = true;
                        model.ModulesProcedureList = response.ModulesList;
                    }
                }
                else
                {
                    result.Message = PandoraErrorCodes.Permission_Denied;
                }
                #endregion
            }
            catch (BaseException be)
            {
                _logger.LogInformation(be.Message);
                result.Message = PandoraErrorCodes.Exception_Error;
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.ToString());
                result.Message = PandoraErrorCodes.Exception_Error;
            }

            model.Result = result;
            return(Json(model));
        }
Ejemplo n.º 2
0
        public IActionResult BbsGrid(string keyword, int?page, int?rows, string sort, string order)
        {
            BbsGridModel   model  = new BbsGridModel();
            ResponseResult result = new ResponseResult
            {
                Success = false
            };

            model.Bbs = new List <BBSRelations>();

            try
            {
                PandoraSession session = NetCoreUtility.GetSession(HttpContext);
                if (session == null)
                {
                    return(new StatusCodeResult(440));
                }
                #region Verifica Validità Access Token

                if (PandoraUtility.IsAccessTokenExpired(session.AccessToken))
                {
                    string            pandoraTokenPath = _appSettings.PANDORA_BASE_PATH + _appSettings.PANDORA_TOKEN_PATH;
                    AuthorizationData authData         = PandoraUtility.GetNewAccessToken(pandoraTokenPath, session.UserCode, session.Username, session.Refreshtoken);
                    session.AccessToken  = authData.Access_Token;
                    session.Refreshtoken = authData.Refresh_Token;
                    NetCoreUtility.SetSession(HttpContext, session);
                }

                #endregion

                #region Verifica Rules

                List <string> rulesList = new List <string> {
                    AppUtility.Rules.ReadBBSRule, AppUtility.Rules.DeleteBBSRule
                };
                string pandoraRulePath = _appSettings.PANDORA_BASE_PATH + _appSettings.PANDORA_RULE_PATH + "/verifyrules";
                Dictionary <string, bool> rulesResult = VerifyRules(rulesList, session.RandomId, session.AccessToken, session.ScopeId, pandoraRulePath);

                #endregion

                #region Recupero le Bbs

                if (PandoraUtility.IsVisibleRule(rulesResult, AppUtility.Rules.ReadBBSRule))
                {
                    GetBBSRequest request = new GetBBSRequest()
                    {
                        Keyword = keyword,
                        //we use || because if a parameter is null or empty, it doesn't cause any error
                        OrderByPropertyName = (string.IsNullOrEmpty(sort) || string.IsNullOrEmpty(order)) ? "Name asc" : sort + " " + order,
                        PageNumber          = page ?? 1,
                        PageSize            = rows ?? 10
                    };

                    GetBBSResponse response = _bbsService.GetBbs(session.Username, request, _appSettings.APP_CODE, _appSettings.TS_ESB_MPR_APPCODE, _appSettings.TS_ESB_VERSION, _appSettings.TS_ESB_PLM_PASSWORD, _appSettings.TS_ESB_URL);
                    if (PandoraUtility.CheckEsbStatus(response))
                    {
                        result.Message = AppUtility.GetErrorDescription(Utility.Modules.Registries_BBS, Commands.GetBBS, response.Status.Code, null, response.Status.Description);
                    }
                    else
                    {
                        result.Success  = true;
                        model.Bbs       = response.BBSList;
                        model.TotalRows = response.RecordNumber;
                    }
                }
                else
                {
                    result.Message = PandoraErrorCodes.Permission_Denied;
                }

                #endregion
            }
            catch (BaseException be)
            {
                _logger.LogInformation(be.Message);
                result.Message = PandoraErrorCodes.Exception_Error;
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.ToString());
                result.Message = PandoraErrorCodes.Exception_Error;
            }
            ViewBag.TotalRows = model.TotalRows;
            model.Result      = result;
            return(PartialView(model));
        }