| 1090 | } |
| 1091 | } |
| 1092 | pub fn get_cedar_schema_internal<'a>( |
| 1093 | env: &mut JNIEnv<'a>, |
| 1094 | schema_json_jstr: JString<'a>, |
| 1095 | ) -> Result<JValueOwned<'a>> { |
| 1096 | let rust_str = env.get_string(&schema_json_jstr)?; |
| 1097 | let schema_str = rust_str.to_str()?; |
| 1098 | |
| 1099 | let schema: FFISchema = serde_json::from_str(schema_str)?; |
| 1100 | let cedar_format = schema_to_text(schema); |
| 1101 | |
| 1102 | match cedar_format { |
| 1103 | SchemaToTextAnswer::Success { text, warnings } => { |
| 1104 | let jstr = env.new_string(&text)?; |
| 1105 | Ok(JValueGen::Object(JObject::from(jstr)).into()) |
| 1106 | } |
| 1107 | SchemaToTextAnswer::Failure { errors } => { |
| 1108 | let joined_errors = errors |
| 1109 | .iter() |
| 1110 | .map(|e| e.message.clone()) |
| 1111 | .collect::<Vec<_>>() |
| 1112 | .join("; "); |
| 1113 | Err(joined_errors.into()) |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | #[jni_fn("com.cedarpolicy.model.schema.Schema")] |
| 1119 | pub fn cedarToJsonJni<'a>(mut env: JNIEnv<'a>, _: JClass, cedar_schema: JString<'a>) -> jvalue { |