/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.module.ModuleState
 *  com.l7tech.gateway.common.module.ServerModuleFile
 *  com.l7tech.gateway.common.module.ServerModuleFileState
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityManager$UniqueType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.util.Config
 *  com.l7tech.util.Pair
 *  org.apache.commons.lang3.StringUtils
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.context.ApplicationEventPublisher
 *  org.springframework.context.ApplicationEventPublisherAware
 *  org.springframework.orm.hibernate5.HibernateCallback
 *  org.springframework.transaction.annotation.Propagation
 *  org.springframework.transaction.annotation.Transactional
 */
package com.l7tech.server.module;

import com.l7tech.gateway.common.module.ModuleState;
import com.l7tech.gateway.common.module.ServerModuleFile;
import com.l7tech.gateway.common.module.ServerModuleFileState;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityManager;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.event.admin.ServerModuleFileAdminEvent;
import com.l7tech.server.module.ServerModuleFileManager;
import com.l7tech.server.module.l;
import com.l7tech.server.module.m;
import com.l7tech.util.Config;
import com.l7tech.util.Pair;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/*
 * Exception performing whole class analysis ignored.
 */
public class ServerModuleFileManagerImpl
extends HibernateEntityManager<ServerModuleFile, EntityHeader>
implements ApplicationEventPublisherAware,
ServerModuleFileManager {
    public static final String F_MODULE_SHA256;
    @NotNull
    protected final Config config;
    @NotNull
    protected final String clusterNodeId;
    @NotNull
    protected final StashManagerFactory stashManagerFactory;
    private ApplicationEventPublisher m;
    private static final String n;
    private final String o;
    private static final String[] p;

    protected ServerModuleFileManagerImpl(@NotNull Config config, @NotNull String string, @NotNull StashManagerFactory stashManagerFactory) {
        if (config == null) {
            ServerModuleFileManagerImpl.b(0);
        }
        if (string == null) {
            ServerModuleFileManagerImpl.b(1);
        }
        if (stashManagerFactory == null) {
            ServerModuleFileManagerImpl.b(2);
        }
        String string2 = this.getTableName();
        String string3 = this.getImpClass().getName();
        String string4 = this.getTableName();
        try {
            this.o = p[12] + string4 + p[19] + string3 + p[26] + string2 + p[30];
            this.config = config;
            this.stashManagerFactory = stashManagerFactory;
            this.clusterNodeId = string;
            if (StringUtils.isBlank((CharSequence)string)) {
                throw new IllegalStateException(p[14]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw ServerModuleFileManagerImpl.a(illegalStateException);
        }
    }

    @Override
    public Goid save(ServerModuleFile serverModuleFile) throws SaveException {
        Goid goid = super.save(serverModuleFile);
        try {
            if (this.m != null) {
                this.m.publishEvent((ApplicationEvent)new ServerModuleFileAdminEvent((Object)this, ServerModuleFileAdminEvent.Action.UPLOADED, serverModuleFile));
            }
        }
        catch (SaveException saveException) {
            throw ServerModuleFileManagerImpl.a((Exception)((Object)saveException));
        }
        return goid;
    }

    @Override
    public void save(@NotNull Goid goid, @NotNull ServerModuleFile serverModuleFile) throws SaveException {
        try {
            if (goid == null) {
                ServerModuleFileManagerImpl.b(3);
            }
        }
        catch (SaveException saveException) {
            throw ServerModuleFileManagerImpl.a((Exception)((Object)saveException));
        }
        try {
            if (serverModuleFile == null) {
                ServerModuleFileManagerImpl.b(4);
            }
        }
        catch (SaveException saveException) {
            throw ServerModuleFileManagerImpl.a((Exception)((Object)saveException));
        }
        try {
            super.save(goid, serverModuleFile);
            if (this.m != null) {
                this.m.publishEvent((ApplicationEvent)new ServerModuleFileAdminEvent((Object)this, ServerModuleFileAdminEvent.Action.UPLOADED, serverModuleFile));
            }
        }
        catch (SaveException saveException) {
            throw ServerModuleFileManagerImpl.a((Exception)((Object)saveException));
        }
    }

    @Override
    public void delete(ServerModuleFile serverModuleFile) throws DeleteException {
        try {
            super.delete(serverModuleFile);
            if (this.m != null) {
                this.m.publishEvent((ApplicationEvent)new ServerModuleFileAdminEvent((Object)this, ServerModuleFileAdminEvent.Action.DELETED, serverModuleFile));
            }
        }
        catch (DeleteException deleteException) {
            throw ServerModuleFileManagerImpl.a((Exception)((Object)deleteException));
        }
    }

    @Override
    public void delete(Goid goid) throws DeleteException, FindException {
        block4: {
            ServerModuleFile serverModuleFile = (ServerModuleFile)this.findByPrimaryKey(goid);
            try {
                try {
                    super.delete(goid);
                    if (this.m == null || serverModuleFile == null) break block4;
                }
                catch (DeleteException deleteException) {
                    throw ServerModuleFileManagerImpl.a((Exception)((Object)deleteException));
                }
                this.m.publishEvent((ApplicationEvent)new ServerModuleFileAdminEvent((Object)this, ServerModuleFileAdminEvent.Action.DELETED, serverModuleFile));
            }
            catch (DeleteException deleteException) {
                throw ServerModuleFileManagerImpl.a((Exception)((Object)deleteException));
            }
        }
    }

    @Override
    public void updateState(@NotNull Goid goid, @NotNull ModuleState moduleState) throws UpdateException {
        try {
            if (goid == null) {
                ServerModuleFileManagerImpl.b(5);
            }
        }
        catch (RuntimeException runtimeException) {
            throw ServerModuleFileManagerImpl.a(runtimeException);
        }
        try {
            if (moduleState == null) {
                ServerModuleFileManagerImpl.b(6);
            }
        }
        catch (RuntimeException runtimeException) {
            throw ServerModuleFileManagerImpl.a(runtimeException);
        }
        try {
            ServerModuleFile serverModuleFile = (ServerModuleFile)this.findByPrimaryKey(goid);
            try {
                if (serverModuleFile == null) {
                    throw new UpdateException(p[9]);
                }
            }
            catch (RuntimeException runtimeException) {
                throw ServerModuleFileManagerImpl.a(runtimeException);
            }
            serverModuleFile.setStateForNode(this.clusterNodeId, moduleState);
            super.update(serverModuleFile);
        }
        catch (FindException | RuntimeException throwable) {
            throw new UpdateException(p[28] + String.valueOf(goid) + "\"", throwable);
        }
    }

    @Override
    public void updateState(@NotNull Goid goid, @NotNull String string) throws UpdateException {
        try {
            if (goid == null) {
                ServerModuleFileManagerImpl.b(7);
            }
        }
        catch (RuntimeException runtimeException) {
            throw ServerModuleFileManagerImpl.a(runtimeException);
        }
        try {
            if (string == null) {
                ServerModuleFileManagerImpl.b(8);
            }
        }
        catch (RuntimeException runtimeException) {
            throw ServerModuleFileManagerImpl.a(runtimeException);
        }
        try {
            ServerModuleFile serverModuleFile = (ServerModuleFile)this.findByPrimaryKey(goid);
            try {
                if (serverModuleFile == null) {
                    throw new UpdateException(p[2]);
                }
            }
            catch (RuntimeException runtimeException) {
                throw ServerModuleFileManagerImpl.a(runtimeException);
            }
            serverModuleFile.setStateErrorMessageForNode(this.clusterNodeId, string);
            super.update(serverModuleFile);
        }
        catch (FindException | RuntimeException throwable) {
            throw new UpdateException(p[0] + String.valueOf(goid) + "\"", throwable);
        }
    }

    @Override
    @Transactional(propagation=Propagation.SUPPORTS)
    public ServerModuleFileState findStateForCurrentNode(@NotNull ServerModuleFile serverModuleFile) {
        try {
            if (serverModuleFile == null) {
                ServerModuleFileManagerImpl.b(9);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw ServerModuleFileManagerImpl.a(illegalStateException);
        }
        return serverModuleFile.getStateForNode(this.clusterNodeId);
    }

    @Override
    @Transactional(propagation=Propagation.SUPPORTS)
    public boolean isModuleUploadEnabled() {
        return this.config.getBooleanProperty(p[4], false);
    }

    @Override
    @Nullable
    public Pair<InputStream, String> getModuleBytesAsStreamWithSignature(@NotNull Goid goid) throws FindException {
        try {
            if (goid == null) {
                ServerModuleFileManagerImpl.b(10);
            }
        }
        catch (SQLException sQLException) {
            throw ServerModuleFileManagerImpl.a(sQLException);
        }
        try {
            return this.doReadOnlyWork(new l(this, goid));
        }
        catch (SQLException sQLException) {
            throw new FindException(sQLException.toString(), (Throwable)sQLException);
        }
    }

    @Override
    @Transactional(readOnly=true)
    @Nullable
    public ServerModuleFile findModuleWithSha256(@NotNull String string) throws FindException {
        try {
            if (string == null) {
                ServerModuleFileManagerImpl.b(11);
            }
        }
        catch (Exception exception) {
            throw ServerModuleFileManagerImpl.a(exception);
        }
        try {
            return (ServerModuleFile)this.getHibernateTemplate().execute((HibernateCallback)new m(this, string));
        }
        catch (Exception exception) {
            throw new FindException(exception.toString(), (Throwable)exception);
        }
    }

    public Class<? extends Entity> getImpClass() {
        return ServerModuleFile.class;
    }

    @Override
    protected EntityManager.UniqueType getUniqueType() {
        return EntityManager.UniqueType.OTHER;
    }

    @Override
    protected Collection<Map<String, Object>> getUniqueConstraints(@NotNull ServerModuleFile serverModuleFile) {
        try {
            if (serverModuleFile == null) {
                ServerModuleFileManagerImpl.b(12);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw ServerModuleFileManagerImpl.a(illegalStateException);
        }
        Map[] mapArray = new Map[2];
        String[] stringArray = p;
        mapArray[0] = Collections.singletonMap(stringArray[27], serverModuleFile.getName());
        mapArray[1] = Collections.singletonMap(stringArray[29], serverModuleFile.getModuleSha256());
        return Arrays.asList(mapArray);
    }

    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.m = applicationEventPublisher;
    }

    static /* synthetic */ void access$000(ServerModuleFileManagerImpl serverModuleFileManagerImpl, PersistentEntity persistentEntity) {
        serverModuleFileManagerImpl.initializeLazilyLoaded(persistentEntity);
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void b(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 2[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[33];
                var3_1 = 0;
                var2_2 = "\t_\u001a'91e(^[0%0$(T[60&39C[(:000T[#<8 |B\u000f$!1e:^\te9=6(T\u0015 'tg\u000b)A\u001f$!1\u0016(P\u000f 6\u001fP\u0015+: e:X\u0015!u!58P\u000f,;3e/T\t30&e1^\u001f091e:X\u0017 u273\\[!4 $>P\b {\u0005/E\u001a10\u001e/T\t30&\b3U\u000e)0\u0012,0TU0%8*=UU ;5'0T\n1^\u001f091\u00035]\u001e\u0004;^\u0012!\r?]\u000e6!17\u0012^\u001f \u001c0#;T\u000f\b:000T9<!16\u001dB(1'1$1f\u00121=\u0007,;_\u001a1 & 6\u001fP\u0015+: e:X\u0015!u!58P\u000f,;3e/T\t30&e1^\u001f091e:X\u0017 u273\\[!4 $>P\b {\u00a4\u000ft7\u0000\u0016\u0000e8P\u000f$\n6<(T\biu',;_\u001a1 & \u0003A\t*%17(X\u001e6u\u0012\u0017\u0013|[60&39C$(:000T$#<8 |\\\u0014! 8 |x5\u000b\u0010\u0006e\u0016~2\u000bu' .G\u001e7\n9*8D\u0017 \n2,0T$!4 $|U\u001a14t\n\u0012\u0011\u0016*1!)9\u001f\u001f$!5\u001a;^\u0012!uie8P\u000f${3*5U[\u0012\u001d\u0011\u0017\u0019\u0011\u0016*1!)9\u001f\u001c*<0ea\u0011D\f9C\t*'\u0019 /B\u001a\"0\u0005\u001ac4\bu\u0004/P\r (\u001fD\t70:1|R\u00170&  .\u0011\u0015*11h5U[&4:+3E['0t'0P\u0015.t>\u001dC\u001c081+(\u0011\u001d*'t\u0005\u0012^\u000f\u000b 8)|A\u001a749 (T\terq6{\u0011\u0014#uq6r\u0014\be8!6(\u0011\u0015*!t'9\u0011\u0015098\f1^\u001f091\u00164PIpc\u0014;T\u000f\u0010;=4)T8*;'1.P\u0012+!'\u0006?^\u0015#<3\n|x5e\u0016\u0018\u0004\u000fb[\u0013/E\u001a6=\u0019$2P\u001c '\u0012$?E\u00147,\u00069_\u000f,!-\u00025U\u0014:X\u0015!\u0018;!)]\u001e\u0012< -\u000fY\u001aw`b4?^\u0016j9c19R\u0013j&17*T\tj8;!)]\u001ej\u000617*T\t\b:000T=,91\b=_\u001a\"0&\f1A\u0017\n1^\u001f091\u00023X\u001f\u0007|f3\u0000\u0007\u0011e\u00042P\u0016 8\t_\u001a'91e(^[0%0$(T[60&39C[(:000T[#<8 |B\u000f$!1e:^\te9=6(T\u0015 'tg\f1^\u001f091\u00164PIpc\u001dr\\\u0014! 8 \u000fY\u001aw`bea\u0011A(:000T(-4fpj";
                var4_3 = "\t_\u001a'91e(^[0%0$(T[60&39C[(:000T[#<8 |B\u000f$!1e:^\te9=6(T\u0015 'tg\u000b)A\u001f$!1\u0016(P\u000f 6\u001fP\u0015+: e:X\u0015!u!58P\u000f,;3e/T\t30&e1^\u001f091e:X\u0017 u273\\[!4 $>P\b {\u0005/E\u001a10\u001e/T\t30&\b3U\u000e)0\u0012,0TU0%8*=UU ;5'0T\n1^\u001f091\u00035]\u001e\u0004;^\u0012!\r?]\u000e6!17\u0012^\u001f \u001c0#;T\u000f\b:000T9<!16\u001dB(1'1$1f\u00121=\u0007,;_\u001a1 & 6\u001fP\u0015+: e:X\u0015!u!58P\u000f,;3e/T\t30&e1^\u001f091e:X\u0017 u273\\[!4 $>P\b {\u00a4\u000ft7\u0000\u0016\u0000e8P\u000f$\n6<(T\biu',;_\u001a1 & \u0003A\t*%17(X\u001e6u\u0012\u0017\u0013|[60&39C$(:000T$#<8 |\\\u0014! 8 |x5\u000b\u0010\u0006e\u0016~2\u000bu' .G\u001e7\n9*8D\u0017 \n2,0T$!4 $|U\u001a14t\n\u0012\u0011\u0016*1!)9\u001f\u001f$!5\u001a;^\u0012!uie8P\u000f${3*5U[\u0012\u001d\u0011\u0017\u0019\u0011\u0016*1!)9\u001f\u001c*<0ea\u0011D\f9C\t*'\u0019 /B\u001a\"0\u0005\u001ac4\bu\u0004/P\r (\u001fD\t70:1|R\u00170&  .\u0011\u0015*11h5U[&4:+3E['0t'0P\u0015.t>\u001dC\u001c081+(\u0011\u001d*'t\u0005\u0012^\u000f\u000b 8)|A\u001a749 (T\terq6{\u0011\u0014#uq6r\u0014\be8!6(\u0011\u0015*!t'9\u0011\u0015098\f1^\u001f091\u00164PIpc\u0014;T\u000f\u0010;=4)T8*;'1.P\u0012+!'\u0006?^\u0015#<3\n|x5e\u0016\u0018\u0004\u000fb[\u0013/E\u001a6=\u0019$2P\u001c '\u0012$?E\u00147,\u00069_\u000f,!-\u00025U\u0014:X\u0015!\u0018;!)]\u001e\u0012< -\u000fY\u001aw`b4?^\u0016j9c19R\u0013j&17*T\tj8;!)]\u001ej\u000617*T\t\b:000T=,91\b=_\u001a\"0&\f1A\u0017\n1^\u001f091\u00023X\u001f\u0007|f3\u0000\u0007\u0011e\u00042P\u0016 8\t_\u001a'91e(^[0%0$(T[60&39C[(:000T[#<8 |B\u000f$!1e:^\te9=6(T\u0015 'tg\f1^\u001f091\u00164PIpc\u001dr\\\u0014! 8 \u000fY\u001aw`bea\u0011A(:000T(-4fpj".length();
                var1_4 = 56;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerModuleFileManagerImpl.b(v0, ServerModuleFileManagerImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "e\u0007J~Y\u007f{w\u000bbuxHoq\u001cAt~Eug\u000b\u0006?\u0007Js~5";
                    var4_3 = "e\u0007J~Y\u007f{w\u000bbuxHoq\u001cAt~Eug\u000b\u0006?\u0007Js~5".length();
                    var1_4 = 23;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 46;
                        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++] = ServerModuleFileManagerImpl.b(v0, ServerModuleFileManagerImpl.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;
            }
        }
        ServerModuleFileManagerImpl.p = var5;
        ServerModuleFileManagerImpl.F_MODULE_SHA256 = ServerModuleFileManagerImpl.p[16];
        ServerModuleFileManagerImpl.n = ServerModuleFileManagerImpl.p[10];
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 45;
                    case 1 -> 64;
                    case 2 -> 10;
                    case 3 -> 52;
                    case 4 -> 36;
                    case 5 -> 37;
                    default -> 52;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

