use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class ResourceChecker method getServiceAvailability.
/**
* @param checkedServices, contains set of services that have already been checked to prevent infinite loop due
* to (wrong) circular dependencies.
*
* @return
*/
private ServiceAvailability getServiceAvailability(HashSet<String> checkedServices) {
ArrayList<String> unavailableIds = new ArrayList<>();
boolean available = true;
boolean unknown = false;
int maxWaitingTime = 0;
int finalHealth = 0;
for (Entry<AdapterFieldDependency, Method> e : managedResources.entrySet()) {
AdapterFieldDependency afd = e.getKey();
Method m = e.getValue();
try {
boolean isStatic = Modifier.isStatic(m.getModifiers());
if (!isStatic) {
throw new NavajoException("Method: " + m.getName() + " of class " + afd.getJavaClass() + " adapterfielddep: " + afd.getId() + " is not static and it should be.");
}
Object o = m.invoke(null, afd.getType());
if (o != null) {
ResourceManager rm = (ResourceManager) o;
String resourceId = evaluateResourceId(afd.getId());
synchronized (rm) {
int health = rm.getHealth(resourceId);
unknown = (unknown || health == ServiceAvailability.STATUS_UNKNOWN);
if (health > finalHealth) {
finalHealth = health;
}
if (!(rm.isAvailable(resourceId)) || health == ServiceAvailability.STATUS_DEAD) {
available = false;
int wt = rm.getWaitingTime(resourceId);
if (wt > maxWaitingTime) {
maxWaitingTime = wt;
}
unavailableIds.add(resourceId);
}
}
}
// TODO remove catch, propagate errors
} catch (Exception e1) {
logger.error("Could not check avail of: {}, msg", afd.getType(), e1);
}
}
if (unknown) {
finalHealth = ServiceAvailability.STATUS_UNKNOWN;
}
String[] ids = new String[unavailableIds.size()];
ids = unavailableIds.toArray(ids);
ServiceAvailability sa = new ServiceAvailability(webservice, available, finalHealth, maxWaitingTime, ids);
checkedServices.add(webservice);
// Check dependecies
ServiceAvailability dependencyHealth = checkScriptDependencies(checkedServices);
if (dependencyHealth != null && (dependencyHealth.getHealth() > sa.getHealth() || !dependencyHealth.isAvailable())) {
return dependencyHealth;
} else {
return sa;
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class FileNavajoConfig method writeConfig.
@Override
public final void writeConfig(String name, Navajo conf) throws IOException {
Writer output = new FileWriter(new File(getConfigPath() + "/" + name));
try {
conf.write(output);
} catch (NavajoException ex) {
throw new IOException(ex.getMessage());
}
output.close();
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class BasePropertyImpl method getEvaluatedValue.
public final Object getEvaluatedValue() {
Operand o;
// No evaluator present.
if (NavajoFactory.getInstance().getExpressionEvaluator() == null) {
return null;
}
try {
try {
if (!EXPRESSION_PROPERTY.equals(getType())) {
throw NavajoFactory.getInstance().createNavajoException("Can only evaluate expression type properties!");
}
try {
o = NavajoFactory.getInstance().getExpressionEvaluator().evaluate(getValue(), getRootDoc(), null, getParentMessage(), null);
evaluatedType = o.type;
return o.value;
} catch (Throwable e) {
logger.info("Exception while evaluating property: {} expression: {}", getFullPropertyName(), getValue());
return null;
}
} catch (NavajoException ex) {
logger.error("Error: ", ex);
if (myParent != null) {
Message pp = myParent.getArrayParentMessage();
if (pp != null && Message.MSG_TYPE_ARRAY.equals(pp.getType())) {
Message def = pp.getDefinitionMessage();
if (def != null) {
Property ppp = def.getProperty(getName());
if (ppp != null) {
evaluatedType = ppp.getType();
return null;
}
}
}
}
evaluatedType = "string";
return null;
}
} catch (Throwable ex1) {
evaluatedType = "string";
return null;
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class BirtUtils method createDataSource.
/**
* @param n
* @return
* @throws IOException
*/
public File createDataSource(Navajo n) throws IOException {
File sourceFile = File.createTempFile("dat", ".txt", new File(System.getProperty("java.io.tmpdir")));
File origFile = new File(sourceFile.getAbsolutePath() + ".xml");
FileWriter origW = new FileWriter(origFile);
try {
n.write(origW);
} catch (NavajoException e) {
logger.error("Error: ", e);
} finally {
origW.flush();
origW.close();
}
Document t = NavajoLaszloConverter.createLaszloFromNavajo(n, "navajoDataSource");
FileWriter fw = new FileWriter(sourceFile);
logger.debug("Data source created: {}", sourceFile.getAbsolutePath());
XMLDocumentUtils.write(t, fw, false);
fw.flush();
fw.close();
return sourceFile;
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class BIRTXmlMap method load.
/**
* A Mappable class is executed by the Navajo Mapping Environment.
*
* @param parms
* Parameters
* @param inMessage
* Navajo
* @param access
* Access
* @param config
* NavajoConfig
* @throws MappableException
* @throws UserException
*/
@Override
public void load(Access access) throws MappableException, UserException {
// paths
inNavajo = access.getInDoc();
InputStream in = null;
try {
in = DispatcherFactory.getInstance().getNavajoConfig().getConfig("birt.xml");
} catch (IOException e) {
throw new MappableException("No birt.xml configuration file found!");
}
if (in == null) {
throw new MappableException("No birt.xml configuration file found!");
}
try {
Document d = XMLDocumentUtils.createDocument(in, false);
Element a = (Element) XMLutils.findNode(d, "viewerReportDir");
if (a != null) {
viewerReportDir = a.getAttribute("value");
File f = new File(viewerReportDir);
if (!f.exists()) {
throw new MappableException("viewerReportDir:" + viewerReportDir + " not found!");
}
} else {
throw new MappableException("No tag: viewerReportDir found in birt.xml");
}
Element b = (Element) XMLutils.findNode(d, "viewerUrl");
if (b != null) {
viewerUrl = b.getAttribute("value");
// check url?
} else {
throw new MappableException("No tag: viewerUrl found in birt.xml");
}
Element c = (Element) XMLutils.findNode(d, "reportDir");
if (c != null) {
reportDir = c.getAttribute("value");
File f = new File(reportDir);
if (!f.exists()) {
throw new MappableException("reportDir:" + reportDir + " not found!");
}
} else {
throw new MappableException("No tag: reportDir found in birt.xml");
}
logger.debug("Birt configured succesfully!");
} catch (NavajoException e1) {
throw new MappableException("Error reading birt.xml configuration file!");
} finally {
try {
in.close();
} catch (IOException e) {
logger.error("Error: ", e);
}
}
}
Aggregations