[midPoint] get extended attribute in notification
Pavol Mederly
mederly at evolveum.com
Mon May 4 12:38:06 CEST 2015
Miso,
the problem is primarily in this line:
QName USER_INTERNSHIP_QNAME = new QName(NS_FOO, "internship", "extension");
because what is required, is not simply a QName, but a two-name item
path (extension/internship). You have to use new ItemPath(...)
constructor to create the path. Arguments are either QNames or (when
there is no ambiguity) simple strings.
This code works - note that I've put the code into <subjectExpression>
just as an example. Tested with 'piracy' sample - changes names to match
your situation.
<notificationConfiguration>
<handler>
<simpleUserNotifier>
<subjectExpression>
<script>
<code>
import javax.xml.namespace.QName
import com.evolveum.midpoint.prism.path.ItemPath
import com.evolveum.midpoint.prism.delta.ObjectDelta
import
com.evolveum.midpoint.notifications.api.events.ModelEvent
NS_FOO = 'http://whatever.com/my'
INTERNSHIP_NAME = 'shipName'
INTERNSHIP_PATH = new ItemPath('extension',
INTERNSHIP_NAME)
delta = ((ModelEvent) event).getSummarizedFocusDeltas()
log.info("delta.findPropertyDelta(INTERNSHIP_PATH) != null " +
(delta.findPropertyDelta(INTERNSHIP_PATH)!=null))
if (delta.findPropertyDelta(INTERNSHIP_PATH)!=null) {
log.info("internship="+basic.getExtensionPropertyValue(requestee,
NS_FOO, INTERNSHIP_NAME))
}
'abcdef'
</code>
</script>
</subjectExpression>
<transport>mail</transport>
</simpleUserNotifier>
</handler>
<mail>
<debug>false</debug>
<redirectToFile>d:\midpoint\home\mail-notifications.log</redirectToFile>
</mail>
</notificationConfiguration>
Best regards,
Pavol
On 3. 5. 2015 15:52, Steklac Michal wrote:
> Hi,
>
> I made an example in which obtains the value of the attribute family
> name and attribute internship. Attribute value family name received.
> When I trying to get the value for attribute internship, then I get null.
>
> ----------------------------------------------------------------------
> * code to get family name
> ...
> def NS_FOO = 'http://midpoint.evolveum.com/xml/ns/test/foo-1.xsd';
> <http://midpoint.evolveum.com/xml/ns/test/foo-1.xsd%27;>
> delta = ObjectDelta.summarize(((ModelEvent) event).getUserDeltas());
> if(delta != null){
> log.info("delta = " + delta.toString());
> QName USER_FAMILYNAME_QNAME = new QName(NS_FOO,"familyName");
> if(delta.findPropertyDelta(USER_FAMILYNAME_QNAME)!=null){
> log.info("familyname="+requestee.getFamilyName());
> }
> }
> ...
> * output
> ...
> 2015-05-03 15:24:43,391 [RESOURCEOBJECTCHANGELISTENER]
> [midPointScheduler_Worker-5] INFO (com.evolveum.midpoint.expression):
> delta =
> ObjectDelta(UserType:cbd8aee0-802e-43ef-a1c7-30cb79c811f0,MODIFY: Property
> Delta( / fullName, REPLACE), PropertyDelta( / familyName, REPLACE),
> PropertyDelta(metadata / {.../common/common-3}modifyChannel, REPLACE),
> PropertyDelta(metadata / {.../common/common-3}modifyTimestamp, REPLA
> CE), ReferenceDelta(metadata / {.../common/common-3}modifierRef, REPLACE))
> 2015-05-03 15:24:43,397 [RESOURCEOBJECTCHANGELISTENER]
> [midPointScheduler_Worker-5] INFO (com.evolveum.midpoint.expression):
> familyname=Malá
> ...
> ----------------------------------------------------------------------
>
> ----------------------------------------------------------------------
> * code to get intership, which is extension attribute
> ...
> def NS_FOO = 'http://midpoint.evolveum.com/xml/ns/test/foo-1.xsd';
> <http://midpoint.evolveum.com/xml/ns/test/foo-1.xsd%27;>
> delta = ObjectDelta.summarize(((ModelEvent) event).getUserDeltas());
> if(delta != null){
> log.info("delta = " + delta.toString());
> QName USER_INTERNSHIP_QNAME = new QName(NS_FOO, "internship",
> "extension");
> log.info("delta.findPropertyDelta(USER_INTERNSHIP_QNAME)!=null " +
> (delta.findPropertyDelta(USER_INTERNSHIP_QNAME)!=null).toString());
> if(delta.findPropertyDelta(USER_INTERNSHIP_QNAME)!=null){
> log.info("internship="+basic.getExtensionPropertyValue(requestee,
> 'http://evolveum.com/my', <http://evolveum.com/my%27,> 'internship'));
> }
> }
> ...
> * output
> ...
> 2015-05-03 15:32:57,490 [RESOURCEOBJECTCHANGELISTENER]
> [midPointScheduler_Worker-4] INFO (com.evolveum.midpoint.expression):
> delta =
> ObjectDelta(UserType:cbd8aee0-802e-43ef-a1c7-30cb79c811f0,MODIFY: Property
> Delta(extension / internship, REPLACE), PropertyDelta(metadata /
> {.../common/common-3}modifyChannel, REPLACE), PropertyDelta(metadata /
> {.../common/common-3}modifyTimestamp, REPLACE), ReferenceDelta(metadata
> / {.../common/common-3}modifierRef, REPLACE))
> 2015-05-03 15:32:57,491 [RESOURCEOBJECTCHANGELISTENER]
> [midPointScheduler_Worker-4] INFO (com.evolveum.midpoint.expression):
> delta.findPropertyDelta(USER_INTERNSHIP_QNAME)!=null false
> ...
> ----------------------------------------------------------------------
>
> Please tell me what I'm doing wrong.
>
> Thanks,
> Miso
>
> On So, 2015-05-02 at 20:51 +0000, Steklac Michal wrote:
>> Hi,
>>
>> i have extend schema with attribute internship. It is possible get
>> their value in notification.
>>
>> This works for me for attribute givenName
>> ...
>> QName USER_GIVENNAME_QNAME = new QName(NS_FOO,"givenName");
>> if(delta.findPropertyDelta(USER_GIVENNAME_QNAME)!=null){
>> attr = attr+'\nmeno='+requestee.getGivenName();
>> }
>> ...
>>
>> Thanks
>> MiSo
>
>
>
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> http://lists.evolveum.com/mailman/listinfo/midpoint
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20150504/28847e09/attachment.htm>
More information about the midPoint
mailing list