diff --git a/samples/resources/scriptedrest/bitbucket/SearchScript.groovy b/samples/resources/scriptedrest/bitbucket/SearchScript.groovy index 663add99da5..678c6227c20 100644 --- a/samples/resources/scriptedrest/bitbucket/SearchScript.groovy +++ b/samples/resources/scriptedrest/bitbucket/SearchScript.groovy @@ -1,7 +1,12 @@ import groovyx.net.http.HttpResponseException +import javax.imageio.ImageIO +import java.awt.image.BufferedImage import java.nio.file.Files +import static java.awt.RenderingHints.KEY_INTERPOLATION +import static java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC + /* * Copyright (c) 2010-2016 Evolveum * @@ -131,6 +136,7 @@ def parseUser(it, readImage, defaultAvatar) { } byte[] avatar = null; // send only not default profile pictures + byte[] avatarJpg = null; if (readImage && avatarUrl != null) { respImage = connection.get(path: avatarUrl, headers: ['Content-Type': 'image/png'], @@ -143,12 +149,21 @@ def parseUser(it, readImage, defaultAvatar) { if (Arrays.equals(avatar, defaultAvatar)) { avatar = null; } + else { // convert it to JPG for midPoint + ByteArrayInputStream bis = new ByteArrayInputStream(avatar); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + BufferedImage img = ImageIO.read(bis); + ImageIO.write(img, "jpg", bos); + //ImageIO.write(img, 'jpg', new File("D://gusto.jpg") ) + avatarJpg = bos.toByteArray(); + } } return [__UID__ : id, __NAME__ : id, avatarLink : avatarUrl, - avatar : avatar + avatar : avatarJpg ]; } \ No newline at end of file diff --git a/samples/resources/scriptedrest/bitbucket/UpdateScript.groovy b/samples/resources/scriptedrest/bitbucket/UpdateScript.groovy index 879313161df..a55784a9eb2 100644 --- a/samples/resources/scriptedrest/bitbucket/UpdateScript.groovy +++ b/samples/resources/scriptedrest/bitbucket/UpdateScript.groovy @@ -15,6 +15,7 @@ */ import groovy.json.JsonSlurper +import org.apache.commons.codec.binary.Hex import static java.awt.RenderingHints.* import java.awt.image.BufferedImage @@ -104,43 +105,48 @@ switch ( objectClass ) { //connection.setProxy('localhost', 8888, 'http'); -// body = '--------------------------d9644f1fd52e712e\n' + -// 'Content-Disposition: form-data; name="avatar"; filename="gusto.png"\n' + -// 'Content-Type: application/octet-stream\n\n' + -// ' PNG'; -// -// ByteArrayOutputStream outputStream = new ByteArrayOutputStream( ); -// outputStream.write(body.getBytes()); -// outputStream.write(avatar); -// -// byte bodyBytes = outputStream.toByteArray( ); + String hexNewLine = "0D0A"; + byte[] byteNewLine = Hex.decodeHex(hexNewLine.toCharArray()); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream( ); + + // avatar as JPG - no conversion to PNG +// outputStream.write('--------------------------86c9c0934f0c28c5'.getBytes()); +// outputStream.write(byteNewLine); +// outputStream.write('Content-Disposition: form-data; name="avatar"; filename="gusto.jpg'.getBytes()); +// outputStream.write(byteNewLine); +// outputStream.write('Content-Type: image/jpeg'.getBytes()); +// outputStream.write(byteNewLine); +// outputStream.write(byteNewLine); // -// ByteArrayInputStream inputStream = new ByteArrayInputStream(body.getBytes()) //as byte[] +// outputStream.write(avatarOrig); //avatar as JPG // -// resp = connection.post(path: "http://localhost:7990/rest/api/1.0/users/"+userName+"/avatar.png", -// headers: ['X-Atlassian-Token': 'no-check', 'Accept': '*/*', 'Content-Type': 'multipart/form-data; boundary=------------------------d9644f1fd52e712e'], -// contentType: 'application/octet-stream', -// body: body.getBytes()); +// outputStream.write(byteNewLine); +// outputStream.write('--------------------------86c9c0934f0c28c5--'.getBytes()); +// outputStream.write(byteNewLine); - ContentDisposition content = new ContentDisposition("form-data; name=\"avatar\"; filename=\"gusto.png\""); - ByteArrayInputStream bisResized = new ByteArrayInputStream(avatar) //as byte[] - Attachment avatarAtt = new Attachment("d9644f1fd52e712e", bisResized, content) + // avatar as converted PNG + outputStream.write('--------------------------86c9c0934f0c28c5'.getBytes()); + outputStream.write(byteNewLine); + outputStream.write('Content-Disposition: form-data; name="avatar"; filename="avatar.png"'.getBytes()); + outputStream.write(byteNewLine); + outputStream.write('Content-Type: application/octet-stream'.getBytes()); + outputStream.write(byteNewLine); + outputStream.write(byteNewLine); - List atts = new LinkedList(); - atts.add(avatarAtt); + outputStream.write(avatar); //avatar as PNG - def body = new MultipartBody(atts, MediaType.APPLICATION_OCTET_STREAM_TYPE, false) + outputStream.write(byteNewLine); + outputStream.write('--------------------------86c9c0934f0c28c5--'.getBytes()); + outputStream.write(byteNewLine); - resp = connection.post(path: "http://localhost:7990/rest/api/1.0/users/"+userName+"/avatar.png", - headers: ['X-Atlassian-Token': 'no-check', 'Accept': '*/*', 'Content-Type': 'multipart/form-data'], -// contentType: 'application/octet-stream', - body: body); + byte[] bodyBytes = outputStream.toByteArray(); -// requestContentType: 'multipart/form-data', + resp = connection.post(path: "http://localhost:7990/rest/api/1.0/users/"+userName+"/avatar.png", + headers: ['X-Atlassian-Token': 'no-check', 'Accept': '*/*', 'Content-Type': 'multipart/form-data; boundary=------------------------86c9c0934f0c28c5'], + contentType: 'application/octet-stream', + body: bodyBytes); - def slurper = new JsonSlurper(); - def respJson = slurper.parseText(resp.getData().text) // need to manually convert - log.ok("response: {0}", respJson /* resp.getData()==null ? resp : resp.getData().text*/); + log.ok("response: {0}", resp.getData()==null ? resp : resp.getData()); } } diff --git a/samples/resources/scriptedrest/bitbucket/resource.xml b/samples/resources/scriptedrest/bitbucket/resource.xml index 73dfaf25dc0..2daa00d6b03 100644 --- a/samples/resources/scriptedrest/bitbucket/resource.xml +++ b/samples/resources/scriptedrest/bitbucket/resource.xml @@ -57,12 +57,6 @@ 0 mr:stringIgnoreCase - - normal - - $user/name - - normal @@ -70,6 +64,12 @@ $user/name + + normal + + $user/name + + @@ -84,6 +84,12 @@ $user/jpegPhoto + + strong + + $user/jpegPhoto + + diff --git a/samples/resources/scriptedrest/confluence-wiki/resource.xml b/samples/resources/scriptedrest/confluence-wiki/resource.xml index ba25101cd7d..7c9512ebfd0 100644 --- a/samples/resources/scriptedrest/confluence-wiki/resource.xml +++ b/samples/resources/scriptedrest/confluence-wiki/resource.xml @@ -59,12 +59,6 @@ 0 mr:stringIgnoreCase - - normal - - $user/name - - normal @@ -72,6 +66,12 @@ $user/name + + normal + + $user/name + + diff --git a/samples/resources/scriptedrest/jira/resource.xml b/samples/resources/scriptedrest/jira/resource.xml index 94b0898933e..e3189fa99fd 100644 --- a/samples/resources/scriptedrest/jira/resource.xml +++ b/samples/resources/scriptedrest/jira/resource.xml @@ -59,12 +59,6 @@ 0 mr:stringIgnoreCase - - normal - - $user/name - - normal @@ -72,6 +66,12 @@ $user/name + + normal + + $user/name + + ri:emailAddress