use of com.evolveum.midpoint.gui.api.prism.ItemStatus 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.prism.ItemStatus 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.prism.ItemStatus in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test110CreateWrapperUserNewEmpty.
/**
* Create wrapper for brand new empty user.
*/
@Test
public void test110CreateWrapperUserNewEmpty() throws Exception {
PrismObject<UserType> user = getUserDefinition().instantiate();
when();
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObjectWrapperFactory<UserType> factory = getServiceLocator(task).findObjectWrapperFactory(user.getDefinition());
WrapperContext context = new WrapperContext(task, result);
context.setCreateIfEmpty(true);
context.setShowEmpty(true);
PrismObjectWrapper<UserType> objectWrapper = factory.createObjectWrapper(user, ItemStatus.ADDED, context);
then();
displayDumpable("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), "user description", user, getUserDefinition().instantiate(), ItemStatus.ADDED);
assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, null);
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
PrismContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(UserType.F_ACTIVATION);
WrapperTestUtil.assertWrapper(activationContainerWrapper, getString("ActivationType.activation"), UserType.F_ACTIVATION, user, ItemStatus.ADDED);
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, null);
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);
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, 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(false);
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, false);
// empty
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
ObjectDelta<UserType> objectDelta = objectWrapper.getObjectDelta();
displayDumpable("Delta", objectDelta);
assertTrue("non-add delta produced from wrapper: " + objectDelta, objectDelta.isAdd());
PrismObject<UserType> objectToAdd = objectDelta.getObjectToAdd();
assertTrue("non-empty object in add delta produced from wrapper: " + objectDelta, objectToAdd.isEmpty());
}
use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test102CreateWrapperUserEmpty.
@Test
public void test102CreateWrapperUserEmpty() throws Exception {
PrismObject<UserType> user = getUser(USER_EMPTY_OID);
PrismObject<UserType> userOld = user.clone();
when();
Task task = createTask();
OperationResult result = task.getResult();
ModelServiceLocator modelServiceLocator = getServiceLocator(task);
PrismObjectWrapperFactory<UserType> factory = modelServiceLocator.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);
WrapperTestUtil.assertWrapper(objectWrapper, getString("prismContainer.mainPanelDisplayName"), null, user, ItemStatus.NOT_CHANGED);
assertEquals("wrong number of containers in " + objectWrapper, 1, objectWrapper.getValues().size());
PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_NAME, PrismTestUtil.createPolyString(USER_EMPTY_USERNAME));
WrapperTestUtil.assertPropertyWrapperByName(mainContainerValueWrapper, UserType.F_TIMEZONE, null);
// Not sure about this
// ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainer(ItemPath.create(UserType.F_ACTIVATION));
// assertNull("Unexpected activation "+activationContainerWrapper, activationContainerWrapper);
assertEquals("Wrong main container wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
ItemStatus objectStatus = objectWrapper.getStatus();
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, false);
// empty
assertItemWrapperFullControl(mainContainerValueWrapper, UserType.F_LOCALITY, false);
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());
}
Aggregations