public Dictionary <string, string> GetServicesFromKartkatalogen(string category)
        {
            Dictionary <string, string> ServiceList = new Dictionary <string, string>();
            string url          = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "api/search/?facets[0]name=type&facets[0]value=service&limit=1000&orderby=title";
            var    organization = _accessControlService.GetSecurityClaim("organization")[0];

            if (category == Constants.AlertCategoryDataset)
            {
                if (_accessControlService.IsAdmin())
                {
                    url = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=7000&orderby=title";
                }
                else if (organization.ToLower() == "kartverket")
                {
                    url = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=4000&orderby=title&facets[1]name=organization&facets[1]value=Kartverket&facets[2]name=organization&facets[2]value=Geovekst";
                }
                else
                {
                    url = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"] + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=4000&orderby=title&facets[1]name=organization&facets[1]value=" + organization;
                }
            }
            WebClient c = new WebClient();

            c.Encoding = System.Text.Encoding.UTF8;
            var data     = c.DownloadString(url);
            var response = Newtonsoft.Json.Linq.JObject.Parse(data);

            var result = response["Results"];

            foreach (var service in result)
            {
                var ServiceUuid = service["Uuid"].ToString();
                if (string.IsNullOrWhiteSpace(ServiceUuid))
                {
                    ServiceUuid = service["Uuid"].ToString();
                }

                var Organization = service["Organization"] != null ? service["Organization"].ToString() : "";

                if (!ServiceList.ContainsKey(ServiceUuid))
                {
                    if (_accessControlService.IsAdmin() || _accessControlService.IsItemOwner(Organization, _accessControlService.GetSecurityClaim("organization")[0]))
                    {
                        if (!service["Title"].ToString().StartsWith("Høydedata") && !service["Title"].ToString().StartsWith("Ortofoto"))
                        {
                            ServiceList.Add(ServiceUuid, service["Title"].ToString());
                        }
                    }
                }
            }
            return(ServiceList);
        }
        public Dictionary <string, string> GetServicesFromKartkatalogen(string category)
        {
            Dictionary <string, string> serviceList = new Dictionary <string, string>();
            var    urlToKartkatalogenApi            = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogenUrl"];
            string url = urlToKartkatalogenApi + "api/search/?facets[0]name=type&facets[0]value=service&limit=1000&orderby=title";
            var    currentUserOrganizationName = CurrentUserOrganizationName();

            // TODO - handle limit in API request
            if (category == Constants.AlertCategoryDataset)
            {
                if (_accessControlService.IsAdmin())
                {
                    url = urlToKartkatalogenApi + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=7000&orderby=title";
                }
                else if (currentUserOrganizationName.ToLower() == "kartverket")
                {
                    url = urlToKartkatalogenApi + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=7000&orderby=title&facets[1]name=organization&facets[1]value=Kartverket&facets[2]name=organization&facets[2]value=Geovekst";
                }
                else
                {
                    url = urlToKartkatalogenApi + "api/search/?facets[0]name=type&facets[0]value=dataset&limit=7000&orderby=title&facets[1]name=organization&facets[1]value=" + currentUserOrganizationName;
                }
            }
            WebClient c = new WebClient();

            c.Encoding = System.Text.Encoding.UTF8;
            var data     = c.DownloadString(url);
            var response = Newtonsoft.Json.Linq.JObject.Parse(data);

            var result = response["Results"];

            foreach (var service in result)
            {
                var serviceUuid = service["Uuid"].ToString();

                var serviceOrganization = service["Organization"] != null ? service["Organization"].ToString() : "";

                if (!serviceList.ContainsKey(serviceUuid))
                {
                    if (_accessControlService.IsAdmin() || _accessControlService.IsItemOwner(serviceOrganization, currentUserOrganizationName))
                    {
                        if (!service["Title"].ToString().StartsWith("Høydedata") && !service["Title"].ToString().StartsWith("Ortofoto"))
                        {
                            serviceList.Add(serviceUuid, service["Title"].ToString());
                        }
                    }
                }
            }
            return(serviceList);
        }
Example #3
0
        private Document initialisationDocument(Document inputDocument, HttpPostedFileBase documentfile, HttpPostedFileBase thumbnail, bool retired = false, bool sosi = false, Document originalDocument = null)
        {
            Document document = GetDocument(originalDocument);

            document.systemId              = GetSystemId(document.systemId);
            document.name                  = DocumentName(inputDocument.name);
            document.seoname               = DocumentSeoName(inputDocument.name);
            document.modified              = DateTime.Now;
            document.description           = inputDocument.description;
            document.approvalDocument      = inputDocument.approvalDocument;
            document.approvalReference     = inputDocument.approvalReference;
            document.ApplicationSchema     = inputDocument.ApplicationSchema;
            document.GMLApplicationSchema  = inputDocument.GMLApplicationSchema;
            document.CartographyFile       = inputDocument.CartographyFile;
            document.CartographyDetailsUrl = inputDocument.CartographyDetailsUrl;
            document.versionName           = inputDocument.versionName;
            document.versionNumber         = GetVersionNr(inputDocument.versionNumber, originalDocument, inputDocument);
            document.registerId            = GetRegisterId(inputDocument, document);
            document.Accepted              = inputDocument.Accepted;
            string url = System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "data/" + Document.DataDirectory;

            document.documentUrl     = documentUrl(url, documentfile, document.documentUrl, document.name, document.register.name, document.versionNumber);
            document.thumbnail       = GetThumbnail(document, documentfile, url, thumbnail);
            document.documentownerId = GetDocumentOwnerId(inputDocument.documentownerId);
            document.submitterId     = GetSubmitterId(inputDocument.submitterId);
            document.versioningId    = GetVersioningId(document, inputDocument.versioningId);

            bool sendNotification = false;

            if (originalDocument == null)
            {
                document.dateSubmitted   = DateTime.Now;
                document.statusId        = "Submitted";
                db.Entry(document).State = EntityState.Modified;
                db.RegisterItems.Add(document);
                if (!_accessControlService.IsAdmin())
                {
                    sendNotification = true;
                }
            }
            else
            {
                ApprovalProcess(document, retired, inputDocument, sosi);
                db.Entry(document).State = EntityState.Modified;
            }

            _translationService.UpdateTranslations(inputDocument, document);

            db.SaveChanges();
            if (sendNotification)
            {
                _notificationService.SendSubmittedNotification(document);
            }

            return(document);
        }
        //[Route("dataset/{parentRegister}/{registerowner}/{registername}/{itemowner}/{itemname}/rediger")]
        //[Route("dataset/{registername}/{itemowner}/{itemname}/rediger")]
        public ActionResult Edit(Dataset dataset, CoverageDataset coverage, string registername, string itemname, string metadataUuid, string parentRegister, string registerowner, string itemowner, bool dontUpdateDescription = false)
        {
            Dataset originalDataset = (Dataset)_registerItemService.GetRegisterItem(parentRegister, registername, itemname, 1, itemowner);

            if (originalDataset != null)
            {
                if (metadataUuid != null)
                {
                    Dataset model = GetMetadataFromKartkatalogen(originalDataset, metadataUuid, dontUpdateDescription);
                    Viewbags(model);
                    return(View(model));
                }

                if (originalDataset.IsNationalDataset())
                {
                    if (_accessControlService.IsAdmin())
                    {
                        return(EditDataset(dataset, originalDataset));
                    }
                    if (_accessControlService.IsMunicipalUser())
                    {
                        return(EditCoverageDataset(coverage, originalDataset));
                    }
                }
                else if (_accessControlService.Access(originalDataset))
                {
                    if (ModelState.IsValid)
                    {
                        return(EditDataset(dataset, originalDataset, coverage));
                    }
                }
                else
                {
                    throw new HttpException(401, "Access Denied");
                }
            }
            Viewbags(originalDataset);
            return(View(originalDataset));
        }
        private Document initialisationDocument(Document inputDocument, HttpPostedFileBase documentfile, HttpPostedFileBase thumbnail, bool retired = false, bool sosi = false, Document originalDocument = null)
        {
            Document document = GetDocument(originalDocument);

            document.systemId                  = GetSystemId(document.systemId);
            document.name                      = DocumentName(inputDocument.name);
            document.seoname                   = DocumentSeoName(inputDocument.name);
            document.modified                  = DateTime.Now;
            document.description               = inputDocument.description;
            document.approvalDocument          = inputDocument.approvalDocument;
            document.approvalReference         = inputDocument.approvalReference;
            document.UmlModelTreeStructureLink = inputDocument.UmlModelTreeStructureLink;
            document.ApplicationSchema         = inputDocument.ApplicationSchema;
            document.GMLApplicationSchema      = inputDocument.GMLApplicationSchema;
            document.CartographyFile           = inputDocument.CartographyFile;
            document.CartographyDetailsUrl     = inputDocument.CartographyDetailsUrl;
            document.versionName               = inputDocument.versionName;
            document.versionNumber             = GetVersionNr(inputDocument.versionNumber, originalDocument, inputDocument);
            document.registerId                = GetRegisterId(inputDocument, document);
            document.Accepted                  = inputDocument.Accepted;
            document.documentownerId           = GetDocumentOwnerId(inputDocument.documentownerId);
            if (document.documentownerId != Guid.Empty)
            {
                document.documentowner = db.Organizations.Where(o => o.systemId == document.documentownerId).FirstOrDefault();
            }
            document.submitterId = GetSubmitterId(inputDocument.submitterId);
            string url = System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "data/" + Document.DataDirectory;

            document.documentUrl = documentUrl(url, documentfile, document.documentUrl, document.name, document.register.name, document.versionNumber, document?.status?.value, originalDocument?.status?.value);
            if (document.documentUrl == "IllegalSchemaLocation")
            {
                ModelState.AddModelError("ErrorMessageFileName", ErrorMessageIllegalSchemaLocation);
                document.documentUrl = "";
                return(document);
            }
            document.documentUrl2 = inputDocument.documentUrl2;
            document.thumbnail    = GetThumbnail(document, documentfile, url, thumbnail);
            document.versioningId = GetVersioningId(document, inputDocument.versioningId);

            bool sendNotification = false;

            if (originalDocument == null)
            {
                document.dateSubmitted = DateTime.Now;
                if (document.documentownerId != Guid.Empty)
                {
                    document.documentowner = db.Organizations.Where(o => o.systemId == document.documentownerId).FirstOrDefault();
                }
                document.statusId        = "Submitted";
                db.Entry(document).State = EntityState.Modified;
                db.RegisterItems.Add(document);
                if (!_accessControlService.IsAdmin())
                {
                    sendNotification = true;
                }
            }
            else
            {
                ApprovalProcess(document, retired, inputDocument, sosi);
                db.Entry(document).State = EntityState.Modified;
            }

            _translationService.UpdateTranslations(inputDocument, document);

            db.SaveChanges();
            if (sendNotification)
            {
                _notificationService.SendSubmittedNotification(document);
            }

            return(document);
        }
 public static bool IsAdmin()
 {
     return(AccessControl.IsAdmin());
 }
 private bool IsAdmin()
 {
     return(_accessControlService.IsAdmin());
 }