Skip to content

Commit

Permalink
fix for inducements tabs (not need define assignmentObjectRelations)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 9, 2021
1 parent 283ac75 commit 51a5281
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,63 +442,10 @@ protected ObjectFilter getSubtypeFilter() {
return null;
}

@NotNull
protected IModel<AssignmentPopupDto> createAssignmentPopupModel() {
return new LoadableModel<>(false) {

@Override
protected AssignmentPopupDto load() {
List<AssignmentObjectRelation> assignmentObjectRelations = getAssignmentObjectRelationList();
return new AssignmentPopupDto(assignmentObjectRelations);
}
};
}

private List<AssignmentObjectRelation> getAssignmentObjectRelationList() {
if (AbstractAssignmentTypePanel.this.getContainerModel().getObject() == null) {
return null;
}

List<AssignmentObjectRelation> assignmentRelationsList =
WebComponentUtil.divideAssignmentRelationsByAllValues(loadAssignmentTargetRelationsList());
if (assignmentRelationsList == null || assignmentRelationsList.isEmpty()) {
return assignmentRelationsList;
}
QName assignmentType = getAssignmentType();
if (assignmentType == null) {
return assignmentRelationsList;
}
List<AssignmentObjectRelation> assignmentRelationsListFilteredByType =
new ArrayList<>();
assignmentRelationsList.forEach(assignmentRelation -> {
QName objectType = assignmentRelation.getObjectTypes() != null
&& !assignmentRelation.getObjectTypes().isEmpty()
? assignmentRelation.getObjectTypes().get(0) : null;
if (QNameUtil.match(assignmentType, objectType)) {
assignmentRelationsListFilteredByType.add(assignmentRelation);
}
});
return assignmentRelationsListFilteredByType;
}
protected abstract IModel<AssignmentPopupDto> createAssignmentPopupModel();

protected abstract QName getAssignmentType();

@NotNull
private <AH extends AssignmentHolderType> List<AssignmentObjectRelation> loadAssignmentTargetRelationsList() {
OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNMENT_TARGET_RELATIONS);
List<AssignmentObjectRelation> assignmentTargetRelations = new ArrayList<>();
PrismObject<AH> obj = getFocusObject();
try {
AssignmentCandidatesSpecification spec = getPageBase().getModelInteractionService()
.determineAssignmentTargetSpecification(obj, result);
assignmentTargetRelations = spec != null ? spec.getAssignmentObjectRelations() : new ArrayList<>();
} catch (SchemaException | ConfigurationException ex) {
result.recordPartialError(ex.getLocalizedMessage());
LOGGER.error("Couldn't load assignment target specification for the object {} , {}", obj.getName(), ex.getLocalizedMessage());
}
return assignmentTargetRelations;
}

protected void addSelectedAssignmentsPerformed(AjaxRequestTarget target, List<AssignmentType> newAssignmentsList) {
if (CollectionUtils.isEmpty(newAssignmentsList)) {
warn(getPageBase().getString("AssignmentTablePanel.message.noAssignmentSelected"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,59 @@ protected ObjectQuery getCustomizeQuery() {
}
return query;
}

@NotNull
protected IModel<AssignmentPopupDto> createAssignmentPopupModel() {
return new LoadableModel<>(false) {

@Override
protected AssignmentPopupDto load() {
List<AssignmentObjectRelation> assignmentObjectRelations = getAssignmentObjectRelationList();
return new AssignmentPopupDto(assignmentObjectRelations);
}
};
}

private List<AssignmentObjectRelation> getAssignmentObjectRelationList() {
if (AbstractAssignmentPanel.this.getContainerModel().getObject() == null) {
return null;
}

List<AssignmentObjectRelation> assignmentRelationsList =
WebComponentUtil.divideAssignmentRelationsByAllValues(loadAssignmentTargetRelationsList());
if (assignmentRelationsList == null || assignmentRelationsList.isEmpty()) {
return assignmentRelationsList;
}
QName assignmentType = getAssignmentType();
if (assignmentType == null) {
return assignmentRelationsList;
}
List<AssignmentObjectRelation> assignmentRelationsListFilteredByType =
new ArrayList<>();
assignmentRelationsList.forEach(assignmentRelation -> {
QName objectType = assignmentRelation.getObjectTypes() != null
&& !assignmentRelation.getObjectTypes().isEmpty()
? assignmentRelation.getObjectTypes().get(0) : null;
if (QNameUtil.match(assignmentType, objectType)) {
assignmentRelationsListFilteredByType.add(assignmentRelation);
}
});
return assignmentRelationsListFilteredByType;
}

@NotNull
private <AH extends AssignmentHolderType> List<AssignmentObjectRelation> loadAssignmentTargetRelationsList() {
OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNMENT_TARGET_RELATIONS);
List<AssignmentObjectRelation> assignmentTargetRelations = new ArrayList<>();
PrismObject<AH> obj = getFocusObject();
try {
AssignmentCandidatesSpecification spec = getPageBase().getModelInteractionService()
.determineAssignmentTargetSpecification(obj, result);
assignmentTargetRelations = spec != null ? spec.getAssignmentObjectRelations() : new ArrayList<>();
} catch (SchemaException | ConfigurationException ex) {
result.recordPartialError(ex.getLocalizedMessage());
LOGGER.error("Couldn't load assignment target specification for the object {} , {}", obj.getName(), ex.getLocalizedMessage());
}
return assignmentTargetRelations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.model.IModel;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.ArrayList;
Expand All @@ -41,6 +42,17 @@ protected List<IColumn<PrismContainerValueWrapper<AssignmentType>, String>> init
return new ArrayList<>();
}

@NotNull
protected IModel<AssignmentPopupDto> createAssignmentPopupModel() {
return new LoadableModel<>(false) {

@Override
protected AssignmentPopupDto load() {
return new AssignmentPopupDto(null);
}
};
}

@Override
protected QName getAssignmentType() {
return null;
Expand Down

0 comments on commit 51a5281

Please sign in to comment.