use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class AssociationFromLinkExpressionEvaluator method evaluate.
/* (non-Javadoc)
* @see com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java.util.Collection, java.util.Map, boolean, java.lang.String, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
String desc = context.getContextDescription();
Object orderOneObject = context.getVariables().get(ExpressionConstants.VAR_ORDER_ONE_OBJECT);
if (orderOneObject == null) {
throw new ExpressionEvaluationException("No order one object variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
}
if (!(orderOneObject instanceof AbstractRoleType)) {
throw new ExpressionEvaluationException("Order one object variable in " + desc + " is not a role, it is " + orderOneObject.getClass().getName() + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
}
AbstractRoleType thisRole = (AbstractRoleType) orderOneObject;
LOGGER.trace("Evaluating association from link on: {}", thisRole);
RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDef == null) {
throw new ExpressionEvaluationException("No association target object class definition variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to create an association.");
}
ShadowDiscriminatorType projectionDiscriminator = evaluatorType.getProjectionDiscriminator();
if (projectionDiscriminator == null) {
throw new ExpressionEvaluationException("No projectionDiscriminator in " + desc);
}
ShadowKindType kind = projectionDiscriminator.getKind();
if (kind == null) {
throw new ExpressionEvaluationException("No kind in projectionDiscriminator in " + desc);
}
String intent = projectionDiscriminator.getIntent();
PrismContainer<ShadowAssociationType> output = outputDefinition.instantiate();
QName assocName = context.getMappingQName();
String resourceOid = rAssocTargetDef.getResourceType().getOid();
Collection<SelectorOptions<GetOperationOptions>> options = null;
// Always process the first role (myself) regardless of recursion setting
gatherAssociationsFromAbstractRole(thisRole, output, resourceOid, kind, intent, assocName, options, desc, context);
if (thisRole instanceof OrgType && matchesForRecursion((OrgType) thisRole)) {
gatherAssociationsFromAbstractRoleRecurse((OrgType) thisRole, output, resourceOid, kind, intent, assocName, options, desc, context);
}
return ItemDelta.toDeltaSetTriple(output, null);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.
private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
ShadowType shadowType;
try {
shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
} catch (ObjectNotFoundException e) {
// Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
// the chance to react yet. Just ignore such shadow.
LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
continue;
}
if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
ShadowAssociationType shadowAssociationType = newValue.asContainerable();
shadowAssociationType.setName(assocName);
ObjectReferenceType shadowRef = new ObjectReferenceType();
shadowRef.setOid(linkRef.getOid());
shadowAssociationType.setShadowRef(shadowRef);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class ResourceRelatedHandlerPanel method initLayout.
private void initLayout() {
final VisibleEnableBehaviour visibleIfEdit = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return parentPage.isEdit();
}
};
final VisibleEnableBehaviour visibleIfView = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !parentPage.isEdit();
}
};
enabledIfEdit = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit();
}
};
final VisibleEnableBehaviour visibleForResourceCoordinates = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresResourceCoordinates();
}
};
final WebMarkupContainer resourceRefContainer = new WebMarkupContainer(ID_RESOURCE_REF_CONTAINER);
resourceRefContainer.add(visibleForResourceCoordinates);
resourceRefContainer.setOutputMarkupId(true);
add(resourceRefContainer);
final DropDownChoice<TaskAddResourcesDto> resourceRef = new DropDownChoice<>(ID_RESOURCE_REF, new PropertyModel<TaskAddResourcesDto>(getModel(), ResourceRelatedHandlerDto.F_RESOURCE_REFERENCE), new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {
@Override
public List<TaskAddResourcesDto> getObject() {
return createResourceList();
}
}, new ChoiceableChoiceRenderer<TaskAddResourcesDto>());
resourceRef.setOutputMarkupId(true);
resourceRef.add(enabledIfEdit);
resourceRef.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Task task = parentPage.createSimpleTask(OPERATION_LOAD_RESOURCE);
OperationResult result = task.getResult();
List<QName> objectClassList = new ArrayList<>();
TaskAddResourcesDto resourcesDto = getModelObject().getResourceRef();
if (resourcesDto != null) {
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(ResourceType.class, resourcesDto.getOid(), parentPage, task, result);
try {
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, parentPage.getPrismContext());
schema.getObjectClassDefinitions();
for (Definition def : schema.getDefinitions()) {
objectClassList.add(def.getTypeName());
}
getModelObject().setObjectClassList(objectClassList);
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object class list from resource.", e);
error("Couldn't load object class list from resource.");
}
}
target.add(resourceRefContainer);
}
});
resourceRefContainer.add(resourceRef);
WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
kindContainer.add(visibleForResourceCoordinates);
add(kindContainer);
final DropDownChoice kind = new DropDownChoice<>(ID_KIND, new PropertyModel<ShadowKindType>(getModel(), ResourceRelatedHandlerDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
kind.setOutputMarkupId(true);
kind.setNullValid(true);
kindContainer.add(kind);
WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
intentContainer.add(visibleForResourceCoordinates);
add(intentContainer);
final TextField<String> intent = new TextField<>(ID_INTENT, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_INTENT));
intentContainer.add(intent);
intent.setOutputMarkupId(true);
intent.add(enabledIfEdit);
WebMarkupContainer objectClassContainer = new WebMarkupContainer(ID_OBJECT_CLASS_CONTAINER);
objectClassContainer.add(visibleForResourceCoordinates);
add(objectClassContainer);
AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
autoCompleteSettings.setShowListOnEmptyInput(true);
final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_OBJECT_CLASS), autoCompleteSettings) {
@Override
protected Iterator<String> getChoices(String input) {
return prepareObjectClassChoiceList(input);
}
};
objectClass.add(enabledIfEdit);
objectClassContainer.add(objectClass);
WebMarkupContainer optionsContainer = new WebMarkupContainer(ID_OPTIONS_CONTAINER);
optionsContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresDryRun();
}
});
add(optionsContainer);
WebMarkupContainer dryRunContainer = new WebMarkupContainer(ID_DRY_RUN_CONTAINER);
dryRunContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return getTaskDto().configuresDryRun();
}
});
optionsContainer.add(dryRunContainer);
CheckBox dryRun = new CheckBox(ID_DRY_RUN, new PropertyModel<Boolean>(getModel(), ResourceRelatedHandlerDto.F_DRY_RUN));
dryRun.add(enabledIfEdit);
dryRunContainer.add(dryRun);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class EntitlementConverter method postProcessEntitlementsRead.
//////////
// GET
/////////
public void postProcessEntitlementsRead(ProvisioningContext subjectCtx, PrismObject<ShadowType> resourceObject, OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ResourceType resourceType = subjectCtx.getResource();
LOGGER.trace("Starting postProcessEntitlementRead");
RefinedObjectClassDefinition objectClassDefinition = subjectCtx.getObjectClassDefinition();
Collection<RefinedAssociationDefinition> entitlementAssociationDefs = objectClassDefinition.getAssociationDefinitions();
if (entitlementAssociationDefs != null) {
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceObject);
PrismContainerDefinition<ShadowAssociationType> associationDef = resourceObject.getDefinition().findContainerDefinition(ShadowType.F_ASSOCIATION);
PrismContainer<ShadowAssociationType> associationContainer = associationDef.instantiate();
for (RefinedAssociationDefinition assocDefType : entitlementAssociationDefs) {
ShadowKindType entitlementKind = assocDefType.getKind();
if (entitlementKind == null) {
entitlementKind = ShadowKindType.ENTITLEMENT;
}
for (String entitlementIntent : assocDefType.getIntents()) {
LOGGER.trace("Resolving association {} for kind {} and intent {}", assocDefType.getName(), entitlementKind, entitlementIntent);
ProvisioningContext entitlementCtx = subjectCtx.spawn(entitlementKind, entitlementIntent);
RefinedObjectClassDefinition entitlementDef = entitlementCtx.getObjectClassDefinition();
if (entitlementDef == null) {
throw new SchemaException("No definition for entitlement intent(s) '" + assocDefType.getIntents() + "' in " + resourceType);
}
ResourceObjectAssociationDirectionType direction = assocDefType.getResourceObjectAssociationType().getDirection();
if (direction == ResourceObjectAssociationDirectionType.SUBJECT_TO_OBJECT) {
postProcessEntitlementSubjectToEntitlement(resourceType, resourceObject, objectClassDefinition, assocDefType, entitlementDef, attributesContainer, associationContainer, parentResult);
} else if (direction == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
if (assocDefType.getResourceObjectAssociationType().getShortcutAssociationAttribute() != null) {
postProcessEntitlementSubjectToEntitlement(resourceType, resourceObject, objectClassDefinition, assocDefType, entitlementDef, attributesContainer, associationContainer, assocDefType.getResourceObjectAssociationType().getShortcutAssociationAttribute(), assocDefType.getResourceObjectAssociationType().getShortcutValueAttribute(), parentResult);
} else {
postProcessEntitlementEntitlementToSubject(subjectCtx, resourceObject, assocDefType, entitlementCtx, attributesContainer, associationContainer, parentResult);
}
} else {
throw new IllegalArgumentException("Unknown entitlement direction " + direction + " in association " + assocDefType + " in " + resourceType);
}
}
}
if (!associationContainer.isEmpty()) {
resourceObject.add(associationContainer);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class SynchronizationServiceUtils method isPolicyApplicable.
private static boolean isPolicyApplicable(ObjectSynchronizationDiscriminatorType synchronizationDiscriminator, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
ShadowKindType kind = synchronizationDiscriminator.getKind();
String intent = synchronizationDiscriminator.getIntent();
if (kind == null && intent == null) {
throw new SchemaException("Illegal state, object synchronization discriminator type must have kind/intent specified. Current values are: kind=" + kind + ", intent=" + intent);
}
return SynchronizationUtils.isPolicyApplicable(null, kind, intent, synchronizationPolicy, resource);
}
Aggregations