Skip to content

Commit

Permalink
read also no default image as byte[] for jira
Browse files Browse the repository at this point in the history
  • Loading branch information
gpalos committed Mar 29, 2016
1 parent ea0f6ce commit 7ca2614
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
Expand Up @@ -78,12 +78,9 @@ case "__ACCOUNT__":
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) {
if (thumbnail != null && !thumbnail.contains("/profilepics/")) {
thumbnailPrefix = thumbnail.split("\\?");
connection.setUri(thumbnailPrefix[0]);
log.ok("JSON GET profile picture url: {0}", thumbnailPrefix[0]);
Expand Down
6 changes: 3 additions & 3 deletions samples/resources/scriptedrest/jira/SchemaScript.groovy
Expand Up @@ -61,9 +61,9 @@ avatarUrlAIB.setUpdateable(false);
//avatar -- 48x48
avatarAIB = new AttributeInfoBuilder("avatar", byte[].class);
avatarAIB.setUpdateable(true); // only push, not to read
// at this moment only avatarUrl is avaliable, if you need, you can implement it
// but when avatar picture is pushed to jira it is cropped and image in jira is smaller then what we resized (see updateScript)
avatarAIB.setReadable(false);

// read only custom avatars, default.png is ignored
avatarAIB.setReadable(true); // returned only in findByUID/Name
avatarAIB.setReturnedByDefault(false);

//displayName
Expand Down
43 changes: 38 additions & 5 deletions samples/resources/scriptedrest/jira/SearchScript.groovy
Expand Up @@ -61,7 +61,7 @@ case "__ACCOUNT__":
json = resp.getData();
log.ok("JSON response:\n" + json);

res = parseUser(json);
res = parseUser(json, true);
result.add(res);
}
else {
Expand Down Expand Up @@ -96,15 +96,15 @@ case "__ACCOUNT__":
else {
// has only 1 account
if (data.capacity == null) {
res = parseUser(data);
res = parseUser(data, false);
if (!uniqueUsers.contains(res.__NAME__)) {
result.add(res);
uniqueUsers.add(res.__NAME__);
}
} else {
// has more accounts need to iterate
data.each {
res = parseUser(it);
res = parseUser(it, false);
if (!uniqueUsers.contains(res.__NAME__)) {
result.add(res);
uniqueUsers.add(res.__NAME__);
Expand All @@ -130,7 +130,7 @@ log.info("result: \n" + result);
return result;


def parseUser(it) {
def parseUser(it, readImage) {
log.ok("user: "+it);
id = it."name";

Expand All @@ -140,13 +140,46 @@ def parseUser(it) {

// log.ok("name: "+id+", avatarUrl: "+avatarUrl);

byte[] avatar = null; // send only not default profile pictures
if (readImage && avatarUrl != null && avatarUrl.contains("ownerId")) {
thumbnailPrefix = avatarUrl.split("\\?");

thumbnailQuerys = thumbnailPrefix[1].split("&");

ownerId = null;
avatarId = null;
for (int i=0; i<thumbnailQuerys.size(); i++) {
p = thumbnailQuerys[i].split("=");
key = p[0];
if ("ownerId".equals(key)){
ownerId = p[1];
}
else if ("avatarId".equals(key)) {
avatarId = p[1];
}
}

log.ok("JSON GET profile picture url: {0}, ownerId: {1}, avatarId: {2}", thumbnailPrefix[0], ownerId, avatarId);

connection.setUri(thumbnailPrefix[0]);
respImage = connection.get(path: thumbnailPrefix[0],
headers: ['Content-Type': 'image/png'],
contentType: 'application/octet-stream',
query: [avatarId : avatarId, ownerId : ownerId]
)
ByteArrayInputStream bais = respImage.getData();
avatar = new byte[bais.available()];
bais.read(avatar);
}

// self, timeZone, locale
return [__UID__ : id,
__NAME__ : id,
key : it.key,
emailAddress : it.emailAddress,
avatarUrl : avatarUrl,
displayName : it.displayName,
active : it.active
active : it.active,
avatar : avatar
];
}

0 comments on commit 7ca2614

Please sign in to comment.