Skip to content

Commit

Permalink
read also no default image as byte[]
Browse files Browse the repository at this point in the history
  • Loading branch information
gpalos committed Mar 29, 2016
1 parent f1f519f commit ea0f6ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
13 changes: 11 additions & 2 deletions samples/resources/scriptedrest/confluence-wiki/SchemaScript.groovy
Expand Up @@ -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<AttributeInfo>();
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();
Expand Down
40 changes: 37 additions & 3 deletions samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit ea0f6ce

Please sign in to comment.