Initial commit: ZiRA Classification Tool for Zuyderland CMDB
This commit is contained in:
207
backend/src/services/dataService.ts
Normal file
207
backend/src/services/dataService.ts
Normal file
@@ -0,0 +1,207 @@
|
||||
import { config } from '../config/env.js';
|
||||
import { jiraAssetsService } from './jiraAssets.js';
|
||||
import { mockDataService } from './mockData.js';
|
||||
import { logger } from './logger.js';
|
||||
import type {
|
||||
ApplicationDetails,
|
||||
ApplicationStatus,
|
||||
ApplicationUpdateRequest,
|
||||
ReferenceValue,
|
||||
SearchFilters,
|
||||
SearchResult,
|
||||
TeamDashboardData,
|
||||
} from '../types/index.js';
|
||||
|
||||
// Determine if we should use real Jira Assets or mock data
|
||||
const useJiraAssets = !!(config.jiraPat && config.jiraSchemaId);
|
||||
|
||||
if (useJiraAssets) {
|
||||
logger.info('Using Jira Assets API for data');
|
||||
} else {
|
||||
logger.info('Using mock data (Jira credentials not configured)');
|
||||
}
|
||||
|
||||
export const dataService = {
|
||||
async searchApplications(
|
||||
filters: SearchFilters,
|
||||
page: number = 1,
|
||||
pageSize: number = 25
|
||||
): Promise<SearchResult> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.searchApplications(filters, page, pageSize);
|
||||
}
|
||||
return mockDataService.searchApplications(filters, page, pageSize);
|
||||
},
|
||||
|
||||
async getApplicationById(id: string): Promise<ApplicationDetails | null> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationById(id);
|
||||
}
|
||||
return mockDataService.getApplicationById(id);
|
||||
},
|
||||
|
||||
async updateApplication(
|
||||
id: string,
|
||||
updates: {
|
||||
applicationFunctions?: ReferenceValue[];
|
||||
dynamicsFactor?: ReferenceValue;
|
||||
complexityFactor?: ReferenceValue;
|
||||
numberOfUsers?: ReferenceValue;
|
||||
governanceModel?: ReferenceValue;
|
||||
applicationCluster?: ReferenceValue;
|
||||
applicationType?: ReferenceValue;
|
||||
hostingType?: ReferenceValue;
|
||||
businessImpactAnalyse?: ReferenceValue;
|
||||
overrideFTE?: number | null;
|
||||
applicationManagementHosting?: string;
|
||||
applicationManagementTAM?: string;
|
||||
}
|
||||
): Promise<boolean> {
|
||||
logger.info(`dataService.updateApplication called for ${id}`);
|
||||
logger.info(`Updates from frontend: ${JSON.stringify(updates)}`);
|
||||
|
||||
if (useJiraAssets) {
|
||||
// Convert ReferenceValues to keys for Jira update
|
||||
const jiraUpdates: ApplicationUpdateRequest = {
|
||||
applicationFunctions: updates.applicationFunctions?.map((f) => f.key),
|
||||
dynamicsFactor: updates.dynamicsFactor?.key,
|
||||
complexityFactor: updates.complexityFactor?.key,
|
||||
numberOfUsers: updates.numberOfUsers?.key,
|
||||
governanceModel: updates.governanceModel?.key,
|
||||
applicationCluster: updates.applicationCluster?.key,
|
||||
applicationType: updates.applicationType?.key,
|
||||
hostingType: updates.hostingType?.key,
|
||||
businessImpactAnalyse: updates.businessImpactAnalyse?.key,
|
||||
overrideFTE: updates.overrideFTE,
|
||||
applicationManagementHosting: updates.applicationManagementHosting,
|
||||
applicationManagementTAM: updates.applicationManagementTAM,
|
||||
};
|
||||
logger.info(`Converted to Jira format: ${JSON.stringify(jiraUpdates)}`);
|
||||
return jiraAssetsService.updateApplication(id, jiraUpdates);
|
||||
}
|
||||
return mockDataService.updateApplication(id, updates);
|
||||
},
|
||||
|
||||
async getDynamicsFactors(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getDynamicsFactors();
|
||||
}
|
||||
return mockDataService.getDynamicsFactors();
|
||||
},
|
||||
|
||||
async getComplexityFactors(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getComplexityFactors();
|
||||
}
|
||||
return mockDataService.getComplexityFactors();
|
||||
},
|
||||
|
||||
async getNumberOfUsers(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getNumberOfUsers();
|
||||
}
|
||||
return mockDataService.getNumberOfUsers();
|
||||
},
|
||||
|
||||
async getGovernanceModels(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getGovernanceModels();
|
||||
}
|
||||
return mockDataService.getGovernanceModels();
|
||||
},
|
||||
|
||||
async getOrganisations(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getOrganisations();
|
||||
}
|
||||
return mockDataService.getOrganisations();
|
||||
},
|
||||
|
||||
async getHostingTypes(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getHostingTypes();
|
||||
}
|
||||
return mockDataService.getHostingTypes();
|
||||
},
|
||||
|
||||
async getBusinessImpactAnalyses(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getBusinessImpactAnalyses();
|
||||
}
|
||||
return mockDataService.getBusinessImpactAnalyses();
|
||||
},
|
||||
|
||||
async getApplicationManagementHosting(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationManagementHosting();
|
||||
}
|
||||
return mockDataService.getApplicationManagementHosting();
|
||||
},
|
||||
|
||||
async getApplicationManagementTAM(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationManagementTAM();
|
||||
}
|
||||
return mockDataService.getApplicationManagementTAM();
|
||||
},
|
||||
|
||||
async getStats(includeDistributions: boolean = true) {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getStats(includeDistributions);
|
||||
}
|
||||
return mockDataService.getStats();
|
||||
},
|
||||
|
||||
async getApplicationFunctions(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationFunctions();
|
||||
}
|
||||
return mockDataService.getApplicationFunctions();
|
||||
},
|
||||
|
||||
async getApplicationFunctionCategories(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationFunctionCategories();
|
||||
}
|
||||
return mockDataService.getApplicationFunctionCategories();
|
||||
},
|
||||
|
||||
async getApplicationClusters(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationClusters();
|
||||
}
|
||||
return mockDataService.getApplicationClusters();
|
||||
},
|
||||
|
||||
async getApplicationTypes(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getApplicationTypes();
|
||||
}
|
||||
return mockDataService.getApplicationTypes();
|
||||
},
|
||||
|
||||
async getBusinessImportance(): Promise<ReferenceValue[]> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getBusinessImportance();
|
||||
}
|
||||
return mockDataService.getBusinessImportance();
|
||||
},
|
||||
|
||||
isUsingJiraAssets(): boolean {
|
||||
return useJiraAssets;
|
||||
},
|
||||
|
||||
async testConnection(): Promise<boolean> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.testConnection();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
async getTeamDashboardData(excludedStatuses: ApplicationStatus[] = []): Promise<TeamDashboardData> {
|
||||
if (useJiraAssets) {
|
||||
return jiraAssetsService.getTeamDashboardData(excludedStatuses);
|
||||
}
|
||||
return mockDataService.getTeamDashboardData(excludedStatuses);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user