/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.ExternalEntityHeader
 *  com.l7tech.server.management.api.node.MigrationApi
 *  com.l7tech.server.management.api.node.MigrationApi$MappingCandidate
 *  com.l7tech.server.management.api.node.MigrationApi$MigrationException
 *  com.l7tech.server.management.migration.MigrationManager
 *  com.l7tech.server.management.migration.bundle.MigratedItem
 *  com.l7tech.server.management.migration.bundle.MigrationBundle
 *  com.l7tech.server.management.migration.bundle.MigrationMetadata
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server.migration;

import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.ExternalEntityHeader;
import com.l7tech.server.audit.AuditContextUtils;
import com.l7tech.server.management.api.node.MigrationApi;
import com.l7tech.server.management.migration.MigrationManager;
import com.l7tech.server.management.migration.bundle.MigratedItem;
import com.l7tech.server.management.migration.bundle.MigrationBundle;
import com.l7tech.server.management.migration.bundle.MigrationMetadata;
import com.l7tech.util.ExceptionUtils;
import java.util.Collection;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MigrationApiImpl
implements MigrationApi {
    private static final Logger a;
    private MigrationManager b;
    private static final String[] c;

    public MigrationApiImpl(MigrationManager migrationManager) {
        this.b = migrationManager;
    }

    public Collection<ExternalEntityHeader> listEntities(Class<? extends Entity> clazz) throws MigrationApi.MigrationException {
        return this.b.listEntities(clazz);
    }

    public Collection<ExternalEntityHeader> checkHeaders(Collection<ExternalEntityHeader> collection) {
        return this.b.checkHeaders(collection);
    }

    public MigrationMetadata findDependencies(Collection<ExternalEntityHeader> collection) throws MigrationApi.MigrationException {
        return this.b.findDependencies(collection);
    }

    public MigrationBundle exportBundle(Collection<ExternalEntityHeader> collection) throws MigrationApi.MigrationException {
        try {
            return this.b.exportBundle(collection);
        }
        catch (MigrationApi.MigrationException migrationException) {
            String[] stringArray = c;
            a.log(Level.WARNING, stringArray[0] + ExceptionUtils.getMessage((Throwable)migrationException) + stringArray[3], ExceptionUtils.getDebugException((Throwable)migrationException));
            throw migrationException;
        }
    }

    public Collection<MigrationApi.MappingCandidate> retrieveMappingCandidates(Collection<ExternalEntityHeader> collection, ExternalEntityHeader externalEntityHeader, Map<String, String> map) throws MigrationApi.MigrationException {
        try {
            return MigrationApi.MappingCandidate.asCandidates((Map)this.b.retrieveMappingCandidates(collection, externalEntityHeader, map));
        }
        catch (RuntimeException runtimeException) {
            a.log(Level.WARNING, c[5], runtimeException);
            throw runtimeException;
        }
    }

    public Collection<MigratedItem> importBundle(MigrationBundle migrationBundle, boolean bl2) throws MigrationApi.MigrationException {
        boolean bl3 = AuditContextUtils.isSystem();
        try {
            AuditContextUtils.setSystem(true);
            Collection collection = this.b.importBundle(migrationBundle, bl2);
            return collection;
        }
        catch (MigrationApi.MigrationException migrationException) {
            String[] stringArray = c;
            a.log(Level.WARNING, stringArray[1] + ExceptionUtils.getMessage((Throwable)migrationException) + stringArray[2], ExceptionUtils.getDebugException((Throwable)migrationException));
            throw migrationException;
        }
        catch (Exception exception) {
            a.log(Level.WARNING, c[4], exception);
            throw ExceptionUtils.wrap((Throwable)exception);
        }
        finally {
            AuditContextUtils.setSystem(bl3);
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = "8k5\u001e\t\r\u0014\u00139\n\u0018\u001c_\u001c\tp(\u001f[l-49`\u00188k5\u001e\t\r\u0014\u00139\n\u0018\u001c_\u001c\tp(\u001f[l-49`\u0002Z7\u0002Z7";
                var4_3 = "8k5\u001e\t\r\u0014\u00139\n\u0018\u001c_\u001c\tp(\u001f[l-49`\u00188k5\u001e\t\r\u0014\u00139\n\u0018\u001c_\u001c\tp(\u001f[l-49`\u0002Z7\u0002Z7".length();
                var1_4 = 24;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 122;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = MigrationApiImpl.a(v0, MigrationApiImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "a>k@B\u0001W@5j\u0018W\u0016F[\".Q\\Dy]7|YF\r[ZpOh{J\"a>k@B\u0001W@5j\u0018W\u0016F[\".Q\\Dy]7|YF\r[ZpOh{J";
                    var4_3 = "a>k@B\u0001W@5j\u0018W\u0016F[\".Q\\Dy]7|YF\r[ZpOh{J\"a>k@B\u0001W@5j\u0018W\u0016F[\".Q\\Dy]7|YF\r[ZpOh{J".length();
                    var1_4 = 34;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 51;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = MigrationApiImpl.a(v0, MigrationApiImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        MigrationApiImpl.c = var5;
        MigrationApiImpl.a = Logger.getLogger(MigrationApiImpl.class.getName());
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 7);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 7;
                    case 1 -> 99;
                    case 2 -> 61;
                    case 3 -> 11;
                    case 4 -> 1;
                    case 5 -> 87;
                    default -> 7;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

