/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectModelException
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.objectmodel.folder.Folder
 *  com.l7tech.policy.Policy
 *  com.l7tech.policy.PolicyHeader
 *  com.l7tech.policy.PolicyType
 *  com.l7tech.policy.PolicyVersion
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 *  org.springframework.transaction.annotation.Transactional
 */
package com.l7tech.server.policy;

import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.objectmodel.folder.Folder;
import com.l7tech.policy.Policy;
import com.l7tech.policy.PolicyHeader;
import com.l7tech.policy.PolicyType;
import com.l7tech.policy.PolicyVersion;
import com.l7tech.server.policy.PolicyManager;
import com.l7tech.server.policy.PolicyVersionManager;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor={Throwable.class})
public class VersioningPolicyManager
implements PolicyManager {
    private final PolicyManager a;
    private final PolicyVersionManager b;
    private static final String[] c;

    public VersioningPolicyManager(PolicyManager policyManager, PolicyVersionManager policyVersionManager) {
        this.a = policyManager;
        this.b = policyVersionManager;
    }

    @Override
    public Collection<PolicyHeader> findHeadersByType(PolicyType policyType) throws FindException {
        return this.a.findHeadersByType(policyType);
    }

    @Override
    public void addManagePolicyRole(Policy policy) throws SaveException {
        this.a.addManagePolicyRole(policy);
    }

    @Override
    public Policy findByGuid(String string) throws FindException {
        return this.a(this.a.findByGuid(string));
    }

    @Override
    public Collection<PolicyHeader> findHeadersWithTypes(Set<PolicyType> set) throws FindException {
        return this.a.findHeadersWithTypes(set);
    }

    @Override
    public Collection<PolicyHeader> findHeadersWithTypes(Set<PolicyType> set, boolean bl2) throws FindException {
        return this.a.findHeadersWithTypes(set, bl2);
    }

    public Policy findByPrimaryKey(Goid goid) throws FindException {
        return this.a((Policy)this.a.findByPrimaryKey(goid));
    }

    public Policy findByHeader(EntityHeader entityHeader) throws FindException {
        return this.a((Policy)this.a.findByHeader(entityHeader));
    }

    public List<Policy> findPagedMatching(int n2, int n3, String string, Boolean bl2, Map<String, List<Object>> map) throws FindException {
        return this.a(this.a.findPagedMatching(n2, n3, string, bl2, map));
    }

    public Collection<PolicyHeader> findAllHeaders() throws FindException {
        return this.a.findAllHeaders();
    }

    public Collection<PolicyHeader> findAllHeaders(int n2, int n3) throws FindException {
        return this.a.findAllHeaders(n2, n3);
    }

    public Collection<Policy> findAll() throws FindException {
        return this.a(this.a.findAll());
    }

    public Goid save(Policy policy) throws SaveException {
        return this.a(null, policy);
    }

    public void save(Goid goid, Policy policy) throws SaveException {
        this.a(goid, policy);
    }

    private Goid a(@Nullable Goid goid, Policy policy) throws SaveException {
        try {
            if (policy != null) {
                policy.setVersion(0);
            }
        }
        catch (ObjectModelException objectModelException) {
            throw VersioningPolicyManager.a(objectModelException);
        }
        if (goid == null) {
            goid = this.a.save((PersistentEntity)policy);
        } else {
            this.a.save(goid, (PersistentEntity)policy);
        }
        try {
            this.b.checkpointPolicy(policy, true, true);
        }
        catch (ObjectModelException objectModelException) {
            throw new SaveException(c[0], (Throwable)objectModelException);
        }
        return goid;
    }

    public Integer getVersion(Goid goid) throws FindException {
        return this.a.getVersion(goid);
    }

    public Map<Goid, Integer> findVersionMap() throws FindException {
        return this.a.findVersionMap();
    }

    public void delete(Policy policy) throws DeleteException {
        this.a.delete((PersistentEntity)policy);
    }

    @Override
    public void deleteWithoutValidation(Policy policy) throws DeleteException {
        this.a.deleteWithoutValidation(policy);
    }

    public Policy getCachedEntity(Goid goid, int n2) throws FindException {
        return (Policy)this.a.getCachedEntity(goid, n2);
    }

    public Class<? extends Entity> getInterfaceClass() {
        return this.a.getInterfaceClass();
    }

    public EntityType getEntityType() {
        return this.a.getEntityType();
    }

    public String getTableName() {
        return this.a.getTableName();
    }

    public Policy findByUniqueName(String string) throws FindException {
        return (Policy)this.a.findByUniqueName(string);
    }

    public void delete(Goid goid) throws DeleteException, FindException {
        this.a.delete(goid);
    }

    public void update(Policy policy) throws UpdateException {
        this.a.update((PersistentEntity)policy);
        try {
            this.b.checkpointPolicy(policy, true, false);
        }
        catch (ObjectModelException objectModelException) {
            throw new UpdateException(c[5], (Throwable)objectModelException);
        }
    }

    public void updateWithFolder(Policy policy) throws UpdateException {
        this.a.updateWithFolder((PersistentEntity)policy);
        try {
            this.b.checkpointPolicy(policy, true, false);
        }
        catch (ObjectModelException objectModelException) {
            throw new UpdateException(c[2], (Throwable)objectModelException);
        }
    }

    public Collection<Policy> findByFolder(@NotNull Goid goid) throws FindException {
        try {
            if (goid == null) {
                VersioningPolicyManager.a(0);
            }
        }
        catch (FindException findException) {
            throw VersioningPolicyManager.a((ObjectModelException)((Object)findException));
        }
        return this.a.findByFolder(goid);
    }

    public void updateFolder(Policy policy, Folder folder) throws UpdateException {
        this.a.updateFolder((PersistentEntity)policy, folder);
    }

    public void updateFolder(Goid goid, Folder folder) throws UpdateException {
        this.a.updateFolder(goid, folder);
    }

    public Collection<PolicyHeader> findHeaders(int n2, int n3, Map<String, String> map) throws FindException {
        return this.a.findHeaders(n2, n3, map);
    }

    public Class<? extends Entity> getImpClass() {
        return this.a.getImpClass();
    }

    public void createRoles(Policy policy) throws SaveException {
        this.a.createRoles((PersistentEntity)policy);
    }

    public void updateRoles(Policy policy) throws UpdateException {
        this.a.updateRoles((PersistentEntity)policy);
    }

    private <C extends Collection<Policy>> C a(C c10) throws FindException {
        if (c10 != null) {
            for (Policy policy : c10) {
                this.a(policy);
            }
        }
        return c10;
    }

    private Policy a(Policy policy) throws FindException {
        try {
            if (policy == null) {
                return null;
            }
        }
        catch (FindException findException) {
            throw VersioningPolicyManager.a((ObjectModelException)((Object)findException));
        }
        PolicyVersion policyVersion = this.b.findActiveVersionForPolicy(policy.getGoid());
        try {
            if (policyVersion != null) {
                policy.setVersionOrdinal(policyVersion.getOrdinal());
                policy.setVersionActive(true);
            }
        }
        catch (FindException findException) {
            throw VersioningPolicyManager.a((ObjectModelException)((Object)findException));
        }
        return policy;
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = c;
        throw new IllegalArgumentException(String.format(stringArray[6], stringArray[3], stringArray[4], stringArray[1]));
    }

    private static ObjectModelException a(ObjectModelException objectModelException) {
        return objectModelException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[7];
                var3_1 = 0;
                var2_2 = "7B!}U))\u0016C`lX:lB\\/sP/pBZ%mJ%f\f\u0002\f\u0004E.{{5O\r@$zK37B!}U))\u0016C`lX:lB\\/sP/pBZ%mJ%f\f\f7w\\\")\u0017\\$~M%g\u0005\f0pU%j\u001b\u0002\n\u0004C,{\\>N\rE$0\u0001C-0U{}\u0007O(0J){\u0014I20I#e\u000bO90o){\u0011E/qP\"n2C,vZ5D\u0003B!x\\>";
                var4_3 = "7B!}U))\u0016C`lX:lB\\/sP/pBZ%mJ%f\f\u0002\f\u0004E.{{5O\r@$zK37B!}U))\u0016C`lX:lB\\/sP/pBZ%mJ%f\f\f7w\\\")\u0017\\$~M%g\u0005\f0pU%j\u001b\u0002\n\u0004C,{\\>N\rE$0\u0001C-0U{}\u0007O(0J){\u0014I20I#e\u000bO90o){\u0011E/qP\"n2C,vZ5D\u0003B!x\\>".length();
                var1_4 = 30;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = VersioningPolicyManager.a(v0, VersioningPolicyManager.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "i\u001c\u007f#\u000bwwH\u001d>2\u0006d2\u001c\u0002q-\u000eq.\u001c\u0004{3\u0014{8RRi)\u0002|wI\u0002z \u0013{9[Rn.\u000b{4E\\>}\u0000y4\nw9HRx.\u00152\u0017r\u001dj\u000f\u0012~;\u001c\u0002\u007f3\u0006\u007f2H\u0017la@7$\u001bRq'G7$\u0012Wma\ng$HRp.\u001325YRp4\u000b~";
                    var4_3 = "i\u001c\u007f#\u000bwwH\u001d>2\u0006d2\u001c\u0002q-\u000eq.\u001c\u0004{3\u0014{8RRi)\u0002|wI\u0002z \u0013{9[Rn.\u000b{4E\\>}\u0000y4\nw9HRx.\u00152\u0017r\u001dj\u000f\u0012~;\u001c\u0002\u007f3\u0006\u007f2H\u0017la@7$\u001bRq'G7$\u0012Wma\ng$HRp.\u001325YRp4\u000b~".length();
                    var1_4 = 51;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 116;
                        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++] = VersioningPolicyManager.a(v0, VersioningPolicyManager.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;
            }
        }
        VersioningPolicyManager.c = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x23);
        }
        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 -> 72;
                    case 1 -> 6;
                    case 2 -> 106;
                    case 3 -> 53;
                    case 4 -> 19;
                    case 5 -> 102;
                    default -> 35;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

