「
GAM エンティティプロパティの拡張性」で説明されている手法 (OAV パターンに基づく) を使用して、
GeneXus Access Manager (GAM) のユーザーエンティティを拡張することができます。
ここでは、GAM User テーブルに複数値の項目属性を追加する手順を示します。
ユーザーの電話番号 (自宅、勤務先、携帯電話など) を格納する必要があるとします。GAMUserAttribute データタイプに基づく変数を定義する必要があります。そこで、定義している項目属性の「Id」や「Value」を格納する必要があります。この例では、Id と Value の両方を「Telephone number」とします。
[ IsMultivalue ] プロパティを True に設定する必要があります。
図 1
[ Multivalues ] プロパティは GAMUserAttributeMultivalues コレクション データ タイプであり、「Id」と「value」を持つベクトルを格納します。例では (「job number」、「235555」)、(「home number」、「97666」) などとなります。
図 2
&GAMUser = new()
&GAMUser.Name = !"Nickname"
&GAMUser.EMail = !"example@mail.com"
&GAMUser.FirstName = !"Juan"
&GAMUser.LastName = !"Perez"
&GAMUser.Password = !"123"
&GAMUser.Phone = "2601 20 82"
&GAMUser.URLProfile = !"https://wiki.genexus.com/commwiki/servlet/wiki?24746,Toc%3AGeneXus+Access+Manager+%28GAM%29"
&GAMUser.DontReceiveInformation = False
&GAMUser.CannotChangePassword = False
&GAMUser.MustChangePassword = False
&GAMUser.IsBlocked = False
&GAMUser.PasswordNeverExpires = False
//User Attributes (optional)
&GAMUserAtt = new()
&GAMUserAtt.Id = !"EmployeeID"
&GAMUserAtt.IsMultiValue = False
&GAMUserAtt.Value = !"123456"
&GAMUser.Attributes.Add(&GAMUserAtt)
&GAMUserAtt = new()
&GAMUserAtt.Id = !"Company"
&GAMUserAtt.IsMultiValue = True
&GAMUserAttMV = new()
&GAMUserAttMV.Id = !"GX"
&GAMUserAttMV.Value = !"GeneXus"
&GAMUserAtt.MultiValues.Add(&GAMUserAttMV)
&GAMUserAttMV = new()
&GAMUserAttMV.Id = !"GL"
&GAMUserAttMV.Value = !"Globant"
&GAMUserAtt.MultiValues.Add(&GAMUserAttMV)
&GAMUser.Attributes.Add(&GAMUserAtt)
&GAMUser.Save()
If &GAMUser.Success()
Commit
Else
&GAMErrorCollection = &GAMUser.GetErrors()
For &Error in &GAMErrorCollection
Msg(Format(!"Save User %1 error: %2 (GAM%3)", &Name, &Error.Message, &Error.Code))
EndFor
Endif
これらのメソッドは、
GeneXus X Evolution 3 以降で使用可能です。
メソッド |
説明 |
&GAMUser.GetMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, out:&GAMError collection): GAMPropertyValue |
複数値の GAMUserAttribute の GAMUserAttribute.Id、および GAMUserAttribute.Multivalues.Id がある場合、そのペアに対応する値を返します (図 1 および図 2 を参照)。 |
&GAMUser.SetMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, in:&GAMPropertyValue, out:&GAMError collection):Boolean |
複数値の GAMUserAttribute の GAMUserAttribute.Id、および GAMUserAttribute.Multivalues.Id がある場合、GAMPropertyValue パラメーターを持つこのオブジェクトの値を更新します (図 1 および図 2 を参照)。
|
&User.DeleteMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, out:&GAMError collection): Boolean |
複数値の GAMUserAttribute の GAMUserAttribute.Id、および GAMUserAttribute.Multivalues.Id がある場合、そのペアに対応するレコードを削除します (図 1 および図 2 を参照)。 |
GAM ユーザーの複数値 GAMUserAttribute のすべてのオブジェクトの GAMProperty 値を取得
&GAMUser.Load(&UserGUIDselected)
For &UserAttr In &GAMUser.Attributes //&UserAttr は GAMUserAttribute データタイプ
&UserAttributeId = &UserAttr.Id
&AttrValue = &UserAttr.Value
if &UserAttr.IsMultiValue
&GAMUserAttrMultiValuesCollection = &UserAttr.MultiValues //&GAMUserAttrMultiValuesCollection は GAMUserAttributesMultivalues データタイプのコレクション
for &GAMUserAttributeMultivalues in &GAMUserAttrMultiValuesCollection
&GAMPropertyId = &GAMUserAttributeMultivalues.Id
&GAMPropertyValue = &GAMUser.GetMultivaluedAttribute(&UserAttributeId,&GAMUserAttributeMultivalues.Id,&errors) //&errors は GAMError のコレクション
endfor
endif
EndFor
GAMUserAttributeMultivalues オブジェクトを削除
&GAMUser.Load(&GAMGUID)
&isok = &GAMUser.DeleteMultivaluedAttribute(&UserAttributeId,&GAMPropertyId,&errors)
if &isok
commit
else
For &Error In &errors
msg(&Error.Message + !"(GAM" + &Error.Code.ToString().Trim() + !")")
EndFor
endif
GAMUserAttributeMultivalues オブジェクトを更新
&GAMUser.Load(&GAMGUID)
&isok = &GAMUser.SetMultivaluedAttribute(&UserAttributeId,&GAMPropertyId,&GAMPropertyValue,&errors)
if &isok
commit
else
For &Error In &errors
msg(&Error.Message + !"(GAM" + &Error.Code.ToString().Trim() + !")")
EndFor
endif
GAM エンティティのプロパティを拡張する方法