use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.
the class ShadowAssociationWrapperFactoryImpl method createWrapperInternal.
@Override
protected PrismContainerWrapper<ShadowAssociationType> createWrapperInternal(PrismContainerValueWrapper<?> parent, PrismContainer<ShadowAssociationType> childContainer, ItemStatus status, WrapperContext ctx) {
OperationResult parentResult = ctx.getResult();
if (isNotShadow(ctx, parentResult)) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
if (isNotAssociation(childContainer)) {
parentResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + childContainer.getComplexTypeDefinition().getTypeClass() + " is not supported");
LOGGER.debug("Association for {} is not supported", childContainer.getComplexTypeDefinition().getTypeClass());
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
if (ctx.getObject() == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
ShadowType shadow = (ShadowType) ctx.getObject().asObjectable();
PrismObject<ResourceType> resource = loadResource(shadow, ctx);
if (resource == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
Collection<ResourceAssociationDefinition> resourceAssociationDefinitions = loadRefinedAssociationDefinitions(resource, shadow, parentResult);
if (resourceAssociationDefinitions == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
ctx.setResource(resource.asObjectable());
ctx.setRefinedAssociationDefinitions(resourceAssociationDefinitions);
ShadowAssociationWrapperImpl associationWrapper = createShadowAssociationWrapper(parent, childContainer, shadow, status, ctx);
if (associationWrapper == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
return associationWrapper;
}
use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition 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.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.
the class ShadowAssociationWrapperFactoryImpl method loadRefinedAssociationDefinitions.
private Collection<ResourceAssociationDefinition> loadRefinedAssociationDefinitions(PrismObject<ResourceType> resource, ShadowType shadow, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(CREATE_ASSOCIATION_WRAPPER);
ResourceSchema refinedResourceSchema;
try {
refinedResourceSchema = ResourceSchemaFactory.getCompleteSchema(resource);
} catch (SchemaException e) {
LOGGER.error("Cannot get refined schema for {}, {}", resource, e.getMessage(), e);
result.recordPartialError("Could not get fined schema for " + resource, e);
return null;
}
ShadowKindType kind = shadow.getKind();
String shadowIntent = shadow.getIntent();
ResourceObjectDefinition oc = refinedResourceSchema.findObjectDefinition(kind, shadowIntent);
if (oc == null) {
LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
return null;
}
Collection<ResourceAssociationDefinition> resourceAssociationDefinitions = oc.getAssociationDefinitions();
if (CollectionUtils.isEmpty(resourceAssociationDefinitions)) {
result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
return null;
}
result.computeStatusIfUnknown();
return resourceAssociationDefinitions;
}
use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.
the class ResourceTypeAssignmentPopupTabPanel method initParametersPanel.
@Override
protected void initParametersPanel(Fragment parametersPanel) {
initModels();
WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
kindContainer.setOutputMarkupId(true);
parametersPanel.add(kindContainer);
DropDownChoicePanel<ShadowKindType> kindSelector = WebComponentUtil.createEnumPanel(ShadowKindType.class, ID_KIND, WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), Model.of(), ResourceTypeAssignmentPopupTabPanel.this, true);
kindSelector.setOutputMarkupId(true);
kindSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
kindValueUpdatePerformed(target);
}
});
kindSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
}
});
kindSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
kindSelector.setOutputMarkupPlaceholderTag(true);
kindContainer.add(kindSelector);
WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
intentContainer.setOutputMarkupId(true);
parametersPanel.add(intentContainer);
DropDownChoicePanel<String> intentSelector = new DropDownChoicePanel<String>(ID_INTENT, Model.of(), intentValues, true);
intentSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getKindValue() != null && getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
}
});
intentSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
intentValueUpdatePerformed(target);
}
});
intentSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
intentSelector.setOutputMarkupId(true);
intentSelector.setOutputMarkupPlaceholderTag(true);
intentContainer.add(intentSelector);
WebMarkupContainer associationContainer = new WebMarkupContainer(ID_ASSOCIATION_CONTAINER);
associationContainer.setOutputMarkupId(true);
associationContainer.add(new VisibleBehaviour(() -> isEntitlementAssignment()));
parametersPanel.add(associationContainer);
DropDownChoicePanel<ResourceAssociationDefinition> associationSelector = new DropDownChoicePanel<>(ID_ASSOCIATION, Model.of(), associationValuesModel, new IChoiceRenderer<ResourceAssociationDefinition>() {
private static final long serialVersionUID = 1L;
@Override
public Object getDisplayValue(ResourceAssociationDefinition refinedAssociationDefinition) {
return WebComponentUtil.getAssociationDisplayName(refinedAssociationDefinition);
}
@Override
public String getIdValue(ResourceAssociationDefinition refinedAssociationDefinition, int index) {
return Integer.toString(index);
}
@Override
public ResourceAssociationDefinition getObject(String id, IModel<? extends List<? extends ResourceAssociationDefinition>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
}, true);
associationSelector.setOutputMarkupId(true);
associationSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0 && getKindValue() != null && StringUtils.isNotEmpty(getIntentValue());
}
});
associationSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
associationSelector.setOutputMarkupPlaceholderTag(true);
associationContainer.add(associationSelector);
}
use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.
the class ResourceAttributeRefPanelFactory method getChoicesList.
private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
// attribute/ref
if (wrapper == null) {
return Collections.emptyList();
}
// attribute value
if (wrapper.getParent() == null) {
return Collections.emptyList();
}
// attribute
ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
if (attributeWrapper == null) {
return Collections.emptyList();
}
PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
if (itemWrapper == null) {
return Collections.emptyList();
}
if (!(itemWrapper instanceof ConstructionValueWrapper)) {
return Collections.emptyList();
}
ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
try {
ResourceSchema schema = constructionWrapper.getRefinedSchema();
if (schema == null) {
return new ArrayList<>();
}
ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
if (rOcd == null) {
return Collections.emptyList();
}
if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
}
Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
} catch (SchemaException e) {
LOGGER.warn("Cannot get resource attribute definitions");
}
return Collections.emptyList();
}
Aggregations