Search in sources :

Example 1 with StorageException

use of nl.nn.testtool.storage.StorageException in project iaf by ibissource.

the class ReportNameComparator method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    XmlBuilder results = new XmlBuilder("Results");
    int reportsPassed = 0;
    List<Report> reports = new ArrayList<Report>();
    try {
        List<Integer> storageIds = testStorage.getStorageIds();
        for (Integer storageId : storageIds) {
            Report report = testStorage.getReport(storageId);
            String fullReportPath = (report.getPath() != null ? report.getPath() : "") + report.getName();
            if (excludeRegexPattern == null || !excludeRegexPattern.matcher(fullReportPath).matches()) {
                reports.add(report);
            }
        }
    } catch (StorageException e) {
        addExceptionElement(results, e);
    }
    ReportRunner reportRunner = new ReportRunner();
    reportRunner.setTestTool(testTool);
    reportRunner.setDebugStorage(debugStorage);
    reportRunner.setSecurityContext(new IbisSecurityContext(session, checkRoles));
    Collections.sort(reports, reportNameComparator);
    long startTime = System.currentTimeMillis();
    boolean reportGeneratorEnabledOldValue = testTool.isReportGeneratorEnabled();
    if (enableReportGenerator) {
        testTool.setReportGeneratorEnabled(true);
        testTool.sendReportGeneratorStatusUpdate();
    }
    reportRunner.run(reports, false, true);
    if (enableReportGenerator) {
        testTool.setReportGeneratorEnabled(reportGeneratorEnabledOldValue);
        testTool.sendReportGeneratorStatusUpdate();
    }
    long endTime = System.currentTimeMillis();
    for (Report report : reports) {
        RunResult runResult = reportRunner.getResults().get(report.getStorageId());
        long originalDuration = report.getEndTime() - report.getStartTime();
        long duration = -1;
        boolean equal = false;
        String error = "";
        if (runResult.errorMessage != null) {
            error = runResult.errorMessage;
        } else {
            Report runResultReport = null;
            try {
                runResultReport = reportRunner.getRunResultReport(runResult.correlationId);
            } catch (StorageException e) {
                addExceptionElement(results, e);
            }
            if (runResultReport == null) {
                error = "Result report not found. Report generator not enabled?";
            } else {
                duration = runResultReport.getEndTime() - runResultReport.getStartTime();
                report.setGlobalReportXmlTransformer(reportXmlTransformer);
                runResultReport.setGlobalReportXmlTransformer(reportXmlTransformer);
                runResultReport.setTransformation(report.getTransformation());
                runResultReport.setReportXmlTransformer(report.getReportXmlTransformer());
                if (report.toXml(reportRunner).equals(runResultReport.toXml(reportRunner))) {
                    equal = true;
                    reportsPassed++;
                }
            }
        }
        XmlBuilder result = new XmlBuilder("Result");
        results.addSubElement(result);
        result.addSubElement("Path", report.getPath());
        result.addSubElement("Name", report.getName());
        result.addSubElement("OriginalDuration", "" + originalDuration);
        if (duration > -1)
            result.addSubElement("Duration", "" + duration);
        result.addSubElement("Equal", "" + equal);
        if (!error.isEmpty())
            result.addSubElement("Error", error);
        if (writeToLog || writeToSystemOut) {
            writeToLogOrSysOut("Path=\"" + report.getPath() + "\", " + "Name=\"" + report.getName() + "\", " + "OriginalDuration=\"" + originalDuration + "\", " + ((duration > -1) ? "Duration=\"" + duration + "\", " : "") + "Equal=\"" + equal + "\"" + (!error.isEmpty() ? ", Error=\"" + error + "\"" : ""));
        }
    }
    boolean allReportsPassed = reportsPassed == reports.size();
    if (writeToLog || writeToSystemOut) {
        writeToLogOrSysOut("Total=\"" + reports.size() + "\", " + "Passed=\"" + reportsPassed + "\", " + "Failed=\"" + (reports.size() - reportsPassed) + "\", " + "TotalDuration=\"" + (endTime - startTime) + "\", " + "Equal=\"" + allReportsPassed + "\"");
    }
    PipeForward forward = allReportsPassed ? getSuccessForward() : failureForward;
    return new PipeRunResult(forward, results.toXML());
}
Also used : Report(nl.nn.testtool.Report) ArrayList(java.util.ArrayList) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StorageException(nl.nn.testtool.storage.StorageException) ReportRunner(nl.nn.testtool.run.ReportRunner) RunResult(nl.nn.testtool.run.RunResult) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult)

Example 2 with StorageException

use of nl.nn.testtool.storage.StorageException in project iaf by ibissource.

the class Storage method addNumberExpression.

private void addNumberExpression(StringBuilder query, List<Object> args, String column, String operator, String searchValue) throws StorageException {
    try {
        BigDecimal bigDecimal = new BigDecimal(searchValue);
        addExpression(query, column + " " + operator + " ?");
        args.add(bigDecimal);
    } catch (NumberFormatException e) {
        throw new StorageException("Search value '" + searchValue + "' isn't a valid number");
    }
}
Also used : StorageException(nl.nn.testtool.storage.StorageException) BigDecimal(java.math.BigDecimal)

Example 3 with StorageException

use of nl.nn.testtool.storage.StorageException in project iaf by ibissource.

the class Storage method delete.

@Override
public void delete(Report report) throws StorageException {
    String errorMessage = null;
    if ("Table EXCEPTIONLOG".equals(report.getName())) {
        List checkpoints = report.getCheckpoints();
        Checkpoint checkpoint = (Checkpoint) checkpoints.get(0);
        Message message = Message.asMessage(checkpoint.getMessage());
        IAdapter adapter = ibisManager.getRegisteredAdapter(DELETE_ADAPTER);
        if (adapter != null) {
            PipeLineSession pipeLineSession = new PipeLineSession();
            if (securityContext.getUserPrincipal() != null)
                pipeLineSession.put("principal", securityContext.getUserPrincipal().getName());
            PipeLineResult processResult = adapter.processMessage(TestTool.getCorrelationId(), message, pipeLineSession);
            if (!processResult.isSuccessful()) {
                errorMessage = "Delete failed (see logging for more details)";
            } else {
                try {
                    String result = processResult.getResult().asString();
                    if (!result.equalsIgnoreCase("<ok/>")) {
                        errorMessage = "Delete failed: " + result;
                    }
                } catch (IOException e) {
                    throw new StorageException("Delete failed", e);
                }
            }
        } else {
            errorMessage = "Adapter '" + DELETE_ADAPTER + "' not found";
        }
    } else {
        errorMessage = "Delete method is not implemented for '" + report.getName() + "'";
    }
    if (errorMessage != null) {
        throw new StorageException(errorMessage);
    }
}
Also used : Checkpoint(nl.nn.testtool.Checkpoint) Message(nl.nn.adapterframework.stream.Message) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) IAdapter(nl.nn.adapterframework.core.IAdapter) StorageException(nl.nn.testtool.storage.StorageException)

Example 4 with StorageException

use of nl.nn.testtool.storage.StorageException in project iaf by ibissource.

the class Storage method getReport.

@Override
public Report getReport(Integer storageId) throws StorageException {
    final Report report = new Report();
    report.setTestTool(testTool);
    report.setStorage(this);
    report.setStorageId(storageId);
    report.setName("Table " + table);
    report.setStubStrategy("Never");
    final List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
    report.setCheckpoints(checkpoints);
    StringBuilder query = new StringBuilder("select " + reportColumnNames.get(0));
    for (int i = 1; i < reportColumnNames.size(); i++) {
        query.append(", " + reportColumnNames.get(i));
    }
    query.append(" from " + table + " where LOGID = ?");
    try {
        jdbcTemplate.query(query.toString(), new Object[] { storageId }, new RowMapper() {

            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                for (int i = 0; i < reportColumnNames.size(); i++) {
                    String value = getValue(rs, i + 1);
                    Checkpoint checkpoint = new Checkpoint(report, Thread.currentThread().getName(), Storage.class.getName(), "Column " + reportColumnNames.get(i), Checkpoint.TYPE_INPUTPOINT, 0);
                    checkpoint.setMessage(value);
                    checkpoints.add(checkpoint);
                }
                return null;
            }
        });
    } catch (DataAccessException e) {
        throw new StorageException("Could not read report", e);
    }
    return report;
}
Also used : Report(nl.nn.testtool.Report) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Checkpoint(nl.nn.testtool.Checkpoint) Checkpoint(nl.nn.testtool.Checkpoint) ResultSet(java.sql.ResultSet) StorageException(nl.nn.testtool.storage.StorageException) DataAccessException(org.springframework.dao.DataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 5 with StorageException

use of nl.nn.testtool.storage.StorageException in project iaf by ibissource.

the class Storage method getMetadata.

@Override
public List<List<Object>> getMetadata(int maxNumberOfRecords, final List<String> metadataNames, List<String> searchValues, int metadataValueType) throws StorageException {
    // According to SimpleDateFormat javadoc it needs to be synchronised
    // when accessed by multiple threads, hence instantiate it here instead
    // of instantiating it at class level and synchronising it.
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIMESTAMP_PATTERN);
    List<String> rangeSearchValues = new ArrayList<String>();
    List<String> regexSearchValues = new ArrayList<String>();
    for (int i = 0; i < searchValues.size(); i++) {
        String searchValue = searchValues.get(i);
        if (searchValue != null && searchValue.startsWith("<") && searchValue.endsWith(">")) {
            rangeSearchValues.add(searchValue);
            regexSearchValues.add(null);
            searchValues.remove(i);
            searchValues.add(i, null);
        } else if (searchValue != null && searchValue.startsWith("(") && searchValue.endsWith(")")) {
            rangeSearchValues.add(null);
            regexSearchValues.add(searchValue);
            searchValues.remove(i);
            searchValues.add(i, null);
        } else {
            rangeSearchValues.add(null);
            regexSearchValues.add(null);
        }
    }
    IDbmsSupport dbmsSupport = getDbmsSupport();
    StringBuilder query = new StringBuilder("select " + dbmsSupport.provideFirstRowsHintAfterFirstKeyword(maxNumberOfRecords) + " * from (select ");
    List<Object> args = new ArrayList<Object>();
    boolean first = true;
    for (String metadataName : metadataNames) {
        if (first) {
            first = false;
        } else {
            query.append(", ");
        }
        if (bigValueColumns.contains(metadataName)) {
            query.append("substr(" + metadataName + ", 1, 100)");
        } else {
            query.append(metadataName);
        }
    }
    String rowNumber = dbmsSupport.getRowNumber(metadataNames.get(0), "desc");
    if (StringUtils.isNotEmpty(rowNumber)) {
        if (first) {
            first = false;
        } else {
            query.append(", ");
        }
        query.append(rowNumber);
    }
    query.append(" from " + table);
    for (int i = 0; i < rangeSearchValues.size(); i++) {
        String searchValue = rangeSearchValues.get(i);
        if (searchValue != null) {
            int j = searchValue.indexOf('|');
            if (j != -1) {
                String column = metadataNames.get(i);
                String searchValueLeft = searchValue.substring(1, j);
                String searchValueRight = searchValue.substring(j + 1, searchValue.length() - 1);
                if (StringUtils.isNotEmpty(searchValueLeft)) {
                    if (integerColumns.contains(column)) {
                        addNumberExpression(query, args, column, ">=", searchValueLeft);
                    } else if (timestampColumns.contains(column)) {
                        addTimestampExpression(query, args, column, ">=", searchValueLeft, simpleDateFormat);
                    }
                }
                if (StringUtils.isNotEmpty(searchValueRight)) {
                    if (integerColumns.contains(column)) {
                        addNumberExpression(query, args, column, "<=", searchValueRight);
                    } else if (timestampColumns.contains(column)) {
                        addTimestampExpression(query, args, column, "<=", searchValueRight, simpleDateFormat);
                    }
                }
            } else {
                throw new StorageException("Separator | not found");
            }
        }
    }
    for (int i = 0; i < searchValues.size(); i++) {
        String searchValue = searchValues.get(i);
        if (StringUtils.isNotEmpty(searchValue)) {
            String column = metadataNames.get(i);
            if (integerColumns.contains(column)) {
                addNumberExpression(query, args, column, "<=", searchValue);
            } else if (timestampColumns.contains(column)) {
                addTimestampExpression(query, args, column, "<=", searchValue, simpleDateFormat);
            } else if (fixedStringColumns != null && fixedStringColumns.contains(column)) {
                addFixedStringExpression(query, args, column, searchValue);
            } else {
                addLikeExpression(query, args, column, searchValue);
            }
        }
    }
    query.append(")");
    if (StringUtils.isNotEmpty(rowNumber)) {
        query.append(" where " + dbmsSupport.getRowNumberShortName() + " < ?");
        args.add(maxNumberOfRecords + 1);
    }
    query.append(" order by ");
    query.append(metadataNames.get(0) + " desc");
    log.debug("Metadata query: " + query.toString());
    List metadata;
    try {
        metadata = jdbcTemplate.query(query.toString(), args.toArray(), new RowMapper() {

            public List mapRow(ResultSet rs, int rowNum) throws SQLException {
                List row = new ArrayList();
                for (int i = 0; i < metadataNames.size(); i++) {
                    if (integerColumns.contains(metadataNames.get(i))) {
                        row.add(rs.getInt(i + 1));
                    } else if (timestampColumns.contains(metadataNames.get(i))) {
                        row.add(simpleDateFormat.format(rs.getTimestamp(i + 1)));
                    } else {
                        row.add(getValue(rs, i + 1));
                    }
                }
                return row;
            }
        });
    } catch (DataAccessException e) {
        throw new StorageException("Could not read metadata", e);
    }
    for (int i = 0; i < metadata.size(); i++) {
        if (!SearchUtil.matches((List) metadata.get(i), regexSearchValues)) {
            metadata.remove(i);
            i--;
        }
    }
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) Checkpoint(nl.nn.testtool.Checkpoint) IDbmsSupport(nl.nn.adapterframework.jdbc.dbms.IDbmsSupport) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) StorageException(nl.nn.testtool.storage.StorageException) DataAccessException(org.springframework.dao.DataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Aggregations

StorageException (nl.nn.testtool.storage.StorageException)5 ArrayList (java.util.ArrayList)4 Checkpoint (nl.nn.testtool.Checkpoint)3 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 Report (nl.nn.testtool.Report)2 DataAccessException (org.springframework.dao.DataAccessException)2 RowMapper (org.springframework.jdbc.core.RowMapper)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 IAdapter (nl.nn.adapterframework.core.IAdapter)1 PipeForward (nl.nn.adapterframework.core.PipeForward)1 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)1 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 IDbmsSupport (nl.nn.adapterframework.jdbc.dbms.IDbmsSupport)1 Message (nl.nn.adapterframework.stream.Message)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1