Search in sources :

Example 1 with ShadowAssociationWrapperImpl

use of com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl 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;
}
Also used : ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 2 with ShadowAssociationWrapperImpl

use of com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl 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);
}
Also used : PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 3 with ShadowAssociationWrapperImpl

use of com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method createShadowAssociationWrapper.

private ShadowAssociationWrapperImpl createShadowAssociationWrapper(PrismContainerValueWrapper<?> parent, PrismContainer<ShadowAssociationType> childContainer, ShadowType shadow, ItemStatus status, WrapperContext ctx) {
    // we need to switch association wrapper to single value
    // the transformation will be as following:
    // we have single value ShadowAssociationType || ResourceObjectAssociationType, and from each shadowAssociationType we will create
    // property - name of the property will be association type(QName) and the value will be shadowRef
    OperationResult parentResult = ctx.getResult();
    ResourceType resource = ctx.getResource();
    PrismContainerDefinition<ShadowAssociationType> associationDefinition = childContainer.getDefinition().clone();
    associationDefinition.toMutable().setMaxOccurs(1);
    PrismContainer associationTransformed;
    try {
        associationTransformed = associationDefinition.instantiate();
    } catch (SchemaException e) {
        parentResult.recordPartialError("Association for " + shadow.getKind() + "/" + shadow.getIntent() + " cannot be created " + resource, e);
        LOGGER.error("Association for {}/{} on resource {} cannot be created: {}", shadow.getKind(), shadow.getIntent(), resource, e.getMessage(), e);
        return null;
    }
    ShadowAssociationWrapperImpl associationWrapper = new ShadowAssociationWrapperImpl(parent, associationTransformed, status);
    return associationWrapper;
}
Also used : ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 4 with ShadowAssociationWrapperImpl

use of com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test220AssignRoleLandluberToWally.

@Test
public void test220AssignRoleLandluberToWally() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    DummyGroup mapmakers = new DummyGroup(GROUP_DUMMY_MAPMAKERS_NAME);
    dummyResource.addGroup(mapmakers);
    PrismObject<UserType> user = createUser(USER_WALLY_NAME, USER_WALLY_FULLNAME, true);
    addObject(user);
    String userWallyOid = user.getOid();
    assignRole(userWallyOid, ROLE_MAPMAKER_OID, task, result);
    // preconditions
    assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(userWallyOid);
    display("User after change execution", userAfter);
    String accountWallyOid = getSingleLinkOid(userAfter);
    PrismObject<ShadowType> shadow = getShadowModel(accountWallyOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    display("Shadow", shadow);
    PrismObject<ShadowType> shadowOld = shadow.clone();
    DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_MAPMAKERS_NAME);
    assertNotNull("No group on dummy resource", dummyGroup);
    displayDumpable("Group", dummyGroup);
    assertGroupMember(dummyGroup, USER_WALLY_NAME);
    when();
    PrismObjectWrapper<ShadowType> objectWrapper = createObjectWrapper(task, shadow, ItemStatus.NOT_CHANGED);
    assertTrue("Wrong wrapper created. Expected ShadowWrapper but was " + objectWrapper.getClass().getSimpleName(), objectWrapper instanceof ShadowWrapper);
    ShadowWrapper shadowWrapper = (ShadowWrapper) objectWrapper;
    then();
    displayDumpable("Wrapper after", shadowWrapper);
    WrapperTestUtil.assertWrapper(shadowWrapper, getString("prismContainer.mainPanelDisplayName"), "shadow description", shadow, shadowOld, ItemStatus.NOT_CHANGED);
    assertContainersPaths(objectWrapper, BASIC_SHADOW_CONTAINERS_PATHS);
    PrismContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainer(ShadowType.F_ATTRIBUTES);
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "Attributes", ShadowType.F_ATTRIBUTES, shadow.findContainer(ShadowType.F_ATTRIBUTES), false, ItemStatus.NOT_CHANGED);
    assertEquals("wrong number of containers in " + attributesContainerWrapper, 1, attributesContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ShadowAttributesType> attributesContainerValueWrapper = attributesContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_WALLY_FULLNAME);
    WrapperTestUtil.assertPropertyWrapperByName(attributesContainerValueWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 18, attributesContainerValueWrapper.getItems().size());
    PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ShadowType.F_ACTIVATION);
    WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ShadowType.activation"), UserType.F_ACTIVATION, shadow, ItemStatus.NOT_CHANGED);
    assertEquals("wrong number of containers in " + activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
    PrismContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapperByName(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    // TODO: fix
    PrismContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainer(ShadowType.F_ASSOCIATION);
    assertNotNull("No association container wrapper", associationContainerWrapper);
    assertTrue("Wrong type of group association property wrapper: " + associationContainerWrapper.getClass(), associationContainerWrapper instanceof ShadowAssociationWrapperImpl);
    assertEquals("wrong number of items in " + associationContainerWrapper, 1, associationContainerWrapper.getValues().size());
    PrismReferenceWrapper groupAssociationWrapper = associationContainerWrapper.findReference(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
    assertNotNull("No group association property wrapper", groupAssociationWrapper);
    List<PrismValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
    assertEquals("wrong number of values in " + groupAssociationWrapper, 1, groupAssociationValues.size());
    PrismValueWrapper groupAssociationValue = groupAssociationValues.get(0);
    PrismReferenceValue groupAssociationValuePVal = (PrismReferenceValue) groupAssociationValue.getNewValue();
    displayDumpable("groupAssociationValuePVal", groupAssociationValuePVal);
    assertEquals("wrong number of values in " + groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
    assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationWrapper.getItemName());
    assertEquals("Wrong group association value", GROUP_DUMMY_MAPMAKERS_NAME, groupAssociationValuePVal.asReferencable().getTargetName().getOrig());
// PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
// PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null,"uid"));
// PrismAsserts.assertPropertyValue(groupAssociationValuePVal.asReferencable().getTargetName(), GROUP_DUMMY_MAPMAKERS_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ShadowAssociationWrapperImpl (com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)2 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)1 PrismReferenceWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 Task (com.evolveum.midpoint.task.api.Task)1 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)1 ArrayList (java.util.ArrayList)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Test (org.testng.annotations.Test)1