class MPISecurityAssign_Profile extends RunBase
{
container conProfileId;
UserId userId;
FormBuildStringControl profileIdFld;
SysLookupMultiSelectCtrl sysms;
FormRun callerformRun;
#Task
#define.CurrentVersion(1)
#localMacro.CurrentList
conProfileId
#endMacro
/// <summary>
///
/// </summary>
/// <returns></returns>
public Object dialog()
{
DialogRunbase dialogRunbase;
FormBuildGroupControl msgGroup;
dialogRunbase = super();
dialogRunbase.caption("@Mpi:AssignProfileUser");
dialogRunbase.addGroup("@Mpi:SelectAdditionalProfile");
msgGroup = dialogRunbase.form().design().control(dialogRunbase.curFormBuildGroup().name());
profileIdFld = msgGroup.addControl(FormControlType::String, identifierstr(profileId));
profileIdFld.label("@Mpi:ProfileId");
profileIdFld.displayLength(50);
dialogRunbase.curFormGroup(dialogRunbase.mainFormGroup());
return dialogRunbase;
}
private static Query buildProfileTableQuery(UserId _userId)
{
Query query = new Query(QueryStr(MPIProfileTableQuery));
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(MPIProfileUser));
QueryBuildRange qbr = qbds.addRange(fieldNum(MPIProfileUser, UserId));
qbr.value(_userId);
qbr.status(2);
return query;
}
/// <summary>
///
/// </summary>
/// <param name = "dialog"></param>
public void dialogPostRun(DialogRunbase dialog)
{
FormRun fr;
super(dialog);
fr = dialog.dialogForm().formRun();
if (fr)
{
sysms = SysLookupMultiSelectCtrl::constructWithQuery(fr, Fr.design().control(profileIdFld.id()), MPISecurityAssign_Profile::buildProfileTableQuery(userId),true);
}
}
public container pack()
{
return [#CurrentVersion, #CurrentList];
}
public boolean unpack(container _packedClass)
{
Version version = RunBase::getVersion(_packedClass);
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = _packedClass;
break;
default:
return false;
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected boolean canRunInNewSession()
{
return false;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean getFromDialog()
{
boolean ret;
conProfileId = sysms.get();
ret = super();
return ret;
}
protected void insertRole()
{
int i;
RefRecId MPIProfileTableRecId;
MPIProfileTable MPIProfileTable;
for(i = 1; i <= conLen(conProfileId); i++)
{
MPIProfileTableRecId = conPeek(conProfileId, i);
MPIProfileTable = MPIProfileTable::findRecId(MPIProfileTableRecId);
if(MPIProfileTable)
{
MPISecurityAssign MPISecurityAssign = MPISecurityAssign::construct();
MPISecurityAssign.parmProfileId(MPIProfileTable.Id);
MPISecurityAssign.parmUserId(userId);
MPISecurityAssign.addRolesFromUserProfile();
}
}
this.refreshCaller();
}
protected void refreshCaller()
{
if(callerformRun.name() == formstr(MPISysUserManagement))
{
callerformRun.refreshRoleTree();
FormDataSource MPIProfileUser_ds = callerformRun.dataSource(formDataSourceStr(MPISysUserManagement,MPIProfileUser));
if(MPIProfileUser_ds)
{
MPIProfileUser_ds.executeQuery();
}
}
}
/// <summary>
///
/// </summary>
public void run()
{
#OCCRetryCount
if (! this.validate())
{
throw error("@SYS18447");
}
try
{
ttsbegin;
this.insertRole();
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public void initFromArgs(Args args)
{
UserInfo UserInfo;
if(args && args.caller())
{
callerformRun = args.caller();
if(callerformRun.name() == formstr(MPISysUserManagement))
{
FormObjectSet UserInfo_ds = callerformRun.dataSource(formDataSourceStr(MPISysUserManagement,UserInfo));
UserInfo = UserInfo_ds.cursor() as UserInfo;
userId = UserInfo.id;
}
}
}
public static MPISecurityAssign_Profile construct()
{
return new MPISecurityAssign_Profile();
}
static void main(Args args)
{
MPISecurityAssign_Profile securityAssignProfile;
;
securityAssignProfile = MPISecurityAssign_Profile::construct();
securityAssignProfile.initFromArgs(args);
if (securityAssignProfile.prompt())
{
securityAssignProfile.run();
}
}
public boolean validateContainer()
{
boolean ret = true;
MPIProfileId profileId;
if(conProfileId == conNull())
{
ret = false;
}
if(conLen(conProfileId) == 0)
{
ret = false;
}
if(conLen(conProfileId) == 1)
{
profileId = conPeek(conProfileId,1);
if(!profileId)
{
ret = false;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name = "calledFrom"></param>
/// <returns></returns>
public boolean validate(Object calledFrom = null)
{
boolean ret;
ret = super(calledFrom);
if(!userId)
{
return checkFailed(strFmt("@RET260015", "@SYS4517"));
}
if(!this.validateContainer())
{
return checkFailed(strFmt("@RET260015", "@Mpi:ProfileId"));
}
return ret;
}
}
{
container conProfileId;
UserId userId;
FormBuildStringControl profileIdFld;
SysLookupMultiSelectCtrl sysms;
FormRun callerformRun;
#Task
#define.CurrentVersion(1)
#localMacro.CurrentList
conProfileId
#endMacro
/// <summary>
///
/// </summary>
/// <returns></returns>
public Object dialog()
{
DialogRunbase dialogRunbase;
FormBuildGroupControl msgGroup;
dialogRunbase = super();
dialogRunbase.caption("@Mpi:AssignProfileUser");
dialogRunbase.addGroup("@Mpi:SelectAdditionalProfile");
msgGroup = dialogRunbase.form().design().control(dialogRunbase.curFormBuildGroup().name());
profileIdFld = msgGroup.addControl(FormControlType::String, identifierstr(profileId));
profileIdFld.label("@Mpi:ProfileId");
profileIdFld.displayLength(50);
dialogRunbase.curFormGroup(dialogRunbase.mainFormGroup());
return dialogRunbase;
}
private static Query buildProfileTableQuery(UserId _userId)
{
Query query = new Query(QueryStr(MPIProfileTableQuery));
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(MPIProfileUser));
QueryBuildRange qbr = qbds.addRange(fieldNum(MPIProfileUser, UserId));
qbr.value(_userId);
qbr.status(2);
return query;
}
/// <summary>
///
/// </summary>
/// <param name = "dialog"></param>
public void dialogPostRun(DialogRunbase dialog)
{
FormRun fr;
super(dialog);
fr = dialog.dialogForm().formRun();
if (fr)
{
sysms = SysLookupMultiSelectCtrl::constructWithQuery(fr, Fr.design().control(profileIdFld.id()), MPISecurityAssign_Profile::buildProfileTableQuery(userId),true);
}
}
public container pack()
{
return [#CurrentVersion, #CurrentList];
}
public boolean unpack(container _packedClass)
{
Version version = RunBase::getVersion(_packedClass);
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = _packedClass;
break;
default:
return false;
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected boolean canRunInNewSession()
{
return false;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public boolean getFromDialog()
{
boolean ret;
conProfileId = sysms.get();
ret = super();
return ret;
}
protected void insertRole()
{
int i;
RefRecId MPIProfileTableRecId;
MPIProfileTable MPIProfileTable;
for(i = 1; i <= conLen(conProfileId); i++)
{
MPIProfileTableRecId = conPeek(conProfileId, i);
MPIProfileTable = MPIProfileTable::findRecId(MPIProfileTableRecId);
if(MPIProfileTable)
{
MPISecurityAssign MPISecurityAssign = MPISecurityAssign::construct();
MPISecurityAssign.parmProfileId(MPIProfileTable.Id);
MPISecurityAssign.parmUserId(userId);
MPISecurityAssign.addRolesFromUserProfile();
}
}
this.refreshCaller();
}
protected void refreshCaller()
{
if(callerformRun.name() == formstr(MPISysUserManagement))
{
callerformRun.refreshRoleTree();
FormDataSource MPIProfileUser_ds = callerformRun.dataSource(formDataSourceStr(MPISysUserManagement,MPIProfileUser));
if(MPIProfileUser_ds)
{
MPIProfileUser_ds.executeQuery();
}
}
}
/// <summary>
///
/// </summary>
public void run()
{
#OCCRetryCount
if (! this.validate())
{
throw error("@SYS18447");
}
try
{
ttsbegin;
this.insertRole();
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public void initFromArgs(Args args)
{
UserInfo UserInfo;
if(args && args.caller())
{
callerformRun = args.caller();
if(callerformRun.name() == formstr(MPISysUserManagement))
{
FormObjectSet UserInfo_ds = callerformRun.dataSource(formDataSourceStr(MPISysUserManagement,UserInfo));
UserInfo = UserInfo_ds.cursor() as UserInfo;
userId = UserInfo.id;
}
}
}
public static MPISecurityAssign_Profile construct()
{
return new MPISecurityAssign_Profile();
}
static void main(Args args)
{
MPISecurityAssign_Profile securityAssignProfile;
;
securityAssignProfile = MPISecurityAssign_Profile::construct();
securityAssignProfile.initFromArgs(args);
if (securityAssignProfile.prompt())
{
securityAssignProfile.run();
}
}
public boolean validateContainer()
{
boolean ret = true;
MPIProfileId profileId;
if(conProfileId == conNull())
{
ret = false;
}
if(conLen(conProfileId) == 0)
{
ret = false;
}
if(conLen(conProfileId) == 1)
{
profileId = conPeek(conProfileId,1);
if(!profileId)
{
ret = false;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name = "calledFrom"></param>
/// <returns></returns>
public boolean validate(Object calledFrom = null)
{
boolean ret;
ret = super(calledFrom);
if(!userId)
{
return checkFailed(strFmt("@RET260015", "@SYS4517"));
}
if(!this.validateContainer())
{
return checkFailed(strFmt("@RET260015", "@Mpi:ProfileId"));
}
return ret;
}
}
No comments:
Post a Comment