Skip to content

Commit

Permalink
Merge pull request #3652 from cisagov/feature/CRRM-128
Browse files Browse the repository at this point in the history
Refactor ImportManager Into Injectable Service
  • Loading branch information
randywoods authored Nov 28, 2023
2 parents 292c9d0 + 06a0018 commit 0984982
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace CSETWebCore.Business.AssessmentIO.Import
{
public class ImportManager
public class ImportManager : IImportManager
{
private ITokenManager _token;
private IAssessmentUtil _assessmentUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
////////////////////////////////
//
// Copyright 2023 Battelle Energy Alliance, LLC
//
//
////////////////////////////////
using CSETWebCore.DataLayer.Model;
using System.Threading.Tasks;

namespace CSETWebCore.Business.AssessmentIO.Import
{
public interface IImportManager
{
Task ProcessCSETAssessmentImport(byte[] zipFileFromDatabase, int? currentUserId, string accessKey, CSETContext context, string password = "", bool overwriteAssessment = false);
void LaunchLegacyCSETProcess(string csetFilePath, string token, string processPath, string apiURL);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////
////////////////////////////////
//
// Copyright 2023 Battelle Energy Alliance, LLC
//
Expand All @@ -11,36 +11,30 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Net.Http.Headers;
using System;
using System.IO;
using System.Threading.Tasks;
using Ionic.Zip;
using System.Collections.Generic;
using System.Net.Http;

namespace CSETWebCore.Api.Controllers
{
public class AssessmentImportController : ControllerBase
{
private ITokenManager _tokenManager;
private CSETContext _context;
private IAssessmentUtil _assessmentUtil;
private IUtilities _utilities;
private IImportManager _importManager;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="token"></param>
/// <param name="context"></param>
/// <param name="assessmentUtil"></param>
public AssessmentImportController(ITokenManager token, CSETContext context, IAssessmentUtil assessmentUtil, IUtilities utilities)
public AssessmentImportController(ITokenManager token, CSETContext context, IImportManager importManager)
{
_tokenManager = token;
_context = context;
_assessmentUtil = assessmentUtil;
_utilities = utilities;
_importManager = importManager;
}

[HttpGet]
Expand Down Expand Up @@ -70,8 +64,7 @@ public async Task<IActionResult> ImportLegacyAssessment()

try
{
var manager = new ImportManager(_tokenManager, _assessmentUtil, _utilities, _context);
await manager.ProcessCSETAssessmentImport(target.ToArray(), _tokenManager.GetUserId(), _tokenManager.GetAccessKey(), _context);
await _importManager.ProcessCSETAssessmentImport(target.ToArray(), _tokenManager.GetUserId(), _tokenManager.GetAccessKey(), _context);
}
catch (Exception)
{
Expand Down Expand Up @@ -127,9 +120,7 @@ public async Task<IActionResult> ImportAssessment([FromHeader] string pwd)
}
}


var manager = new ImportManager(_tokenManager, _assessmentUtil, _utilities, _context);
await manager.ProcessCSETAssessmentImport(bytes, currentUserId, accessKey, _context, pwd);
await _importManager.ProcessCSETAssessmentImport(bytes, currentUserId, accessKey, _context, pwd);
}
}
catch (Exception e)
Expand Down
2 changes: 2 additions & 0 deletions CSETWebApi/CSETWeb_Api/CSETWeb_ApiCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
using System.Collections.Generic;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using CSETWebCore.Business.AssessmentIO.Import;

namespace CSETWeb_ApiCore
{
Expand Down Expand Up @@ -155,6 +156,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<IStandardSpecficLevelRepository, StandardSpecficLevelRepository>();
services.AddTransient<ITokenManager, TokenManager>();
services.AddTransient<IApiKeyManager, ApiKeyManager>();
services.AddTransient<IImportManager, ImportManager>();
services.AddTransient<ILocalInstallationHelper, LocalInstallationHelper>();
services.AddTransient<IUserAuthentication, UserAuthentication>();
services.AddTransient<IUserBusiness, UserBusiness>();
Expand Down

0 comments on commit 0984982

Please sign in to comment.