From 4ba897872d2d6ec712e97b02f4e07fd503d52b5a Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Mon, 9 Jan 2023 10:41:16 +0100 Subject: [PATCH] Refactor logging --- .../rest/controller/ReportController.java | 5 - .../names/service/DeviceGroupService.java | 10 +- .../names/service/DeviceTypeService.java | 10 +- .../names/service/DisciplineService.java | 10 +- .../openepics/names/service/MailService.java | 37 ++-- .../openepics/names/service/NamesService.java | 106 +++++++---- .../names/service/StructuresService.java | 178 ++++++++++++------ .../names/service/SubsystemService.java | 14 +- .../names/service/SystemGroupService.java | 13 +- .../names/service/SystemService.java | 14 +- .../org/openepics/names/util/ExcelUtil.java | 32 +++- .../org/openepics/names/util/TextUtil.java | 22 +++ .../util/notification/NotificationName.java | 19 ++ .../notification/NotificationStructure.java | 23 +++ .../util/notification/NotificationUtil.java | 22 ++- 15 files changed, 360 insertions(+), 155 deletions(-) diff --git a/src/main/java/org/openepics/names/rest/controller/ReportController.java b/src/main/java/org/openepics/names/rest/controller/ReportController.java index 8b93938d..35ec892c 100644 --- a/src/main/java/org/openepics/names/rest/controller/ReportController.java +++ b/src/main/java/org/openepics/names/rest/controller/ReportController.java @@ -23,8 +23,6 @@ import java.util.Date; import java.util.Map; import java.util.TreeMap; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.commons.lang3.StringUtils; import org.openepics.names.rest.beans.Status; @@ -60,8 +58,6 @@ public class ReportController { // note // global exception handler available - private static final Logger LOGGER = Logger.getLogger(ReportController.class.getName()); - private static final String NEWLINE = "\n"; private static final String SPACE = " "; @@ -500,7 +496,6 @@ public class ReportController { */ private void addOne(UUID key, Map<UUID, Long> map, Map<UUID, Long> mapNok) { if (key == null) { - LOGGER.log(Level.FINEST, "addOne, key == null"); return; } diff --git a/src/main/java/org/openepics/names/service/DeviceGroupService.java b/src/main/java/org/openepics/names/service/DeviceGroupService.java index 245567ff..06a6e151 100644 --- a/src/main/java/org/openepics/names/service/DeviceGroupService.java +++ b/src/main/java/org/openepics/names/service/DeviceGroupService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -39,6 +40,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -232,7 +234,6 @@ public class DeviceGroupService { List<DeviceGroup> previouses = iDeviceGroupRepository.findPreviousByUuidAndId(uuid, deviceGroup.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, deviceGroup); DeviceGroup previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.FINE, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.DELETE.equals(structureCommandCUD)) { @@ -251,7 +252,8 @@ public class DeviceGroupService { } } - LOGGER.log(Level.FINE, "approveStructure, structureElement: {0}", structureElement); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICEGROUP, structureCommandCUD, StructureCommand.APPROVE, previous, deviceGroup, holder)); @@ -286,6 +288,8 @@ public class DeviceGroupService { List<DeviceGroup> previouses = iDeviceGroupRepository.findPreviousByUuidAndId(uuid, deviceGroup.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, deviceGroup); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICEGROUP, structureCommandCUD, StructureCommand.CANCEL, @@ -321,6 +325,8 @@ public class DeviceGroupService { List<DeviceGroup> previouses = iDeviceGroupRepository.findPreviousByUuidAndId(uuid, deviceGroup.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, deviceGroup); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICEGROUP, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/service/DeviceTypeService.java b/src/main/java/org/openepics/names/service/DeviceTypeService.java index f205b9de..ca6defa6 100644 --- a/src/main/java/org/openepics/names/service/DeviceTypeService.java +++ b/src/main/java/org/openepics/names/service/DeviceTypeService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -37,6 +38,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -225,7 +227,6 @@ public class DeviceTypeService { List<DeviceType> previouses = iDeviceTypeRepository.findPreviousByUuidAndId(uuid, deviceType.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, deviceType); DeviceType previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.FINE, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.UPDATE.equals(structureCommandCUD)) { @@ -234,7 +235,8 @@ public class DeviceTypeService { // not delete names - legacy names } - LOGGER.log(Level.FINE, "approveStructure, structureElement: {0}", structureElement); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceType, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICETYPE, structureCommandCUD, StructureCommand.APPROVE, previous, deviceType, holder)); @@ -268,6 +270,8 @@ public class DeviceTypeService { List<DeviceType> previouses = iDeviceTypeRepository.findPreviousByUuidAndId(uuid, deviceType.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, deviceType); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceType, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICETYPE, structureCommandCUD, StructureCommand.CANCEL, @@ -303,6 +307,8 @@ public class DeviceTypeService { List<DeviceType> previouses = iDeviceTypeRepository.findPreviousByUuidAndId(uuid, deviceType.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, deviceType); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(deviceType, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DEVICETYPE, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/service/DisciplineService.java b/src/main/java/org/openepics/names/service/DisciplineService.java index d5f955be..c84e3621 100644 --- a/src/main/java/org/openepics/names/service/DisciplineService.java +++ b/src/main/java/org/openepics/names/service/DisciplineService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -39,6 +40,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -234,7 +236,6 @@ public class DisciplineService { List<Discipline> previouses = iDisciplineRepository.findPreviousByUuidAndId(uuid, discipline.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, discipline); Discipline previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.FINE, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.UPDATE.equals(structureCommandCUD)) { @@ -255,7 +256,8 @@ public class DisciplineService { } } - LOGGER.log(Level.FINE, "approveStructure, structureElement: {0}", structureElement); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(discipline, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DISCIPLINE, structureCommandCUD, StructureCommand.APPROVE, previous, discipline, holder)); @@ -290,6 +292,8 @@ public class DisciplineService { List<Discipline> previouses = iDisciplineRepository.findPreviousByUuidAndId(uuid, discipline.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, discipline); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(discipline, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DISCIPLINE, structureCommandCUD, StructureCommand.CANCEL, @@ -325,6 +329,8 @@ public class DisciplineService { List<Discipline> previouses = iDisciplineRepository.findPreviousByUuidAndId(uuid, discipline.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, discipline); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(discipline, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.DISCIPLINE, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/service/MailService.java b/src/main/java/org/openepics/names/service/MailService.java index 906196e8..3d181575 100644 --- a/src/main/java/org/openepics/names/service/MailService.java +++ b/src/main/java/org/openepics/names/service/MailService.java @@ -54,20 +54,9 @@ public class MailService { private static final Logger LOGGER = Logger.getLogger(MailService.class.getName()); - private static final String NAMING_PREFIX = "[NT] "; - private static final String SENDING_EMAIL_DISABLED = "Sending email disabled"; - private static final String SENDING_EMAIL_SUBJECT = "Sending email with subject {0}"; - - private static final String TO_EMAIL_ADDRESS_CAN_NOT_BE_USED = "To email address can not be used"; - private static final String CC_EMAIL_ADDRESS_CAN_NOT_BE_USED = "Cc email address can not be used"; - private static final String REPLY_TO_EMAIL_ADDRESS_CAN_NOT_BE_USED = "Reply to email address can not be used"; - - private static final String TO_EMAIL_ADDRESSES_UNVAVAILABLE_CAN_NOT_SEND_EMAIL = "To email addresses unavailable, can not send email"; - private static final String SUBJECT_UNAVAILABLE_CAN_NOT_SEND_EMAIL = "Subject unavailable, can not send email"; - private static final String CONTENT_UNAVAILABLE_CAN_NOT_SEND_EMAIL = "Content unavailable, can not send email"; - + private static final String NAMING_PREFIX = "[NT] "; private static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; - private static final String TEXT_HTML_CHARSET_UTF_8 = "text/html; charset=utf-8"; + private static final String TEXT_HTML_CHARSET_UTF_8 = "text/html; charset=utf-8"; @Value("${naming.mail.notification}") boolean namingMailNotification; @@ -96,7 +85,7 @@ public class MailService { String subject, String content, boolean withAttachment, List<String> attachmentNames, List<InputStream> attachments) { if (!namingMailNotification) { - LOGGER.log(Level.INFO, SENDING_EMAIL_DISABLED); + LOGGER.log(Level.INFO, "Sending email disabled"); return; } @@ -119,15 +108,15 @@ public class MailService { // send if (toEmailAddresses == null || toEmailAddresses.length == 0) { - LOGGER.log(Level.WARNING, TO_EMAIL_ADDRESSES_UNVAVAILABLE_CAN_NOT_SEND_EMAIL); + LOGGER.log(Level.WARNING, "To email addresses unavailable, can not send email"); return; } if (StringUtils.isEmpty(subject)) { - LOGGER.log(Level.WARNING, SUBJECT_UNAVAILABLE_CAN_NOT_SEND_EMAIL); + LOGGER.log(Level.WARNING, "Subject unavailable, can not send email"); return; } if (StringUtils.isEmpty(content)) { - LOGGER.log(Level.WARNING, CONTENT_UNAVAILABLE_CAN_NOT_SEND_EMAIL); + LOGGER.log(Level.WARNING, "Content unavailable, can not send email"); return; } @@ -139,13 +128,13 @@ public class MailService { final List<Address> toRecipients = new ArrayList<>(); for (final String toEmailAddress : toEmailAddresses) { if (StringUtils.isEmpty(toEmailAddress)) { - LOGGER.log(Level.FINE, TO_EMAIL_ADDRESS_CAN_NOT_BE_USED); + LOGGER.log(Level.FINE, "To email address can not be used"); continue; } toRecipients.add(new InternetAddress(toEmailAddress)); } if (toRecipients.isEmpty()) { - LOGGER.log(Level.WARNING, TO_EMAIL_ADDRESSES_UNVAVAILABLE_CAN_NOT_SEND_EMAIL); + LOGGER.log(Level.WARNING, "To email addresses unavailable, can not send email"); return; } message.setRecipients(Message.RecipientType.TO, toRecipients.toArray(new Address[0])); @@ -153,7 +142,7 @@ public class MailService { if (ccEmailAddresses != null) { for (final String ccEmailAddress : ccEmailAddresses) { if (StringUtils.isEmpty(ccEmailAddress)) { - LOGGER.log(Level.FINE, CC_EMAIL_ADDRESS_CAN_NOT_BE_USED); + LOGGER.log(Level.FINE, "Cc email address can not be used"); continue; } ccRecipients.add(new InternetAddress(ccEmailAddress)); @@ -166,7 +155,7 @@ public class MailService { if (replyToEmailAddresses != null) { for (final String replyToEmailAddress : replyToEmailAddresses) { if (StringUtils.isEmpty(replyToEmailAddress)) { - LOGGER.log(Level.FINE, REPLY_TO_EMAIL_ADDRESS_CAN_NOT_BE_USED); + LOGGER.log(Level.FINE, "Reply to email address can not be used"); continue; } replyToAddresses.add(new InternetAddress(replyToEmailAddress)); @@ -205,9 +194,9 @@ public class MailService { message.setContent(content, TEXT_HTML_CHARSET_UTF_8); } - LOGGER.log(Level.INFO, () -> - MessageFormat.format(SENDING_EMAIL_SUBJECT, - subject)); + LOGGER.log(Level.INFO, () -> MessageFormat.format( + "Sending email with subject {0}", + subject)); emailSender.send(message); } catch (MessagingException | IOException e) { logService.logStackTraceElements(LOGGER, Level.WARNING, e); diff --git a/src/main/java/org/openepics/names/service/NamesService.java b/src/main/java/org/openepics/names/service/NamesService.java index a13cd589..08931624 100644 --- a/src/main/java/org/openepics/names/service/NamesService.java +++ b/src/main/java/org/openepics/names/service/NamesService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -59,7 +60,7 @@ import org.openepics.names.util.HolderRepositories; import org.openepics.names.util.HolderSystemDeviceStructure; import org.openepics.names.util.NameElementUtil; import org.openepics.names.util.NameUtil; -import org.openepics.names.util.Utilities; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateNameElementUtil; import org.openepics.names.util.ValidateUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -147,19 +148,27 @@ public class NamesService { // no notify // return name elements for created names - LOGGER.log(Level.FINE, "createNames, nameElements.size: {0}", Utilities.getSize(nameElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); Date when = new Date(); final List<NameElement> createdNameElements = Lists.newArrayList(); for (NameElementCommand nameElement : nameElements) { - // create name within current transaction - createdNameElements.add(createName(nameElement, when, username, holder)); + NameElement createdNameElement = createName(nameElement, when, username, holder); + createdNameElements.add(createdNameElement); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_NAME, TextUtil.ELEMENT_IN, nameElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_NAME, TextUtil.ELEMENT_OUT, createdNameElement)); + } } - LOGGER.log(Level.FINE, "createNames, createdNameElements.size: {0}", createdNameElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Create names", + nameElements.size(), + createdNameElements.size())); return createdNameElements; } @Transactional(propagation = Propagation.MANDATORY) @@ -223,19 +232,21 @@ public class NamesService { // read names // return name elements for names - LOGGER.log(Level.FINE, "readNames, deleted: {0}", deleted); - LOGGER.log(Level.FINE, "readNames, uuid: {0}", uuid); - LOGGER.log(Level.FINE, "readNames, name: {0}", name); - LOGGER.log(Level.FINE, "readNames, nameequivalence: {0}", nameequivalence); - LOGGER.log(Level.FINE, "readNames, systemstructure: {0}", systemstructure); - LOGGER.log(Level.FINE, "readNames, devicestructure: {0}", devicestructure); - LOGGER.log(Level.FINE, "readNames, index: {0}", index); - LOGGER.log(Level.FINE, "readNames, description: {0}", description); - LOGGER.log(Level.FINE, "readNames, includeHistory: {0}", includeHistory); - LOGGER.log(Level.FINE, "readNames, orderBy: {0}", orderBy); - LOGGER.log(Level.FINE, "readNames, isAsc: {0}", isAsc); - LOGGER.log(Level.FINE, "readNames, offset: {0}", offset); - LOGGER.log(Level.FINE, "readNames, limit: {0}", limit); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "deleted", deleted)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "name", name)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "nameequivalence", nameequivalence)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "systemstructure", systemstructure)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "devicestructure", devicestructure)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "index", index)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "description", description)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "includeHistory", includeHistory)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "orderBy", orderBy)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "isAsc", isAsc)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "offset", offset)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "limit", limit)); + } List<Name> names = nameRepository.readNames(deleted, uuid, name, nameequivalence, systemstructure, devicestructure, index, description, includeHistory, orderBy, isAsc, offset, limit); Long totalCount = nameRepository.countNames(deleted, uuid, name, nameequivalence, systemstructure, devicestructure, index, description, includeHistory); @@ -243,7 +254,11 @@ public class NamesService { final List<NameElement> nameElements = NameElementUtil.getNameElements(names); ResponsePageNameElements response = new ResponsePageNameElements(nameElements, totalCount, nameElements.size(), offset, limit); - LOGGER.log(Level.FINE, "readNames, response: {0}", response); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_OUT, + TextUtil.READ_NAMES, + nameElements.size())); return response; } @@ -253,7 +268,7 @@ public class NamesService { // read name or uuid // return name elements - LOGGER.log(Level.FINE, "readNames, name: {0}", name); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_NAMES, "name", name)); final List<NameElement> nameElements = Lists.newArrayList(); try { @@ -278,7 +293,7 @@ public class NamesService { // read mnemonic path // return name elements - LOGGER.log(Level.FINE, "readNamesSystemStructure, mnemonicpath: {0}", mnemonicpath); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read names system structure", "mnemonicpath", mnemonicpath)); return readNames(false, null, null, null, mnemonicpath, null, null, null, @@ -291,7 +306,7 @@ public class NamesService { // read mnemonic path // return name elements - LOGGER.log(Level.FINE, "readNamesDeviceStructure, mnemonicpath: {0}", mnemonicpath); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read names device structure", "mnemonicpath", mnemonicpath)); return readNames(false, null, null, null, null,mnemonicpath, null, null, @@ -304,7 +319,7 @@ public class NamesService { // read history for name // return name elements for names - LOGGER.log(Level.FINE, "readNamesHistory, uuid: {0}", uuid); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read names history", "uuid", uuid)); return readNames(null, uuid, null, null, null, null, null, null, @@ -317,7 +332,7 @@ public class NamesService { // validation outside method // read equivalence - LOGGER.log(Level.FINE, "equivalenceName, name: {0}", name); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Equivalence name", "name", name)); return namingConvention.equivalenceClassRepresentative(name); } @@ -326,7 +341,7 @@ public class NamesService { // validation outside method // read exists - LOGGER.log(Level.FINE, "existsName, name: {0}", name); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Exists name", "name", name)); List<Name> names = nameRepository.readNames(false, null, name, null, null, null, null, null); @@ -339,7 +354,7 @@ public class NamesService { // note // legacy - name exists but either parent does not exist (latest, not deleted, by uuid) - LOGGER.log(Level.FINE, "isLegacyName, name: {0}", name); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is legacy name", "name", name)); List<Name> names = nameRepository.readNames(false, null, name, null, null, null, null, null); ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(names, 1), "name not found", name, null); @@ -416,7 +431,7 @@ public class NamesService { // validation outside method // validate data - not exists - LOGGER.log(Level.FINE, "isValidToCreateName, name: {0}", name); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is valid to create name", "name", name)); // initiate holder of containers for system and device structure content, for performance reasons // note false to not include deleted entries @@ -522,8 +537,6 @@ public class NamesService { // no notify // return name elements for updated names - LOGGER.log(Level.FINE, "updateNames, nameElements.size: {0}", Utilities.getSize(nameElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -578,10 +591,21 @@ public class NamesService { when, username, nameElement.getComment()); nameRepository.createName(name); - updatedNameElements.add(NameElementUtil.getNameElement(name)); + NameElement updatedNameElement = NameElementUtil.getNameElement(name); + updatedNameElements.add(updatedNameElement); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_NAME, TextUtil.ELEMENT_IN, nameElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_NAME, TextUtil.ELEMENT_OUT, updatedNameElement)); + } } - LOGGER.log(Level.FINE, "updateNames, updatedNameElements.size: {0}", updatedNameElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Update names", + nameElements.size(), + updatedNameElements.size())); return updatedNameElements; } @@ -681,7 +705,6 @@ public class NamesService { // update names // use active transaction or, if not available, throw exception - LOGGER.log(Level.FINE, "updateNames, structure change, nameElements.size: {0}", nameElements.size()); updatedNameElements = updateNames(nameElements, username); } return updatedNameElements; @@ -702,8 +725,6 @@ public class NamesService { // no notify // return name elements for deleted names - LOGGER.log(Level.FINE, "deleteNames, nameElements.size: {0}", Utilities.getSize(nameElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -747,10 +768,21 @@ public class NamesService { when, username, nameElement.getComment()); nameRepository.createName(name); - deletedNameElements.add(NameElementUtil.getNameElement(name)); + NameElement deletedNameElement = NameElementUtil.getNameElement(name); + deletedNameElements.add(deletedNameElement); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_NAME, TextUtil.ELEMENT_IN, nameElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_NAME, TextUtil.ELEMENT_OUT, deletedNameElement)); + } } - LOGGER.log(Level.FINE, "deleteNames, deletedNameElements.size: {0}", deletedNameElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Delete names", + nameElements.size(), + deletedNameElements.size())); return deletedNameElements; } diff --git a/src/main/java/org/openepics/names/service/StructuresService.java b/src/main/java/org/openepics/names/service/StructuresService.java index 53ac5c3a..6b5a89d8 100644 --- a/src/main/java/org/openepics/names/service/StructuresService.java +++ b/src/main/java/org/openepics/names/service/StructuresService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.logging.Level; @@ -57,6 +58,7 @@ import org.openepics.names.util.HolderSystemDeviceStructure; import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.Utilities; import org.openepics.names.util.ValidateStructureElementUtil; import org.openepics.names.util.ValidateUtil; @@ -164,8 +166,6 @@ public class StructuresService { // notify // return structure elements for created structures - LOGGER.log(Level.FINE, "createStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -194,12 +194,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(createdStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CREATE_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.CREATE); - LOGGER.log(Level.FINE, "createStructures, createdStructureElements.size: {0}", createdStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Create structures", + structureElements.size(), + createdStructureElements.size())); return createdStructureElements; } @@ -221,25 +233,27 @@ public class StructuresService { // read structures // return structure elements for structures - LOGGER.log(Level.FINE, "readStructures, type: {0}", type); - LOGGER.log(Level.FINE, "readStructures, statuses.length: {0}", Utilities.getLength(statuses)); - LOGGER.log(Level.FINE, "readStructures, deleted: {0}", deleted); - LOGGER.log(Level.FINE, "readStructures, uuid: {0}", uuid); - LOGGER.log(Level.FINE, "readStructures, parentUuid: {0}", parentUuid); - LOGGER.log(Level.FINE, "readStructures, name: {0}", name); - LOGGER.log(Level.FINE, "readStructures, mnemonic: {0}", mnemonic); - LOGGER.log(Level.FINE, "readStructures, mnemonicequivalence: {0}", mnemonicequivalence); - LOGGER.log(Level.FINE, "readStructures, mnemonicpath: {0}", mnemonicpath); - LOGGER.log(Level.FINE, "readStructures, description: {0}", description); - LOGGER.log(Level.FINE, "readStructures, includeHistory: {0}", includeHistory); - LOGGER.log(Level.FINE, "readStructures, orderBy: {0}", orderBy); - LOGGER.log(Level.FINE, "readStructures, isAsc: {0}", isAsc); - LOGGER.log(Level.FINE, "readStructures, offset: {0}", offset); - LOGGER.log(Level.FINE, "readStructures, limit: {0}", limit); - LOGGER.log(Level.FINE, "readStructures, structureChoice: {0}", structureChoice); - if (statuses != null) { - for (Status status : statuses) { - LOGGER.log(Level.FINE, "readStructures, status: {0}", status); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "statuses.length", Utilities.getLength(statuses))); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "deleted", deleted)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "parentUuid", parentUuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "name", name)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "mnemonic", mnemonic)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "mnemonicequivalence", mnemonicequivalence)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "mnemonicpath", mnemonicpath)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "description", description)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "includeHistory", includeHistory)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "orderBy", orderBy)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "isAsc", isAsc)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "offset", offset)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "limit", limit)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "structureChoice", structureChoice)); + if (statuses != null) { + for (Status status : statuses) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "status", status)); + } } } @@ -262,7 +276,6 @@ public class StructuresService { systemGroups = Lists.newArrayList(); totalCount = 0L; } - LOGGER.log(Level.FINE, "readStructures, systemGroups.size: {0}", systemGroups.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForSystemGroups(systemGroups, holder, structureChoice)); } else if (Type.SYSTEM.equals(type)) { List<System> systems = holderRepositories.getSystemRepository().readSystems(statuses, deleted, @@ -271,7 +284,6 @@ public class StructuresService { totalCount = holderRepositories.getSystemRepository().countSystems(statuses, deleted, uuid, parentUuid, name, mnemonic, mnemonicequivalence, mnemonicpath, description, includeHistory); - LOGGER.log(Level.FINE, "readStructures, systems.size: {0}", systems.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForSystems(systems, holder, structureChoice)); } else if (Type.SUBSYSTEM.equals(type)) { List<Subsystem> subsystems = holderRepositories.getSubsystemRepository().readSubsystems(statuses, deleted, @@ -280,7 +292,6 @@ public class StructuresService { totalCount = holderRepositories.getSubsystemRepository().countSubsystems(statuses, deleted, uuid, parentUuid, name, mnemonic, mnemonicequivalence, mnemonicpath, description, includeHistory); - LOGGER.log(Level.FINE, "readStructures, subsystems.size: {0}", subsystems.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForSubsystems(subsystems, holder, structureChoice)); } else if (Type.DISCIPLINE.equals(type)) { // discipline has no parent uuid @@ -296,7 +307,6 @@ public class StructuresService { disciplines = Lists.newArrayList(); totalCount = 0L; } - LOGGER.log(Level.FINE, "readStructures, disciplines.size: {0}", disciplines.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForDisciplines(disciplines, holder, structureChoice)); } else if (Type.DEVICEGROUP.equals(type)) { List<DeviceGroup> deviceGroups = holderRepositories.getDeviceGroupRepository().readDeviceGroups(statuses, deleted, @@ -305,7 +315,6 @@ public class StructuresService { totalCount = holderRepositories.getDeviceGroupRepository().countDeviceGroups(statuses, deleted, uuid, parentUuid, name, mnemonic, mnemonicequivalence, mnemonicpath, description, includeHistory); - LOGGER.log(Level.FINE, "readStructures, deviceGroups.size: {0}", deviceGroups.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceGroups(deviceGroups, holder, structureChoice)); } else if (Type.DEVICETYPE.equals(type)) { List<DeviceType> deviceTypes = holderRepositories.getDeviceTypeRepository().readDeviceTypes(statuses, deleted, @@ -314,12 +323,15 @@ public class StructuresService { totalCount = holderRepositories.getDeviceTypeRepository().countDeviceTypes(statuses, deleted, uuid, parentUuid, name, mnemonic, mnemonicequivalence, mnemonicpath, description, includeHistory); - LOGGER.log(Level.FINE, "readStructures, deviceTypes.size: {0}", deviceTypes.size()); structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceTypes(deviceTypes, holder, structureChoice)); } ResponsePageStructureElements response = new ResponsePageStructureElements(structureElements, totalCount, structureElements.size(), offset, limit); - LOGGER.log(Level.FINE, "readStructures, response: {0}", response); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_OUT, + TextUtil.READ_STRUCTURES, + structureElements.size())); return response; } @@ -330,8 +342,10 @@ public class StructuresService { // read structure latest by uuid for type // return structure elements for structures - LOGGER.log(Level.FINE, "readStructuresChildren, uuid: {0}", uuid); - LOGGER.log(Level.FINE, "readStructuresChildren, type: {0}", type); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures children", "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures children", "type", type)); + } boolean typeSystemGroup = Type.SYSTEMGROUP.equals(type); boolean typeSystem = Type.SYSTEM.equals(type); @@ -382,7 +396,7 @@ public class StructuresService { // read structure latest by mnemonic // return structure elements for structures - LOGGER.log(Level.FINE, "readStructuresMnemonic, mnemonic: {0}", mnemonic); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures mnemonic", "mnemonic", mnemonic)); // TODO handle orderBy, isAsc, offset, limit @@ -410,7 +424,7 @@ public class StructuresService { // read structure latest by mnemonicpath // return structure elements for structures - LOGGER.log(Level.FINE, "readStructuresMnemonicpath, mnemonicpath: {0}", mnemonicpath); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures mnemonic path", "mnemonicpath", mnemonicpath)); // TODO handle orderBy, isAsc, offset, limit @@ -447,8 +461,10 @@ public class StructuresService { // note // type may speed up read - LOGGER.log(Level.FINE, "readStructuresHistory, uuid: {0}", uuid); - LOGGER.log(Level.FINE, "readStructuresHistory, type: {0}", type); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures history", "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures history", "type", type)); + } boolean typeSystemGroup = Type.SYSTEMGROUP.equals(type); boolean typeSystem = Type.SYSTEM.equals(type); @@ -510,7 +526,7 @@ public class StructuresService { // validation outside method // read equivalence - LOGGER.log(Level.FINE, "equivalenceMnemonic, mnemonic: {0}", mnemonic); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Equivalence mnemonic", "mnemonic", mnemonic)); return namingConvention.equivalenceClassRepresentative(mnemonic); } @@ -519,7 +535,10 @@ public class StructuresService { // validation outside method // read exists - LOGGER.log(Level.FINE, "existsStructure, mnemonicpath: {0}", mnemonicpath); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Exists structure", "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Exists structure", "mnemonicpath", mnemonicpath)); + } if (Type.SYSTEMGROUP.equals(type)) { List<SystemGroup> systemGroups = holderRepositories.getSystemGroupRepository().readSystemGroups(Status.APPROVED, false, null, null, null, null, mnemonicpath, null); @@ -548,7 +567,10 @@ public class StructuresService { // validation outside method // validate data - not exists - LOGGER.log(Level.FINE, "isValidToCreateStructure, mnemonicpath: {0}", mnemonicpath); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is valid to create structure", "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is valid to create structure", "mnemonicpath", mnemonicpath)); + } // initiate holder of containers for system and device structure content, for performance reasons // note false to not include deleted entries @@ -737,8 +759,6 @@ public class StructuresService { // notify // return structure elements for updated structures - LOGGER.log(Level.FINE, "updateStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -767,12 +787,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(updatedStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.UPDATE_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.UPDATE); - LOGGER.log(Level.FINE, "updateStructures, updatedStructureElements.size: {0}", updatedStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Update structures", + structureElements.size(), + updatedStructureElements.size())); return updatedStructureElements; } @@ -790,8 +822,6 @@ public class StructuresService { // notify // return structure elements for deleted structures - LOGGER.log(Level.FINE, "deleteStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -820,12 +850,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(deletedStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.DELETE_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.DELETE); - LOGGER.log(Level.FINE, "deleteStructures, deletedStructureElements.size: {0}", deletedStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Delete structures", + structureElements.size(), + deletedStructureElements.size())); return deletedStructureElements; } @@ -843,8 +885,6 @@ public class StructuresService { // notify // return structure elements for approved structures - LOGGER.log(Level.FINE, "approveStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -880,12 +920,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(approvedStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.APPROVE); - LOGGER.log(Level.FINE, "approveStructures, approvedStructureElements.size: {0}", approvedStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Approve structures", + structureElements.size(), + approvedStructureElements.size())); return approvedStructureElements; } @@ -901,8 +953,6 @@ public class StructuresService { // notify // return structure elements for cancelled structures - LOGGER.log(Level.FINE, "cancelStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -931,12 +981,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(cancelledStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.CANCEL); - LOGGER.log(Level.FINE, "cancelStructures, cancelledStructureElements.size: {0}", cancelledStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Cancel structures", + structureElements.size(), + cancelledStructureElements.size())); return cancelledStructureElements; } @@ -952,8 +1014,6 @@ public class StructuresService { // notify // return structure elements for rejected structures - LOGGER.log(Level.FINE, "rejectStructures, structureElements.size: {0}", Utilities.getSize(structureElements)); - // initiate holder of containers for system and device structure content, for performance reasons HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories); @@ -982,12 +1042,24 @@ public class StructuresService { Utilities.addToCollection(notifications, structureElementNotification.notificationStructure()); Utilities.addToCollection(rejectedStructureElements, structureElementNotification.structureElement()); + + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.ELEMENT_IN, structureElement)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.ELEMENT_OUT, structureElementNotification.structureElement())); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.NOTIFICATION, structureElementNotification.notificationStructure())); + } } // notify notificationService.notifyStructures(notifications, StructureCommand.REJECT); - LOGGER.log(Level.FINE, "rejectStructures, rejectedStructureElements.size: {0}", rejectedStructureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS_IN_OUT, + "Reject structures", + structureElements.size(), + rejectedStructureElements.size())); return rejectedStructureElements; } diff --git a/src/main/java/org/openepics/names/service/SubsystemService.java b/src/main/java/org/openepics/names/service/SubsystemService.java index 877782e8..e35fe8ad 100644 --- a/src/main/java/org/openepics/names/service/SubsystemService.java +++ b/src/main/java/org/openepics/names/service/SubsystemService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -30,7 +31,6 @@ import org.openepics.names.repository.SubsystemRepository; import org.openepics.names.repository.model.Subsystem; import org.openepics.names.rest.beans.Status; import org.openepics.names.rest.beans.Type; -import org.openepics.names.rest.beans.element.NameElement; import org.openepics.names.rest.beans.element.NameElementCommand; import org.openepics.names.rest.beans.element.StructureElementCommand; import org.openepics.names.util.EssNamingConvention; @@ -39,6 +39,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -227,7 +228,6 @@ public class SubsystemService { List<Subsystem> previouses = iSubsystemRepository.findPreviousByUuidAndId(uuid, subsystem.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, subsystem); Subsystem previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.FINE, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.CREATE.equals(structureCommandCUD)) { @@ -235,8 +235,7 @@ public class SubsystemService { boolean existsName = hasMnemonic && namesService.existsName(StructureUtil.getMnemonicPath(subsystem, holder)); if (hasMnemonic && !existsName) { NameElementCommand nameElement = new NameElementCommand(null, subsystem.getUuid(), null, null, StructuresService.SYSTEM_STRUCTURE_ONLY, null); - NameElement createdNameElement = namesService.createName(nameElement, when, username, holder); - LOGGER.log(Level.FINE, "approveStructures, nameElement created, name: {0}", createdNameElement.getName()); + namesService.createName(nameElement, when, username, holder); } } else if (StructureCommand.UPDATE.equals(structureCommandCUD)) { namesService.updateNames(previous, subsystem, username); @@ -244,7 +243,8 @@ public class SubsystemService { // not delete names - legacy names } - LOGGER.log(Level.FINE, "approveStructure, structureElement: {0}", structureElement); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(subsystem, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SUBSYSTEM, structureCommandCUD, StructureCommand.APPROVE, previous, subsystem, holder)); @@ -279,6 +279,8 @@ public class SubsystemService { List<Subsystem> previouses = iSubsystemRepository.findPreviousByUuidAndId(uuid, subsystem.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, subsystem); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(subsystem, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SUBSYSTEM, structureCommandCUD, StructureCommand.CANCEL, @@ -314,6 +316,8 @@ public class SubsystemService { List<Subsystem> previouses = iSubsystemRepository.findPreviousByUuidAndId(uuid, subsystem.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, subsystem); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(subsystem, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SUBSYSTEM, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/service/SystemGroupService.java b/src/main/java/org/openepics/names/service/SystemGroupService.java index a7ff1619..60897d1f 100644 --- a/src/main/java/org/openepics/names/service/SystemGroupService.java +++ b/src/main/java/org/openepics/names/service/SystemGroupService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -32,7 +33,6 @@ import org.openepics.names.repository.model.System; import org.openepics.names.repository.model.SystemGroup; import org.openepics.names.rest.beans.Status; import org.openepics.names.rest.beans.Type; -import org.openepics.names.rest.beans.element.NameElement; import org.openepics.names.rest.beans.element.NameElementCommand; import org.openepics.names.rest.beans.element.StructureElementCommand; import org.openepics.names.util.EssNamingConvention; @@ -41,6 +41,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -237,7 +238,6 @@ public class SystemGroupService { List<SystemGroup> previouses = iSystemGroupRepository.findPreviousByUuidAndId(uuid, systemGroup.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, systemGroup); SystemGroup previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.INFO, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.CREATE.equals(structureCommandCUD)) { @@ -245,8 +245,7 @@ public class SystemGroupService { boolean existsName = hasMnemonic && namesService.existsName(StructureUtil.getMnemonicPath(systemGroup, holder)); if (hasMnemonic && !existsName) { NameElementCommand nameElement = new NameElementCommand(null, systemGroup.getUuid(), null, null, StructuresService.SYSTEM_STRUCTURE_ONLY, null); - NameElement createdNameElement = namesService.createName(nameElement, when, username, holder); - LOGGER.log(Level.FINE, "approveStructure, nameElement created, name: {0}", createdNameElement.getName()); + namesService.createName(nameElement, when, username, holder); } } else if (StructureCommand.UPDATE.equals(structureCommandCUD)) { namesService.updateNames(previous, systemGroup, username); @@ -266,6 +265,8 @@ public class SystemGroupService { } } + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(systemGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEMGROUP, structureCommandCUD, StructureCommand.APPROVE, previous, systemGroup, holder)); @@ -300,6 +301,8 @@ public class SystemGroupService { List<SystemGroup> previouses = iSystemGroupRepository.findPreviousByUuidAndId(uuid, systemGroup.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, systemGroup); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(systemGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEMGROUP, structureCommandCUD, StructureCommand.CANCEL, @@ -335,6 +338,8 @@ public class SystemGroupService { List<SystemGroup> previouses = iSystemGroupRepository.findPreviousByUuidAndId(uuid, systemGroup.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, systemGroup); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(systemGroup, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEMGROUP, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/service/SystemService.java b/src/main/java/org/openepics/names/service/SystemService.java index b15aa75e..dd471d15 100644 --- a/src/main/java/org/openepics/names/service/SystemService.java +++ b/src/main/java/org/openepics/names/service/SystemService.java @@ -18,6 +18,7 @@ package org.openepics.names.service; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.UUID; @@ -32,7 +33,6 @@ import org.openepics.names.repository.model.Subsystem; import org.openepics.names.repository.model.System; import org.openepics.names.rest.beans.Status; import org.openepics.names.rest.beans.Type; -import org.openepics.names.rest.beans.element.NameElement; import org.openepics.names.rest.beans.element.NameElementCommand; import org.openepics.names.rest.beans.element.StructureElementCommand; import org.openepics.names.util.EssNamingConvention; @@ -41,6 +41,7 @@ import org.openepics.names.util.StructureChoice; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureElementUtil; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; import org.openepics.names.util.notification.NotificationUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -237,7 +238,6 @@ public class SystemService { List<System> previouses = iSystemRepository.findPreviousByUuidAndId(uuid, system.getId()); StructureCommand structureCommandCUD = StructureUtil.getStructureCommandCUD(previouses, system); System previous = previouses != null && !previouses.isEmpty() ? previouses.get(0) : null; - LOGGER.log(Level.FINE, "approveStructure, structureCommandCUD: {0}", structureCommandCUD); // additional if (StructureCommand.CREATE.equals(structureCommandCUD)) { @@ -245,8 +245,7 @@ public class SystemService { boolean existsName = hasMnemonic && namesService.existsName(StructureUtil.getMnemonicPath(system, holder)); if (hasMnemonic && !existsName) { NameElementCommand nameElement = new NameElementCommand(null, system.getUuid(), null, null, StructuresService.SYSTEM_STRUCTURE_ONLY, null); - NameElement createdNameElement = namesService.createName(nameElement, when, username, holder); - LOGGER.log(Level.FINE, "approveStructure, nameElement created, name: {0}", createdNameElement.getName()); + namesService.createName(nameElement, when, username, holder); } } else if (StructureCommand.UPDATE.equals(structureCommandCUD)) { namesService.updateNames(previous, system, username); @@ -266,7 +265,8 @@ public class SystemService { } } - LOGGER.log(Level.FINE, "approveStructure, structureElement: {0}", structureElement); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.APPROVE_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(system, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEM, structureCommandCUD, StructureCommand.APPROVE, previous, system, holder)); @@ -301,6 +301,8 @@ public class SystemService { List<System> previouses = iSystemRepository.findPreviousByUuidAndId(uuid, system.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, system); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.CANCEL_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(system, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEM, structureCommandCUD, StructureCommand.CANCEL, @@ -336,6 +338,8 @@ public class SystemService { List<System> previouses = iSystemRepository.findPreviousByUuidAndId(uuid, system.getId()); StructureCommand structureCommandCUD = NotificationUtil.getStructureCommandCUD(previouses, system); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.REJECT_STRUCTURE, TextUtil.COMMAND, structureCommandCUD)); + return new StructureElementNotification( StructureElementUtil.getStructureElementProcessed(system, holder, StructureChoice.STRUCTURE), NotificationUtil.prepareNotification(Type.SYSTEM, structureCommandCUD, StructureCommand.REJECT, diff --git a/src/main/java/org/openepics/names/util/ExcelUtil.java b/src/main/java/org/openepics/names/util/ExcelUtil.java index 9580316f..c423e156 100644 --- a/src/main/java/org/openepics/names/util/ExcelUtil.java +++ b/src/main/java/org/openepics/names/util/ExcelUtil.java @@ -110,10 +110,10 @@ public class ExcelUtil { private static final String SHEET = "Entries"; - private static final String ENTRIES_EXCEL_TO_NAME_ELEMENT_COMMANDS = "excelToNameElementCommands, # entries: {0}"; - private static final String ENTRIES_EXCEL_TO_STRUCTURE_ELEMENT_COMMANDS = "excelToStructureElementCommands, # entries: {0}"; - private static final String ENTRIES_NAME_ELEMENTS_TO_EXCEL = "nameElementsToExcel, # entries: {0}"; - private static final String ENTRIES_STRUCTURE_ELEMENTS_TO_EXCEL = "structureElementsToExcel, # entries: {0}"; +// private static final String ENTRIES_EXCEL_TO_NAME_ELEMENT_COMMANDS = "excelToNameElementCommands, # entries: {0}"; +// private static final String ENTRIES_EXCEL_TO_STRUCTURE_ELEMENT_COMMANDS = "excelToStructureElementCommands, # entries: {0}"; +// private static final String ENTRIES_NAME_ELEMENTS_TO_EXCEL = "nameElementsToExcel, # entries: {0}"; +// private static final String ENTRIES_STRUCTURE_ELEMENTS_TO_EXCEL = "structureElementsToExcel, # entries: {0}"; private static final String FAILED_TO_EXPORT_VALUES_TO_FILE = "Failed to export values to file"; private static final String FILE_COULD_NOT_BE_PARSED_FOR_VALUE_AT_ROW_CELL = "File could not be parsed for value at row: {0} cell: {1}"; @@ -213,7 +213,11 @@ public class ExcelUtil { } workbook.close(); - LOGGER.log(Level.FINE, ENTRIES_EXCEL_TO_NAME_ELEMENT_COMMANDS, list.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS, + "Excel to name element commands", + list.size())); return list; } catch (IllegalArgumentException | IOException e) { throw new ServiceException( @@ -301,7 +305,11 @@ public class ExcelUtil { } workbook.close(); - LOGGER.log(Level.FINE, ENTRIES_EXCEL_TO_STRUCTURE_ELEMENT_COMMANDS, list.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS, + "Excel to structure element commands", + list.size())); return list; } catch (IllegalArgumentException | IOException e) { throw new ServiceException( @@ -384,7 +392,11 @@ public class ExcelUtil { * @return Excel file */ public static ByteArrayInputStream nameElementsToExcel(List<NameElement> nameElements) { - LOGGER.log(Level.FINE, ENTRIES_NAME_ELEMENTS_TO_EXCEL, nameElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS, + "Name elements to Excel", + nameElements.size())); try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream();) { Sheet sheet = workbook.createSheet(SHEET); @@ -470,7 +482,11 @@ public class ExcelUtil { * @return Excel file */ public static ByteArrayInputStream structureElementsToExcel(List<StructureElement> structureElements) { - LOGGER.log(Level.FINE, ENTRIES_STRUCTURE_ELEMENTS_TO_EXCEL, structureElements.size()); + LOGGER.log(Level.INFO, + () -> MessageFormat.format( + TextUtil.DESCRIPTION_NUMBER_ELEMENTS, + "Structure elements to Excel", + structureElements.size())); try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream();) { Sheet sheet = workbook.createSheet(SHEET); diff --git a/src/main/java/org/openepics/names/util/TextUtil.java b/src/main/java/org/openepics/names/util/TextUtil.java index 424d999c..9fc25289 100644 --- a/src/main/java/org/openepics/names/util/TextUtil.java +++ b/src/main/java/org/openepics/names/util/TextUtil.java @@ -126,6 +126,28 @@ public class TextUtil { // TODO check if necessary when authentication authorization is introduced public static final String TEST_WHO = "test who"; + // log + public static final String DESCRIPTION_NUMBER_ELEMENTS = "{0}, # elements: {1}"; + public static final String DESCRIPTION_NUMBER_ELEMENTS_OUT = "{0}, # elements (out): {1}"; + public static final String DESCRIPTION_NUMBER_ELEMENTS_IN_OUT = "{0}, # elements (in): {1}, # elements (out): {2}"; + public static final String DESCRIPTION_NAME_VALUE = "{0}, {1}: {2}"; + public static final String COMMAND = "command"; + public static final String ELEMENT_IN = "element (in)"; + public static final String ELEMENT_OUT = "element (out)"; + public static final String NOTIFICATION = "notification"; + public static final String CREATE_NAME = "Create name"; + public static final String UPDATE_NAME = "Update name"; + public static final String DELETE_NAME = "Delete name"; + public static final String CREATE_STRUCTURE = "Create structure"; + public static final String UPDATE_STRUCTURE = "Update structure"; + public static final String DELETE_STRUCTURE = "Delete structure"; + public static final String APPROVE_STRUCTURE = "Approve structure"; + public static final String CANCEL_STRUCTURE = "Cancel structure"; + public static final String REJECT_STRUCTURE = "Reject structure"; + public static final String READ_NAMES = "Read names"; + public static final String READ_STRUCTURES = "Read structures"; + public static final String PREPARE_NOTIFICATION = "Prepare notification"; + /** * This class is not to be instantiated. */ diff --git a/src/main/java/org/openepics/names/util/notification/NotificationName.java b/src/main/java/org/openepics/names/util/notification/NotificationName.java index 8a3afbf9..93b0d671 100644 --- a/src/main/java/org/openepics/names/util/notification/NotificationName.java +++ b/src/main/java/org/openepics/names/util/notification/NotificationName.java @@ -112,4 +112,23 @@ public class NotificationName { return who; } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + sb.append("\"nameCommandCUD\": " + getNameCommandCUD()); + sb.append(", \"uuid\": " + getUuid()); + sb.append(", \"oldIndex\": " + getOldIndex()); + sb.append(", \"oldName\": " + getOldName()); + sb.append(", \"oldDescription\": " + getOldDescription()); + sb.append(", \"newIndex\": " + getNewIndex()); + sb.append(", \"newName\": " + getNewName()); + sb.append(", \"newDescription\": " + getNewDescription()); + sb.append(", \"comment\": " + getComment()); + sb.append(", \"when\": " + getWhen()); + sb.append(", \"who\": " + getWho()); + sb.append("}"); + return sb.toString(); + } + } diff --git a/src/main/java/org/openepics/names/util/notification/NotificationStructure.java b/src/main/java/org/openepics/names/util/notification/NotificationStructure.java index ffaf1051..20e091da 100644 --- a/src/main/java/org/openepics/names/util/notification/NotificationStructure.java +++ b/src/main/java/org/openepics/names/util/notification/NotificationStructure.java @@ -138,4 +138,27 @@ public class NotificationStructure { return who; } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + sb.append("\"structureCommandCUD\": " + getStructureCommandCUD()); + sb.append(", \"structureCommandACR\": " + getStructureCommandACR()); + sb.append(", \"uuid\": " + getUuid()); + sb.append(", \"type\": " + getType()); + sb.append(", \"oldName\": " + getOldName()); + sb.append(", \"oldMnemonic\": " + getOldMnemonic()); + sb.append(", \"oldMnemonicpath\": " + getOldMnemonicpath()); + sb.append(", \"oldDescription\": " + getOldDescription()); + sb.append(", \"newName\": " + getNewName()); + sb.append(", \"newMnemonic\": " + getNewMnemonic()); + sb.append(", \"newMnemonicpath\": " + getNewMnemonicpath()); + sb.append(", \"newDescription\": " + getNewDescription()); + sb.append(", \"comment\": " + getComment()); + sb.append(", \"when\": " + getWhen()); + sb.append(", \"who\": " + getWho()); + sb.append("}"); + return sb.toString(); + } + } diff --git a/src/main/java/org/openepics/names/util/notification/NotificationUtil.java b/src/main/java/org/openepics/names/util/notification/NotificationUtil.java index 4b1d95d4..25faf35d 100644 --- a/src/main/java/org/openepics/names/util/notification/NotificationUtil.java +++ b/src/main/java/org/openepics/names/util/notification/NotificationUtil.java @@ -18,6 +18,7 @@ package org.openepics.names.util.notification; +import java.text.MessageFormat; import java.util.Collections; import java.util.Date; import java.util.List; @@ -38,6 +39,7 @@ import org.openepics.names.util.HolderSystemDeviceStructure; import org.openepics.names.util.NameCommand; import org.openepics.names.util.StructureCommand; import org.openepics.names.util.StructureUtil; +import org.openepics.names.util.TextUtil; import org.openepics.names.util.ValidateUtil; /** @@ -105,9 +107,11 @@ public class NotificationUtil { * @return notification */ public static NotificationName prepareNotification(NameCommand nameCommand, Name previous, Name name) { - LOGGER.log(Level.FINE, "prepareNotification, nameCommand: {0}", nameCommand); - LOGGER.log(Level.FINE, "prepareNotification, previous: {0}", previous); - LOGGER.log(Level.FINE, "prepareNotification, name: {0}", name); + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "nameCommand", nameCommand)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "previous", previous)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "name", name)); + } if (ValidateUtil.isAnyNull(nameCommand, name)) { return null; @@ -193,11 +197,13 @@ public class NotificationUtil { */ public static NotificationStructure prepareNotification(Type type, StructureCommand structureCommandCUD, StructureCommand structureCommandACR, Structure previous, Structure structure, HolderSystemDeviceStructure holderSystemDeviceStructure) { - LOGGER.log(Level.FINE, "prepareNotification, type: {0}", type); - LOGGER.log(Level.FINE, "prepareNotification, structureCommandCUD: {0}", structureCommandCUD); - LOGGER.log(Level.FINE, "prepareNotification, structureCommandACR: {0}", structureCommandACR); - LOGGER.log(Level.FINE, "prepareNotification, previous: {0}", previous); - LOGGER.log(Level.FINE, "prepareNotification, structure: {0}", structure); + if (LOGGER.isLoggable(Level.FINER)) { + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "type", type)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "structureCommandCUD", structureCommandCUD)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "structureCommandACR", structureCommandACR)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "previous", previous)); + LOGGER.log(Level.FINER, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.PREPARE_NOTIFICATION, "structure", structure)); + } if (ValidateUtil.isAnyNull(holderSystemDeviceStructure, type, structureCommandCUD, structure)) { return null; -- GitLab