Search in sources :

Example 1 with FieldPropertySet

use of it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method formNameMessage.

private String formNameMessage(FieldProperty fieldProperty, BulkInfo bulkInfo, PrintDetailBulk detail, ApplicationModel applicationModel, Folder application, String labelKey) {
    String message = "";
    if (fieldProperty.getAttribute("formName") != null) {
        List<Object> params = new ArrayList<Object>();
        FieldPropertySet printForm1 = bulkInfo.getPrintForms().get(fieldProperty.getAttribute("formName"));
        if (printForm1 != null && printForm1.getKey() != null && printForm1.getKey().equals("false")) {
            if (labelKey != null)
                detail.addField(new Pair<String, String>(null, applicationModel.getMessage(labelKey)));
            printField(printForm1, applicationModel, application, detail, bulkInfo);
        } else {
            for (FieldProperty paramFieldProperty : bulkInfo.getPrintForm(fieldProperty.getAttribute("formName"))) {
                Object param = applicationModel.getProperties().get(paramFieldProperty.getAttribute("property"));
                if (param == null)
                    param = application.getPropertyValue(paramFieldProperty.getAttribute("property"));
                if (param == null)
                    param = "";
                params.add(param);
            }
            message = message.concat(applicationModel.getMessage(labelKey, params.toArray()));
        }
    } else {
        message = message.concat(applicationModel.getMessage(labelKey));
    }
    return message;
}
Also used : FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) Pair(it.cnr.cool.util.Pair)

Example 2 with FieldPropertySet

use of it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method printField.

@SuppressWarnings("unchecked")
private void printField(FieldPropertySet printForm, ApplicationModel applicationModel, Folder application, PrintDetailBulk detail, BulkInfo bulkInfo) {
    for (FieldProperty printFieldProperty : printForm.getFieldProperties()) {
        if (printFieldProperty.getAttribute("formName") != null) {
            Object objValue = application.getPropertyValue(printFieldProperty.getAttribute("formName"));
            FieldPropertySet printFormDetail = bulkInfo.getPrintForms().get(printFieldProperty.getAttribute("formName"));
            for (FieldProperty printFieldPropertyDetail : printFormDetail.getFieldProperties()) {
                if (printFieldPropertyDetail.getAttribute("key") != null && printFieldPropertyDetail.getAttribute("key").equals(String.valueOf(objValue))) {
                    detail.addField(new Pair<String, String>(null, applicationModel.getMessage(printFieldPropertyDetail.getAttribute("label"))));
                }
            }
            final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
            if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
                detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
            }
            continue;
        }
        String message = null;
        String label = printFieldProperty.getAttribute("label");
        if (label == null) {
            String labelJSON = printFieldProperty.getAttribute("jsonlabel");
            if (labelJSON != null) {
                JSONObject jsonLabel = new JSONObject(labelJSON);
                message = applicationModel.getMessage(jsonLabel.getString("key"));
                if (message == null || message.equalsIgnoreCase(jsonLabel.getString("key")))
                    message = jsonLabel.getString("default");
            } else {
                FieldProperty subProperty = printFieldProperty.getSubProperty("jsonlabel");
                label = subProperty.getAttribute("key");
                message = applicationModel.getMessage(label);
                if (message == null || message.equalsIgnoreCase(subProperty.getAttribute("key")))
                    message = subProperty.getAttribute("default");
            }
        } else {
            message = applicationModel.getMessage(label);
        }
        String value;
        Object objValue = application.getPropertyValue(printFieldProperty.getProperty());
        if (objValue == null && printFieldProperty.getProperty() != null) {
            final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
            if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
                detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
            }
            continue;
        } else if (printFieldProperty.getProperty() == null) {
            detail.addField(new Pair<String, String>(null, message));
        } else {
            if (application.getProperty(printFieldProperty.getProperty()).isMultiValued()) {
                List<Object> values = (List<Object>) objValue;
                if (values.isEmpty()) {
                    final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
                    if (dichiarazioniEmptyMessage.isPresent() && Optional.ofNullable(detail.getFields()).orElse(Collections.emptyList()).isEmpty()) {
                        detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
                    }
                    return;
                }
                if (values.size() > 1) {
                    for (int k = 0; k < values.size(); k++) {
                        detail.addField(new Pair<String, String>(k == 0 ? (message + "<br>") : "", String.valueOf(values.get(k))));
                    }
                } else {
                    value = StringUtils.collectionToDelimitedString(((Collection<?>) objValue), ", ");
                    detail.addField(new Pair<String, String>(message, value));
                }
            } else {
                if (printFieldProperty.getAttribute("widget") != null) {
                    if (printFieldProperty.getAttribute("widget").contains("ui.datepicker")) {
                        value = StringUtil.DATEFORMAT.format(((Calendar) objValue).getTime());
                    } else if (printFieldProperty.getAttribute("widget").contains("ui.datetimepicker")) {
                        value = StringUtil.DATETIMEFORMAT.format(((Calendar) objValue).getTime());
                    } else {
                        if (objValue instanceof Boolean) {
                            if (printFieldProperty.getAttribute("generated") != null)
                                value = Boolean.valueOf(String.valueOf(objValue)) ? "" : "No";
                            else
                                value = "";
                        } else {
                            value = String.valueOf(objValue);
                        }
                    }
                } else {
                    value = String.valueOf(objValue);
                }
                if (Optional.ofNullable(label).isPresent()) {
                    final String finalLabel = label.concat("_").concat(value);
                    final Optional<String> message1 = Optional.ofNullable(applicationModel.getMessage(finalLabel));
                    if (message1.isPresent() && !message1.get().equals(finalLabel)) {
                        message = message1.get();
                        value = "";
                    }
                }
                detail.addField(new Pair<String, String>(message, value));
            }
        }
    }
}
Also used : FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) JSONObject(org.json.JSONObject) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) JSONObject(org.json.JSONObject) List(java.util.List) Pair(it.cnr.cool.util.Pair)

Example 3 with FieldPropertySet

use of it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet in project cool-jconon by consiglionazionaledellericerche.

the class PrintService method getDichiarazioni.

/**
 * 1. Prendiamo tutte le associazioni della domanda (application)
 * 2. Per ogni associazione prendiamo il corrispondente PrintForm dal BulkInfo
 * (passato come parametro)
 * 3. Per ogni fieldProperty del PrintForm si costruisce una riga(?) dell'output
 *
 * @param bulkInfo
 * @param application
 * @param callProperty
 * @return
 */
protected List<PrintDetailBulk> getDichiarazioni(BulkInfo bulkInfo, Folder application, JCONONPropertyIds callProperty, ApplicationModel applicationModel, Dichiarazioni dichiarazione) {
    List<PrintDetailBulk> result = new ArrayList<PrintDetailBulk>();
    // Recupero il bando
    // chi e' il parent?
    Folder call = application.getParents().get(0);
    List<String> associations = call.getPropertyValue(callProperty.value());
    boolean isCittadinoItaliano = (boolean) Optional.ofNullable(application.getProperty(JCONONPropertyIds.APPLICATION_FL_CITTADINO_ITALIANO.value())).map(Property::getValue).orElse(Boolean.TRUE);
    if (isCittadinoItaliano) {
        associations.remove(P_JCONON_APPLICATION_ASPECT_GODIMENTO_DIRITTI);
    } else {
        associations.remove(P_JCONON_APPLICATION_ASPECT_ISCRIZIONE_LISTE_ELETTORALI);
    }
    for (int i = 0; i < associations.size(); i++) {
        String association = associations.get(i);
        FieldProperty fieldProperty = null;
        FieldPropertySet printForm = bulkInfoService.find(association).getPrintForms().get(association);
        if (printForm != null) {
            Property<?> property = application.getProperty(printForm.getKey());
            if (property != null) {
                fieldProperty = printForm.getFieldProperty(property.getValueAsString());
            }
            PrintDetailBulk detail = new PrintDetailBulk();
            detail.setTitle(getTitle(i, dichiarazione));
            if (printForm.getKey() == null) {
                printField(printForm, applicationModel, application, detail, bulkInfo);
            } else {
                String labelKey = fieldProperty != null ? fieldProperty.getAttribute("label") : null;
                if (application.getPropertyValue(printForm.getKey()) == null || fieldProperty == null || labelKey == null) {
                    final Optional<String> dichiarazioniEmptyMessage = getDichiarazioniEmptyMessage();
                    if (!dichiarazioniEmptyMessage.isPresent()) {
                        continue;
                    } else {
                        detail.addField(new Pair<String, String>(null, dichiarazioniEmptyMessage.get()));
                    }
                } else {
                    detail.addField(new Pair<String, String>(null, formNameMessage(fieldProperty, bulkInfo, detail, applicationModel, application, labelKey)));
                }
            }
            if (detail.getFields() != null && !detail.getFields().isEmpty())
                result.add(detail);
        }
    }
    return result;
}
Also used : FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty) FieldPropertySet(it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet) PrintDetailBulk(it.cnr.si.cool.jconon.model.PrintDetailBulk) FieldProperty(it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)

Aggregations

FieldProperty (it.cnr.bulkinfo.BulkInfoImpl.FieldProperty)3 FieldPropertySet (it.cnr.bulkinfo.BulkInfoImpl.FieldPropertySet)3 Pair (it.cnr.cool.util.Pair)2 PDImageXObject (org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject)2 JSONObject (org.json.JSONObject)2 PrintDetailBulk (it.cnr.si.cool.jconon.model.PrintDetailBulk)1 List (java.util.List)1