Search in sources :

Example 1 with EditBoxModel

use of org.jaffa.presentation.portlet.widgets.model.EditBoxModel in project jaffa-framework by jaffa-projects.

the class FormSelectionMaintenanceComponent method createPrintRequestObject.

private FormPrintRequest createPrintRequestObject(GridModelRow row, boolean showForm) {
    if (log.isDebugEnabled()) {
        log.debug("Create Print Request Object");
    }
    FormSelectionMaintenanceOutRowDto rowDto = (FormSelectionMaintenanceOutRowDto) row.get("object");
    EditBoxModel mPrinter = (EditBoxModel) row.get("printer");
    EditBoxModel mCopies = (EditBoxModel) row.get("copies");
    EditBoxModel mEmail = (EditBoxModel) row.get("email");
    CheckBoxModel mPublish = (CheckBoxModel) row.get("publish");
    String variation = (String) row.get("formVariation");
    FormPrintRequest formPrintRequest = new FormPrintRequest();
    formPrintRequest.setFormAlternateName(rowDto.getFormAlternateName());
    formPrintRequest.setFormName(rowDto.getFormName());
    if (getFormUserId() != null) {
        formPrintRequest.setUserName(getFormUserId());
    } else {
        formPrintRequest.setUserName(getHeaderDto().getUserId());
    }
    formPrintRequest.setVariation(variation);
    // Set the additionalDataObject per row, else use the global object.
    if (rowDto.getAdditionalDataObject() != null) {
        formPrintRequest.setAdditionalDataObject(rowDto.getAdditionalDataObject());
    } else if (getAdditionalDataObject() != null) {
        formPrintRequest.setAdditionalDataObject(getAdditionalDataObject());
    }
    LinkedHashMap keys = new LinkedHashMap();
    keys.put(getKey1(), getValue1());
    if (getKey2() != null) {
        keys.put(getKey2(), getValue2());
    }
    if (getKey3() != null) {
        keys.put(getKey3(), getValue3());
    }
    if (getKey4() != null) {
        keys.put(getKey4(), getValue4());
    }
    if (getKey5() != null) {
        keys.put(getKey5(), getValue5());
    }
    if (getKey6() != null) {
        keys.put(getKey6(), getValue6());
    }
    formPrintRequest.setKeys(keys);
    if (showForm) {
        formPrintRequest.setPrintCopies(new Integer(0));
    } else {
        formPrintRequest.setEmailToAddresses(mEmail.getValue());
        formPrintRequest.setPrintCopies(new Integer(mCopies.getValue()));
        formPrintRequest.setPrinterId(mPrinter.getValue());
    }
    if (log.isDebugEnabled()) {
        log.debug("*** Creating Print Request.  Setting Additional Data Object = " + rowDto.getAdditionalDataObject());
    }
    return formPrintRequest;
}
Also used : FormPrintRequest(org.jaffa.modules.printing.services.FormPrintRequest) FormSelectionMaintenanceOutRowDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) CheckBoxModel(org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)

Example 2 with EditBoxModel

use of org.jaffa.presentation.portlet.widgets.model.EditBoxModel in project jaffa-framework by jaffa-projects.

the class FormSelectionMaintenanceComponent method print.

/**
 * Generates all forms and/or labels for the current Event and Keyset.
 * This method should be used when a User Interface is not needed.
 * Prior to calling this method, set the Event and Keyset using
 * setEvent(), setKey1(), setValue1(), setKey2(), setValue2(),setKey3(), setValue3(),
 * setKey4(), setValue4(), setKey5(), setValue5(), setKey6(), setValue6().
 * The forms and/or labels that match the current
 * Event and Keyset will be printed and/or emailed.
 * @throws ApplicationExceptions - When an exception occurs for a given
 * Form or Label, the exception will be caught and added to the
 * ApplicationExceptions.ApplicationExceptionArray.  Therefore multiple
 * exceptions may be caught and finally thrown at the end of this method.
 * Forms and/or Labels that do not experience an exception will be
 * generated successfully.
 */
public void print() throws ApplicationExceptions, Exception {
    if (log.isDebugEnabled()) {
        log.debug(" Begin generating forms and labels. ");
        log.debug("Event = " + getEvent() + ".");
        log.debug("Key 1 " + getKey1() + " = " + getValue1() + ".");
        log.debug("Key 2 " + getKey2() + " = " + getValue2() + ".");
        log.debug("Key 3 " + getKey3() + " = " + getValue3() + ".");
        log.debug("Key 4 " + getKey4() + " = " + getValue4() + ".");
        log.debug("Key 5 " + getKey5() + " = " + getValue5() + ".");
        log.debug("Key 6 " + getKey6() + " = " + getValue6() + ".");
    }
    ApplicationExceptions appExps = new ApplicationExceptions();
    GridModel gridModelRows = new GridModel();
    FormSelectionMaintenanceOutDto finderOutDto = null;
    setFormUserId(SecurityManager.getPrincipal() != null ? SecurityManager.getPrincipal().getName() : null);
    // Validate that Event and Key1 are populated at a minimum.
    if (getEvent() == null) {
        throw new ApplicationExceptions(new MandatoryFieldException("[label.Jaffa.Printing.FormSelection.Event]"));
    }
    if (getKey1() == null || getValue1() == null) {
        throw new ApplicationExceptions(new MandatoryFieldException("[label.Jaffa.Printing.FormSelection.Key1]"));
    }
    try {
        finderOutDto = (FormSelectionMaintenanceOutDto) doInquiry2();
    } catch (Exception ex) {
        throw new ApplicationExceptions(new ApplicationException(ex.getMessage()));
    }
    if (finderOutDto != null && finderOutDto.getRowsCount() > 0) {
        EditBoxModel printerModel = null;
        GridModelRow gridModelRow = null;
        FormSelectionMaintenanceOutRowDto[] rows = finderOutDto.getRows();
        for (FormSelectionMaintenanceOutRowDto row : rows) {
            gridModelRow = gridModelRows.newRow();
            gridModelRow.addElement("select", new CheckBoxModel(Boolean.TRUE));
            gridModelRow.addElement("formName", row.getFormName());
            gridModelRow.addElement("formAlternateName", row.getFormAlternateName());
            gridModelRow.addElement("formVariation", row.getFormVariation());
            gridModelRow.addElement("event", row.getEvent());
            gridModelRow.addElement("key1", row.getKey1());
            gridModelRow.addElement("key2", row.getKey2());
            gridModelRow.addElement("key3", row.getKey3());
            gridModelRow.addElement("key4", row.getKey4());
            gridModelRow.addElement("key5", row.getKey5());
            gridModelRow.addElement("key6", row.getKey6());
            gridModelRow.addElement("value1", row.getValue1());
            gridModelRow.addElement("value2", row.getValue2());
            gridModelRow.addElement("value3", row.getValue3());
            gridModelRow.addElement("value4", row.getValue4());
            gridModelRow.addElement("value5", row.getValue5());
            gridModelRow.addElement("value6", row.getValue6());
            printerModel = new EditBoxModel(row.getPrinter(), PrinterDefinitionMeta.META_PRINTER_ID);
            printerModel.setMandatory(false);
            gridModelRow.addElement("printer", printerModel);
            gridModelRow.addElement("email", new EditBoxModel(getEmailAddress()));
            gridModelRow.addElement("publish", new CheckBoxModel(Boolean.FALSE));
            gridModelRow.addElement("copies", new EditBoxModel(row.getCopies()));
            gridModelRow.addElement("object", row);
            try {
                ApplicationExceptions aes = new ApplicationExceptions();
                validateFields(gridModelRow, aes, false);
                if (aes != null && aes.size() > 0) {
                    for (Iterator i = aes.iterator(); i.hasNext(); ) {
                        ApplicationException appEx = (ApplicationException) i.next();
                        appExps.add(appEx);
                    }
                } else {
                    m_tx.dispatchPrintRequest(createPrintRequestObject(gridModelRow, false));
                }
            } catch (Exception ex) {
                appExps.add(new ApplicationException(ex.getMessage()));
            }
        }
    } else {
        if (appExps.size() == 0) {
            appExps.add(new FormSelectionException(FormSelectionException.NO_FORM_DEFINED_FOR_EVENT, getEvent()));
        }
    }
    if (appExps != null && appExps.size() > 0) {
        throw appExps;
    }
    if (log.isDebugEnabled()) {
        log.debug(" Finished generating forms and labels. ");
    }
}
Also used : FormSelectionException(org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) FrameworkException(org.jaffa.exceptions.FrameworkException) FormSelectionException(org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException) ApplicationException(org.jaffa.exceptions.ApplicationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) CheckBoxModel(org.jaffa.presentation.portlet.widgets.model.CheckBoxModel) ApplicationException(org.jaffa.exceptions.ApplicationException) FormSelectionMaintenanceOutRowDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) Iterator(java.util.Iterator) FormSelectionMaintenanceOutDto(org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutDto) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 3 with EditBoxModel

use of org.jaffa.presentation.portlet.widgets.model.EditBoxModel in project jaffa-framework by jaffa-projects.

the class PropertyEditorHelper method addRow.

/**
 * Call from the action class to add a new row at the end of the property list
 * @param model grid model to add the row to
 */
public static void addRow(GridModel model) {
    GridModelRow row = model.newRow();
    row.addElement(KEY, new EditBoxModel(EMPTY));
    row.addElement(VALUE, new EditBoxModel(EMPTY));
    row.addElement(COMMENT, new EditBoxModel(EMPTY));
}
Also used : EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 4 with EditBoxModel

use of org.jaffa.presentation.portlet.widgets.model.EditBoxModel in project jaffa-framework by jaffa-projects.

the class PropertyEditorHelper method getPropertiesWM.

/**
 * Convert a property string into a grid model, if the model is already
 * being cached on the form, it returns the cached version. If it was not cached
 * it is added to the cache after it has been create.
 * <p>
 * <b>NOTE: if the model is cached and this method is called with a 'new' source
 * string, it will only return the current cached version, not a new grid based
 * on the new source string. If you want this, clear the model cache prior to calling
 * this method
 * </b>
 * @param form the form object that will contains this model
 * @param cacheName the name being used by the form to cache this model
 * @param source the source string containing the property data
 * @return the converted grid model
 */
public static GridModel getPropertiesWM(FormBase form, String cacheName, String source) {
    GridModel model = (GridModel) form.getWidgetCache().getModel(cacheName);
    if (model == null) {
        model = new GridModel();
        ListProperties p = new ListProperties();
        try {
            if (source != null)
                p.load(new ByteArrayInputStream(source.getBytes()));
            for (Enumeration e = p.keys(); e.hasMoreElements(); ) {
                String key = (String) e.nextElement();
                String value = (String) p.getProperty(key);
                String comment = (String) p.getComments(key);
                GridModelRow row = model.newRow();
                row.addElement(KEY, new EditBoxModel(key == null ? EMPTY : key));
                row.addElement(VALUE, new EditBoxModel(value == null ? EMPTY : value));
                row.addElement(COMMENT, new EditBoxModel(comment == null ? EMPTY : value));
            }
            form.getWidgetCache().addModel(cacheName, model);
        } catch (IOException e) {
            log.error("Failed to Load Properties For Field : " + cacheName, e);
        }
    }
    return model;
}
Also used : ListProperties(org.jaffa.util.ListProperties) Enumeration(java.util.Enumeration) ByteArrayInputStream(java.io.ByteArrayInputStream) GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) IOException(java.io.IOException) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 5 with EditBoxModel

use of org.jaffa.presentation.portlet.widgets.model.EditBoxModel in project jaffa-framework by jaffa-projects.

the class PropertyEditorHelper method getProperties.

/**
 * Convert the user grid back to a string format
 * @param model User grid model that contains the property entries
 * @return the formated string, including a date time stamp.
 * Returns a null string if there are no rows.
 */
public static String getProperties(GridModel model) {
    if (model == null || model.getRows() == null || model.getRows().size() == 0)
        return null;
    ListProperties p = new ListProperties();
    for (Iterator i = model.getRows().iterator(); i.hasNext(); ) {
        GridModelRow row = (GridModelRow) i.next();
        EditBoxModel e = (EditBoxModel) row.get(KEY);
        String key = (String) (e == null ? null : e.getValue());
        e = (EditBoxModel) row.get(VALUE);
        String value = (String) (e == null ? null : e.getValue());
        e = (EditBoxModel) row.get(COMMENT);
        String comment = (String) (e == null ? null : e.getValue());
        if ((key != null && key.length() > 0) || (value != null && value.length() > 0)) {
            log.debug("Save Prop '" + (key == null ? "null" : key + "[" + key.length() + "]") + "=" + (value == null ? "null" : value + "[" + value.length() + "]") + "'");
            p.setProperty(key, value, comment);
        }
    }
    try {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        p.store(b, null);
        b.close();
        return b.toString();
    } catch (IOException e) {
        log.error("Failed to Store Field Properties", e);
        return null;
    }
}
Also used : ListProperties(org.jaffa.util.ListProperties) Iterator(java.util.Iterator) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Aggregations

EditBoxModel (org.jaffa.presentation.portlet.widgets.model.EditBoxModel)34 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)8 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)7 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)6 FormSelectionMaintenanceOutRowDto (org.jaffa.modules.printing.components.formselectionmaintenance.dto.FormSelectionMaintenanceOutRowDto)4 Iterator (java.util.Iterator)3 DateTime (org.jaffa.datatypes.DateTime)3 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)3 DateOnlyFieldMetaData (org.jaffa.metadata.DateOnlyFieldMetaData)3 DateTimeFieldMetaData (org.jaffa.metadata.DateTimeFieldMetaData)3 DecimalFieldMetaData (org.jaffa.metadata.DecimalFieldMetaData)3 IntegerFieldMetaData (org.jaffa.metadata.IntegerFieldMetaData)3 StringFieldMetaData (org.jaffa.metadata.StringFieldMetaData)3 FormSelectionException (org.jaffa.modules.printing.components.formselectionmaintenance.FormSelectionException)3 DateTimeModel (org.jaffa.presentation.portlet.widgets.model.DateTimeModel)3 DropDownModel (org.jaffa.presentation.portlet.widgets.model.DropDownModel)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 org.jaffa.components.maint (org.jaffa.components.maint)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2