Exemplo n.º 1
0
        public ActionResult ViolationLibrary(string violationTypeNumber = "")
        {
            Server.ScriptTimeout = 600;
            //No role based authentication needed, just make sure they have a valid credential for Library services.
            var authResult = CERSSecurityManager.AuthenticateHttpAuthorizationHeader();

            if (authResult.Result.Status == AuthenticationStatus.Success)
            {
                using (EDTTransactionScope transScope = new EDTTransactionScope(authResult.Account, EDTEndpoint.ViolationLibraryQuery, Request.UserHostAddress, authenticationRequestID: authResult.EDTAuthenticationRequestID))
                {
                    try
                    {
                        var xmlResult = transScope.Repository.ViolationTypes.Search(typeNumber: violationTypeNumber).ToXml();
                        transScope.WriteActivity("Generated XML Package Successfully");
                        return(XmlElement(xmlResult));
                    }
                    catch (Exception ex)
                    {
                        transScope.WriteActivity("Exception Occurred", ex);
                        transScope.WriteMessage("Exception Occurred. " + ex.Format(), EDTTransactionMessageType.Error);
                        transScope.Complete(EDTTransactionStatus.ErrorProcessing);
                        return(HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
                    }
                }
            }
            else
            {
                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, authResult));
            }
        }
Exemplo n.º 2
0
        public ActionResult DataDictionaryLibrary(DataRegistryDataSourceType dictionary, string identifier)
        {
            Server.ScriptTimeout = 600;

            //No role based authentication needed, just make sure they have a valid credential for Library services.
            var authResult = CERSSecurityManager.AuthenticateHttpAuthorizationHeader();

            if (authResult.Result.Status == AuthenticationStatus.Success)
            {
                using (EDTTransactionScope transScope = new EDTTransactionScope(authResult.Account, EDTEndpoint.DataDictionaryQuery, Request.UserHostAddress, authenticationRequestID: authResult.EDTAuthenticationRequestID))
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(identifier))
                        {
                            transScope.WriteActivity("Finding DataElement by Specific Identifier: \"" + identifier + "\".");
                        }
                        else
                        {
                            transScope.WriteActivity("Get All DataElements.");
                        }

                        var elements = DataRegistry.GetDataElements(dictionary, identifier);
                        transScope.WriteActivity("Fetched " + elements.Count + " Data Elements");
                        var xmlResult = elements.ToXml();
                        transScope.WriteActivity("Generated XML Package Successfully");
                        return(XmlElement(xmlResult));
                    }
                    catch (Exception ex)
                    {
                        transScope.WriteActivity("Exception Occurred", ex);
                        transScope.WriteMessage("Exception Occurred. " + ex.Format(), EDTTransactionMessageType.Error);
                        transScope.Complete(EDTTransactionStatus.ErrorProcessing);
                        return(HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
                    }
                }
            }
            else
            {
                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, authResult));
            }
        }
Exemplo n.º 3
0
        public ActionResult Document(Guid uniqueKey)
        {
            var authResult = CERSSecurityManager.AuthenticateHttpAuthorizationHeader();

            if (authResult.IsAuthenticatedAndAuthorized)
            {
                byte[] docData               = null;
                bool   docNotFound           = false;
                bool   docUniqueKeyNotFound  = false;
                bool   docPhysicallyNotFound = false;

                //Begin Transaction
                using (EDTTransactionScope transScope = new EDTTransactionScope(authResult.Account, EDTEndpoint.RegulatorFacilitySubmittalDocumentQuery, Request.UserHostAddress, authenticationRequestID: authResult.EDTAuthenticationRequestID))
                {
                    try
                    {
                        var dataModel = transScope.Repository.DataModel;
                        var doc       = dataModel.FacilitySubmittalElementDocuments.SingleOrDefault(p => p.Key == uniqueKey && !p.Voided);
                        if (doc != null)
                        {
                            transScope.WriteActivity(string.Format("FacilitySubmittalElementDocument CERSUniqueKey {0} metadata found.", uniqueKey));
                            var edtAuthorizationResult = CERSSecurityManager.EDTAuthorize(authResult.Account, doc.FacilitySubmittalElementResourceDocument.Resource.FacilitySubmittalElement.CERSID, PermissionRole.EDTFacilitySubmittalQuery);
                            transScope.Connect(edtAuthorizationResult.RegulatorID);

                            if (edtAuthorizationResult.Authorized)
                            {
                                if (doc.Document != null)
                                {
                                    transScope.WriteActivity("Document metadata found.");
                                    docData = DocumentStorage.GetBytes(doc.Document.Location);
                                    if (docData != null)
                                    {
                                        transScope.WriteActivity(string.Format("Document physically found in storage file size {0}kb.", doc.FileSize));
                                        transScope.Complete(EDTTransactionStatus.Accepted);
                                    }
                                    else
                                    {
                                        docPhysicallyNotFound = true;
                                        transScope.WriteMessage("Document NOT physically found in storage.", EDTTransactionMessageType.Error);
                                        transScope.Complete(EDTTransactionStatus.Rejected);
                                    }
                                }
                                else
                                {
                                    transScope.WriteMessage("Document metadata not found.", EDTTransactionMessageType.Error);
                                    transScope.Complete(EDTTransactionStatus.Rejected);
                                    docNotFound = true;
                                }
                            }
                            else
                            {
                                string errorMessage = "Account is not authorized to download this document. The account is not affiliated with any regulators associated with this Facility, or the account does not have sufficient rights.";
                                transScope.SetStatus(EDTTransactionStatus.Rejected);
                                transScope.WriteActivity(errorMessage);
                                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, errorMessage));
                            }
                        }
                        else
                        {
                            transScope.WriteActivity("Document Unique Key Not Found");
                            transScope.Complete(EDTTransactionStatus.Rejected);
                            docUniqueKeyNotFound = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        transScope.WriteActivity("Exception Occurred.", ex);
                        transScope.WriteMessage("Exception Occurred. " + ex.Format(), EDTTransactionMessageType.Error);
                        return(HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Format()));
                    }
                }

                if (docNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "Document for UniqueKey '" + uniqueKey + "' was not found."));
                }
                else if (docUniqueKeyNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "A Document does not exists with the UniqueKey '" + uniqueKey + "'."));
                }
                else if (docPhysicallyNotFound)
                {
                    return(HttpStatusCodeResult(HttpStatusCode.NotFound, "The document's metadata exists, but the physical document (filesystem) was not found."));
                }
                else
                {
                    return(File(docData, "application/octet-stream"));
                }
            }
            else
            {
                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, authResult));
            }
        }
Exemplo n.º 4
0
        public ActionResult ChemicalLibrary(string identifier)
        {
            Server.ScriptTimeout = 600;
            //No role based authentication needed, just make sure they have a valid credential for Library services.
            var authResult = CERSSecurityManager.AuthenticateHttpAuthorizationHeader();

            if (authResult.Result.Status == AuthenticationStatus.Success)
            {
                using (EDTTransactionScope transScope = new EDTTransactionScope(authResult.Account, EDTEndpoint.ChemicalLibraryQuery, Request.UserHostAddress, authenticationRequestID: authResult.EDTAuthenticationRequestID))
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(identifier))
                        {
                            List <Chemical> chemicals = new List <Chemical>();
                            Chemical        chemical  = null;

                            //1.) Check one.  Check cerskey
                            //Guid key = new Guid(identifier);
                            chemical = transScope.Repository.Chemicals.GetByCCLID(identifier);

                            //2.) Check two. Check CAS
                            if (chemical == null)
                            {
                                chemical = transScope.Repository.Chemicals.GetByCAS(identifier);

                                if (chemical == null)
                                {
                                    //3.) Check 3. Check USEpaSRSNumber
                                    chemical = transScope.Repository.Chemicals.GetByUSEPASRSNumber(identifier);
                                }
                            }

                            if (chemical != null)
                            {
                                chemicals.Add(chemical);
                            }

                            var xmlResult = chemicals.ToXml();
                            transScope.WriteActivity("Generated XML Package Successfully");
                            return(XmlElement(xmlResult));
                        }
                        else
                        {
                            var xmlResult = transScope.Repository.Chemicals.Search().ToXml();
                            transScope.WriteActivity("Generated XML Package Successfully");
                            return(XmlElement(xmlResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        transScope.WriteActivity("Exception Occurred", ex);
                        transScope.WriteMessage("Exception Occurred. " + ex.Format(), EDTTransactionMessageType.Error);
                        transScope.Complete(EDTTransactionStatus.ErrorProcessing);
                        return(HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
                    }
                }
            }
            else
            {
                return(HttpStatusCodeResult(HttpStatusCode.Unauthorized, authResult));
            }
        }