Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 25, 2019
2 parents 79135da + fe49d4c commit e5eb235
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 94 deletions.
11 changes: 7 additions & 4 deletions samples/resources/scriptedsql/CreateScript.groovy
Expand Up @@ -2,12 +2,9 @@ import groovy.sql.Sql
import org.forgerock.openicf.connectors.scriptedsql.ScriptedSQLConfiguration
import org.forgerock.openicf.misc.scriptedcommon.OperationType
import org.identityconnectors.common.logging.Log
import org.identityconnectors.framework.common.exceptions.ConnectorException
import org.identityconnectors.framework.common.objects.Attribute
import org.identityconnectors.framework.common.objects.ObjectClass
import org.identityconnectors.framework.common.objects.OperationOptions
import org.identityconnectors.framework.common.objects.Uid
import org.identityconnectors.framework.common.objects.AttributeUtil

import java.sql.Connection

Expand All @@ -24,6 +21,11 @@ log.info("Entering " + operation + " Script")

def sql = new Sql(connection)

//return new Uid(_some_unique_identifier)
return null

/*
// todo fix sample
switch (objectClass) {
case ObjectClass.ACCOUNT:
return handleAccount(sql)
Expand Down Expand Up @@ -77,4 +79,5 @@ Uid handleOrganization(Sql sql) {
])
return new Uid(keys[0][0])
}
}
*/
7 changes: 7 additions & 0 deletions samples/resources/scriptedsql/SearchScript.groovy
Expand Up @@ -27,6 +27,12 @@ log.info("Entering " + operation + " Script")

def sql = new Sql(connection)

// todo use handler to result connector objects

return new SearchResult() // update search result values if needed

// todo fix sample
/*
switch (objectClass) {
case ObjectClass.ACCOUNT:
handleAccount(sql)
Expand Down Expand Up @@ -155,4 +161,5 @@ static String buildWhereClause(Filter filter, Map sqlParams, String uidColumn, S
return where
}
*/

92 changes: 2 additions & 90 deletions samples/resources/scriptedsql/SyncScript.groovy
@@ -1,9 +1,7 @@
import groovy.sql.Sql
import org.forgerock.openicf.connectors.scriptedsql.ScriptedSQLConfiguration
import org.forgerock.openicf.misc.scriptedcommon.ICFObjectBuilder
import org.forgerock.openicf.misc.scriptedcommon.OperationType
import org.identityconnectors.common.logging.Log
import org.identityconnectors.framework.common.exceptions.ConnectorException

def configuration = configuration as ScriptedSQLConfiguration
def operation = operation as OperationType
Expand All @@ -26,95 +24,9 @@ switch (operation) {
}

void handleSync(Sql sql, Object tokenObject, SyncResultsHandler handler) {
String token = (String) tokenObject

switch (objectClass) {
case ObjectClass.ACCOUNT:
handleSyncAccount(sql, token, handler)
break
default:
throw new ConnectorException("Sync not supported for object class " + objectClass)
}
// todo implement
}

Object handleGetLatestSyncToken(Sql sql) {
switch (objectClass) {
case ObjectClass.ACCOUNT:
return handleSyncTokenAccount(sql)
default:
throw new ConnectorException("Sync not supported for object class " + objectClass)
}
}

Object handleSyncAccount(Sql sql, Object token, SyncResultsHandler handler) {
def result = []
def tstamp = null

if (token != null) {
tstamp = new java.sql.Timestamp(token)
} else {
def today = new Date()
tstamp = new java.sql.Timestamp(today.time)
}

Closure closure = { row ->
SyncDelta delta = buildSyncDelta(row)

if (!handler.handle(delta)) {
throw new IllegalStateException()
}
}

// XXX the following line is probably fine for MySQL
// sql.eachRow("select * from Users where timestamp > ${tstamp}",
// {result.add([operation:"CREATE_OR_UPDATE", uid:Integer.toString(it.id), token:it.timestamp.getTime(), attributes:[__NAME__:it.login, firstname:it.firstname, lastname:it.lastname, fullname:it.fullname, organization:it.organization, email:it.email, __ENABLE__:!(it.disabled as Boolean)]])}

// the following line (the select statement) is for PostgreSQL with
// timestamp in microseconds - we truncate the timestamp to milliseconds
try {
sql.eachRow("select id,login,firstname,lastname,fullname,email,organization,disabled," +
"date_trunc('milliseconds', timestamp) as timestamp from Users where date_trunc('milliseconds',timestamp) > ${tstamp}", closure)
} catch (IllegalStateException ex) {

}

log.ok("Sync script: found " + result.size() + " events to sync")
return result;
}

Object handleSyncTokenAccount(Sql sql) {
row = sql.firstRow("select date_trunc('milliseconds', timestamp) as timestamp from users order by timestamp desc")

return row["timestamp"].getTime();
}

private SyncDelta buildSyncDelta(SyncDeltaType type, GroovyRowResult row) {
SyncDeltaBuilder builder = new SyncDeltaBuilder()
builder.setDeltaType(SyncDeltaType.CREATE_OR_UPDATE)
builder.setObjectClass(ObjectClass.ACCOUNT)

def newToken = null // todo
if (newToken != null) {
builder.setToken(new SyncToken(newToken))
}

ConnectorObject obj = ICFObjectBuilder.co {
uid row.id as String
id row.name
attribute 'description', row.description
}
builder.setObject(obj)

//result.add([operation: "CREATE_OR_UPDATE",
// uid: Integer.toString(it.id),
// token: it.timestamp.getTime(),
// attributes: [__NAME__: it.login,
// firstname: it.firstname,
// lastname: it.lastname,
// fullname: it.fullname,
// organization: it.organization,
// email: it.email,
// __ENABLE__: !(it.disabled as Boolean)]])

return builder.build()
// todo implement
}
21 changes: 21 additions & 0 deletions samples/resources/scriptedsql/UpdateScript.groovy
@@ -0,0 +1,21 @@
import groovy.sql.Sql
import org.forgerock.openicf.connectors.scriptedsql.ScriptedSQLConfiguration
import org.forgerock.openicf.misc.scriptedcommon.OperationType
import org.identityconnectors.common.logging.Log
import org.identityconnectors.framework.common.objects.*

def log = log as Log
def operation = operation as OperationType
def options = options as OperationOptions
def objectClass = objectClass as ObjectClass
def attributes = attributes as Set<Attribute>
def uid = uid as Uid
def id = id as Name
def configuration = configuration as ScriptedSQLConfiguration

log.info("Entering " + operation + " Script")

def sql = new Sql(connection)

//return new Uid(_some_unique_identifier)
return null

0 comments on commit e5eb235

Please sign in to comment.