Search in sources :

Example 46 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class SvgRenderer method renderToBinary.

public Binary renderToBinary(InputStream is) throws XMLParseException, IOException {
    XMLElement svgRoot = renderStream(is);
    Binary result = new Binary();
    OutputStream os = result.getOutputStream();
    Writer fw = new OutputStreamWriter(os);
    svgRoot.write(fw);
    fw.flush();
    fw.close();
    os.close();
    return result;
}
Also used : OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 47 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class RDShapeImport method storeBinaryShapeRecord.

private void storeBinaryShapeRecord(String shapeId, File recordFile) {
    try {
        Binary data = new Binary(recordFile);
        Navajo pms = NavajoClientFactory.getClient().doSimpleSend(null, "geospatial/InitInsertCBSPolyPoint");
        Message params = pms.getMessage("Parameters");
        if (params != null) {
            params.getProperty("ShapeId").setValue(shapeId);
            params.getProperty("ShapeData").setValue(data);
            NavajoClientFactory.getClient().doSimpleSend(params.getRootDoc(), "geospatial/ProcessInsertCBSPolyPoint");
        }
    } catch (Exception e) {
        logger.error("Error: ", e);
    }
}
Also used : Message(com.dexels.navajo.document.Message) Binary(com.dexels.navajo.document.types.Binary) Navajo(com.dexels.navajo.document.Navajo)

Example 48 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BasePropertyImpl method setValue.

private final void setValue(String value, Boolean internal) {
    Object old = null;
    if (hasPropertyDataListeners()) {
        old = getTypedValue();
    }
    if (BINARY_PROPERTY.equals(getType())) {
        try {
            if (value != null) {
                myBinary = new Binary(new StringReader(value));
            } else {
                myBinary = null;
            }
        } catch (IOException e) {
            logger.error("Error: ", e);
        }
        return;
    }
    myBinary = null;
    setCheckedValue(value);
    firePropertyChanged(PROPERTY_VALUE, old, value, internal);
}
Also used : StringReader(java.io.StringReader) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException)

Example 49 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BasePropertyImpl method isEqual.

@Override
public final boolean isEqual(Property p) {
    if (!getName().equals(p.getName())) {
        return false;
    }
    if ((this.getType() != null && p.getType() != null) && !this.getType().equals(p.getType())) {
        return false;
    }
    // Check for date properties.
    if (p.getType().equals(Property.DATE_PROPERTY)) {
        // If both values are null they're equal.
        if (p.getTypedValue() == null && this.getTypedValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getTypedValue() == null || this.getTypedValue() == null) {
            return false;
        }
        java.util.Date myDate = (java.util.Date) getTypedValue();
        java.util.Date otherDate = (java.util.Date) p.getTypedValue();
        return dateFormat2.get().format(myDate).equals(dateFormat2.get().format(otherDate));
    } else // Check for selection properties.
    if (p.getType().equals(Property.SELECTION_PROPERTY)) {
        try {
            List<Selection> l = p.getAllSelectedSelections();
            List<Selection> me = this.getAllSelectedSelections();
            // equal.
            if (me.size() != l.size()) {
                return false;
            }
            for (int j = 0; j < l.size(); j++) {
                Selection other = l.get(j);
                boolean match = false;
                for (int k = 0; k < me.size(); k++) {
                    Selection mysel = me.get(k);
                    if (mysel.getValue().equals(other.getValue())) {
                        match = true;
                        k = me.size() + 1;
                    }
                }
                if (!match) {
                    return false;
                }
            }
            return true;
        } catch (Exception e) {
            logger.warn("Error: ", e);
            return false;
        }
    } else if (p.getType().equals(Property.BINARY_PROPERTY)) {
        // If both values are null they're equal.
        if (p.getTypedValue() == null && this.getTypedValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getTypedValue() == null || this.getTypedValue() == null) {
            return false;
        }
        return ((Binary) this.getTypedValue()).isEqual((Binary) p.getTypedValue());
    } else // Else I am some other property.
    {
        // If both values are null they're equal.
        if (p.getValue() == null && this.getValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getValue() == null || this.getValue() == null) {
            return false;
        }
        return p.getValue().equals(this.getValue());
    }
}
Also used : Date(java.util.Date) Selection(com.dexels.navajo.document.Selection) ArrayList(java.util.ArrayList) List(java.util.List) Binary(com.dexels.navajo.document.types.Binary) Date(java.util.Date) PropertyTypeException(com.dexels.navajo.document.PropertyTypeException) NavajoException(com.dexels.navajo.document.NavajoException) ParseException(java.text.ParseException) ExpressionChangedException(com.dexels.navajo.document.ExpressionChangedException) IOException(java.io.IOException)

Example 50 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class MergePDFsFromDatasource method evaluate.

@SuppressWarnings("unchecked")
@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 7) {
        throw new TMLExpressionException("Invalid number of operands.");
    }
    // List items contains all the ids of the document
    ArrayList<String> items = null;
    if (getOperand(0) != null) {
        if (getOperand(0) instanceof ArrayList) {
            items = (ArrayList<String>) getOperand(0);
        } else if (getOperand(0) instanceof String) {
            items = (ArrayList<String>) Arrays.stream(((String) getOperand(0)).split(";")).map(o -> o.toString()).collect(Collectors.toList());
        }
    }
    int transactionContext = -1;
    if (getOperand(1) != null && getOperand(1) instanceof Integer) {
        transactionContext = ((Integer) getOperand(1)).intValue();
    }
    String datasource = null;
    if (getOperand(2) != null && getOperand(2) instanceof String) {
        datasource = (String) getOperand(2);
    }
    String username = null;
    if (getOperand(3) != null && getOperand(3) instanceof String) {
        username = (String) getOperand(3);
    }
    String tableId = null;
    if (getOperand(4) != null && getOperand(4) instanceof String) {
        tableId = (String) getOperand(4);
    }
    String objectType = null;
    if (getOperand(5) != null && getOperand(5) instanceof String) {
        objectType = (String) getOperand(5);
    }
    String binaryColumnName = null;
    if (getOperand(6) != null && getOperand(6) instanceof String) {
        binaryColumnName = (String) getOperand(6);
    }
    // Max in operator in oracle takes 1000 ites, but we need more ::
    int numOfItems = items.size();
    String queryPart = "";
    if (numOfItems == 1) {
        queryPart = " in " + items.toString().replace("[", "('").replace("]", "')").replace(" ", "");
    } else {
        int startPosition = 0;
        int endPosition = 999;
        if (startPosition + endPosition >= numOfItems) {
            endPosition = numOfItems - 1;
        } else {
            endPosition = startPosition + 999;
        }
        while (endPosition <= numOfItems && startPosition != endPosition) {
            queryPart = queryPart + " or " + tableId + " in " + items.subList(startPosition, endPosition).toString().replace(",", "','").replace("[", "('").replace("]", "')").replace(" ", "");
            startPosition = endPosition;
            if (endPosition + 999 >= numOfItems) {
                endPosition = numOfItems;
            } else {
                endPosition = startPosition + 999;
            }
        }
        queryPart = queryPart.substring(4).substring(tableId.length());
    }
    String query = "select * FROM document where (" + tableId + queryPart + ") AND objectType  = '" + objectType + "'";
    JDBCMappable sql = null;
    ArrayList<Object> result = new ArrayList<>();
    try {
        sql = JDBCFactory.getJDBCMap(getAccess());
        if (transactionContext != -1) {
            sql.setTransactionContext(transactionContext);
        } else {
            sql.setDatasource(datasource);
            sql.setUsername(username);
        }
        sql.setQuery(query);
        System.out.println(query);
        ResultSetMap[] resultSet = sql.getResultSet();
        if (resultSet.length > 0) {
            for (int i = 0; i < resultSet.length; i++) {
                result.add(resultSet[i].getColumnValue(0));
            }
        }
        int dataPosition = -1;
        // We got them all, now MERGE :D
        if (result.size() > 0) {
            // First find DATA position
            for (int i = 0; i < resultSet[0].getValuesSize(); i++) {
                if (resultSet[0].getColumnName(i).equalsIgnoreCase(binaryColumnName)) {
                    dataPosition = i;
                    break;
                }
            }
            // Then combine
            try {
                PDFMergerUtility merger = new PDFMergerUtility();
                File tempFile = File.createTempFile("pdfmerge", "pdf");
                String fileName = tempFile.getCanonicalPath();
                merger.setDestinationFileName(fileName);
                // Logic to short by items.
                for (String item : items) {
                    for (int i = 0; i < resultSet.length; i++) {
                        if (resultSet[i].getColumnValue(tableId).toString().equals(item)) {
                            // FOUND
                            merger.addSource(((Binary) resultSet[i].getColumnValue(dataPosition)).getFile());
                            break;
                        }
                    }
                }
                merger.mergeDocuments();
                Binary resultPDF = new Binary(new File(fileName), false);
                tempFile.delete();
                return resultPDF;
            } catch (IOException e) {
                throw new TMLExpressionException(this, e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        sql.kill();
        throw new TMLExpressionException(this, "Fatal error: " + e.getMessage() + ", query = " + query, e);
    } finally {
        sql.kill();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ResultSetMap(com.dexels.navajo.adapter.sqlmap.ResultSetMap) PDFMergerUtility(org.apache.pdfbox.util.PDFMergerUtility) IOException(java.io.IOException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) IOException(java.io.IOException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) JDBCMappable(com.dexels.navajo.jdbc.JDBCMappable) Binary(com.dexels.navajo.document.types.Binary) File(java.io.File)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6