/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.cluster.ClusterProperty
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.EntityTypeRegistry
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  org.hibernate.HibernateException
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.orm.hibernate5.HibernateCallback
 *  org.springframework.transaction.annotation.Propagation
 *  org.springframework.transaction.annotation.Transactional
 */
package com.l7tech.server.cluster;

import com.l7tech.gateway.common.cluster.ClusterProperty;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.EntityTypeRegistry;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.ServerConfig;
import com.l7tech.server.cluster.ClusterPropertyManager;
import com.l7tech.server.cluster.w;
import com.l7tech.server.event.admin.AuditSigningStatusChange;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.HibernateException;
import org.springframework.context.ApplicationEvent;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional(propagation=Propagation.REQUIRED, rollbackFor={Throwable.class})
public class ClusterPropertyManagerImpl
extends HibernateEntityManager<ClusterProperty, EntityHeader>
implements ClusterPropertyManager {
    private final Logger m = Logger.getLogger(ClusterPropertyManagerImpl.class.getName());
    private final String n;
    private static final String[] o;

    public ClusterPropertyManagerImpl() {
        String string = this.getTableName();
        String string2 = ClusterProperty.class.getName();
        String string3 = this.getTableName();
        String[] stringArray = o;
        this.n = stringArray[0] + string3 + stringArray[2] + string2 + stringArray[5] + string + stringArray[8];
    }

    @Override
    @Transactional(readOnly=true)
    public String getProperty(String string) throws FindException {
        ClusterProperty clusterProperty = this.a(string, false);
        try {
            if (clusterProperty != null) {
                return clusterProperty.getValue();
            }
        }
        catch (FindException findException) {
            throw ClusterPropertyManagerImpl.a((Exception)((Object)findException));
        }
        return null;
    }

    private void a(ClusterProperty clusterProperty) {
        block4: {
            block5: {
                try {
                    try {
                        if (!clusterProperty.getName().equals(o[3])) break block4;
                        if (!clusterProperty.getValue().equals(o[6])) break block5;
                    }
                    catch (HibernateException hibernateException) {
                        throw ClusterPropertyManagerImpl.a((Exception)((Object)hibernateException));
                    }
                    this.applicationContext.publishEvent((ApplicationEvent)new AuditSigningStatusChange(this, o[1]));
                    break block4;
                }
                catch (HibernateException hibernateException) {
                    throw ClusterPropertyManagerImpl.a((Exception)((Object)hibernateException));
                }
            }
            this.applicationContext.publishEvent((ApplicationEvent)new AuditSigningStatusChange(this, o[9]));
        }
    }

    @Override
    public ClusterProperty putProperty(String string, String string2) throws FindException, SaveException, UpdateException {
        ClusterProperty clusterProperty = this.a(string, true);
        if (clusterProperty == null) {
            clusterProperty = new ClusterProperty(string, string2);
            Goid goid = this.save(clusterProperty);
            try {
                if (!goid.equals((Object)clusterProperty.getGoid())) {
                    clusterProperty.setGoid(goid);
                }
            }
            catch (FindException findException) {
                throw ClusterPropertyManagerImpl.a((Exception)((Object)findException));
            }
            return clusterProperty;
        }
        clusterProperty.setValue(string2);
        this.update(clusterProperty);
        return clusterProperty;
    }

    @Override
    public Goid save(ClusterProperty clusterProperty) throws SaveException {
        this.a(clusterProperty);
        return super.save(clusterProperty);
    }

    @Override
    public void update(ClusterProperty clusterProperty) throws UpdateException {
        this.a(clusterProperty);
        super.update(clusterProperty);
    }

    private ClusterProperty b(ClusterProperty clusterProperty) {
        try {
            if (clusterProperty == null) {
                return null;
            }
        }
        catch (HibernateException hibernateException) {
            throw ClusterPropertyManagerImpl.a((Exception)((Object)hibernateException));
        }
        ServerConfig serverConfig = ServerConfig.getInstance();
        String string = serverConfig.getNameFromClusterName(clusterProperty.getName());
        try {
            if (string != null) {
                clusterProperty.setProperty(ClusterProperty.DESCRIPTION_PROPERTY_KEY, serverConfig.getPropertyDescription(string));
            }
        }
        catch (HibernateException hibernateException) {
            throw ClusterPropertyManagerImpl.a((Exception)((Object)hibernateException));
        }
        return clusterProperty;
    }

    @Override
    public ClusterProperty getCachedEntityByName(String string, int n2) throws FindException {
        ClusterProperty clusterProperty;
        ClusterProperty clusterProperty2 = (ClusterProperty)super.getCachedEntityByName(string, n2);
        try {
            clusterProperty = clusterProperty2 == null ? null : this.b(clusterProperty2);
        }
        catch (FindException findException) {
            throw ClusterPropertyManagerImpl.a((Exception)((Object)findException));
        }
        return clusterProperty;
    }

    @Override
    @Transactional(readOnly=true)
    public Collection<ClusterProperty> findAll() throws FindException {
        Collection<ClusterProperty> collection = super.findAll();
        for (ClusterProperty clusterProperty : collection) {
            this.b(clusterProperty);
        }
        return collection;
    }

    @Transactional(readOnly=true)
    private ClusterProperty a(String string, boolean bl2) throws FindException {
        try {
            return (ClusterProperty)this.getHibernateTemplate().execute((HibernateCallback)new w(this, string, bl2));
        }
        catch (HibernateException hibernateException) {
            String string2 = o[7];
            this.m.log(Level.WARNING, string2, hibernateException);
            throw new FindException(string2, (Throwable)hibernateException);
        }
    }

    @Override
    public ClusterProperty findByHeader(EntityHeader entityHeader) throws FindException {
        ClusterProperty clusterProperty;
        try {
            if (EntityType.CLUSTER_PROPERTY != entityHeader.getType()) {
                throw new IllegalArgumentException(o[4] + String.valueOf(entityHeader));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterPropertyManagerImpl.a(illegalArgumentException);
        }
        ClusterProperty clusterProperty2 = null;
        Goid goid = null;
        try {
            goid = Goid.parseGoid((String)entityHeader.getStrId());
        }
        catch (IllegalArgumentException illegalArgumentException) {
            // empty catch block
        }
        if (goid != null) {
            clusterProperty2 = (ClusterProperty)super.findByPrimaryKey(EntityTypeRegistry.getEntityClass((EntityType)EntityType.CLUSTER_PROPERTY), goid);
        }
        try {
            clusterProperty = clusterProperty2 != null ? clusterProperty2 : (ClusterProperty)super.findByUniqueName(entityHeader.getName());
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterPropertyManagerImpl.a(illegalArgumentException);
        }
        return clusterProperty;
    }

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

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = "8,i\u0010D\u000210\n~7h]\u0007\u0010:--&\r?+b\u0014\u0010R(79h\u0014\n\u001b\u0015\u00170p\u001c\b\u0015?~6c\u001c\u0000\u0019)~*\u007f\r\u0001F{\u0007~)n\u0018\u0016\u0019{\u0004*,s\u0018\u0019;,t\u0012\u0016\\);*t\u0014\u0001\n209&\r\u0016\u0013+;,r\u0004";
                var4_3 = "8,i\u0010D\u000210\n~7h]\u0007\u0010:--&\r?+b\u0014\u0010R(79h\u0014\n\u001b\u0015\u00170p\u001c\b\u0015?~6c\u001c\u0000\u0019)~*\u007f\r\u0001F{\u0007~)n\u0018\u0016\u0019{\u0004*,s\u0018\u0019;,t\u0012\u0016\\);*t\u0014\u0001\n209&\r\u0016\u0013+;,r\u0004".length();
                var1_4 = 5;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ClusterPropertyManagerImpl.b(v0, ClusterPropertyManagerImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "U\u0015B5$yC[AM9,<\u0003\u0014\u001dE";
                    var4_3 = "U\u0015B5$yC[AM9,<\u0003\u0014\u001dE".length();
                    var1_4 = 13;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 6;
                        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++] = ClusterPropertyManagerImpl.b(v0, ClusterPropertyManagerImpl.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;
            }
        }
        ClusterPropertyManagerImpl.o = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x78);
        }
        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 -> 125;
                    case 1 -> 125;
                    case 2 -> 37;
                    case 3 -> 94;
                    case 4 -> 71;
                    case 5 -> 95;
                    default -> 120;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

