All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cass.rollup.coprocessor.general.TrustCoprocessor Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package cass.rollup.coprocessor.general;

import cass.rollup.InquiryPacket;
import cass.rollup.coprocessor.AssertionCoprocessor;
import com.eduworks.ec.array.EcObject;
import com.eduworks.ec.crypto.EcPk;
import org.cass.profile.EcAssertion;
import org.stjs.javascript.Array;
import org.stjs.javascript.JSObjectAdapter;
import org.stjs.javascript.functions.Callback0;

public class TrustCoprocessor extends AssertionCoprocessor {

    public EcPk agent;
    public double multiplier = 1.0;
    public boolean removeNoConfidence = false;

    public void mutateAssertions(InquiryPacket ip, Array listOfCompetencies, Callback0 success) {
        Array keys = EcObject.keys(this.assertionProcessor.assertions);
        for (int keyIndex = 0; keyIndex < keys.$length(); keyIndex++) {
            Array ary = (Array) JSObjectAdapter.$get(this.assertionProcessor.assertions, keys.$get(keyIndex));
            for (int i = 0; i < ary.$length(); i++) {
                EcAssertion a = ary.$get(i);
                if (a.getAgent().toPem() == agent.toPem()) {
                    a.confidence = a.confidence * multiplier;
                    if (removeNoConfidence && a.confidence == 0.0)
                        ary.splice(i--, 1);
                }
            }
        }
        success.$invoke();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy