Java Code Examples for com.smartgwt.client.data.Record#getAttributeAsObject()

The following examples show how to use com.smartgwt.client.data.Record#getAttributeAsObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaModelDataSource.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets model of a digital object. It searches for synthetic attribute
 * {@link #FIELD_MODELOBJECT}. If not found it searches for {@link SearchDataSource#FIELD_MODEL}
 * and sets FIELD_MODELOBJECT attribute.
 *
 * @param digitalObject record fetched by {@link SearchDataSource} or {@link RelationDataSource}
 * @return model object or {@code null}
 */
public static MetaModelRecord getModel(Record digitalObject) {
    MetaModelRecord mmr = (MetaModelRecord) digitalObject.getAttributeAsObject(FIELD_MODELOBJECT);
    if (mmr == null) {
        String model = digitalObject.getAttribute(SearchDataSource.FIELD_MODEL);
        if (model != null) {
            if (resultSet == null) {
                return null;
            }
            Record mr = resultSet.findByKey(model);
            if (mr != null) {
                mmr = MetaModelRecord.get(mr);
                digitalObject.setAttribute(FIELD_MODELOBJECT, mmr);
            } else {
                ClientUtils.severe(LOG, "unkown model ID '%s' of record %s", model, digitalObject.getAttribute(SearchDataSource.FIELD_PID));
            }
        }
    }
    return mmr;
}
 
Example 2
Source File: DigitalObjectDataSource.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates digital object instance from record.
 * @param r record
 * @param checked {@code false} means ignore missing attributes and return {@code null}
 * @return instance of digital object
 */
private static DigitalObject create(Record r, boolean checked) {
    if (r == null) {
        throw new NullPointerException();
    }
    DigitalObject dobj = (DigitalObject) r.getAttributeAsObject(FIELD_INSTANCE);
    if (dobj != null) {
        return dobj;
    }


    Long workflowJobId = r.getAttributeAsLong(WorkflowModelConsts.JOB_ID);
    String pid = getAttribute(r, FIELD_PID, checked && workflowJobId == null);

    String modelId = getAttribute(r, FIELD_MODEL, checked);
    if ((pid == null && workflowJobId == null) || modelId == null) {
        return null;
    }
    String batchId = r.getAttribute(ModsCustomDataSource.FIELD_BATCHID);
    MetaModelRecord model = MetaModelDataSource.getModel(r);
    return new DigitalObject(pid, batchId, modelId, model, workflowJobId, r);
}
 
Example 3
Source File: WorkflowTaskFormView.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private Object getParameterValue(Record record, ValueType valueType, DisplayType displayType) {
    Object val = record.getAttributeAsObject(WorkflowParameterDataSource.FIELD_VALUE);
    if (valueType == ValueType.DATETIME && val instanceof String) {
        DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601);
        val = format.parse((String) val);
    } else if (displayType == DisplayType.CHECKBOX && val instanceof String) {
        if (Boolean.TRUE.toString().equalsIgnoreCase((String) val)) {
            val = true;
        } else if (Boolean.FALSE.toString().equalsIgnoreCase((String) val)) {
            val = false;
        } else {
            try {
                val = new BigDecimal((String) val).compareTo(BigDecimal.ZERO) > 0;
            } catch (NumberFormatException e) {
                // ignore
            }
        }
    } else if (displayType == DisplayType.CHECKBOX && val instanceof Number) {
        val = ((Number) val).doubleValue() > 0;
    }
    return val;
}
 
Example 4
Source File: RepeatableFormItem.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Replace string values of record attributes with types declared by item children.
     * This is necessary as declarative forms do not use DataSource stuff.
     * @param record record to scan for attributes
     * @param item item with possible profile
     * @return resolved record
     */
    private static Record resolveRecordValues(Record record, FormItem item) {
        Field f = getProfile(item);
        if (f != null) {
            for (Field field : f.getFields()) {
                String fType = field.getType();
                if ("date".equals(fType) || "datetime".equals(fType)) {
                    // parses ISO dateTime to Date; otherwise DateItem cannot recognize the value!
                    Object value = record.getAttributeAsObject(field.getName());
                    if (!(value instanceof String)) {
                        continue;
                    }
                    String sd = (String) value;
//                    ClientUtils.severe(LOG, "name: %s, is date, %s", field.getName(), sd);
//                    Date d = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).parse("1994-11-05T13:15:30Z");
                    try {
                        Date d = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).parse(sd);
                        record.setAttribute(field.getName(), d);
                    } catch (IllegalArgumentException ex) {
                        LOG.log(Level.WARNING, sd, ex);
                    }
                }
            }
        }
        return record;
    }
 
Example 5
Source File: StreamProfileDataSource.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/** Gets stream instance or {@code null}. */
public static StreamProfile get(Record r) {
    if (r == null) {
        return null;
    }
    StreamProfile sv = (StreamProfile) r.getAttributeAsObject(FIELD_INSTANCE);
    if (sv == null) {
        sv = new StreamProfile(r);
        if (sv.getId() == null) {
            return null;
        }
        r.setAttribute(FIELD_INSTANCE, sv);
    }
    return sv;
}