String savePreservedMessagesFromMap()

in wilma-extras/shortCircuit/src/main/java/com/epam/wilma/extras/shortcircuit/ShortCircuitResponseInformationFileHandler.java [59:90]


    String savePreservedMessagesFromMap(String path, FileFactory fileFactory, FileOutputStreamFactory fileOutputStreamFactory,
                                        HttpServletResponse httpServletResponse) {
        String response = null;
        String filenamePrefix = "sc" + UniqueIdGenerator.getNextUniqueId() + "_";
        if (!SHORT_CIRCUIT_MAP.isEmpty()) {
            String[] keySet = SHORT_CIRCUIT_MAP.keySet().toArray(new String[SHORT_CIRCUIT_MAP.size()]);
            for (String entryKey : keySet) {
                ShortCircuitResponseInformation information = SHORT_CIRCUIT_MAP.get(entryKey);
                if (information != null) { //save only the cached files
                    //save this into file, folder is in folder variable
                    String filename = path + filenamePrefix + UniqueIdGenerator.getNextUniqueId() + ".json";
                    File file = fileFactory.createFile(filename);
                    try {
                        saveMapObject(fileOutputStreamFactory, file, entryKey, information);
                    } catch (IOException e) {
                        String message = "Cache save failed at file: " + filename + ", with message: " + e.getLocalizedMessage();
                        logger.info("ShortCircuit: " + message);
                        response = "{ \"resultsFailure\": \"" + message + "\" }";
                        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        break;
                    }
                }
            }
        }
        if (response == null) {
            String message = "Cache saved as: " + path + filenamePrefix + "*.json files";
            response = "{ \"resultsSuccess\": \"" + message + "\" }";
            httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            logger.info("ShortCircuit: " + message);
        }
        return response;
    }