Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/new-approva…
Browse files Browse the repository at this point in the history
…l-gui
  • Loading branch information
mederly committed Mar 29, 2016
2 parents d44622f + 7ca2614 commit 9fda82b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 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
37 changes: 34 additions & 3 deletions samples/resources/scriptedrest/confluence-wiki/SearchScript.groovy
Expand Up @@ -64,8 +64,39 @@ 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;
}

byte[] avatar = null; // send only not default profile pictures
if (thumbnail != null && !thumbnail.contains("/profilepics/")) {
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 +111,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
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 9fda82b

Please sign in to comment.