com.futuresight.util.mystique.ConditionMystTurn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-mystique Show documentation
Show all versions of json-mystique Show documentation
Json Utility to transform Jsons
/*
* Copyright (c) Balajee TM 2016.
* All rights reserved.
* License - @see
*/
/*
* Created on 25 Aug, 2016 by balajeetm
*/
package com.futuresight.util.mystique;
import java.util.List;
import org.springframework.stereotype.Component;
import com.futuresight.util.mystique.lever.MysCon;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
/**
* The Class ConditionMystTurn.
*
* @author balajeetm
*/
@Component
public class ConditionMystTurn extends AbstractMystTurn {
/* (non-Javadoc)
* @see com.futuresight.util.mystique.AbstractMystique#transmute(java.util.List, com.google.gson.JsonObject, com.google.gson.JsonObject)
*/
@Override
protected JsonElement transmute(List source, JsonObject deps, JsonObject aces, JsonObject turn) {
JsonElement transform = null;
JsonElement elementSource = jsonLever.getFirst(source);
turn = jsonLever.getAsJsonObject(turn, new JsonObject());
JsonElement granularSource = getGranularSource(elementSource, turn, deps, aces);
JsonElement value = turn.get(MysCon.VALUE);
Boolean equals = isEquals(granularSource, value);
JsonObject defaultJson = jsonLever.getAsJsonObject(turn.get(String.valueOf(equals)));
transform = jsonLever.isNull(defaultJson) ? new JsonPrimitive(equals) : transformToDefault(defaultJson,
source, deps, aces);
return transform;
}
/**
* Checks if is equals.
*
* @param source the source
* @param expected the expected
* @return the boolean
*/
private Boolean isEquals(JsonElement source, JsonElement expected) {
Boolean isEqual = Boolean.FALSE;
// This is to check the existence case. The condition is to check the existence of the element
if (null == expected) {
if (jsonLever.isNotNull(source)) {
isEqual = Boolean.TRUE;
}
}
else {
if (jsonLever.isNull(source) && expected.isJsonNull()) {
isEqual = Boolean.TRUE;
}
isEqual = expected.equals(source);
}
return isEqual;
}
}