diff --git a/samples/resources/scriptedrest/confluence-wiki/SchemaScript.groovy b/samples/resources/scriptedrest/confluence-wiki/SchemaScript.groovy index 498a55e2272..1a649bf1d5a 100644 --- a/samples/resources/scriptedrest/confluence-wiki/SchemaScript.groovy +++ b/samples/resources/scriptedrest/confluence-wiki/SchemaScript.groovy @@ -49,15 +49,24 @@ nameAIB.setCreateable(false); //avatar -- 256x256 avatarAIB = new AttributeInfoBuilder("avatar", byte[].class); -avatarAIB.setUpdateable(true); // only send, not to read -avatarAIB.setReadable(false); +avatarAIB.setUpdateable(true); +// read only custom avatars, default.png is ignored +avatarAIB.setReadable(true); // returned only in findByUID/Name avatarAIB.setReturnedByDefault(false); // if needed: email, url, fullname, can get by method getUser + +// returned only in findByUID/Name +thumbnailLinkAIB = new AttributeInfoBuilder("thumbnailLink"); +thumbnailLinkAIB.setUpdateable(false); // only read, not to send +thumbnailLinkAIB.setReadable(true); +thumbnailLinkAIB.setReturnedByDefault(false); + accAttrsInfo = new HashSet(); accAttrsInfo.add(nameAIB.build()); accAttrsInfo.add(avatarAIB.build()); +accAttrsInfo.add(thumbnailLinkAIB.build()); // Create the __ACCOUNT__ Object class final ObjectClassInfo ociAccount = new ObjectClassInfoBuilder().setType("__ACCOUNT__").addAllAttributeInfo(accAttrsInfo).build(); diff --git a/samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy b/samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy index f3df1299457..bdc2b31eb9e 100644 --- a/samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy +++ b/samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy @@ -64,8 +64,42 @@ case "__ACCOUNT__": log.ok("JSON response:\n" + json); if (json.name) { // exists + // need to replace configured endpoint to other endpoint + restEndpoint = "https://wiki.evolveum.com/rest/prototype/1"; + path = restEndpoint+"/search/user"; + connection.setUri(restEndpoint) + log.ok("JSON GET detail url: {0}", path); + respDetail = connection.get(path: path, + headers: ['Content-Type': 'application/json'], + query: ['query': json.name]) + jsonDetail = respDetail.getData(); + log.ok("JSON response detail:\n {0}", jsonDetail); + thumbnail = ""; + if (jsonDetail && jsonDetail.result && jsonDetail.result[0].thumbnailLink && jsonDetail.result[0].thumbnailLink.href) { + thumbnail = jsonDetail.result[0].thumbnailLink.href; + } + if (thumbnail.contains("/profilepics/")) { // default images + thumbnail = null; + } + + byte[] avatar = null; // send only not default profile pictures + if (thumbnail != null) { + thumbnailPrefix = thumbnail.split("\\?"); + connection.setUri(thumbnailPrefix[0]); + log.ok("JSON GET profile picture url: {0}", thumbnailPrefix[0]); + respImage = connection.get(path: thumbnailPrefix[0], + headers: ['Content-Type': 'image/png'], + contentType: 'application/octet-stream', + ) + ByteArrayInputStream bais = respImage.getData(); + avatar = new byte[bais.available()]; + bais.read(avatar); + } + user = [__UID__ : json.name, - __NAME__: json.name + __NAME__: json.name, + thumbnailLink : thumbnail, + avatar : avatar ]; result.add(user); @@ -80,9 +114,9 @@ case "__ACCOUNT__": body: viewAll) data = resp.getData(); - log.ok("JSON response:\n" + data); + log.ok("JSON response:\n {0}", data); data.each { - log.ok("JSON LINE:\n" + it); + log.ok("JSON LINE:\n {0}", it); user = [__UID__ : it, __NAME__: it