Search in sources :

Example 11 with NavajoException

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;
    }
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) ArrayList(java.util.ArrayList) NavajoException(com.dexels.navajo.document.NavajoException) Method(java.lang.reflect.Method) NavajoException(com.dexels.navajo.document.NavajoException)

Example 12 with NavajoException

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();
}
Also used : FileWriter(java.io.FileWriter) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with NavajoException

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;
    }
}
Also used : Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Property(com.dexels.navajo.document.Property)

Example 14 with NavajoException

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;
}
Also used : FileWriter(java.io.FileWriter) NavajoException(com.dexels.navajo.document.NavajoException) Document(org.w3c.dom.Document) File(java.io.File)

Example 15 with NavajoException

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);
        }
    }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

NavajoException (com.dexels.navajo.document.NavajoException)46 Message (com.dexels.navajo.document.Message)28 Property (com.dexels.navajo.document.Property)25 Navajo (com.dexels.navajo.document.Navajo)21 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)12 SystemException (com.dexels.navajo.script.api.SystemException)9 Operand (com.dexels.navajo.document.Operand)8 UserException (com.dexels.navajo.script.api.UserException)8 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)6 Selection (com.dexels.navajo.document.Selection)5 MappableException (com.dexels.navajo.script.api.MappableException)5 ArrayList (java.util.ArrayList)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 ManualAsyncClient (com.dexels.navajo.client.async.ManualAsyncClient)3 FatalException (com.dexels.navajo.script.api.FatalException)3 File (java.io.File)3 ClientException (com.dexels.navajo.client.ClientException)2 NavajoResponseHandler (com.dexels.navajo.client.NavajoResponseHandler)2 Header (com.dexels.navajo.document.Header)2