Skip to content

Commit

Permalink
detect user already exists in create scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gpalos committed Mar 30, 2016
1 parent 2ec58ff commit f60a021
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
15 changes: 15 additions & 0 deletions samples/resources/scriptedrest/confluence-wiki/CreateScript.groovy
@@ -1,3 +1,5 @@
import org.identityconnectors.framework.common.exceptions.AlreadyExistsException

/*
* Copyright (c) 2010-2016 Evolveum
*
Expand Down Expand Up @@ -33,5 +35,18 @@

log.info("Entering "+action+" Script, attributes: "+attributes);

// detect if user already exists
def body = '[ "'+id+'" ]';
resp = connection.post(path: "https://wiki.evolveum.com/rpc/json-rpc/confluenceservice-v2/getUser",
headers: ['Accept': '*/*', 'Content-Type': 'application/json'],
body: body)
json = resp.getData();
log.ok("JSON create search response:\n" + json);

//userName = json."name";
if (json && json.name && id.equals(json.name)) {
throw new AlreadyExistsException("User "+id+" already exists");
}


throw new UnsupportedOperationException("not supported operation, only update/delete avatar is implemented");
Expand Up @@ -45,7 +45,7 @@ log.info("Entering "+action+" Script");
nameAIB = new AttributeInfoBuilder(Name.NAME);
nameAIB.setRequired(true);
nameAIB.setUpdateable(false);
nameAIB.setCreateable(false);
nameAIB.setCreateable(true); // only detect existence

//avatar -- 256x256
avatarAIB = new AttributeInfoBuilder("avatar", byte[].class);
Expand Down
7 changes: 7 additions & 0 deletions samples/resources/scriptedrest/confluence-wiki/resource.xml
Expand Up @@ -65,6 +65,13 @@
<c:path>$user/name</c:path>
</target>
</inbound>
<!-- to detect existing users as AlreadyExistsException over CreateScript -->
<outbound>
<strength>normal</strength>
<source>
<c:path>$user/name</c:path>
</source>
</outbound>
</attribute>

<attribute>
Expand Down
13 changes: 13 additions & 0 deletions samples/resources/scriptedrest/jira/CreateScript.groovy
@@ -1,3 +1,5 @@
import org.identityconnectors.framework.common.exceptions.AlreadyExistsException

/*
* Copyright (c) 2010-2016 Evolveum
*
Expand Down Expand Up @@ -32,5 +34,16 @@

log.info("Entering "+action+" Script, attributes: "+attributes);

// detect if user already exists
resp = connection.get(path: "https://jira.evolveum.com/rest/api/latest/user",
query: ['username' : id]);
json = resp.getData();
log.ok("JSON create search response:\n" + json);

//userName = json."name";
if (json && json."name" && id.equals(json."name")) {
throw new AlreadyExistsException("User "+id+" already exists");
}


throw new UnsupportedOperationException("not supported operation, only update/delete avatar is implemented");
2 changes: 1 addition & 1 deletion samples/resources/scriptedrest/jira/SchemaScript.groovy
Expand Up @@ -44,7 +44,7 @@ log.info("Entering "+action+" Script");
nameAIB = new AttributeInfoBuilder(Name.NAME);
nameAIB.setRequired(true);
nameAIB.setUpdateable(false);
nameAIB.setCreateable(false);
nameAIB.setCreateable(true); // only detect existence

// key
keyAIB = new AttributeInfoBuilder("key");
Expand Down
7 changes: 7 additions & 0 deletions samples/resources/scriptedrest/jira/resource.xml
Expand Up @@ -65,6 +65,13 @@
<c:path>$user/name</c:path>
</target>
</inbound>
<!-- to detect existing users as AlreadyExistsException over CreateScript -->
<outbound>
<strength>normal</strength>
<source>
<c:path>$user/name</c:path>
</source>
</outbound>
</attribute>
<attribute>
<c:ref>ri:emailAddress</c:ref>
Expand Down

0 comments on commit f60a021

Please sign in to comment.