// Path: modules/migration/oaep-data-migration/src/main/java/org/wso2/migration/util/DataMigrationConstants.java
// public class DataMigrationConstants {
//     public static final String EVENT_PUBLISHER_PATH = "/repository/deployment/server/eventpublishers";
//     public static final String EVENT_RECIEVER_PATH = "/repository/deployment/server/eventreceivers";
//     public static final String CARBON_HOME = "carbon.home";
//     public static final int SUPER_TENANT_ID = -1234;
// }
// 
// Path: modules/migration/oaep-data-migration/src/main/java/org/wso2/migration/util/DataMigrationUtil.java
// public class DataMigrationUtil {
// 
//     private DataMigrationUtil() {
// 
//     }
// 
//     public static boolean isNewlyEncrypted(String encryptedValue) throws DataMigrationException, CryptoException {
//         CryptoUtil cryptoUtil;
//         try {
//             cryptoUtil = CryptoUtil.getDefaultCryptoUtil(CarbonCoreDataHolder.getInstance().
//                             getServerConfigurationService(),
//                     CarbonCoreDataHolder.getInstance().getRegistryService());
//         } catch (Exception e) {
//             throw new DataMigrationException("Error while initializing cryptoUtil", e);
//         }
//         return cryptoUtil.base64DecodeAndIsSelfContainedCipherText(encryptedValue);
//     }
// 
//     public static String reEncryptByNewAlgorithm(String value) throws CryptoException {
//         byte[] decryptedValue = CryptoUtil.getDefaultCryptoUtil().base64DecodeAndDecrypt(
//                 value, "RSA");
//         return CryptoUtil.getDefaultCryptoUtil()
//                 .encryptAndBase64Encode(decryptedValue);
//     }
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.wso2.migration.exception.DataMigrationException;
import org.wso2.migration.util.DataMigrationConstants;
import org.wso2.migration.util.DataMigrationUtil;
import java.io.File;
import java.util.Objects;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

    private static void migrateReceivers(String carbonHome) throws DataMigrationException {
        File recieverPath = readFiles(carbonHome + DataMigrationConstants.EVENT_RECIEVER_PATH);
        try {
            migrateData(recieverPath);
            log.info("Migrating receivers was successful");
        } catch (DataMigrationException e) {
            throw new DataMigrationException("Error while migrating receivers in path : "
                    .concat(recieverPath.getName()), e);
        }
    }

    private static void migrateData(File folder) throws DataMigrationException {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        DocumentBuilder builder;
        Document doc;
        try {
            for (File fileEntry : Objects.requireNonNull(folder.listFiles())) {
                builder = documentBuilderFactory.newDocumentBuilder();
                if (!fileEntry.getName().endsWith(".xml")) {
                    log.error("File type is not supported. file : '".
                            concat(fileEntry.getName()).concat("'. Hence ignored"));
                }
                doc = builder.parse(fileEntry);
                XPathFactory xpathFactory = XPathFactory.newInstance();
                XPath xpath = xpathFactory.newXPath();
                NodeList data = getEncryptedPayload(doc, xpath);
                if (data.getLength() > 0) {
                    for (int i = 0; i < data.getLength(); i++) {
// Path: modules/migration/oaep-data-migration/src/main/java/org/wso2/migration/util/DataMigrationConstants.java
// public class DataMigrationConstants {
//     public static final String EVENT_PUBLISHER_PATH = "/repository/deployment/server/eventpublishers";
//     public static final String EVENT_RECIEVER_PATH = "/repository/deployment/server/eventreceivers";
//     public static final String CARBON_HOME = "carbon.home";
//     public static final int SUPER_TENANT_ID = -1234;
// }
// 
// Path: modules/migration/oaep-data-migration/src/main/java/org/wso2/migration/util/DataMigrationUtil.java
// public class DataMigrationUtil {
// 
//     private DataMigrationUtil() {
// 
//     }
// 
//     public static boolean isNewlyEncrypted(String encryptedValue) throws DataMigrationException, CryptoException {
//         CryptoUtil cryptoUtil;
//         try {
//             cryptoUtil = CryptoUtil.getDefaultCryptoUtil(CarbonCoreDataHolder.getInstance().
//                             getServerConfigurationService(),
//                     CarbonCoreDataHolder.getInstance().getRegistryService());
//         } catch (Exception e) {
//             throw new DataMigrationException("Error while initializing cryptoUtil", e);
//         }
//         return cryptoUtil.base64DecodeAndIsSelfContainedCipherText(encryptedValue);
//     }
// 
//     public static String reEncryptByNewAlgorithm(String value) throws CryptoException {
//         byte[] decryptedValue = CryptoUtil.getDefaultCryptoUtil().base64DecodeAndDecrypt(
//                 value, "RSA");
//         return CryptoUtil.getDefaultCryptoUtil()
//                 .encryptAndBase64Encode(decryptedValue);
//     }
// }


// Path: modules/migration/oaep-data-migration/src/main/java/org/wso2/migration/service/InputOutputDataMigration.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.wso2.migration.exception.DataMigrationException;
import org.wso2.migration.util.DataMigrationConstants;
import org.wso2.migration.util.DataMigrationUtil;
import java.io.File;
import java.util.Objects;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;


    private static void migrateReceivers(String carbonHome) throws DataMigrationException {
        File recieverPath = readFiles(carbonHome + DataMigrationConstants.EVENT_RECIEVER_PATH);
        try {
            migrateData(recieverPath);
            log.info("Migrating receivers was successful");
        } catch (DataMigrationException e) {
            throw new DataMigrationException("Error while migrating receivers in path : "
                    .concat(recieverPath.getName()), e);
        }
    }

    private static void migrateData(File folder) throws DataMigrationException {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        DocumentBuilder builder;
        Document doc;
        try {
            for (File fileEntry : Objects.requireNonNull(folder.listFiles())) {
                builder = documentBuilderFactory.newDocumentBuilder();
                if (!fileEntry.getName().endsWith(".xml")) {
                    log.error("File type is not supported. file : '".
                            concat(fileEntry.getName()).concat("'. Hence ignored"));
                }
                doc = builder.parse(fileEntry);
                XPathFactory xpathFactory = XPathFactory.newInstance();
                XPath xpath = xpathFactory.newXPath();
                NodeList data = getEncryptedPayload(doc, xpath);
                if (data.getLength() > 0) {
                    for (int i = 0; i < data.getLength(); i++) {
                        if (!DataMigrationUtil.isNewlyEncrypted(data.item(i).getNodeValue())) {