// 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;
/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.migration.service;




/**
 * Migrate encrypted data in event publishers and event receivers
 **/
public class InputOutputDataMigration extends Migrator {
    private static final Log log = LogFactory.getLog(InputOutputDataMigration.class);
    private static InputOutputDataMigration instance = new InputOutputDataMigration();
    public static InputOutputDataMigration getInstance() {
        return instance;
    }

    @Override
    public void migrate() throws DataMigrationException {
// 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;

/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.wso2.migration.service;




/**
 * Migrate encrypted data in event publishers and event receivers
 **/
public class InputOutputDataMigration extends Migrator {
    private static final Log log = LogFactory.getLog(InputOutputDataMigration.class);
    private static InputOutputDataMigration instance = new InputOutputDataMigration();
    public static InputOutputDataMigration getInstance() {
        return instance;
    }

    @Override
    public void migrate() throws DataMigrationException {
        String carbonPath = System.getProperty(DataMigrationConstants.CARBON_HOME);