/** * For converting a string into this {@link Enum}. * * @param string which corresponds to one of this enum values * @return corresponding enum */ public static ConsentStatus fromString(String string) { for (ConsentStatus status : ConsentStatus.values()) { if (status.toString().contentEquals(string)) { return status; } } return null; } }
@Override public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put(JSON_KEY_ID, this.getId()); json.put(JSON_KEY_LABEL, this.getLabel()); json.put(JSON_KEY_DESCRIPTION, this.getDescription()); json.put(JSON_KEY_ISREQUIRED, this.isRequired()); json.put(JSON_KEY_STATUS, this.getStatus().toString()); if (this.formFields != null) { JSONArray fields = new JSONArray(this.formFields); json.put(JSON_KEY_FIELDS, fields); } return json; }
/** * A constructor from JSON representation. * * @param consentJSON JSON in the format produced by toJSON() */ public DefaultConsent(JSONObject consentJSON) { this.id = consentJSON.optString(JSON_KEY_ID); this.label = consentJSON.optString(JSON_KEY_LABEL); this.description = processDescription(consentJSON.optString(JSON_KEY_DESCRIPTION)); this.required = consentJSON.optBoolean(JSON_KEY_ISREQUIRED); setStatus(ConsentStatus.fromString(consentJSON.optString(JSON_KEY_ISREQUIRED))); JSONArray fields = consentJSON.optJSONArray(JSON_KEY_FIELDS); if (fields == null) { this.formFields = null; } else { this.formFields = new LinkedList<>(); for (Object field : fields) { this.formFields.add((String) field); } } validate(); }
@Override public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put(JSON_KEY_ID, this.getId()); json.put(JSON_KEY_LABEL, this.getLabel()); json.put(JSON_KEY_DESCRIPTION, this.getDescription()); json.put(JSON_KEY_ISREQUIRED, this.isRequired()); json.put(JSON_KEY_STATUS, this.getStatus().toString()); if (this.dataFields != null) { JSONArray dFields = new JSONArray(this.dataFields); json.put(JSON_KEY_DATAFIELDS, dFields); } if (this.formFields != null) { JSONArray fields = new JSONArray(this.formFields); json.put(JSON_KEY_FIELDS, fields); } return json; }
this.description = processDescription(consentJSON.optString(JSON_KEY_DESCRIPTION)); this.required = consentJSON.optBoolean(JSON_KEY_ISREQUIRED); setStatus(ConsentStatus.fromString(consentJSON.optString(JSON_KEY_STATUS))); JSONArray dFields = consentJSON.optJSONArray(JSON_KEY_DATAFIELDS); JSONArray fields = consentJSON.optJSONArray(JSON_KEY_FIELDS);
/** * For converting a string into this {@link Enum}. * * @param string which corresponds to one of this enum values * @return corresponding enum */ public static ConsentStatus fromString(String string) { for (ConsentStatus status : ConsentStatus.values()) { if (status.toString().contentEquals(string)) { return status; } } return null; } }