# oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
# Copyright (c) 2018, Gluu
#
# Author: Val Pecaoco
# Updated by Jose Gonzalez on 2018-02-19

from org.xdi.model.custom.script.type.scim import ScimType
from org.xdi.util import StringHelper, ArrayHelper
from java.util import Arrays, ArrayList
from org.xdi.service.cdi.util import CdiUtil
from org.gluu.oxtrust.ldap.service import PersonService
from org.gluu.oxtrust.model import GluuCustomPerson

import java

class ScimEventHandler(ScimType):

    def __init__(self, currentTimeMillis):
        self.currentTimeMillis = currentTimeMillis

    def init(self, configurationAttributes):
        print "ScimEventHandler (init): Initialized successfully"
        return True   

    def destroy(self, configurationAttributes):
        print "ScimEventHandler (destroy): Destroyed successfully"
        return True   

    def getApiVersion(self):
        #return 2 if you want the post* scripts getting called
        return 1

    # user is an instance of org.gluu.oxtrust.model.GluuCustomPerson
    # configurationAttributes is a Map<String, org.xdi.model.SimpleCustomProperty>
    def createUser(self, user, configurationAttributes):

        print "ScimEventHandler (createUser): Current id = " + user.getUid()

        testProp1 = configurationAttributes.get("testProp1").getValue2()
        testProp2 = configurationAttributes.get("testProp2").getValue2()

        print "ScimEventHandler (createUser): testProp1 = " + testProp1
        print "ScimEventHandler (createUser): testProp2 = " + testProp2

        return True

    def postCreateUser(self, user, configurationAttributes):
        return True

    def updateUser(self, user, configurationAttributes):
        personService = CdiUtil.bean(PersonService)
        oneUser = personService.getPersonByUid(user.getUid())
        print "ScimEventHandler (updateUser): user's displayName = " + oneUser.getDisplayName()
        return True

    def postUpdateUser(self, user, configurationAttributes):
        return True

    def deleteUser(self, user, configurationAttributes):
        print "ScimEventHandler (deleteUser): Current id = " + user.getUid()
        return True

    def postDeleteUser(self, user, configurationAttributes):
        return True

    def createGroup(self, group, configurationAttributes):
        print "ScimEventHandler (createGroup): Current displayName = " + group.getDisplayName()
        return True

    def postCreateGroup(self, group, configurationAttributes):
        return True

    def updateGroup(self, group, configurationAttributes):
        print "ScimEventHandler (updateGroup): Current displayName = " + group.getDisplayName()
        return True

    def postUpdateGroup(self, group, configurationAttributes):
        return True

    def deleteGroup(self, group, configurationAttributes):
        print "ScimEventHandler (deleteGroup): Current displayName = " + group.getDisplayName()
        return True

    def postDeleteGroup(self, group, configurationAttributes):
        return True

@@ -119,17 +119,17 @@
  (c) 201
-8
+4
 , Gluu%0A#
@@ -143,61 +143,23 @@
 or: 
-Val Pecaoco%0A# Updated by Jose Gonzalez on 2018-02-19%0A
+Jose Gonzalez%0A#
 %0Afro
@@ -309,53 +309,8 @@
 ist%0A
-from org.xdi.service.cdi.util import CdiUtil%0A
 from
@@ -361,16 +361,61 @@
 Service%0A
+from org.xdi.service.cdi.util import CdiUtil%0A
 from org
@@ -957,20 +957,20 @@
 pts 
-getting call
+being execut
 ed%0A 
@@ -990,160 +990,8 @@
  1%0A%0A
-    # user is an instance of org.gluu.oxtrust.model.GluuCustomPerson%0A    # configurationAttributes is a Map%3CString, org.xdi.model.SimpleCustomProperty%3E%0A
     
@@ -1439,90 +1439,8 @@
 ue%0A%0A
-    def postCreateUser(self, user, configurationAttributes):%0A        return True%0A%0A
     
@@ -1553,18 +1553,18 @@
        o
-ne
+ld
 User = p
@@ -1656,14 +1656,11 @@
 r): 
-user's
+Old
  dis
@@ -1672,17 +1672,17 @@
 ame 
-= %22 + one
+%25s%22 %25 old
 User
@@ -1711,81 +1711,87 @@
     
-return True%0A%0A    def postUpdateUser(self, user, configurationAttributes):
+print %22ScimEventHandler (updateUser): New displayName %22 + user.getDisplayName()
 %0A   
@@ -1967,90 +1967,8 @@
 ue%0A%0A
-    def postDeleteUser(self, user, configurationAttributes):%0A        return True%0A%0A
     
@@ -2143,92 +2143,8 @@
 ue%0A%0A
-    def postCreateGroup(self, group, configurationAttributes):%0A        return True%0A%0A
     
@@ -2319,92 +2319,8 @@
 ue%0A%0A
-    def postUpdateGroup(self, group, configurationAttributes):%0A        return True%0A%0A
     
@@ -2481,32 +2481,454 @@
      return True
+%0A        %0A    def postCreateUser(self, user, configurationAttributes):%0A        return True%0A%0A    def postUpdateUser(self, user, configurationAttributes):%0A        return True%0A%0A    def postDeleteUser(self, user, configurationAttributes):%0A        return True%0A%0A    def postUpdateGroup(self, group, configurationAttributes):%0A        return True%0A%0A    def postCreateGroup(self, group, configurationAttributes):%0A        return True
 %0A%0A    def postDe
@@ -2975,29 +2975,28 @@
 ibutes):%0A        return True
-%0A

Update scim script