Search in sources :

Example 1 with Link

use of life.genny.qwanda.Link in project rulesservice by genny-project.

the class QRules method getRecipientCodes.

public String[] getRecipientCodes(final QEventAttributeValueChangeMessage msg) {
    String[] results = null;
    Set<EntityEntity> links = msg.getBe().getLinks();
    Set<String> recipientCodesSet = new HashSet<String>();
    for (EntityEntity ee : links) {
        Link link = ee.getLink();
        String[] recipientArray = VertxUtils.getSubscribers(realm(), link.getTargetCode());
        if (recipientArray != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArray));
        }
        String[] recipientArray2 = VertxUtils.getSubscribers(realm(), link.getSourceCode());
        if (recipientArray2 != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArray2));
        }
    }
    results = (String[]) FluentIterable.from(recipientCodesSet).toArray(String.class);
    return results;
}
Also used : EntityEntity(life.genny.qwanda.entity.EntityEntity) Link(life.genny.qwanda.Link) HashSet(java.util.HashSet)

Example 2 with Link

use of life.genny.qwanda.Link in project rulesservice by genny-project.

the class QRules method getParent.

/*
	 * Get user's company code
	 */
public BaseEntity getParent(final String targetCode, final String linkCode) {
    try {
        String beJson = QwandaUtils.apiGet(getQwandaServiceUrl() + "/qwanda/entityentitys/" + targetCode + "/linkcodes/" + linkCode + "/parents", getToken());
        Link[] linkArray = RulesUtils.fromJson(beJson, Link[].class);
        if (linkArray.length > 0) {
            ArrayList<Link> arrayList = new ArrayList<Link>(Arrays.asList(linkArray));
            Link first = arrayList.get(0);
            RulesUtils.println("The parent code is   ::  " + first.getSourceCode());
            return RulesUtils.getBaseEntityByCode(getQwandaServiceUrl(), getDecodedTokenMap(), getToken(), first.getSourceCode(), false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Link(life.genny.qwanda.Link) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadDataException(life.genny.qwanda.exception.BadDataException) ParseException(org.json.simple.parser.ParseException)

Example 3 with Link

use of life.genny.qwanda.Link in project rulesservice by genny-project.

the class QRules method getAllChildrens.

/*
	 * Get all childrens for the given source code with the linkcode and linkValue
	 */
public List<BaseEntity> getAllChildrens(final String sourceCode, final String linkCode, final String linkValue) {
    List<BaseEntity> childList = new ArrayList<BaseEntity>();
    try {
        String beJson = QwandaUtils.apiGet(getQwandaServiceUrl() + "/qwanda/entityentitys/" + sourceCode + "/linkcodes/" + linkCode + "/children/" + linkValue, getToken());
        Link[] linkArray = RulesUtils.fromJson(beJson, Link[].class);
        if (linkArray.length > 0) {
            ArrayList<Link> arrayList = new ArrayList<Link>(Arrays.asList(linkArray));
            for (Link link : arrayList) {
                // RulesUtils.println("The Child BaseEnity code is :: " + link.getTargetCode());
                childList.add(RulesUtils.getBaseEntityByCode(getQwandaServiceUrl(), getDecodedTokenMap(), getToken(), link.getTargetCode(), false));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return childList;
}
Also used : BaseEntity(life.genny.qwanda.entity.BaseEntity) ArrayList(java.util.ArrayList) Link(life.genny.qwanda.Link) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadDataException(life.genny.qwanda.exception.BadDataException) ParseException(org.json.simple.parser.ParseException)

Example 4 with Link

use of life.genny.qwanda.Link in project rulesservice by genny-project.

the class QRules method getRecipientCodes.

public String[] getRecipientCodes(final QEventLinkChangeMessage msg) {
    String[] results = null;
    Link link = msg.getLink();
    Set<String> recipientCodesSet = new HashSet<String>();
    if (link != null) {
        String[] recipientArray = VertxUtils.getSubscribers(realm(), link.getTargetCode());
        if (recipientArray != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArray));
        }
        String[] recipientArray2 = VertxUtils.getSubscribers(realm(), link.getSourceCode());
        if (recipientArray2 != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArray2));
        }
    }
    Link oldlink = msg.getOldLink();
    if (oldlink != null) {
        String[] recipientArrayOld = VertxUtils.getSubscribers(realm(), oldlink.getTargetCode());
        if (recipientArrayOld != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArrayOld));
        }
        String[] recipientArray2Old = VertxUtils.getSubscribers(realm(), oldlink.getSourceCode());
        if (recipientArray2Old != null) {
            recipientCodesSet.addAll(Sets.newHashSet(recipientArray2Old));
        }
    }
    results = (String[]) FluentIterable.from(recipientCodesSet).toArray(String.class);
    return results;
}
Also used : Link(life.genny.qwanda.Link) HashSet(java.util.HashSet)

Example 5 with Link

use of life.genny.qwanda.Link in project rulesservice by genny-project.

the class QRules method sendRating.

public void sendRating(String data) throws ClientProtocolException, IOException {
    if (data != null) {
        JsonObject dataJson = new JsonObject(data);
        String begCode = dataJson.getString("itemCode");
        String userCode = getUser().getCode();
        String driverCode = null;
        /* we get all the linked BEs to beg */
        List<Link> links = getLinks(begCode, "LNK_BEG");
        if (links != null) {
            for (Link link : links) {
                String linkValue = link.getLinkValue();
                if (linkValue != null && linkValue.equals("DRIVER")) {
                    driverCode = link.getTargetCode();
                }
            }
        }
        if (begCode != null && driverCode != null) {
            /*
				 * we save the BEG code as an attribute in order to track what job a driver is
				 * being currently rated against. if this comment does not make sense please
				 * refer to the french man.
				 */
            updateBaseEntityAttribute(userCode, userCode, "STT_JOB_IS_RATING", begCode);
            /* we send the questions */
            sendQuestions(userCode, driverCode, "QUE_USER_RATING_GRP", true);
            /* we send the layout */
            sendSublayout("driver-rating", "rate-driver.json", driverCode, true);
        }
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Link(life.genny.qwanda.Link)

Aggregations

Link (life.genny.qwanda.Link)12 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 BaseEntity (life.genny.qwanda.entity.BaseEntity)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 BadDataException (life.genny.qwanda.exception.BadDataException)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 ParseException (org.json.simple.parser.ParseException)3 JsonObject (io.vertx.core.json.JsonObject)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 QEventLinkChangeMessage (life.genny.qwanda.message.QEventLinkChangeMessage)2 List (java.util.List)1 Answer (life.genny.qwanda.Answer)1 EntityEntity (life.genny.qwanda.entity.EntityEntity)1 JSONObject (org.json.simple.JSONObject)1