[midPoint] Binary attribute, ScriptedSQL, Groovy and Oracle Blob - the ultimate guide
Wojciech Staszewski
wojciech.staszewski at diagnostyka.pl
Wed Nov 22 00:08:55 CET 2017
For now, the code below is working as expected:
1) MidPoint
"stamp" (image) attribute in schema extension with "xsd:base64Binary"
type.
2) SchemaScript.groovy:
account.addAttributeInfo(AttributeInfoBuilder.build("stamp",
byte[].class));
3) SearchScript.groovy (read the stamp from database):
def stampquery = "select stamp from users" + where;
stamp_blob =
sql.firstRow(stampquery).stamp;
if ( stamp_blob ) { stamp_in =
stamp_blob.getBinaryStream().getBytes(); } else { stamp_in = null }
and set the attribute: stamp:stamp_in,
4) UpdateScript.groovy (write
the stamp to datablase)
case "stamp":
// oracle "blob" is an
interface, write to the blob can be done using BinaryOutputStream.
//
first, we need to lock the blob in the database by running "select for
update" query:
blob_out = (oracle.sql.BLOB) sql.firstRow("select stamp
from users where id = ? for update",[uid]).stamp;
// now we have to
define binary output stream to write the blob:
outstream =
((BLOB)blob_out).getBinaryOutputStream();
// and write the attribute
received as a byte array to this stream:
stamp_out =
attributes?.get("stamp")?.get(0);
outstream.write(stamp_out);
// at
the end we close the stream.
outstream.close();
break;
---------
Have fun.
Regards!
WS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20171122/84e7421f/attachment.htm>
More information about the midPoint
mailing list