Search in sources :

Example 6 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method test310modifySystemConfigurationAddCollectionView.

@Test
public void test310modifySystemConfigurationAddCollectionView() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ModelServiceLocator locator = getServiceLocator(task);
    SystemConfigurationType systemConfigBefore = getSystemConfiguration();
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
    ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW);
    PrismContainerWrapper<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
    // GIVEN
    PrismContainerValue<GuiObjectListViewType> newCollection = collections.getItem().createNewValue();
    ctx.setShowEmpty(true);
    PrismContainerValueWrapper<GuiObjectListViewType> newCollectionValueWrapper = locator.createValueWrapper(collections, newCollection, ValueStatus.ADDED, ctx);
    collections.getValues().add(newCollectionValueWrapper);
    PrismPropertyWrapper<QName> type = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_TYPE);
    type.getValue().setRealValue(new QName("RoleType"));
    PrismPropertyWrapper<String> identifier = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_IDENTIFIER);
    identifier.getValue().setRealValue("my-roles-collection");
    // WHEN
    ObjectDelta<SystemConfigurationType> delta = objectWrapper.getObjectDelta();
    GuiObjectListViewType expectedValue = new GuiObjectListViewType(prismContext);
    expectedValue.setIdentifier("my-roles-collection");
    expectedValue.setType(new QName("RoleType"));
    assertModification(delta, guiObjectViewPath, ModificationTypeType.ADD, expectedValue);
    executeChanges(delta, null, task, result);
    // THEN
    SystemConfigurationType systemConfigAfter = getSystemConfiguration();
    AdminGuiConfigurationType adminGuiConfig = systemConfigAfter.getAdminGuiConfiguration();
    assertNotNull("Unexpected empty admin gui configuration.", adminGuiConfig);
    GuiObjectListViewsType collectionViews = adminGuiConfig.getObjectCollectionViews();
    assertNotNull("Unexpected empty gui object collection views", collectionViews);
    GuiObjectListViewType myRolesCollection = null;
    for (GuiObjectListViewType collectionView : collectionViews.getObjectCollectionView()) {
        if ("my-roles-collection".equals(collectionView.getIdentifier())) {
            myRolesCollection = collectionView;
        }
    }
    assertNotNull("Newly added collection view not present in system configuration, something strange", myRolesCollection);
    assertFalse("c:RoleType should not be equals to RoleType", RoleType.COMPLEX_TYPE.equals(myRolesCollection.getType()));
    assertTrue("c:RoleType should match RoleType", QNameUtil.match(RoleType.COMPLEX_TYPE, myRolesCollection.getType()));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method test111modifyUserAssignment.

@Test
public void test111modifyUserAssignment() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
    PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
    assertNotNull("unexpected null assignment wrapper", assignment);
    assertEquals("Unexpected values for assignment " + assignment.getValues().size(), 1, assignment.getValues().size());
    PrismContainerValueWrapper<AssignmentType> assignmentValue = assignment.getValues().iterator().next();
    PrismContainerWrapper<ResourceAttributeDefinitionType> resourceAttrDefWrapper = assignmentValue.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
    assertNotNull("unexpected null assignment wrapper", resourceAttrDefWrapper);
    assertEquals("Unexpected values for assignment " + resourceAttrDefWrapper.getValues().size(), 0, resourceAttrDefWrapper.getValues().size());
    ModelServiceLocator locator = getServiceLocator(task);
    PrismContainerValue<ResourceAttributeDefinitionType> newAttribute = resourceAttrDefWrapper.getItem().createNewValue();
    PrismContainerValueWrapper<ResourceAttributeDefinitionType> resourceAttrDefValueWrapper = locator.createValueWrapper(resourceAttrDefWrapper, newAttribute, ValueStatus.ADDED, ctx);
    resourceAttrDefWrapper.getValues().add(resourceAttrDefValueWrapper);
    PrismPropertyWrapper<ItemPathType> attributeRefWrapper = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_REF);
    attributeRefWrapper.getValue().setRealValue(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
    PrismPropertyWrapper<QName> matchingRule = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_MATCHING_RULE);
    matchingRule.getValue().setRealValue(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
    PrismContainerWrapper<MappingType> outbound = resourceAttrDefValueWrapper.findContainer(ResourceAttributeDefinitionType.F_OUTBOUND);
    PrismContainerValueWrapper<MappingType> mapping = outbound.getValue();
    MappingType mappingType = mapping.getRealValue();
    mappingType.setExpression(createAsIsExpression());
    ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
    assertModificationsSize(delta, 1);
    logger.info("Attr delta: {}", delta.debugDump());
    ResourceAttributeDefinitionType expectedvalue = new ResourceAttributeDefinitionType(locator.getPrismContext());
    expectedvalue.setRef(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
    expectedvalue.setMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
    MappingType expectedMapping = new MappingType();
    expectedMapping.setExpression(createAsIsExpression());
    expectedvalue.setOutbound(expectedMapping);
    assertModification(delta, resourceAttrDefValueWrapper.getPath(), ModificationTypeType.ADD, expectedvalue);
    executeChanges(delta, executeOptions().raw(), task, result);
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
    PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
    assertNotNull("Unexpected null assignment container for " + userElaineAfter, assignmentAfter);
    assertEquals("Unexpected number of assignments, " + assignmentAfter.debugDump(), 1, assignmentAfter.getValues().size());
    PrismContainerValue<AssignmentType> assignmentTypeAfter = assignmentAfter.getValues().iterator().next();
    AssignmentType expected = new AssignmentType(locator.getPrismContext());
    ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
    ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(resourceDummy.getOid(), ObjectTypes.RESOURCE);
    ref.setRelation(SchemaConstants.ORG_DEFAULT);
    constructionType.setResourceRef(ref);
    constructionType.setKind(ShadowKindType.ACCOUNT);
    constructionType.setIntent("default");
    constructionType.getAttribute().add(expectedvalue);
    expected.setConstruction(constructionType);
    ActivationType activationType = new ActivationType(locator.getPrismContext());
    activationType.setEffectiveStatus(ActivationStatusType.ENABLED);
    expected.setActivation(activationType);
// TODO assertions after
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) QName(javax.xml.namespace.QName) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method createDummyResourceAssignment.

private PrismContainerValue<AssignmentType> createDummyResourceAssignment(PrismObjectWrapper<UserType> objectWrapper, int existingAssignments, Task task, OperationResult result) throws Exception {
    PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
    assertNotNull("unexpected null assignment wrapper", assignment);
    assertEquals("Unexpected values for assignment " + assignment.getValues().size(), existingAssignments, assignment.getValues().size());
    ModelServiceLocator locator = getServiceLocator(task);
    PrismContainerValue<AssignmentType> newAssignment = assignment.getItem().createNewValue();
    AssignmentType newAssignmentType = newAssignment.asContainerable();
    ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
    constructionType.setResourceRef(ObjectTypeUtil.createObjectRef(resourceDummy, locator.getPrismContext()));
    constructionType.setKind(ShadowKindType.ACCOUNT);
    constructionType.setIntent("default");
    newAssignmentType.setConstruction(constructionType);
    PrismContainerValue<AssignmentType> newAssignmentClone = newAssignment.clone();
    WrapperContext ctx = new WrapperContext(task, result);
    PrismContainerValueWrapper vw = locator.createValueWrapper(assignment, newAssignment, ValueStatus.ADDED, ctx);
    assignment.getValues().add(vw);
    return newAssignmentClone;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)

Example 9 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class AbstractGuiIntegrationTest method getServiceLocator.

protected ModelServiceLocator getServiceLocator(final Task pageTask) {
    return new ModelServiceLocator() {

        @Override
        public ModelService getModelService() {
            return modelService;
        }

        @Override
        public ModelInteractionService getModelInteractionService() {
            return modelInteractionService;
        }

        @Override
        public DashboardService getDashboardService() {
            return dashboardService;
        }

        @Override
        public Task createSimpleTask(String operationName) {
            MidPointPrincipal user = AuthUtil.getPrincipalUser();
            if (user == null) {
                throw new IllegalStateException("No authenticated user");
            }
            return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
        }

        @Override
        public PrismContext getPrismContext() {
            return prismContext;
        }

        @Override
        public SecurityEnforcer getSecurityEnforcer() {
            return securityEnforcer;
        }

        @Override
        public SecurityContextManager getSecurityContextManager() {
            return securityContextManager;
        }

        @NotNull
        @Override
        public CompiledGuiProfile getCompiledGuiProfile() {
            Task task = createSimpleTask("getCompiledGuiProfile");
            try {
                return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
            } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
                throw new SystemException(e.getMessage(), e);
            }
        }

        @Override
        public Task getPageTask() {
            return pageTask;
        }

        @Override
        public ExpressionFactory getExpressionFactory() {
            return expressionFactory;
        }

        @Override
        public LocalizationService getLocalizationService() {
            return localizationService;
        }

        @Override
        public Locale getLocale() {
            return Locale.US;
        }

        @Override
        public GuiComponentRegistry getRegistry() {
            return registry;
        }

        @Override
        public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
            return registry.getObjectWrapperFactory(objectDef);
        }

        @Override
        public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
            ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
            ctx.setCreateIfEmpty(true);
            return factory.createWrapper(null, item, status, ctx);
        }

        @Override
        public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
            ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
            return factory.createValueWrapper(parentWrapper, newValue, status, context);
        }

        @Override
        public MidpointFormValidatorRegistry getFormValidatorRegistry() {
            return null;
        }

        @Override
        public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
            return null;
        }

        @Override
        public CorrelationService getCorrelationService() {
            return null;
        }
    };
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) PrismValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator)

Example 10 with ModelServiceLocator

use of com.evolveum.midpoint.gui.api.util.ModelServiceLocator in project midpoint by Evolveum.

the class TestWrapperDelta method test311modifySystemConfigurationModifyCollectionType.

@Test
public void test311modifySystemConfigurationModifyCollectionType() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ModelServiceLocator locator = getServiceLocator(task);
    SystemConfigurationType systemConfigBefore = getSystemConfiguration();
    WrapperContext ctx = new WrapperContext(task, result);
    PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
    ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW);
    PrismContainerWrapper<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
    PrismContainerValueWrapper<GuiObjectListViewType> foundCollection = null;
    for (PrismContainerValueWrapper<GuiObjectListViewType> collection : collections.getValues()) {
        GuiObjectListViewType collectionRealValue = collection.getRealValue();
        if ("my-roles-collection".equals(collectionRealValue.getIdentifier())) {
            foundCollection = collection;
            break;
        }
    }
    // GIVEN
    PrismPropertyWrapper<QName> collectionType = foundCollection.findProperty(GuiObjectListViewType.F_TYPE);
    collectionType.getValue().setRealValue(RoleType.COMPLEX_TYPE);
    // WHEN
    ObjectDelta<SystemConfigurationType> systemConfigDelta = objectWrapper.getObjectDelta();
    assertTrue("Delta should be empty!", systemConfigDelta.isEmpty());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ModelServiceLocator (com.evolveum.midpoint.gui.api.util.ModelServiceLocator)12 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 Task (com.evolveum.midpoint.task.api.Task)9 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Test (org.testng.annotations.Test)8 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ItemStatus (com.evolveum.midpoint.gui.api.prism.ItemStatus)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 QName (javax.xml.namespace.QName)3 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)2 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 PrismValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper)1 ShadowWrapperFactoryImpl (com.evolveum.midpoint.gui.impl.factory.wrapper.ShadowWrapperFactoryImpl)1 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)1 UniformItemPath (com.evolveum.midpoint.prism.path.UniformItemPath)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 ValueStatus (com.evolveum.midpoint.web.component.prism.ValueStatus)1