Search in sources :

Example 1 with StringList

use of com.storedobject.common.StringList in project SODevelopment by syampillai.

the class SchedulerLogViewer method process.

@Override
protected boolean process() {
    close();
    Schedule s = jobField.getObject();
    DatePeriod p = periodField.getValue();
    StringList cols = StringList.create("Status", "Message", "Date", "StartedAt", "CompletedAt");
    ObjectBrowser<Log> logs = new ObjectBrowser<>(Log.class, cols, EditorAction.VIEW, s.getName() + " (" + s.getDescription() + ")");
    logs.load("Schedule=" + s.getId() + " AND Date " + p.getDBCondition());
    logs.execute();
    return true;
}
Also used : StringList(com.storedobject.common.StringList) Log(com.storedobject.job.Log) Schedule(com.storedobject.job.Schedule) DatePeriod(com.storedobject.core.DatePeriod) ObjectBrowser(com.storedobject.ui.ObjectBrowser)

Example 2 with StringList

use of com.storedobject.common.StringList in project SODevelopment by syampillai.

the class SteppedObjectForm method getStepComponent.

@Override
protected final Component getStepComponent(int step) {
    ObjectForm<T> of;
    of = createObjectForm(step);
    if (of == null) {
        of = new ObjectForm<>(objectClass);
        IncludeField includeField = getIncludeFieldChecker(step);
        if (includeField == null) {
            StringList list = getFields(step);
            if (list != null) {
                of.setIncludeFieldChecker(list::contains);
            }
        } else {
            of.setIncludeFieldChecker(includeField);
        }
    }
    of.setView(this);
    forms.add(of);
    return of.getComponent();
}
Also used : IncludeField(com.storedobject.vaadin.IncludeField) StringList(com.storedobject.common.StringList)

Example 3 with StringList

use of com.storedobject.common.StringList in project SODevelopment by syampillai.

the class SystemUtility method clicked.

@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
@Override
public void clicked(Component c) {
    clearAlerts();
    if (c == downloadConnInfo) {
        TextContentProducer cp = new TextContentProducer() {

            @Override
            public void generateContent() {
                Writer w = getWriter();
                SQLConnector.getDebugInfo(connectionAge.getValue()).forEach(d -> {
                    try {
                        w.write(d);
                        w.write("\n\n");
                    } catch (IOException ignored) {
                    }
                });
            }
        };
        getApplication().view(cp);
        return;
    }
    if (c == clear) {
        select.setValue("");
        where.setValue("");
        orderBy.setValue("");
        from.focus();
        return;
    }
    if (c == loadRaw) {
        Id id = new Id(new BigInteger("" + rawId.getValue()));
        StoredObject so = StoredObject.get(id);
        if (so == null) {
            warning("No object found for Id = " + id);
            return;
        }
        if (so instanceof StreamData) {
            getApplication().view("Id " + so.getId() + ", Transaction " + so.getTransactionId(), (StreamData) so);
            return;
        }
        getApplication().view(StringUtility.makeLabel(so.getClass()) + " (Id " + so.getId() + ", Transaction " + so.getTransactionId() + ")", so);
        return;
    }
    if (c == viewTranRaw) {
        long t = rawTranId.getValue();
        TransactionInformation ti = TransactionInformation.get(new BigInteger("" + t));
        if (ti == null) {
            warning("Transaction not found: " + t);
            return;
        }
        StringBuilder s = new StringBuilder("Transaction: ");
        s.append(t).append("\n");
        ti.dump(s);
        TextArea ta = new TextArea();
        ta.setWidthFull();
        ta.setValue(s.toString());
        View.createCloseableView(ta, "Transaction " + t).execute();
        return;
    }
    if (c == executeRaw) {
        String command = rawCommand.getValue().trim();
        getApplication().getServer().execute(command);
        return;
    }
    if (objectClass() == null) {
        return;
    }
    if (c == edit) {
        ObjectEditor.create(objectClass).execute();
        return;
    }
    if (c == editRaw) {
        // noinspection rawtypes
        new ObjectEditor(objectClass).execute();
        return;
    }
    if (c == downloadData) {
        final Class<? extends StoredObject> clazz = objectClass;
        TextContentProducer cp = new TextContentProducer() {

            @Override
            public void generateContent() throws Exception {
                Writer w = getWriter();
                for (StoredObject so : StoredObject.list(clazz, where.getValue().trim(), any.getValue())) {
                    so.save(w);
                }
            }
        };
        getApplication().view(cp);
        return;
    }
    if (c == updateData) {
        new Update().execute();
        return;
    }
    String cols = select.getValue().trim();
    if (c == executeSQL) {
        StringList columns;
        if (cols.isEmpty()) {
            columns = StoredObjectUtility.browseColumns(objectClass);
            select.setValue(columns.toString(", "));
        } else {
            if (cols.startsWith("/")) {
                new QueryGrid(StoredObject.query(objectClass, cols)).execute();
                return;
            }
            columns = StringList.create(cols);
        }
        Browser b = new Browser(objectClass, columns);
        b.execute();
        b.load(where.getValue().trim(), orderBy.getValue().trim());
        return;
    }
    if (c == pdf) {
        new ObjectList(getApplication(), objectClass, any.getValue(), cols.startsWith("/") ? StringList.EMPTY : StringList.create(cols)) {

            @Override
            public String getOrderBy() {
                return orderBy.getValue().trim();
            }

            @Override
            public String getExtraCondition() {
                return where.getValue();
            }
        }.execute();
        return;
    }
    if (c == downloadExcelData) {
        if (cols.isEmpty()) {
            ClassAttribute<? extends StoredObject> ca = StoredObjectUtility.classAttribute(objectClass);
            StringBuilder sb = new StringBuilder();
            assert ca != null;
            for (String s : ca.getAttributes()) {
                sb.append(",").append(s);
            }
            cols = sb.substring(1);
            select.setValue(cols);
        }
        Query query = StoredObject.query(objectClass, cols, where.getValue().trim(), orderBy.getValue().trim(), any.getValue());
        if (cols.startsWith("/")) {
            cols = cols.substring(1);
        }
        StringList columns = StringList.create(cols);
        Excel excel = new Excel() {

            @Override
            public void generateContent() throws Exception {
                columns.forEach(c -> setCellValue(getNextCell(), c));
                getNextRow();
                Cell cell;
                Object value;
                boolean first = true;
                for (ResultSet rs : query) {
                    int colCount = rs.getMetaData().getColumnCount();
                    for (int c = 1; c <= colCount; c++) {
                        cell = getNextCell();
                        setCellValue(cell, value = rs.getObject(c));
                        if (Utility.isRightAligned(value)) {
                            cell.setCellStyle(getRightAlignedStyle());
                            if (first) {
                                getCell(getCellIndex(), getRowIndex() - 1).setCellStyle(getRightAlignedStyle());
                            }
                        }
                    }
                    first = false;
                    getNextRow();
                }
                workbook.setSheetName(0, StringUtility.makeLabel(objectClass));
            }
        };
        getApplication().view(excel);
    }
}
Also used : TextArea(com.vaadin.flow.component.textfield.TextArea) Excel(com.storedobject.office.Excel) ResultSet(java.sql.ResultSet) Cell(org.apache.poi.ss.usermodel.Cell) StringList(com.storedobject.common.StringList) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ObjectList(com.storedobject.report.ObjectList) Writer(java.io.Writer)

Aggregations

StringList (com.storedobject.common.StringList)3 DatePeriod (com.storedobject.core.DatePeriod)1 Log (com.storedobject.job.Log)1 Schedule (com.storedobject.job.Schedule)1 Excel (com.storedobject.office.Excel)1 ObjectList (com.storedobject.report.ObjectList)1 ObjectBrowser (com.storedobject.ui.ObjectBrowser)1 IncludeField (com.storedobject.vaadin.IncludeField)1 TextArea (com.vaadin.flow.component.textfield.TextArea)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 BigInteger (java.math.BigInteger)1 ResultSet (java.sql.ResultSet)1 Cell (org.apache.poi.ss.usermodel.Cell)1