use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.
the class ShadowAssociationWrapperImpl method getDelta.
@Override
public <D extends ItemDelta<?, ?>> Collection<D> getDelta() throws SchemaException {
Collection<D> deltas = new ArrayList<D>();
ContainerDelta<ShadowAssociationType> delta = createEmptyDelta(getDeltaPathForStatus(getStatus()));
switch(getStatus()) {
case ADDED:
if (CollectionUtils.isEmpty(getValues())) {
return null;
}
// we know that there is always only one value
PrismContainerValueWrapper<ShadowAssociationType> containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
}
}
if (delta.isEmpty()) {
return null;
}
return (Collection) MiscUtil.createCollection(delta);
case NOT_CHANGED:
containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
switch(updatedRefValue.getStatus()) {
case ADDED:
delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
break;
case NOT_CHANGED:
break;
case DELETED:
delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
break;
}
}
}
break;
case DELETED:
containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef((PrismReferenceValue) updatedRefValue.getNewValue()));
delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
}
}
break;
}
if (!delta.isEmpty()) {
deltas.add((D) delta);
}
if (deltas.isEmpty()) {
return null;
}
return deltas;
}
use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.
the class ShadowAssociationWrapperFactoryImpl method createValuesWrapper.
@Override
protected List<PrismContainerValueWrapper<ShadowAssociationType>> createValuesWrapper(PrismContainerWrapper<ShadowAssociationType> itemWrapper, PrismContainer<ShadowAssociationType> item, WrapperContext context) throws SchemaException {
if (!(itemWrapper instanceof ShadowAssociationWrapperImpl)) {
return super.createValuesWrapper(itemWrapper, item, context);
}
ShadowAssociationWrapperImpl associationWrapper = (ShadowAssociationWrapperImpl) itemWrapper;
PrismContainerValueWrapper<ShadowAssociationType> shadowValueWrapper = createContainerValueWrapper(associationWrapper, associationWrapper.getItem().createNewValue(), ItemStatus.ADDED == associationWrapper.getStatus() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context);
Collection<PrismReferenceWrapper> shadowReferences = new ArrayList<>();
for (ResourceAssociationDefinition def : context.getRefinedAssociationDefinitions()) {
PrismReference shadowAss = fillInShadowReference(def, item);
PrismReferenceWrapper shadowReference = (PrismReferenceWrapper) referenceWrapperFactory.createWrapper(shadowValueWrapper, shadowAss, shadowAss.isEmpty() ? ItemStatus.ADDED : ItemStatus.NOT_CHANGED, context);
shadowReference.setFilter(WebComponentUtil.createAssociationShadowRefFilter(def, getPrismContext(), context.getResource().getOid()));
shadowReferences.add(shadowReference);
}
shadowValueWrapper.getItems().addAll((Collection) shadowReferences);
setupExpanded(shadowValueWrapper);
return Collections.singletonList(shadowValueWrapper);
}
use of com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper in project midpoint by Evolveum.
the class AssignmentPanel method getAssignmentMenuActions.
private <AH extends FocusType> List<InlineMenuItem> getAssignmentMenuActions() {
List<InlineMenuItem> menuItems = new ArrayList<>();
PrismObject<AH> obj = getMultivalueContainerListPanel().getFocusObject();
try {
boolean isUnassignAuthorized = getParentPage().isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI, AuthorizationPhaseType.REQUEST, obj, null, null, null);
if (isUnassignAuthorized) {
menuItems.add(new ButtonInlineMenuItem(getAssignmentsLimitReachedUnassignTitleModel()) {
private static final long serialVersionUID = 1L;
@Override
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_DELETE_MENU_ITEM);
}
@Override
public InlineMenuItemAction initAction() {
return getMultivalueContainerListPanel().createDeleteColumnAction();
}
});
}
} catch (Exception ex) {
LOGGER.error("Couldn't check unassign authorization for the object: {}, {}", obj.getName(), ex.getLocalizedMessage());
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_ASSIGN_ACTION_URI)) {
menuItems.add(new ButtonInlineMenuItem(createStringResource("PageBase.button.unassign")) {
private static final long serialVersionUID = 1L;
@Override
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_DELETE_MENU_ITEM);
}
@Override
public InlineMenuItemAction initAction() {
return getMultivalueContainerListPanel().createDeleteColumnAction();
}
});
}
}
menuItems.add(new ButtonInlineMenuItem(createStringResource("PageBase.button.edit")) {
private static final long serialVersionUID = 1L;
@Override
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_EDIT_MENU_ITEM);
}
@Override
public InlineMenuItemAction initAction() {
return getMultivalueContainerListPanel().createEditColumnAction();
}
});
ButtonInlineMenuItem menu = new ButtonInlineMenuItem(createStringResource("AssignmentPanel.viewTargetObject")) {
private static final long serialVersionUID = 1L;
@Override
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_NAVIGATE_ARROW);
}
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction<PrismContainerValueWrapper<AssignmentType>>() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
PrismContainerValueWrapper<AssignmentType> assignmentContainer = getRowModel().getObject();
PrismReferenceWrapper<ObjectReferenceType> targetRef;
try {
targetRef = assignmentContainer.findReference(ItemPath.create(AssignmentType.F_TARGET_REF));
} catch (SchemaException e) {
getSession().error("Couldn't show details page. More information provided in log.");
LOGGER.error("Couldn't show details page, no targetRef reference wrapper found: {}", e.getMessage(), e);
target.add(getPageBase().getFeedbackPanel());
return;
}
if (targetRef != null && targetRef.getValues() != null && targetRef.getValues().size() > 0) {
PrismReferenceValueWrapperImpl<ObjectReferenceType> refWrapper = targetRef.getValues().get(0);
if (!StringUtils.isEmpty(refWrapper.getNewValue().getOid())) {
Class<? extends ObjectType> targetClass = ObjectTypes.getObjectTypeFromTypeQName(refWrapper.getRealValue().getType()).getClassDefinition();
WebComponentUtil.dispatchToObjectDetailsPage(targetClass, refWrapper.getNewValue().getOid(), AssignmentPanel.this, false);
}
}
}
};
}
@Override
public boolean isHeaderMenuItem() {
return false;
}
};
menu.setVisibilityChecker((InlineMenuItem.VisibilityChecker) (rowModel, isHeader) -> {
PrismContainerValueWrapper<AssignmentType> assignment = (PrismContainerValueWrapper<AssignmentType>) rowModel.getObject();
if (assignment == null) {
return false;
}
PrismReferenceWrapper<Referencable> target = null;
try {
target = assignment.findReference(AssignmentType.F_TARGET_REF);
} catch (Exception e) {
LOGGER.error("Couldn't find targetRef in assignment");
}
return target != null && !target.isEmpty();
});
menuItems.add(menu);
return menuItems;
}
Aggregations