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

org.schema.EcOrganization Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package org.schema;

import com.eduworks.ec.array.EcArray;
import org.cassproject.ebac.repository.EcEncryptedValue;
import org.cassproject.ebac.repository.EcRepository;
import org.cassproject.schema.general.EcRemoteLinkedData;
import org.stjs.javascript.Array;
import org.stjs.javascript.JSCollections;
import org.stjs.javascript.JSObjectAdapter;
import org.stjs.javascript.functions.Callback1;

public class EcOrganization extends Organization {

    /**
     * Searches a repository for organizations that match the search query
     *
     * @param {EcRepository}          repo Repository to search using the query
     * @param {String}                query Query string to pass to the search web service
     * @param {Callback1> success Callback triggered after
     *                                completing the search, returns the results
     * @param {Callback1}     failure Callback triggered if error searching
     * @param {Object}                paramObj Parameter object for search
     * @memberOf EcOrganization
     * @method search
     * @static
     */
    public static void search(EcRepository repo, String query, final Callback1> success, Callback1 failure, Object paramObj) {
        String queryAdd = "";
        queryAdd = new Organization().getSearchStringByType();

        if (query == null || query == "") query = queryAdd;
        else query = "(" + query + ") AND " + queryAdd;

        repo.searchWithParams(query, paramObj, null, new Callback1>() {
            @Override
            public void $invoke(Array p1) {
                if (success != null) {
                    Array ret = JSCollections.$array();
                    for (int i = 0; i < p1.$length(); i++) {
                        EcOrganization comp = new EcOrganization();
                        if (p1.$get(i).isAny(comp.getTypes())) {
                            comp.copyFrom(p1.$get(i));
                        }
                        else if (p1.$get(i).isA(EcEncryptedValue.myType)) {
                            EcEncryptedValue val = new EcEncryptedValue();
                            val.copyFrom(p1.$get(i));
                            if (val.isAnEncrypted(new EcOrganization().getFullType())) {
                                EcRemoteLinkedData obj = val.decryptIntoObject();
                                comp.copyFrom(obj);
                                EcEncryptedValue.encryptOnSave(comp.id, true);
                            }
                        }
                        ret.$set(i, comp);
                    }
                    success.$invoke(ret);
                }
            }
        }, failure);
    }

    /**
     * Adds the given person's id to the member list
     *
     * @param {EcPerson}          person Person to add to the Organization's member list
     * @method addMember
     */
    public void addMember(EcPerson person) {
        if (member == null) JSObjectAdapter.$put(this, "member", new Array());
        if (!EcArray.isArray(member)) throw new RuntimeException("Member is not Array");
        Array ary = (Array) (Object) member;
        String psid = person.shortId();
        for (int i=0;i ary = (Array) (Object) member;
        for (int i = 0; i < ary.$length(); i++) {
            if (EcRemoteLinkedData.trimVersionFromUrl(ary.$get(i)) == EcRemoteLinkedData.trimVersionFromUrl(id)) {
                ary.splice(i, 1);
            }
        }
    }

    /**
     * Attempts to find and return the organization's fingerprint from the id.
     *
     * @return {String}
     * @method getFingerprintFromId
     */
    public String getFingerprintFromId() {
        return getGuid();
    }

    /**
     * Attempts to find and return the organization's fingerprint from the id.
     *
     * @return {String}
     * @method getFingerprintFromId
     */
    public String getFingerprint() {
        return getGuid();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy