use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext 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
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext 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;
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext 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;
}
};
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test100CreateWrapperUserJack.
@Test
public void test100CreateWrapperUserJack() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
when();
assertLoggedInUserOid(USER_ADMINISTRATOR_OID);
PrismObject<UserType> user = getUser(USER_JACK_OID);
PrismObject<UserType> userOld = user.clone();
PrismObjectWrapperFactory<UserType> factory = getServiceLocator(task).findObjectWrapperFactory(user.getDefinition());
WrapperContext context = new WrapperContext(task, result);
PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.NOT_CHANGED, context);
then();
displayDumpable("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, userOld, ItemStatus.NOT_CHANGED);
assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
PrismObjectValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_JACK_USERNAME));
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
Item ship = userOld.findItem(ItemPath.create(UserType.F_EXTENSION, PIRACY_SHIP));
assertNotNull("Ship is null", ship);
WrapperTestUtil.assertPropertyWrapper(mainContainerValueWrapper, extensionPath(PIRACY_SHIP), AdminGuiTestConstants.USER_JACK_SHIP);
PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(UserType.F_ACTIVATION);
WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ActivationType.activation"), UserType.F_ACTIVATION, user, 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);
assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
ItemStatus objectStatus = objectWrapper.getStatus();
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
// not visible, because it is empty
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false);
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_WEAPON), null);
assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_COLORS), ItemProcessing.AUTO);
assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_SECRET), ItemProcessing.IGNORE);
assertItemWrapperProcessing(mainContainerValueWrapper, extensionPath(PIRACY_RANT), ItemProcessing.MINIMAL);
when();
mainContainerValueWrapper.setShowEmpty(true);
then();
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_NAME, true);
// emphasized
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_GIVEN_NAME, true);
// emphasized
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
// empty
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, true);
// empty
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, true);
ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
displayDumpable("Delta", objectDelta);
assertTrue("non-empty delta produced from wrapper: " + objectDelta, objectDelta.isEmpty());
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class TaskBasicTabPanel method initLayout.
private void initLayout() {
ItemPanelSettings settings = new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> getTask().getHandlerUri() == null).build();
TaskHandlerSelectorPanel handlerSelectorPanel = new TaskHandlerSelectorPanel(ID_HANDLER, PrismPropertyWrapperModel.fromContainerWrapper(getModel(), TaskType.F_HANDLER_URI), settings) {
@Override
protected void onUpdatePerformed(AjaxRequestTarget target) {
String newHandlerUri = getTask().getHandlerUri();
if (StringUtils.isBlank(newHandlerUri) || !newHandlerUri.startsWith("http://")) {
LOGGER.trace("Nothing to do, handler still not set");
return;
}
TaskHandler taskHandler = getPageBase().getTaskManager().getHandler(newHandlerUri);
if (taskHandler == null) {
LOGGER.trace("Nothing to do, cannot find TaskHandler for {}", newHandlerUri);
return;
}
if (!WebComponentUtil.hasAnyArchetypeAssignment(getTask())) {
String archetypeOid = taskHandler.getArchetypeOid(newHandlerUri);
WebComponentUtil.addNewArchetype(TaskBasicTabPanel.this.getModelObject(), archetypeOid, target, getPageBase());
}
PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
ctx.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(getTask().asPrismObject()));
try {
wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
// TODO ugly hack: after updateWrapper method is called, both previously set items (handlerUri and assignments)
// are marked as NOT_CHANGED with the same value. We need to find a way how to force the ValueStatus
// or change the mechanism for computing deltas. Probably only the first will work
PrismPropertyWrapper<String> handlerWrapper = TaskBasicTabPanel.this.getModelObject().findProperty(ItemPath.create(TaskType.F_HANDLER_URI));
handlerWrapper.getValue().setStatus(ValueStatus.ADDED);
PrismContainerWrapper<AssignmentType> assignmentWrapper = TaskBasicTabPanel.this.getModelObject().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
assignmentWrapperValue.setStatus(ValueStatus.ADDED);
}
}
} catch (SchemaException | IllegalArgumentException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
updateHandlerPerformed(target);
}
};
handlerSelectorPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return satisfyArchetypeAssignment();
}
});
add(handlerSelectorPanel);
ItemVisibilityHandler visibilityHandler = wrapper -> getBasicTabVisibility(wrapper.getPath());
ItemEditabilityHandler editabilityHandler = wrapper -> getBasicTabEditability(wrapper.getPath());
try {
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(visibilityHandler).editabilityHandler(editabilityHandler).mandatoryHandler(getItemMandatoryHandler());
Panel panel = getPageBase().initItemPanel(ID_MAIN_PANEL, TaskType.COMPLEX_TYPE, getModel(), builder.build());
add(panel);
} catch (SchemaException e) {
LOGGER.error("Cannot create task basic panel: {}", e.getMessage(), e);
// TODO opertion result? localization?
getSession().error("Cannot create task basic panel");
throw new RestartResponseException(PageTasks.class);
}
}
Aggregations