/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.policy.Policy
 *  com.l7tech.policy.PolicyVersion
 *  org.springframework.transaction.TransactionStatus
 *  org.springframework.transaction.support.TransactionCallback
 */
package com.l7tech.server.bundling;

import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.policy.Policy;
import com.l7tech.policy.PolicyVersion;
import com.l7tech.server.bundling.EntityBundleImporterImpl;
import com.l7tech.server.bundling.EntityMappingResult;
import java.util.Map;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;

class t
implements TransactionCallback<Throwable> {
    final EntityMappingResult val$results;
    final Map val$resourceMapping;
    final EntityBundleImporterImpl this$0;
    private static final String a = t.a(106, t.a("\\\t\u0006 \u001ec)y\u0001\u0006*Qby{\t\u001c+\u00157fmH\u000b<\u0014v}z\fH>\u001e{`|\u0011H!\u00037zz\u001a\u001e'\u0012r)z\u0006\u001c'\u0005n)h\u0001\u001c&Q\u007fl~\f\r<K7"));

    /*
     * Ignored method signature, as it can't be verified against descriptor
     */
    t(EntityBundleImporterImpl entityBundleImporterImpl, EntityMappingResult entityMappingResult, Map map) {
        this.this$0 = entityBundleImporterImpl;
        this.val$results = entityMappingResult;
        this.val$resourceMapping = map;
    }

    /*
     * Loose catch block
     */
    public Throwable doInTransaction(TransactionStatus transactionStatus) {
        try {
            block9: {
                String string;
                Policy policy;
                block7: {
                    Entity entity;
                    block8: {
                        entity = this.this$0.entityCrud.find(this.val$results.getTargetEntityHeader());
                        if (entity == null) {
                            transactionStatus.setRollbackOnly();
                            return new FindException(a + this.val$results.getTargetEntityHeader().toStringVerbose());
                        }
                        policy = entity instanceof Policy ? (Policy)entity : ((PublishedService)entity).getPolicy();
                        string = policy.getXml();
                        PolicyVersion policyVersion = this.this$0.policyVersionManager.findLatestRevisionForPolicy(policy.getGoid());
                        policy.setXml(policyVersion.getXml());
                        Policy policy2 = new Policy(policy);
                        this.this$0.dependencyAnalyzer.replaceDependencies(policy2, this.val$resourceMapping, true);
                        policy.setXml(policy2.getXml());
                        policyVersion.setXml(policy.getXml());
                        this.this$0.policyVersionManager.update((PersistentEntity)policyVersion);
                        if (!policyVersion.isActive()) break block7;
                        try {
                            block10: {
                                if (!(entity instanceof Policy)) break block8;
                                break block10;
                                catch (Throwable throwable) {
                                    throw t.a(throwable);
                                }
                            }
                            this.this$0.policyManager.update((PersistentEntity)policy);
                            break block9;
                        }
                        catch (Throwable throwable) {
                            throw t.a(throwable);
                        }
                    }
                    this.this$0.serviceManager.update((PersistentEntity)((PublishedService)entity));
                    break block9;
                }
                policy.setXml(string);
            }
            transactionStatus.flush();
            return null;
        }
        catch (Throwable throwable) {
            transactionStatus.setRollbackOnly();
            return throwable;
        }
    }

    private static Throwable a(Throwable throwable) {
        return throwable;
    }

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

