use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class ResourceDetailsModel method createConfigContainerWrappers.
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers(OperationResult result) throws SchemaException {
Task task = getModelServiceLocator().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
PrismObjectWrapper<ResourceType> resourceWrapper = getObjectWrapper();
PrismContainerWrapper<ConnectorConfigurationType> configuration = resourceWrapper.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<ConnectorConfigurationType> connectorConfigurationType = null;
ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
if (configuration == null || configuration.isEmpty()) {
PrismReferenceWrapper<Referencable> connectorRef = resourceWrapper.findReference(ResourceType.F_CONNECTOR_REF);
if (connectorRef == null || connectorRef.getValue() == null || connectorRef.getValue().getRealValue() == null) {
return null;
}
PrismObject<ConnectorType> connector = WebModelServiceUtils.resolveReferenceNoFetch(connectorRef.getValue().getRealValue(), getPageBase(), task, result);
if (connector == null) {
return null;
}
ConnectorType connectorType = connector.asObjectable();
PrismSchema schema;
try {
schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, getPrismContext());
} catch (SchemaException e) {
throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
}
PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
// Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
definitionFixed.toMutable().setMaxOccurs(1);
connectorConfigurationType = definitionFixed.instantiate();
configurationStatus = ItemStatus.ADDED;
WrapperContext ctx = new WrapperContext(task, result);
ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
configuration = getModelServiceLocator().createItemWrapper(connectorConfigurationType, configurationStatus, ctx);
}
return configuration;
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class PageAdminObjectDetails method createObjectWrapper.
private PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, boolean isReadonly, Task task, OperationResult result) {
ItemStatus itemStatus = computeWrapperStatus();
PrismObjectWrapperFactory<O> factory = getRegistry().getObjectWrapperFactory(object.getDefinition());
WrapperContext context = new WrapperContext(task, result);
context.setCreateIfEmpty(ItemStatus.ADDED == itemStatus);
context.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(object));
// Boolean instead of boolean isReadonly
if (isReadonly) {
context.setReadOnly(isReadonly);
}
try {
PrismObjectWrapper<O> wrapper = factory.createObjectWrapper(object, itemStatus, context);
result.recordSuccess();
return wrapper;
} catch (Exception ex) {
result.recordFatalError(getString("PageAdminObjectDetails.message.loadObjectWrapper.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
showResult(result, false);
throw new RestartResponseException(getRestartResponsePage());
}
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class PrismContainerValuePanel method prepareNewContainers.
private void prepareNewContainers(AjaxRequestTarget target, List<PrismContainerDefinition<?>> containers) {
Task task = getPageBase().createSimpleTask("Create child containers");
WrapperContext ctx = new WrapperContext(task, task.getResult());
ctx.setCreateIfEmpty(true);
containers.forEach(container -> {
try {
ItemWrapper iw = getPageBase().createItemWrapper(container, getModelObject(), ctx);
if (iw != null) {
getModelObject().addItem(iw);
}
} catch (SchemaException e) {
OperationResult result = ctx.getResult();
result.recordFatalError(createStringResource("PrismContainerValuePanel.message.prepareNewContainers.fatalError", container).getString(), e);
getPageBase().showResult(ctx.getResult());
}
});
refreshPanel(target);
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class FocusProjectionsTabPanel method addSelectedAccountPerformed.
private void addSelectedAccountPerformed(AjaxRequestTarget target, List<ResourceType> newResources) {
getPageBase().hideMainPopup(target);
if (newResources.isEmpty()) {
warn(getString("pageUser.message.noResourceSelected"));
return;
}
for (ResourceType resource : newResources) {
try {
ShadowType shadow = new ShadowType();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.asReferenceValue().setObject(resource.asPrismObject());
shadow.setResourceRef(resourceRef);
ResourceType usedResource = resource;
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource.asPrismObject(), LayerType.PRESENTATION);
if (refinedSchema == null) {
Task task = getPageBase().createSimpleTask(FocusPersonasTabPanel.class.getSimpleName() + ".loadResource");
OperationResult result = task.getResult();
PrismObject<ResourceType> loadedResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
result.recomputeStatus();
refinedSchema = ResourceSchemaFactory.getCompleteSchema(loadedResource, LayerType.PRESENTATION);
if (refinedSchema == null) {
error(getString("pageAdminFocus.message.couldntCreateAccountNoSchema", resource.getName()));
continue;
}
// shadow.setResource(loadedResource.asObjectable());
usedResource = loadedResource.asObjectable();
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined schema for {}\n{}", resource, refinedSchema.debugDump());
}
ResourceObjectTypeDefinition accountDefinition = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
if (accountDefinition == null) {
error(getString("pageAdminFocus.message.couldntCreateAccountNoAccountSchema", resource.getName()));
continue;
}
// shadow.asPrismContainer().findOrCreateContainer(ShadowType.F_ATTRIBUTES).applyDefinition(accountDefinition.toResourceAttributeContainerDefinition());
QName objectClass = accountDefinition.getObjectClassDefinition().getTypeName();
ObjectReferenceType usedResourceRef = new ObjectReferenceType();
usedResourceRef.asReferenceValue().setObject(usedResource.asPrismObject());
shadow.setResourceRef(usedResourceRef);
shadow.setObjectClass(objectClass);
shadow.setIntent(accountDefinition.getIntent());
shadow.setKind(accountDefinition.getKind());
getPrismContext().adopt(shadow);
Task task = getPageBase().createSimpleTask(OPERATION_ADD_ACCOUNT);
PrismObjectWrapperFactory<ShadowType> factory = getPageBase().getRegistry().getObjectWrapperFactory(shadow.asPrismContainer().getDefinition());
WrapperContext context = new WrapperContext(task, task.getResult());
ShadowWrapper wrapperNew = (ShadowWrapper) factory.createObjectWrapper(shadow.asPrismContainer(), ItemStatus.ADDED, context);
if (task.getResult() != null && !WebComponentUtil.isSuccessOrHandledError(task.getResult())) {
showResult(task.getResult(), false);
}
wrapperNew.setProjectionStatus(UserDtoStatus.ADD);
projectionModel.getObject().add(wrapperNew);
} catch (Exception ex) {
error(getString("pageAdminFocus.message.couldntCreateAccount", resource.getName(), ex.getMessage()));
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create account", ex);
}
}
target.add(getMultivalueContainerListPanel());
}
use of com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext in project midpoint by Evolveum.
the class TestWrapperDelta method test110modifyUserAddAssignment.
@Test
public void test110modifyUserAddAssignment() 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);
PrismContainerValue<AssignmentType> newAssignmentClone = createDummyResourceAssignment(objectWrapper, 0, task, result);
ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
assertModificationsSize(delta, 1);
assertModification(delta, UserType.F_ASSIGNMENT, ModificationTypeType.ADD, newAssignmentClone.asContainerable());
executeChanges(delta, null, task, result);
display(result);
assertSuccess(result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
UserAsserter.forUser(userElaineAfter).assignments().assertAssignments(1);
PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
List<PrismContainerValue<AssignmentType>> assignmentValues = assignmentAfter.getValues();
assertEquals("Unexpected number of assignments " + assignmentValues.size(), 1, assignmentValues.size());
PrismContainerValue<AssignmentType> assignmentValue = assignmentValues.iterator().next();
assertTrue(newAssignmentClone.equals(assignmentValue, ParameterizedEquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS));
}
Aggregations