Exemplo n.º 1
0
        public ProviderEndpoint EditEndpoint(int appId, int endpointId, ProviderEndpointModel model, LoggedInUserDetails user)
        {
            // Check whether organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException(
                          "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Get endpoint
            var endpoint = _endpoints.FirstOrDefault(i => i.ID == endpointId);

            // Check whether endpoint found
            if (endpoint == null)
            {
                throw new BaseException("Endpoint not found");
            }

            // Check whether user has access to application
            _security.CheckAccessToApplication(user, appId);

            // Setup update details
            endpoint.Description = model.Description;
            endpoint.Name        = string.IsNullOrEmpty(model.Name) ? string.Empty : model.Name;
            endpoint.ServiceUri  = model.Uri;
            endpoint.IsActive    = model.IsActive;
            endpoint.UpdatedAt   = GetDate;
            endpoint.UpdatedBy   = user.ID;

            // Save changes
            _endpoints.Update(endpoint);
            return(endpoint);
        }
Exemplo n.º 2
0
        public ActionResult EditProviderEndpoint(int id, int endpointId)
        {
            // Setup model
            ProviderEndpointModel result = _applications.SetupProviderEndpointModel(id, endpointId, LoggedInUser);

            // Return result
            return(PartialView("_EditProviderEndpoint", result));
        }
Exemplo n.º 3
0
        public ActionResult AddProviderEndpoint(int id)
        {
            // Setup add provider endpoint model
            ProviderEndpointModel result = _applications.SetupAddProviderEndpointModel(id, LoggedInUser);

            // Return result
            return(PartialView("_AddProviderEndpoint", result));
        }
Exemplo n.º 4
0
        public ActionResult EditProviderEndpoint(int id, int endpointId, ProviderEndpointModel model)
        {
            // Edit endpoint details
            ProviderEndpoint endpoint = _applications.EditEndpoint(id, endpointId, model, LoggedInUser);

            // Setup status
            Toastr.Success("Changes to endpoint were successfully saved.");

            // Return result
            return(RedirectToAction("Details", new { endpointId = endpoint.ApplicationId }));
        }
Exemplo n.º 5
0
        public ActionResult AddProviderEndpoint(int id, ProviderEndpointModel model)
        {
            // Add endpoint
            _applications.AddEndpoint(id, model, LoggedInUser);

            // Setup status message
            Toastr.Success("Provider endpoint was successfully created! You can add data agreement for this schema now.");

            // Return result
            return(RedirectToAction("Details", new { id }));
        }
        public static ProviderEndpointModel ToModel(this ProviderEndpoint endpoint)
        {
            var result = new ProviderEndpointModel();

            result.Name          = endpoint.Name;
            result.Uri           = endpoint.ServiceUri;
            result.Description   = endpoint.Description;
            result.ID            = endpoint.ID;
            result.LastUpdatedAt = endpoint.UpdatedAt;
            result.IsActive      = endpoint.IsActive;
            return(result);
        }
Exemplo n.º 7
0
        public void AddEndpoint(int id, ProviderEndpointModel model, LoggedInUserDetails user)
        {
            // Check whether organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException("Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether application does not belong to user
            _security.CheckAccessToApplication(user, id);

            // Get schema identifiers used by this application
            var usedSchemas = _endpoints.Where(i => i.ApplicationId == id).Select(i => i.DataSchemaID);

            // Get all published schemas
            var schemas = _schemas.Where(i => i.Status == (int)TemplateStatus.Active).Select(i => i.ID);

            // Get unused published schemas
            var availableSchemas = schemas.Except(usedSchemas).ToList();

            // Check whether no available schemas found
            if (!availableSchemas.Any() || !availableSchemas.Contains(model.SelectedSchemaID))
            {
                // Return error if all schemas in use
                throw new BaseException("Your application already uses all available schemas. DataLinker allows only one endpoint per schema.");
            }

            // Get selected schema
            var dataSchema = _schemas.FirstOrDefault(i => i.ID == model.SelectedSchemaID);

            // Setup endpoint details
            var endPoint = new ProviderEndpoint
            {
                DataSchemaID   = model.SelectedSchemaID,
                ApplicationId  = id,
                CreatedAt      = GetDate,
                CreatedBy      = user.ID.Value,
                Description    = model.Description,
                IsActive       = true,
                IsIndustryGood = dataSchema.IsIndustryGood,
                Name           = string.IsNullOrEmpty(model.Name) ? string.Empty : model.Name,
                ServiceUri     = model.Uri
            };

            // Save new endpoint
            _endpoints.Add(endPoint);
        }
Exemplo n.º 8
0
        public ProviderEndpointModel SetupAddProviderEndpointModel(int id, LoggedInUserDetails user)
        {
            // Check whether organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException("Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether application belongs to user
            _security.CheckAccessToApplication(user, id);

            // Get published schemas
            var schemas = _schemas.Where(i => i.Status == (int)TemplateStatus.Active).ToList();

            // Check whether no published schemas
            if (!schemas.Any())
            {
                throw new BaseException("Sorry, we don't have published schemas.");
            }

            // Get schema ids used by this application
            var schemaIds = _endpoints.Where(i => i.ApplicationId == id).Select(i => i.DataSchemaID);

            // Get schemas unused by this application
            var availableSchemas = schemas.Where(i => schemaIds.All(p => p != i.ID));

            // Setup model
            var result = new ProviderEndpointModel
            {
                Schemas = new Dictionary <string, string>()
            };

            // Setup schemas
            foreach (var schema in availableSchemas)
            {
                result.Schemas.Add(schema.ID.ToString(), schema.Name);
            }

            // Check whether no schemas available for usage
            if (!result.Schemas.Any())
            {
                throw new BaseException("Your application already uses all available schemas. DataLinker allows only one endpoint per schema.");
            }

            return(result);
        }
Exemplo n.º 9
0
        private List <ProviderEndpointModel> GetEndpointModels(int applicationId)
        {
            // Define result
            var result = new List <ProviderEndpointModel>();

            // Get endpoints for provider
            var endpoints = _endpoints.Where(p => p.ApplicationId == applicationId).ToList();

            // Setup provider endpoints
            foreach (var providerEndpoint in endpoints)
            {
                // Get schema
                var schema = _schemas.FirstOrDefault(i => i.ID == providerEndpoint.DataSchemaID);

                // Setup endpoint model
                var endpointModel = new ProviderEndpointModel()
                {
                    Description = providerEndpoint.Description,
                    ID          = providerEndpoint.ID,
                    Name        = providerEndpoint.Name
                };

                endpointModel.Schema = schema.ToModel();

                // Setup endpoint status
                endpointModel.LicenseStatus = (PublishStatus)GetLicenseStatus(applicationId, schema.ID);

                // Get schema file
                var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == providerEndpoint.DataSchemaID);

                // Setup schema file Id for download URL
                endpointModel.Schema.SchemaFileId = schemaFile.ID;
                result.Add(endpointModel);
            }

            // Return result
            return(result);
        }