/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.gateway.common.service.ServiceHeader
 *  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.PolicyVersion
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.service;

import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.gateway.common.service.ServiceHeader;
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.PolicyVersion;
import com.l7tech.server.policy.PolicyVersionManager;
import com.l7tech.server.service.ServiceManager;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PolicyVersioningServiceManager
implements ServiceManager {
    private final ServiceManager a;
    private final PolicyVersionManager b;
    private static final String[] c;

    public PolicyVersioningServiceManager(ServiceManager serviceManager, PolicyVersionManager policyVersionManager) {
        this.a = serviceManager;
        this.b = policyVersionManager;
    }

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

    @Override
    public void addManageServiceRole(PublishedService publishedService) throws SaveException {
        this.a.addManageServiceRole(publishedService);
    }

    @Override
    public Collection<ServiceHeader> findAllHeaders(boolean bl2) throws FindException {
        return this.a.findAllHeaders(bl2);
    }

    @Override
    public Collection<PublishedService> findByRoutingUri(String string) throws FindException {
        return this.a.findByRoutingUri(string);
    }

    @Override
    public String resolveWsdlTarget(String string) {
        return this.a.resolveWsdlTarget(string);
    }

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

    public void delete(PublishedService publishedService) throws DeleteException {
        this.a.delete((PersistentEntity)publishedService);
    }

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

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

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

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

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

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

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

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

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

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

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

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

    public List<PublishedService> 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 Integer getVersion(Goid goid) throws FindException {
        return this.a.getVersion(goid);
    }

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

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

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private Goid a(@Nullable Goid goid, PublishedService publishedService) throws SaveException {
        Policy policy = publishedService.getPolicy();
        try {
            if (policy != null) {
                policy.setVersion(0);
            }
        }
        catch (ObjectModelException objectModelException) {
            throw PolicyVersioningServiceManager.a((Exception)((Object)objectModelException));
        }
        if (goid == null) {
            goid = this.a.save((PersistentEntity)publishedService);
        } else {
            this.a.save(goid, (PersistentEntity)publishedService);
        }
        try {
            if (policy == null) return goid;
            try {
                this.b.checkpointPolicy(policy, true, true);
                return goid;
            }
            catch (ObjectModelException objectModelException) {
                throw new SaveException(c[3], (Throwable)objectModelException);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyVersioningServiceManager.a(illegalArgumentException);
        }
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public void update(PublishedService publishedService) throws UpdateException {
        try {
            this.a.update((PersistentEntity)publishedService);
            if (publishedService.getPolicy() == null) return;
            try {
                this.b.checkpointPolicy(publishedService.getPolicy(), true, false);
                return;
            }
            catch (ObjectModelException objectModelException) {
                throw new UpdateException(c[1], (Throwable)objectModelException);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyVersioningServiceManager.a(illegalArgumentException);
        }
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public void updateWithFolder(PublishedService publishedService) throws UpdateException {
        try {
            this.a.updateWithFolder((PersistentEntity)publishedService);
            if (publishedService.getPolicy() == null) return;
            try {
                this.b.checkpointPolicy(publishedService.getPolicy(), true, false);
                return;
            }
            catch (ObjectModelException objectModelException) {
                throw new UpdateException(c[0], (Throwable)objectModelException);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyVersioningServiceManager.a(illegalArgumentException);
        }
    }

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

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

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

    public void createRoles(PublishedService publishedService) throws SaveException {
        this.a.createRoles((PersistentEntity)publishedService);
    }

    public void updateRoles(PublishedService publishedService) throws UpdateException {
        this.a.updateRoles((PersistentEntity)publishedService);
    }

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

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

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

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[7];
                var3_1 = 0;
                var2_2 = "\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'7\u0010NHx)i%@YL~6n!\u0005\u00044\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'7\u0010NHx)i%@YL~6n!\u0005\u00048!\u000fG\u0006`ws'\u0003B\u0006\u007f%u4\u0005X\u0006\u007f%u4\tIL#\u0010h.\tIPZ%u1\tEGe.`\u0011\u0005X_e#b\u000f\u0001DHk%u2\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'1\u0001\\@b''1\u0005X_e#bl\n$\u000fFMi2@-\tN";
                var4_3 = "\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'7\u0010NHx)i%@YL~6n!\u0005\u00044\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'7\u0010NHx)i%@YL~6n!\u0005\u00048!\u000fG\u0006`ws'\u0003B\u0006\u007f%u4\u0005X\u0006\u007f%u4\tIL#\u0010h.\tIPZ%u1\tEGe.`\u0011\u0005X_e#b\u000f\u0001DHk%u2\u0017\u000eKK`%'6\u000f\nZm6bb\u0010EEe#~b\u0016O[\u007f)h,@]Ai.'1\u0001\\@b''1\u0005X_e#bl\n$\u000fFMi2@-\tN".length();
                var1_4 = 52;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PolicyVersioningServiceManager.a(v0, PolicyVersioningServiceManager.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "cr-<\u0001E\tV ,&\u001e\u0000'lo>\u0007\u0019L\u000b\u0002p+;\rM\u0002Ve8iK\u0005\u0014\u0005 %/L\u0005\u0014\f%9i\u0001U\u0014V $&\u0018\u0000\u0005G $<\u0000L\fDi$-.Y!Ml.,\u001e";
                    var4_3 = "cr-<\u0001E\tV ,&\u001e\u0000'lo>\u0007\u0019L\u000b\u0002p+;\rM\u0002Ve8iK\u0005\u0014\u0005 %/L\u0005\u0014\f%9i\u0001U\u0014V $&\u0018\u0000\u0005G $<\u0000L\fDi$-.Y!Ml.,\u001e".length();
                    var1_4 = 62;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 68;
                        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++] = PolicyVersioningServiceManager.a(v0, PolicyVersioningServiceManager.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;
            }
        }
        PolicyVersioningServiceManager.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 -> 102;
                    case 1 -> 68;
                    case 2 -> 14;
                    case 3 -> 13;
                    case 4 -> 40;
                    case 5 -> 100;
                    default -> 35;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

