From 1cdec11c26eaf638aec061e23ec120915d7105a0 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 18 Jun 2024 15:50:39 +0200 Subject: [PATCH] Add logging for Service Manager --- .../production/services/ServiceManager.java | 225 +++++++++++++----- 1 file changed, 172 insertions(+), 53 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java b/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java index 30c82187d79..1a14c35d03b 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java @@ -13,6 +13,8 @@ import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.kitodo.production.services.command.CommandService; import org.kitodo.production.services.command.KitodoScriptService; import org.kitodo.production.services.data.AuthorityService; @@ -57,6 +59,7 @@ import org.kitodo.production.services.validation.MetadataValidationService; public class ServiceManager { + private static final Logger logger = LogManager.getLogger(ServiceManager.class); private static AuthorityService authorityService; private static BatchService batchService; @@ -109,654 +112,748 @@ private ServiceManager() { private static void initializeAuthorizationService() { if (Objects.isNull(authorityService)) { + logServiceInitialization(); authorityService = AuthorityService.getInstance(); } } private static void initializeBatchService() { if (Objects.isNull(batchService)) { + logServiceInitialization(); batchService = BatchService.getInstance(); } } private static void initializeClientService() { if (Objects.isNull(clientService)) { + logServiceInitialization(); clientService = ClientService.getInstance(); } } private static void initializeDataEditorService() { if (Objects.isNull(dataEditorService)) { + logServiceInitialization(); dataEditorService = new DataEditorService(); } } private static void initializeDocketService() { if (Objects.isNull(docketService)) { + logServiceInitialization(); docketService = DocketService.getInstance(); } } private static void initializeFilterService() { if (Objects.isNull(filterService)) { + logServiceInitialization(); filterService = FilterService.getInstance(); } } private static void initializeKitodoScriptService() { if (Objects.isNull(kitodoScriptService)) { + logServiceInitialization(); kitodoScriptService = KitodoScriptService.getInstance(); } } private static void initializeImageService() { if (Objects.isNull(imageService)) { + logServiceInitialization(); imageService = ImageService.getInstance(); } } private static void initializeImportService() { if (Objects.isNull(importService)) { + logServiceInitialization(); importService = ImportService.getInstance(); } } private static void initializeLdapGroupService() { if (Objects.isNull(ldapGroupService)) { + logServiceInitialization(); ldapGroupService = new LdapGroupService(); } } private static void initializeLdapServerService() { if (Objects.isNull(ldapServerService)) { + logServiceInitialization(); ldapServerService = LdapServerService.getInstance(); } } private static void initializeMetsService() { if (Objects.isNull(metsService)) { + logServiceInitialization(); metsService = MetsService.getInstance(); } } private static void initializeMassImportService() { if (Objects.isNull(massImportService)) { + logServiceInitialization(); massImportService = MassImportService.getInstance(); } } private static void initializePropertyService() { if (Objects.isNull(propertyService)) { + logServiceInitialization(); propertyService = PropertyService.getInstance(); } } private static void initializeProcessService() { if (Objects.isNull(processService)) { + logServiceInitialization(); processService = ProcessService.getInstance(); } } private static void initializeFolderService() { if (Objects.isNull(folderService)) { + logServiceInitialization(); folderService = new FolderService(); } } private static void initializeOcrdWorkflowService() { if (Objects.isNull(ocrdWorkflowService)) { + logServiceInitialization(); ocrdWorkflowService = OcrdWorkflowService.getInstance(); } } private static void initializeProjectService() { if (Objects.isNull(projectService)) { + logServiceInitialization(); projectService = ProjectService.getInstance(); } } private static void initializeRulesetService() { if (Objects.isNull(rulesetService)) { + logServiceInitialization(); rulesetService = RulesetService.getInstance(); } } private static void initializeSessionService() { if (Objects.isNull(sessionService)) { + logServiceInitialization(); sessionService = SessionService.getInstance(); } } private static void initializeSecurityAccessService() { if (Objects.isNull(securityAccessService)) { + logServiceInitialization(); securityAccessService = SecurityAccessService.getInstance(); } } private static void initializeTaskService() { if (Objects.isNull(taskService)) { + logServiceInitialization(); taskService = TaskService.getInstance(); } } private static void initializeTemplateService() { if (Objects.isNull(templateService)) { + logServiceInitialization(); templateService = TemplateService.getInstance(); } } private static void initializeRoleService() { if (Objects.isNull(roleService)) { + logServiceInitialization(); roleService = RoleService.getInstance(); } } private static void initializeUserService() { if (Objects.isNull(userService)) { + logServiceInitialization(); userService = UserService.getInstance(); } } private static void initializeWorkflowService() { if (Objects.isNull(workflowService)) { + logServiceInitialization(); workflowService = WorkflowService.getInstance(); } } private static void initializeWorkflowConditionService() { if (Objects.isNull(workflowConditionService)) { + logServiceInitialization(); workflowConditionService = WorkflowConditionService.getInstance(); } } private static void initializeFileService() { if (Objects.isNull(fileService)) { + logServiceInitialization(); fileService = new FileService(); } } private static void initializeCommandService() { if (Objects.isNull(commandService)) { + logServiceInitialization(); commandService = new CommandService(); } } private static void initializeSchemaService() { if (Objects.isNull(schemaService)) { + logServiceInitialization(); schemaService = new SchemaService(); } } private static void initializeFileStructureValidationService() { if (Objects.isNull(fileStructureValidationService)) { + logServiceInitialization(); fileStructureValidationService = new FileStructureValidationService(); } } private static void initializeLongTermPreservationValidationService() { if (Objects.isNull(longTermPreservationValidationService)) { + logServiceInitialization(); longTermPreservationValidationService = new LongTermPreservationValidationService(); } } private static void initializeMetadataValidationService() { if (Objects.isNull(metadataValidationService)) { + logServiceInitialization(); metadataValidationService = new MetadataValidationService(); } } private static void initializeMigrationService() { if (Objects.isNull(migrationService)) { + logServiceInitialization(); migrationService = new MigrationService(); } } private static void initializeRulesetManagementService() { if (Objects.isNull(rulesetManagementService)) { + logServiceInitialization(); rulesetManagementService = RulesetManagementService.getInstance(); } } private static void initializeListColumnService() { if (Objects.isNull(listColumnService)) { + logServiceInitialization(); listColumnService = ListColumnService.getInstance(); } } private static void initializeCommentService() { if (Objects.isNull(commentService)) { + logServiceInitialization(); commentService = CommentService.getInstance(); } } private static void initializeIndexingService() { if (Objects.isNull(indexingService)) { + logServiceInitialization(); indexingService = IndexingService.getInstance(); } } private static void initializeDataEditorSettingService() { if (Objects.isNull(dataEditorSettingService)) { + logServiceInitialization(); dataEditorSettingService = DataEditorSettingService.getInstance(); } } private static void initializeOpacConfigurationService() { if (Objects.isNull(importConfigurationService)) { + logServiceInitialization(); importConfigurationService = ImportConfigurationService.getInstance(); } } private static void initializeSearchFieldService() { if (Objects.isNull(searchFieldService)) { + logServiceInitialization(); searchFieldService = SearchFieldService.getInstance(); } } private static void initializeMappingFileService() { if (Objects.isNull(mappingFileService)) { + logServiceInitialization(); mappingFileService = MappingFileService.getInstance(); } } /** - * Initialize AuthorityService if it is not yet initialized and next return - * it. + * Initialize AuthorityService if it is not yet initialized and nextb(); + * return it. * * @return AuthorityService object */ public static AuthorityService getAuthorityService() { initializeAuthorizationService(); + logServiceDelivery(); return authorityService; } /** - * Initialize BatchService if it is not yet initialized and next return it. + * Initialize BatchService if it is not yet initialized and nextb(); return + * it. * * @return BatchService object */ public static BatchService getBatchService() { initializeBatchService(); + logServiceDelivery(); return batchService; } /** - * Initialize ClientService if it is not yet initialized and next return it. + * Initialize ClientService if it is not yet initialized and nextb(); return + * it. * * @return ClientService object */ public static ClientService getClientService() { initializeClientService(); + logServiceDelivery(); return clientService; } /** - * Initialize DataEditorService if it is not yet initialized and next return - * it. + * Initialize DataEditorService if it is not yet initialized and nextb(); + * return it. * * @return DataEditorService object */ public static DataEditorService getDataEditorService() { initializeDataEditorService(); + logServiceDelivery(); return dataEditorService; } /** - * Initialize DocketService if it is not yet initialized and next return it. + * Initialize DocketService if it is not yet initialized and nextb(); return + * it. * * @return DocketService object */ public static DocketService getDocketService() { initializeDocketService(); + logServiceDelivery(); return docketService; } /** - * Initialize FilterService if it is not yet initialized and next return it. + * Initialize FilterService if it is not yet initialized and nextb(); return + * it. * * @return FilterService object */ public static FilterService getFilterService() { initializeFilterService(); + logServiceDelivery(); return filterService; } /** - * Initialize ImportService if it is not yet initialized and return it. + * Initialize ImportService if it is not yet initialized andb(); return it. + * * @return ImportService object */ public static ImportService getImportService() { initializeImportService(); + logServiceDelivery(); return importService; } /** - * Initialize LdapGroupService if it is not yet initialized and next return - * it. + * Initialize LdapGroupService if it is not yet initialized and nextb(); + * return it. * * @return LdapGroupService object */ public static LdapGroupService getLdapGroupService() { initializeLdapGroupService(); + logServiceDelivery(); return ldapGroupService; } /** - * Initialize LdapServerService if it is not yet initialized and next return - * it. + * Initialize LdapServerService if it is not yet initialized and nextb(); + * return it. * * @return LdapServerService object */ public static LdapServerService getLdapServerService() { initializeLdapServerService(); + logServiceDelivery(); return ldapServerService; } /** - * Initialize ImageService if it is not yet initialized and next return + * Initialize ImageService if it is not yet initialized and nextb(); return * it. * * @return ImageService object */ public static ImageService getImageService() { initializeImageService(); + logServiceDelivery(); return imageService; } /** - * Initialize MetsService if it is not yet initialized and next return it. + * Initialize MetsService if it is not yet initialized and nextb(); return + * it. * * @return MetsService object */ public static MetsService getMetsService() { initializeMetsService(); + logServiceDelivery(); return metsService; } /** - * Initialize MassImportService if it is not yet initialized and next return it. + * Initialize MassImportService if it is not yet initialized and nextb(); + * return it. * * @return MassImportService object */ public static MassImportService getMassImportService() { initializeMassImportService(); + logServiceDelivery(); return massImportService; } /** - * Initialize PropertyService if it is not yet initialized and next return - * it. + * Initialize PropertyService if it is not yet initialized and nextb(); + * return it. * * @return PropertyService object */ public static PropertyService getPropertyService() { initializePropertyService(); + logServiceDelivery(); return propertyService; } /** - * Initialize ProcessService if it is not yet initialized and next return - * it. + * Initialize ProcessService if it is not yet initialized and nextb(); + * return it. * * @return ProcessService object */ public static ProcessService getProcessService() { initializeProcessService(); + logServiceDelivery(); return processService; } /** - * Initialize FolderService if it is not yet initialized and next return it. + * Initialize FolderService if it is not yet initialized and nextb(); return + * it. * * @return FolderService object */ public static FolderService getFolderService() { initializeFolderService(); + logServiceDelivery(); return folderService; } /** - * Initialize OcrdWorkflowService if it is not yet initialized and next return - * it. + * Initialize OcrdWorkflowService if it is not yet initialized and nextb(); + * return it. * * @return OcrdWorkflowService object */ public static OcrdWorkflowService getOcrdWorkflowService() { initializeOcrdWorkflowService(); + logServiceDelivery(); return ocrdWorkflowService; } /** - * Initialize ProjectService if it is not yet initialized and next return - * it. + * Initialize ProjectService if it is not yet initialized and nextb(); + * return it. * * @return ProjectService object */ public static ProjectService getProjectService() { initializeProjectService(); + logServiceDelivery(); return projectService; } /** - * Initialize RulesetService if it is not yet initialized and next return - * it. + * Initialize RulesetService if it is not yet initialized and nextb(); + * return it. * * @return RulesetService object */ public static RulesetService getRulesetService() { initializeRulesetService(); + logServiceDelivery(); return rulesetService; } /** - * Initialize SessionService if it is not yet initialized and next return - * it. + * Initialize SessionService if it is not yet initialized and nextb(); + * return it. * * @return SessionService object */ public static SessionService getSessionService() { initializeSessionService(); + logServiceDelivery(); return sessionService; } /** * Initialize SecurityAccessService if it is not yet initialized and next - * return it. + * b(); return it. * * @return SecurityAccessService object */ public static SecurityAccessService getSecurityAccessService() { initializeSecurityAccessService(); + logServiceDelivery(); return securityAccessService; } /** - * Initialize TaskService if it is not yet initialized and next return it. + * Initialize TaskService if it is not yet initialized and nextb(); return + * it. * * @return TaskService object */ public static TaskService getTaskService() { initializeTaskService(); + logServiceDelivery(); return taskService; } /** - * Initialize TemplateService if it is not yet initialized and next return - * it. + * Initialize TemplateService if it is not yet initialized and nextb(); + * return it. * * @return TemplateService object */ public static TemplateService getTemplateService() { initializeTemplateService(); + logServiceDelivery(); return templateService; } /** - * Initialize RoleService if it is not yet initialized and next return it. + * Initialize RoleService if it is not yet initialized and nextb(); return + * it. * * @return RoleService object */ public static RoleService getRoleService() { initializeRoleService(); + logServiceDelivery(); return roleService; } /** - * Initialize UserService if it is not yet initialized and next return it. + * Initialize UserService if it is not yet initialized and nextb(); return + * it. * * @return UserService object */ public static UserService getUserService() { initializeUserService(); + logServiceDelivery(); return userService; } /** - * Initialize WorkflowService if it is not yet initialized and next return - * it. + * Initialize WorkflowService if it is not yet initialized and nextb(); + * return it. * * @return WorkflowService object */ public static WorkflowService getWorkflowService() { initializeWorkflowService(); + logServiceDelivery(); return workflowService; } /** - * Initialize WorkflowConditionService if it is not yet initialized and next return - * it. + * Initialize WorkflowConditionService if it is not yet initialized and + * nextb(); return it. * * @return WorkflowConditionService object */ public static WorkflowConditionService getWorkflowConditionService() { initializeWorkflowConditionService(); + logServiceDelivery(); return workflowConditionService; } /** - * Initialize FileService if it is not yet initialized and next return it. + * Initialize FileService if it is not yet initialized and nextb(); return + * it. * * @return FileService object */ public static FileService getFileService() { initializeFileService(); + logServiceDelivery(); return fileService; } /** - * Initialize CommandService if it is not yet initialized and next return - * it. + * Initialize CommandService if it is not yet initialized and nextb(); + * return it. * * @return CommandService object */ public static CommandService getCommandService() { initializeCommandService(); + logServiceDelivery(); return commandService; } /** - * Initialize SchemaService if it is not yet initialized and next return it. + * Initialize SchemaService if it is not yet initialized and nextb(); return + * it. * * @return SchemaService object */ public static SchemaService getSchemaService() { initializeSchemaService(); + logServiceDelivery(); return schemaService; } /** * Initialize FileStructureValidationService if it is not yet initialized - * and next return it. + * and nextb(); return it. * * @return FileStructureValidationService object */ public static FileStructureValidationService getFileStructureValidationService() { initializeFileStructureValidationService(); + logServiceDelivery(); return fileStructureValidationService; } /** - * Initialize KitodoScriptService if it is not yet initialized and next + * Initialize KitodoScriptService if it is not yet initialized and next b(); * return it. * * @return KitodoScriptService object */ public static KitodoScriptService getKitodoScriptService() { initializeKitodoScriptService(); + logServiceDelivery(); return kitodoScriptService; } /** * Initialize LongTermPreservationValidationService if it is not yet - * initialized and next return it. + * initialized and nextb(); return it. * * @return LongTermPreservationValidationService object */ public static LongTermPreservationValidationService getLongTermPreservationValidationService() { initializeLongTermPreservationValidationService(); + logServiceDelivery(); return longTermPreservationValidationService; } /** * Initialize MetadataValidationService if it is not yet initialized and - * next return it. + * nextb(); return it. * * @return MetadataValidationService object */ public static MetadataValidationService getMetadataValidationService() { initializeMetadataValidationService(); + logServiceDelivery(); return metadataValidationService; } /** - * Initialize MigrationService if it is not yet initialized and - * next return it. + * Initialize MigrationService if it is not yet initialized and nextb(); + * return it. * * @return MigrationService object */ public static MigrationService getMigrationService() { initializeMigrationService(); + logServiceDelivery(); return migrationService; } /** * Initialize RulesetManagementService if it is not yet initialized and next - * return it. + * b(); return it. * * @return RulesetService object */ public static RulesetManagementService getRulesetManagementService() { initializeRulesetManagementService(); + logServiceDelivery(); return rulesetManagementService; } /** - * Initialize ListColumnService if it is not yet initialized and return it. + * Initialize ListColumnService if it is not yet initialized andb(); return + * it. * * @return ColumnService object */ public static ListColumnService getListColumnService() { initializeListColumnService(); + logServiceDelivery(); return listColumnService; } /** - * Initialize CommentService if it is not yet initialized and return it. + * Initialize CommentService if it is not yet initialized andb(); return it. * * @return CommentService object */ public static CommentService getCommentService() { initializeCommentService(); + logServiceDelivery(); return commentService; } /** - * Initialize IndexingService if it is not yet initialize and return it. + * Initialize IndexingService if it is not yet initialize andb(); return it. * * @return IndexingService object */ public static IndexingService getIndexingService() { initializeIndexingService(); + logServiceDelivery(); return indexingService; } @@ -767,6 +864,7 @@ public static IndexingService getIndexingService() { */ public static DataEditorSettingService getDataEditorSettingService() { initializeDataEditorSettingService(); + logServiceDelivery(); return dataEditorSettingService; } @@ -777,6 +875,7 @@ public static DataEditorSettingService getDataEditorSettingService() { */ public static ImportConfigurationService getImportConfigurationService() { initializeOpacConfigurationService(); + logServiceDelivery(); return importConfigurationService; } @@ -787,6 +886,7 @@ public static ImportConfigurationService getImportConfigurationService() { */ public static SearchFieldService getSearchFieldService() { initializeSearchFieldService(); + logServiceDelivery(); return searchFieldService; } @@ -797,6 +897,25 @@ public static SearchFieldService getSearchFieldService() { */ public static MappingFileService getMappingFileService() { initializeMappingFileService(); + logServiceDelivery(); return mappingFileService; } + + private static void logServiceInitialization() { + if (logger.isTraceEnabled()) { + logger.trace(new RuntimeException().getStackTrace()[1].getMethodName() + .replace("initialize", "Initializing ")); + } + } + + private static void logServiceDelivery() { + if (logger.isTraceEnabled()) { + StackTraceElement[] callStack = new Exception().getStackTrace(); + String serviceName = callStack[1].getMethodName().substring(3); + String fullClassName = callStack[2].getClassName(); + int lastDotPos = fullClassName.lastIndexOf('.'); + String requestingClass = fullClassName.substring(lastDotPos + 1); + logger.trace(String.format("Providing %s to %s", serviceName, requestingClass)); + } + } }