Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ImportManager Into Injectable Service #3652

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading