/** * Writes the clinical status {@code value} to {@code isNormal}. * * @param value the value to be saved * @param isNormal the {@link BaseProperty} object where the value will be written */ private void setClinicalStatusValue( @Nullable final String value, @Nonnull final BaseProperty<ObjectPropertyReference> isNormal) { if (StringUtils.equals(value, VALUE_AFFECTED)) { isNormal.setValue(0); } else if (StringUtils.equals(value, VALUE_UNAFFECTED)) { isNormal.setValue(1); } }
@Override public BaseProperty fromString(String value) { BaseProperty prop = newProperty(); prop.setValue(value); return prop; }
@Override public BaseProperty fromString(String value) { BaseProperty prop = newProperty(); prop.setValue(value); return prop; }
public BaseProperty fromValue(Object value) { BaseProperty property = newProperty(); property.setValue(value); return property; }
@Override public BaseProperty fromString(String value) { BaseProperty property = newProperty(); Number nvalue = null; if (StringUtils.isNotEmpty(value)) { nvalue = new Integer(value); } property.setValue(nvalue); return property; }
@Override public BaseProperty fromString(String value) { BaseProperty property = newProperty(); property.setValue(value); return property; }
@Override public BaseProperty fromString(String value) { BaseProperty prop = newProperty(); prop.setValue(value); return prop; }
@Override public BaseProperty fromStringArray(String[] strings) { List<String> list = new ArrayList<String>(); for (int i = 0; i < strings.length; i++) { list.add(strings[i]); } BaseProperty prop = newProperty(); prop.setValue(StringUtils.join(list.toArray(), ",")); return prop; }
@Override public BaseProperty fromStringArray(String[] strings) { List<String> list = new ArrayList<String>(); for (int i = 0; i < strings.length; i++) { if (!strings[i].trim().equals("")) { list.add(strings[i]); } } BaseProperty prop = newProperty(); prop.setValue(StringUtils.join(list, ",")); return prop; }
@Override public BaseProperty fromStringArray(String[] strings) { List<String> list = new ArrayList<String>(); for (int i = 0; i < strings.length; i++) { if (!StringUtils.isBlank(strings[i])) { list.add(strings[i]); } } BaseProperty prop = newProperty(); prop.setValue(StringUtils.join(list, ",")); return prop; }
@Override public BaseProperty fromString(String value) { if (value.equals(FORM_PASSWORD_PLACEHODLER)) { return null; } BaseProperty property = newProperty(); if (value.startsWith(HASH_IDENTIFIER + SEPARATOR) || value.startsWith(CRYPT_IDENTIFIER + SEPARATOR)) { property.setValue(value); } else { property.setValue(getProcessedPassword(value)); } return property; }
/** * Writes a {@code value} for a {@code property} to the {@code dataHolder}. * * @param dataHolder the {@link BaseObject} where data will be written * @param property the property of interest * @param value the value for {@code property} as {@link Integer} */ private void writePropertyData( @Nonnull final BaseObject dataHolder, @Nonnull final String property, @Nullable final Integer value) { final String valueStr = value != null ? value.toString() : "unknown"; @SuppressWarnings("unchecked") final BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) dataHolder.getField(property); field.setValue(valueStr); }
@Override public BaseProperty fromString(String value) { BaseProperty property = newProperty(); if ((value == null) || (value.equals(""))) { if (getEmptyIsToday() == 1) { property.setValue(new Date()); } return property; } try { SimpleDateFormat sdf = new SimpleDateFormat(getDateFormat()); property.setValue(sdf.parse(value)); } catch (ParseException e) { return null; } return property; }
private void setStringField(@Nonnull final BaseObject xwikiDataObject, SolvedData data, String property, PatientWritePolicy policy) { @SuppressWarnings("unchecked") BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) xwikiDataObject.getField(property); if (field == null) { return; } if (data == null) { field.setValue(null); } else { String value = (SolvedData.STATUS_PROPERTY_NAME.equals(property)) ? data.getStatus() : data.getNotes(); if (value != null || PatientWritePolicy.REPLACE.equals(policy)) { field.setValue(applyCast(value)); } } }
@SuppressWarnings("unchecked") @Override public void save(Patient patient, DocumentModelBridge doc) { BaseProperty<ObjectPropertyReference> isNormal = (BaseProperty<ObjectPropertyReference>) ((XWikiDocument) doc).getXObject(Patient.CLASS_REFERENCE).getField( PATIENT_DOCUMENT_FIELDNAME); PatientData<String> data = patient.getData(this.getName()); if (isNormal == null || data == null) { return; } if (StringUtils.equals(data.getValue(), VALUE_AFFECTED)) { isNormal.setValue(0); } else if (StringUtils.equals(data.getValue(), VALUE_UNAFFECTED)) { isNormal.setValue(1); } }
@SuppressWarnings("unchecked") @Override public void save(Patient patient, DocumentModelBridge doc) { BaseObject dataHolder = ((XWikiDocument) doc).getXObject(Patient.CLASS_REFERENCE); PatientData<Integer> data = patient.getData(getName()); if (data == null || dataHolder == null) { return; } for (String propertyName : getProperties()) { Integer value = data.get(propertyName); BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) dataHolder.getField(propertyName); if (value != null) { field.setValue(value.toString()); } else { field.setValue("unknown"); } } }
/** * Set tags of the given document. * * @param document document to put the tags to. * @param tags list of tags. * @param context XWiki context. */ private void setDocumentTags(XWikiDocument document, List<String> tags, XWikiContext context) { BaseProperty prop = (BaseProperty) document.getObject(TAG_CLASS, true, context).safeget(TAG_PROPERTY); // Properties aren't added to an object unless a value is specified either from the Web or from an XML. if (prop == null) { prop = createTagProperty(document.getObject(TAG_CLASS, true, context), context); } prop.setValue(tags); }
@Override public BaseProperty fromString(String value) { BaseProperty prop = newProperty(); if (isMultiSelect()) { ((ListProperty) prop).setList(getListFromString(value, getSeparators(), false)); } else { prop.setValue(value); } return prop; }
@SuppressWarnings("unchecked") @Override public void save(Patient patient, DocumentModelBridge doc) { PatientData<String> data = patient.getData(getName()); BaseObject xwikiDataObject = ((XWikiDocument) doc).getXObject(Patient.CLASS_REFERENCE); if (data == null || !data.isNamed() || xwikiDataObject == null) { return; } for (String key : this.getProperties()) { String datum = data.get(this.fields.get(key)); BaseProperty<ObjectPropertyReference> field = (BaseProperty<ObjectPropertyReference>) xwikiDataObject.getField(key); if (field != null) { field.setValue(applyCast(datum)); } } }
public void set(String fieldname, java.lang.Object value, XWikiContext context) { BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) bclass.get(fieldname); BaseProperty prop = (BaseProperty) safeget(fieldname); if ((value instanceof String) && (pclass != null)) { prop = pclass.fromString((String) value); } else { if ((prop == null) && (pclass != null)) { prop = pclass.newProperty(); } if (prop != null) { prop.setValue(value); } } if (prop != null) { safeput(fieldname, prop); } }