use of com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency in project navajo by Dexels.
the class CompiledTestScript2 method getDependentObjects.
@Override
public ArrayList<Dependency> getDependentObjects() {
ArrayList<Dependency> deps = new ArrayList<Dependency>();
deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter3", "whatever", "id2"));
return deps;
}
use of com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency in project navajo by Dexels.
the class CompiledTestScript method getDependentObjects.
@Override
public ArrayList<Dependency> getDependentObjects() {
ArrayList<Dependency> deps = new ArrayList<Dependency>();
deps.add(new ExpressionValueDependency(1, "mies", "noot"));
deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter", "whatever", "'id1'"));
deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter", "whatever", "'id2'"));
deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestDoesNotExistAdapter", "whatever", "'id3'"));
deps.add(new ExpressionValueDependency(1, "aap", "noot"));
deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter2", "whatever", "'id4'"));
return deps;
}
use of com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency in project navajo by Dexels.
the class TslCompiler method checkDependentFieldResource.
private final void checkDependentFieldResource(Class localContextClass, String fieldName, List<String> expressionValues, List<Dependency> deps) {
if (!(HasDependentResources.class.isAssignableFrom(localContextClass))) {
return;
}
if (expressionValues == null) {
return;
}
for (int all = 0; all < expressionValues.size(); all++) {
String expressionValue = expressionValues.get(all);
DependentResource[] dependentFields = instantiatedAdapters.get(localContextClass);
if (dependentFields == null && HasDependentResources.class.isAssignableFrom(localContextClass)) {
try {
HasDependentResources hr = (HasDependentResources) localContextClass.getDeclaredConstructor().newInstance();
dependentFields = hr.getDependentResourceFields();
} catch (Throwable t) {
logger.error("Dependency detection problem:", t);
}
instantiatedAdapters.put(localContextClass, dependentFields);
}
if (dependentFields == null) {
return;
}
for (int i = 0; i < dependentFields.length; i++) {
if (fieldName.equals(dependentFields[i].getValue())) {
if (dependentFields[i] instanceof GenericMultipleDependentResource) {
Class<? extends AdapterFieldDependency> depClass = dependentFields[i].getDependencyClass();
try {
Constructor c = depClass.getConstructor(long.class, String.class, String.class, String.class);
AdapterFieldDependency afd = (AdapterFieldDependency) c.newInstance(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
deps.add(afd);
AdapterFieldDependency[] allDeps = (AdapterFieldDependency[]) afd.getMultipleDependencies();
for (int a = 0; a < allDeps.length; a++) {
addDependency("dependentObjects.add( new " + depClass.getName() + "(-1, \"" + allDeps[a].getJavaClass() + "\", \"" + allDeps[a].getType() + "\", \"" + allDeps[a].getId() + "\"));\n", "FIELD" + allDeps[a].getJavaClass() + ";" + allDeps[a].getType() + ";" + fieldName + ";" + allDeps[a].getId());
deps.add(allDeps[a]);
}
} catch (Exception e) {
logger.info("Error adding dependency, wasn't logged before so reduced level to info. ", e);
}
} else {
addDependency("dependentObjects.add( new AdapterFieldDependency(-1, \"" + localContextClass.getName() + "\", \"" + dependentFields[i].getType() + "\", \"" + expressionValue + "\"));\n", "FIELD" + localContextClass.getName() + ";" + dependentFields[i].getType() + ";" + fieldName + ";" + expressionValue);
Dependency d = new AdapterFieldDependency(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
deps.add(d);
}
}
}
}
}
use of com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency in project navajo by Dexels.
the class ScriptCompiler method processDependencies.
private Set<String> processDependencies(List<Dependency> dependencies) {
Set<String> dependentResources = new HashSet<>();
for (Dependency d : dependencies) {
if ("resource".equals(d.getType()) && (d instanceof AdapterFieldDependency)) {
final AdapterFieldDependency adapterFieldDep = (AdapterFieldDependency) d;
logger.info("ID: {}. It's an aadapter field. with multiple: {} type {}", adapterFieldDep.getId(), adapterFieldDep.hasMultipleDependencies(), adapterFieldDep.getClass());
Operand op = expressionEvaluator.evaluate(adapterFieldDep.getId(), null, Optional.empty(), Optional.empty());
if (op != null && op.value instanceof String) {
logger.debug("Succeeded evaluation of id: {}", ((String) op.value));
dependentResources.add((String) op.value);
}
logger.info("Resource dependency detected: {} type: {} dependency id: {}", d.getClass().getName(), d.getType(), d.getId());
Dependency[] subs = adapterFieldDep.getMultipleDependencies();
if (subs != null) {
for (Dependency dependency : subs) {
logger.info("Nested dependency detected: {}, type {}", dependency.getClass().getName(), dependency.getType());
}
}
}
}
return dependentResources;
}
use of com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency in project navajo by Dexels.
the class ResourceChecker method init.
@SuppressWarnings({ "rawtypes", "unchecked" })
public final void init() {
if (myCompiledScript.getDependentObjects() == null) {
logger.warn("ResourceChecker: Could not find dependent objects for: {}", myCompiledScript.getClass());
return;
}
Iterator<Dependency> dependencies = myCompiledScript.getDependentObjects().iterator();
while (dependencies.hasNext()) {
Dependency dep = dependencies.next();
if (AdapterFieldDependency.class.isAssignableFrom(dep.getClass())) {
AdapterFieldDependency afd = (AdapterFieldDependency) dep;
if (!afd.getType().equals(GenericDependentResource.SERVICE_DEPENDENCY)) {
try {
Class c = Class.forName(afd.getJavaClass(), true, myCompiledScript.getClass().getClassLoader());
Method m = c.getMethod("getResourceManager", String.class);
if (m != null) {
managedResources.put(afd, m);
}
} catch (Throwable e) {
}
} else {
// Script dependency
scriptDependencies.add(evaluateResourceId(afd.getId()));
}
}
}
initialized = true;
}
Aggregations