Skip to content

Commit

Permalink
Role mining improvement and removing unwanted operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tchrapovic committed Jan 11, 2024
1 parent 8055b83 commit 1be53f9
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import java.util.List;
import java.util.Set;

import com.evolveum.midpoint.model.api.mining.RoleAnalysisService;

import com.evolveum.midpoint.prism.PrismObject;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -80,12 +84,25 @@ protected void initLayout() {
throw new RuntimeException(e);
}

Set<RoleType> candidateRoles = new HashSet<>();
RoleAnalysisService roleAnalysisService = getPageBase().getRoleAnalysisService();
for (AssignmentType assignmentType : inducement) {
if (assignmentType.getTargetRef() == null) {
continue;
}
PrismObject<RoleType> role = assignmentType.getTargetRef().asReferenceValue().getObject();
if (role != null) {
candidateRoles.add(role.asObjectable());
}

}

BusinessRoleApplicationDto deltas = getObjectDetailsModels().getPatternDeltas();
deltas.setCandidateRoles(new HashSet<>(inducement), (PageBase) getPage());
deltas.setCandidateRoles(candidateRoles, (PageBase) getPage());

List<BusinessRoleDto> patternDeltas = deltas.getBusinessRoleDtos();
for (BusinessRoleDto value : patternDeltas) {
value.updateValue(inducement, (PageBase) getPage());
value.updateValue(new ArrayList<>(candidateRoles), (PageBase) getPage());
}

RoleMiningProvider<BusinessRoleDto> provider = getAndUpdateProvider(patternDeltas);
Expand Down Expand Up @@ -132,7 +149,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
public void performAddOperation(AjaxRequestTarget ajaxRequestTarget, IModel<SelectableBean<UserType>> iModel) {
BusinessRoleApplicationDto patternDeltas = getObjectDetailsModels().getPatternDeltas();

Set<AssignmentType> candidateRoles = patternDeltas.getCandidateRoles();
Set<RoleType> candidateRoles = patternDeltas.getCandidateRoles();
UserType user = iModel.getObject().getValue();

BusinessRoleDto newValue = new BusinessRoleDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private void businessRoleMigrationPerform(
LOGGER.error("Couldn't create activity for role migration: " + roleOid);
}
if (activity != null) {
roleAnalysisService.executeMigrationTask(
roleAnalysisService.executeMigrationTask(getModelInteractionService(),
patternDeltas.getCluster(), activity, roleObject, taskOid, null, task, result);
if (result.isWarning()) {
warn(result.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
import com.evolveum.midpoint.gui.impl.page.admin.abstractrole.AbstractRoleDetailsModel;
import com.evolveum.midpoint.gui.impl.page.admin.role.mining.model.BusinessRoleApplicationDto;
import com.evolveum.midpoint.model.api.mining.RoleAnalysisService;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

/**
Expand Down Expand Up @@ -70,25 +68,16 @@ protected void onExitPerformed(AjaxRequestTarget target) {
if (isRoleMigration) {
RoleAnalysisService roleAnalysisService = getPageBase().getRoleAnalysisService();
RoleType businessRole = patterns.getBusinessRole().asObjectable();
Set<AssignmentType> candidateRoles = patterns.getCandidateRoles();
Set<RoleType> candidateRoles = patterns.getCandidateRoles();

List<RoleType> roles = new ArrayList<>();
Task task = getPageBase().createSimpleTask("Load role");
for (AssignmentType assignmentType : candidateRoles) {
String oid = assignmentType.getTargetRef().getOid();
PrismObject<RoleType> rolePrismObject = roleAnalysisService.getRoleTypeObject(oid,
task, task.getResult());
if (rolePrismObject != null) {
roles.add(rolePrismObject.asObjectable());
}
}

businessRole.getInducement().clear();

IModel<List<AbstractMap.SimpleEntry<String, String>>> selectedItems = Model.ofList(new ArrayList<>());
for (RoleType role : roles) {
for (RoleType role : candidateRoles) {
selectedItems.getObject().add(
new AbstractMap.SimpleEntry(
new AbstractMap.SimpleEntry<>(
role.getOid(),
WebComponentUtil.getDisplayNameOrName(role.asPrismObject())));
}
Expand Down Expand Up @@ -126,14 +115,15 @@ protected void processSelectOrDeselectItem(
protected SelectableBeanObjectDataProvider<RoleType> createProvider(
SelectableBeanObjectDataProvider<RoleType> defaultProvider) {

List<RoleType> prepareRoles = new ArrayList<>(roles);
List<RoleType> prepareRoles = new ArrayList<>(candidateRoles);
ObjectQuery customQuery = getCustomQuery();

roleAnalysisService.loadSearchObjectIterative(
//TODO fix me. This is not correct way how to do this. Wrong position.
roleAnalysisService.loadSearchObjectIterative(getPageBase().getModelService(),
RoleType.class, customQuery, null, prepareRoles, task, task.getResult());

return new SelectableBeanObjectDataProvider<>(
BusinessRoleWizardPanel.this, new HashSet<>(roles)) {
BusinessRoleWizardPanel.this, new HashSet<>(candidateRoles)) {

@Override
protected List<RoleType> searchObjects(Class type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public class BusinessRoleApplicationDto implements Serializable {
List<BusinessRoleDto> businessRoleDtos;
boolean isCandidate = false;
Long patternId;
transient Set<AssignmentType> candidateRoles;
transient Set<RoleType> candidateRoles;

public BusinessRoleApplicationDto(
@NotNull PrismObject<RoleAnalysisClusterType> cluster,
@NotNull PrismObject<RoleType> businessRole,
@NotNull List<BusinessRoleDto> businessRoleDtos,
@NotNull Set<AssignmentType> candidateRoles) {
@NotNull Set<RoleType> candidateRoles) {
setDraft(businessRole);
this.cluster = cluster;
this.businessRole = businessRole;
Expand Down Expand Up @@ -92,11 +92,11 @@ public void setCandidate(boolean candidate) {
isCandidate = candidate;
}

public Set<AssignmentType> getCandidateRoles() {
public Set<RoleType> getCandidateRoles() {
return candidateRoles;
}

public void setCandidateRoles(Set<AssignmentType> candidateRoles, PageBase pageBase) {
public void setCandidateRoles(Set<RoleType> candidateRoles, PageBase pageBase) {
this.candidateRoles = candidateRoles;

for (BusinessRoleDto businessRoleDto : businessRoleDtos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import com.evolveum.midpoint.prism.PrismContainerValue;

import com.evolveum.midpoint.prism.impl.binding.AbstractMutableObjectable;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.gui.api.page.PageBase;
Expand All @@ -41,11 +43,13 @@ public class BusinessRoleDto implements Serializable {
int assignedCount;
boolean include;
int unassignedCount;
transient Set<AssignmentType> candidateRoles;
Set<RoleType> candidateRoles;

public BusinessRoleDto(PrismObject<UserType> prismObjectUser, PrismObject<RoleType> prismRoleObject,
public BusinessRoleDto(PrismObject<UserType> prismObjectUser,
PrismObject<RoleType> prismRoleObject,
List<ObjectDelta<? extends ObjectType>> objectDeltas,
int assignedCount, int unassignedCount, boolean include, Set<AssignmentType> candidateRoles) {
int assignedCount, int unassignedCount, boolean include,
Set<RoleType> candidateRoles) {
this.prismObjectUser = prismObjectUser;
this.prismRoleObject = prismRoleObject;
this.objectDeltas = objectDeltas;
Expand All @@ -56,8 +60,11 @@ public BusinessRoleDto(PrismObject<UserType> prismObjectUser, PrismObject<RoleTy
this.candidateRoles = candidateRoles;
}

public BusinessRoleDto(@NotNull PrismObject<UserType> prismObjectUser,
@NotNull PrismObject<RoleType> prismObjectRole, Set<AssignmentType> candidateRoles, PageBase pageBase) {
public BusinessRoleDto(
@NotNull PrismObject<UserType> prismObjectUser,
@NotNull PrismObject<RoleType> prismObjectRole,
Set<RoleType> candidateRoles,
PageBase pageBase) {
this.candidateRoles = candidateRoles;
prepareUserDeltas(prismObjectUser, prismObjectRole, pageBase);
}
Expand All @@ -76,7 +83,7 @@ private List<DeltaDto> prepareDeltaDtos(List<ObjectDelta<? extends ObjectType>>
* @param inducements The list of inducements to be used for updating the value.
* @param pageBase The pageBase object.
*/
public void updateValue(List<AssignmentType> inducements, PageBase pageBase) {
public void updateValue(List<RoleType> inducements, PageBase pageBase) {
this.candidateRoles = new HashSet<>(inducements);
prepareUserDeltas(prismObjectUser, prismRoleObject, pageBase);
}
Expand All @@ -92,7 +99,7 @@ private void prepareUserDeltas(@NotNull PrismObject<UserType> prismObjectUser,

List<String> userRolesAssignmentOids = getRolesOidAssignment(userObject);
List<String> roleRolesAssignmentOids = this.candidateRoles.stream()
.map(r -> r.getTargetRef().getOid())
.map(AbstractMutableObjectable::getOid)
.toList();

Set<String> appliedRoles = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.evolveum.midpoint.web.component.AjaxCompositedIconSubmitButton;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleAnalysisClusterType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleAnalysisSessionType;

Expand Down Expand Up @@ -133,7 +132,7 @@ public void detectionPerform(AjaxRequestTarget target) {
roleAnalysisService.recomputeClusterDetectionOptions(clusterOid, detectionOption,
task, result);

roleAnalysisService.executeDetectionTask(cluster.asPrismObject(), null,
roleAnalysisService.executeDetectionTask(getModelInteractionService(), cluster.asPrismObject(), null,
null, task, result);

if (result.isWarning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.common.mining.objects.detection.DetectionOption;

import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.util.exception.*;
Expand Down Expand Up @@ -167,7 +165,7 @@ public void clusteringPerform(@NotNull AjaxRequestTarget target) {
LOGGER.error("Couldn't execute changes on RoleAnalysisSessionType object: {}", session.getOid(), e);
}

roleAnalysisService.executeClusteringTask(session.asPrismObject(), null, null, task, result);
roleAnalysisService.executeClusteringTask(getModelInteractionService(), session.asPrismObject(), null, null, task, result);

if (result.isWarning()) {
warn(result.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ protected void onSubmitPerformed(AjaxRequestTarget target) {
PrismObject<RoleAnalysisSessionType> sessionTypeObject = roleAnalysisService.getSessionTypeObject(sessionOid, task, result);

if (sessionTypeObject != null) {
roleAnalysisService.executeClusteringTask(sessionTypeObject, null, null, task, result);
roleAnalysisService.executeClusteringTask(getPageBase().getModelInteractionService(), sessionTypeObject, null, null, task, result
);
}
} catch (Throwable e) {
LoggingUtils.logException(LOGGER, "Couldn't process clustering", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected void onSubmit(AjaxRequestTarget target) {
LOGGER.error("Couldn't create activity for role migration: " + role.getOid(), e);
}
if (activity != null) {
roleAnalysisService.executeMigrationTask(
roleAnalysisService.executeMigrationTask(getPageBase().getModelInteractionService(),
cluster.asPrismObject(), activity, role.asPrismObject(), taskOid,
null, task, result);
if (result.isWarning()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ protected void onSubmit(AjaxRequestTarget target) {
Set<String> users = pattern.getUsers();
Long patternId = pattern.getId();

Set<AssignmentType> candidateInducements = new HashSet<>();
Set<RoleType> candidateInducements = new HashSet<>();

for (String roleOid : roles) {
PrismObject<RoleType> roleObject = roleAnalysisService
.getRoleTypeObject(roleOid, task, result);
if (roleObject != null) {
candidateInducements.add(ObjectTypeUtil.createAssignmentTo(roleOid, ObjectTypes.ROLE));
candidateInducements.add(roleObject.asObjectable());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
Task task = getPageBase().createSimpleTask(OP_PROCESS_CANDIDATE_ROLE);
OperationResult result = task.getResult();

Set<AssignmentType> candidateInducements = new HashSet<>();
Set<RoleType> candidateInducements = new HashSet<>();

List<MiningRoleTypeChunk> simpleMiningRoleTypeChunks = miningOperationChunk.getSimpleMiningRoleTypeChunks();
for (MiningRoleTypeChunk roleChunk : simpleMiningRoleTypeChunks) {
Expand All @@ -743,7 +743,7 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
PrismObject<RoleType> roleObject = getPageBase().getRoleAnalysisService()
.getRoleTypeObject(roleOid, task, result);
if (roleObject != null) {
candidateInducements.add(ObjectTypeUtil.createAssignmentTo(roleOid, ObjectTypes.ROLE));
candidateInducements.add(roleObject.asObjectable());
}
}
}
Expand All @@ -768,11 +768,16 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
PageBase pageBase = getPageBase();
RoleAnalysisService roleAnalysisService = pageBase.getRoleAnalysisService();

Set<AssignmentType> assignmentTypeSet = new HashSet<>();
for (RoleType candidateInducement : candidateInducements) {
assignmentTypeSet.add(ObjectTypeUtil.createAssignmentTo(candidateInducement.getOid(), ObjectTypes.ROLE));
}

executeChangesOnCandidateRole(roleAnalysisService, pageBase, target,
cluster,
candidateRole,
candidateMembers,
candidateInducements,
assignmentTypeSet,
task,
result
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
Task task = getPageBase().createSimpleTask(OP_PROCESS_CANDIDATE_ROLE);
OperationResult result = task.getResult();

Set<AssignmentType> candidateInducements = new HashSet<>();
Set<RoleType> candidateInducements = new HashSet<>();

List<MiningRoleTypeChunk> simpleMiningRoleTypeChunks = miningOperationChunk.getSimpleMiningRoleTypeChunks();
for (MiningRoleTypeChunk roleChunk : simpleMiningRoleTypeChunks) {
Expand All @@ -760,7 +760,7 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
PrismObject<RoleType> roleObject = getPageBase().getRoleAnalysisService()
.getRoleTypeObject(roleOid, task, result);
if (roleObject != null) {
candidateInducements.add(ObjectTypeUtil.createAssignmentTo(roleOid, ObjectTypes.ROLE));
candidateInducements.add(roleObject.asObjectable());
}
}
}
Expand All @@ -785,11 +785,16 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
PageBase pageBase = getPageBase();
RoleAnalysisService roleAnalysisService = pageBase.getRoleAnalysisService();

Set<AssignmentType> assignmentTypeSet = new HashSet<>();
for (RoleType candidateInducement : candidateInducements) {
assignmentTypeSet.add(ObjectTypeUtil.createAssignmentTo(candidateInducement.getOid(), ObjectTypes.ROLE));
}

executeChangesOnCandidateRole(roleAnalysisService, pageBase, target,
cluster,
candidateRole,
candidateMembers,
candidateInducements,
assignmentTypeSet,
task,
result
);
Expand Down Expand Up @@ -820,7 +825,7 @@ private void onSubmitCandidateRolePerform(@NotNull AjaxRequestTarget target,
}

List<BusinessRoleDto> businessRoleDtos = operationData.getBusinessRoleDtos();
Set<AssignmentType> inducement = operationData.getCandidateRoles();
Set<RoleType> inducement = operationData.getCandidateRoles();
if (!inducement.isEmpty() && !businessRoleDtos.isEmpty()) {
PageRole pageRole = new PageRole(operationData.getBusinessRole(), operationData);
setResponsePage(pageRole);
Expand Down

0 comments on commit 1be53f9

Please sign in to comment.