public void Add(LicenseMatch data) { // Validate data // Save data _service.Add(data); }
public void UpdateWithNewProvider(int schemaId, int providerLicenseId, int userId) { // Get provider clauses for a given license var providerClauses = _organisationClauses.Where(i => i.OrganizationLicenseID == providerLicenseId).ToList(); // Get published licenses var publishedLicenses = _organisationLicenses.Where(i => i.Status == (int)PublishStatus.Published); // Get consumer licenses for a given schema from published var consumerLicenses = publishedLicenses.Where(i => i.ProviderEndpointID == 0 && i.DataSchemaID == schemaId); // for each consumer get clause selection foreach (var consumerLicense in consumerLicenses) { // Compare provider selections with consumer selection var isMatch = IsClausesMatch(consumerLicense.ID, providerClauses); if (isMatch) { // Add consumer matches for those who match provider selections // Setup license match var licenseMatch = new LicenseMatch { ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicenseId, CreatedAt = GetDate, CreatedBy = userId }; // Save license match _service.Add(licenseMatch); } } }
public void CreateConsumerTemplatedLicense(int appId, int schemaId, int providerLicenseId, LoggedInUserDetails user) { // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException(orgIsInactiveError); } // Get published template var licenseTemplate = _licenseTemplates.FirstOrDefault(i => i.Status == (int)TemplateStatus.Active); var providerLicense = _service.GetById(providerLicenseId); if (providerLicense == null) { throw new BaseException($"Provider license not found {providerLicenseId}"); } // Create consumer license var consumerLicense = new OrganizationLicense { ApplicationID = appId, DataSchemaID = schemaId, LicenseTemplateID = providerLicense.LicenseTemplateID, CustomLicenseID = providerLicense.CustomLicenseID, CreatedAt = GetDate, Status = (int)PublishStatus.Draft, CreatedBy = user.ID.Value }; _service.Add(consumerLicense); // Setup consumer match var consumerMatch = new LicenseMatch { ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicenseId, CreatedBy = user.ID.Value, CreatedAt = GetDate }; // Save consumer match _licenseMatches.Add(consumerMatch); // Send for legal approval RequestLicenseVerification(consumerLicense.ID, appId, schemaId, user); }
public List <OrganizationLicense> CreateConsumerCustomLicense(int appId, int schemaId, List <DataProvider> providers, LoggedInUserDetails user) { // Check access to application _security.CheckAccessToApplication(user, appId); // Get selected provider licenses var selectedProviders = providers.Where(i => i.IsSelected == true); // Define result var result = new List <OrganizationLicense>(); // Create organisation license with the same custom license id foreach (var providerLicense in selectedProviders) { var consumerLicense = new OrganizationLicense { ApplicationID = appId, DataSchemaID = schemaId, CustomLicenseID = providerLicense.CustomLicenseId, CreatedBy = user.ID.Value, CreatedAt = GetDate, Status = (int)PublishStatus.Draft }; // Save new consumer license to database _service.Add(consumerLicense); // Create license match for consumer & provider license var licenseMatch = new LicenseMatch { ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicense.LicenseId, CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Save new license match _licenseMatches.Add(licenseMatch); // Add created license to result result.Add(consumerLicense); } // Return created data return(result); }
public void Init() { schemaModel = new SchemaModel { DataSchemaID = 1, Description = "Blah blah", Name = "Name", Status = TemplateStatus.Draft, Version = 1 }; dSchemaDraft = new DataSchema { ID = 1, Name = "Draft", CreatedBy = 1, CreatedAt = today, Status = (int)TemplateStatus.Draft }; dSchemaPublished = new DataSchema { ID = 2, Name = "Published", CreatedAt = today, CreatedBy = 1, PublishedAt = today }; dSchemaRetracted = new DataSchema { ID = 3, Name = "Retracted", CreatedAt = today, Status = (int)TemplateStatus.Retracted }; schemaFile = new SchemaFile { DataSchemaID = dSchemaDraft.ID, CreatedBy = 1, FileFormat = ".xml", ID = 1 }; consumerOrganization = new Organization { ID = 1 }; providerOrganization = new Organization { ID = 2 }; providerApplication = new Application { ID = 1, OrganizationID = providerOrganization.ID }; consumerApplication = new Application { ID = 2, OrganizationID = consumerOrganization.ID }; providerLicense = new OrganizationLicense { ID = 1, ApplicationID = providerApplication.ID }; consumerLicense = new OrganizationLicense { ID = 2, ApplicationID = consumerApplication.ID }; licenseMatch = new LicenseMatch { ID = 1, ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicense.ID }; endpoint = new ProviderEndpoint { ApplicationId = providerApplication.ID, DataSchemaID = dSchemaPublished.ID, IsActive = true }; var file = new Mock <HttpPostedFileBase>(); file.Setup(i => i.InputStream).Returns(new MemoryStream()); file.Setup(i => i.FileName).Returns("file.xml"); schemaModel.UploadFile = file.Object; var mock = new Mock <UrlHelper>(); // Setup file var fileMock = new Mock <HttpPostedFileBase>(); fileMock.Setup(x => x.FileName).Returns("file1.xml"); var context = new Mock <ControllerContext>(); context.Setup(m => m.HttpContext.Request.Files.Count).Returns(1); context.Setup(m => m.HttpContext.Request.Files[0]).Returns(fileMock.Object); context.Setup(m => m.HttpContext.Request.Url).Returns(new Uri("http://test.com")); sysAdmin = new User { ID = 1, IsActive = true, Email = "*****@*****.**", IsSysAdmin = true }; // Setup Services metaDataService = new Mock <IDataSchemaService>(); fileService = new Mock <ISchemaFileService>(); organizationService = new Mock <IOrganizationService>(); userService = new Mock <IUserService>(); notificationService = new Mock <INotificationService>(); endpointService = new Mock <IProviderEndpointService>(); applicationService = new Mock <IApplicationsService>(); configurationService = new Mock <IConfigurationService>(); organizationLicenseService = new Mock <IOrganizationLicenseService>(); userService.Setup(u => u.Get(sysAdmin.ID)).Returns(sysAdmin); configurationService.SetupProperty(p => p.ManageSchemasPageSize, 5); // Setup organization service organizationService.Setup(m => m.Get(consumerOrganization.ID)).Returns(consumerOrganization); organizationService.Setup(m => m.Get(providerOrganization.ID)).Returns(providerOrganization); // Setup application service applicationService.Setup(m => m.Get(providerApplication.ID)).Returns(providerApplication); applicationService.Setup(m => m.Get(consumerApplication.ID)).Returns(consumerApplication); // Setup endpoint service endpointService.Setup(m => m.Get(endpoint.ID)).Returns(endpoint); // Setup organization licenses organizationLicenseService.Setup(i => i.Get(It.IsAny <Expression <Func <OrganizationLicense, bool> > >())) .Returns(new List <OrganizationLicense>()); organizationLicenseService.Setup(m => m.GetAllProviderLicensesForMonth(It.IsAny <DateTime>())) .Returns(new List <OrganizationLicense> { providerLicense }); organizationLicenseService.Setup(m => m.Get(consumerLicense.ID)).Returns(consumerLicense); // Schema file service fileService.Setup(m => m.Add(It.IsAny <SchemaFile>())).Returns(true); fileService.Setup(m => m.Update(It.IsAny <SchemaFile>())).Returns(true); fileService.Setup(m => m.Get(schemaFile.ID)).Returns(schemaFile); fileService.Setup(m => m.Get(It.IsAny <Expression <Func <SchemaFile, bool> > >())) .Returns(new List <SchemaFile> { schemaFile }); // Dataschema service metaDataService.Setup(m => m.GetAllSchemas(1, false)).Returns(new List <DataSchema> { dSchemaDraft }); metaDataService.Setup(m => m.Add(It.IsAny <DataSchema>())).Returns(true); metaDataService.Setup(m => m.Update(It.IsAny <DataSchema>())).Returns(true); metaDataService.Setup(m => m.Get(dSchemaDraft.ID)).Returns(dSchemaDraft); metaDataService.Setup(m => m.Get(dSchemaPublished.ID)).Returns(dSchemaPublished); metaDataService.Setup(m => m.Get(dSchemaRetracted.ID)).Returns(dSchemaRetracted); // License matches var mService = new MockService <LicenseMatch>(); matchesService = new LicenseMatchesService(mService); matchesService.Add(licenseMatch); // Setup controller controller = new SchemasController(metaDataService.Object, fileService.Object, userService.Object, organizationService.Object, endpointService.Object, applicationService.Object, notificationService.Object, organizationLicenseService.Object, matchesService, configurationService.Object) { ControllerContext = context.Object, LoggedInUser = new LoggedInUserDetails(sysAdmin), Url = mock.Object }; }