use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test800EditSchemaJackPropReadAllModifySomeUser.
/**
* MID-3126
*/
@Test
public void test800EditSchemaJackPropReadAllModifySomeUser() throws Exception {
given();
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_PROP_READ_ALL_MODIFY_SOME_USER_OID);
login(USER_JACK_USERNAME);
PrismObject<UserType> user = getUser(USER_JACK_OID);
display("user before", user);
when();
PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(getTestTask(), user, ItemStatus.NOT_CHANGED);
then();
displayDumpable("Wrapper after", objectWrapper);
assertEquals("Wrong object wrapper readOnly", Boolean.FALSE, (Boolean) objectWrapper.isReadOnly());
PrismContainerValueWrapper<UserType> mainContainerValueWrapper = objectWrapper.getValue();
ItemStatus objectStatus = objectWrapper.getStatus();
PrismPropertyWrapper<PolyString> nameWrapper = mainContainerValueWrapper.findProperty(UserType.F_NAME);
// Is this OK?
assertEquals("Wrong name readOnly", Boolean.TRUE, (Boolean) nameWrapper.isReadOnly());
assertEquals("Wrong name visible", Boolean.TRUE, (Boolean) nameWrapper.isVisible(mainContainerValueWrapper, null));
assertEquals("Wrong name definition.canRead", Boolean.TRUE, (Boolean) nameWrapper.canRead());
assertEquals("Wrong name definition.canAdd", Boolean.FALSE, (Boolean) nameWrapper.canAdd());
assertEquals("Wrong name definition.canModify", Boolean.FALSE, (Boolean) nameWrapper.canModify());
PrismPropertyWrapper<PolyString> givenNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_GIVEN_NAME);
// Is this OK?
assertEquals("Wrong givenName readOnly", Boolean.TRUE, (Boolean) givenNameWrapper.isReadOnly());
assertEquals("Wrong givenName visible", Boolean.TRUE, (Boolean) givenNameWrapper.isVisible(mainContainerValueWrapper, null));
assertEquals("Wrong givenName definition.canRead", Boolean.TRUE, (Boolean) givenNameWrapper.canRead());
assertEquals("Wrong givenName definition.canAdd", Boolean.FALSE, (Boolean) givenNameWrapper.canAdd());
assertEquals("Wrong givenName definition.canModify", Boolean.FALSE, (Boolean) givenNameWrapper.canModify());
PrismPropertyWrapper<PolyString> fullNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_FULL_NAME);
assertEquals("Wrong fullName readOnly", Boolean.FALSE, (Boolean) fullNameWrapper.isReadOnly());
assertEquals("Wrong fullName visible", Boolean.TRUE, (Boolean) fullNameWrapper.isVisible(mainContainerValueWrapper, null));
assertEquals("Wrong fullName definition.canRead", Boolean.TRUE, (Boolean) fullNameWrapper.canRead());
assertEquals("Wrong fullName definition.canAdd", Boolean.FALSE, (Boolean) fullNameWrapper.canAdd());
assertEquals("Wrong fullName definition.canModify", Boolean.TRUE, (Boolean) fullNameWrapper.canModify());
PrismPropertyWrapper<String> additionalNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_ADDITIONAL_NAME);
// Is this OK?
assertEquals("Wrong additionalName readOnly", Boolean.TRUE, (Boolean) additionalNameWrapper.isReadOnly());
// not visible, because it is empty
assertEquals("Wrong additionalName visible", Boolean.FALSE, (Boolean) additionalNameWrapper.isVisible(mainContainerValueWrapper, null));
assertEquals("Wrong additionalName definition.canRead", Boolean.TRUE, (Boolean) additionalNameWrapper.canRead());
assertEquals("Wrong additionalName definition.canAdd", Boolean.FALSE, (Boolean) additionalNameWrapper.canAdd());
assertEquals("Wrong additionalName definition.canModify", Boolean.FALSE, (Boolean) additionalNameWrapper.canModify());
PrismPropertyWrapper<String> localityNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_LOCALITY);
assertEquals("Wrong locality readOnly", Boolean.TRUE, (Boolean) localityNameWrapper.isReadOnly());
assertEquals("Wrong locality visible", Boolean.TRUE, (Boolean) localityNameWrapper.isVisible(mainContainerValueWrapper, null));
assertEquals("Wrong locality definition.canRead", Boolean.TRUE, (Boolean) localityNameWrapper.canRead());
assertEquals("Wrong locality definition.canAdd", Boolean.FALSE, (Boolean) localityNameWrapper.canAdd());
assertEquals("Wrong locality definition.canModify", Boolean.FALSE, (Boolean) localityNameWrapper.canModify());
when();
mainContainerValueWrapper.setShowEmpty(true);
then();
additionalNameWrapper = mainContainerValueWrapper.findProperty(UserType.F_ADDITIONAL_NAME);
// visible, because show empty
assertEquals("Wrong additionalName visible", Boolean.TRUE, (Boolean) additionalNameWrapper.isVisible(mainContainerValueWrapper, null));
}
use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class ConfigurationStep method createConfigContainerWrappers.
// @NotNull
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers() throws SchemaException {
PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
if (parentPage.isNewResource()) {
return null;
}
ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
if (configuration == null) {
PrismObject<ConnectorType> connector = ResourceTypeUtil.getConnectorIfPresent(resource);
if (connector == null) {
throw new IllegalStateException("No resolved connector object in resource object");
}
ConnectorType connectorType = connector.asObjectable();
PrismSchema schema;
try {
schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, parentPage.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);
configuration = definitionFixed.instantiate();
configurationStatus = ItemStatus.ADDED;
}
Task task = getPageBase().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
WrapperContext ctx = new WrapperContext(task, getResult());
ctx.setReadOnly(parentPage.isReadOnly());
ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
return getPageBase().createItemWrapper(configuration, configurationStatus, ctx);
}
use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class PrismObjectWrapperFactoryImpl method createValueWrapper.
@Override
public PrismContainerValueWrapper<O> createValueWrapper(PrismContainerWrapper<O> parent, PrismContainerValue<O> value, ValueStatus status, WrapperContext context) throws SchemaException {
PrismContainerValueWrapper<O> objectValueWrapper = super.createValueWrapper(parent, value, status, context);
if (CollectionUtils.isEmpty(context.getVirtualContainers())) {
return objectValueWrapper;
}
for (VirtualContainersSpecificationType virtualContainer : context.getVirtualContainers()) {
if (virtualContainer.getPath() != null) {
continue;
}
MutableComplexTypeDefinition mCtd = getPrismContext().definitionFactory().createComplexTypeDefinition(VIRTUAL_CONTAINER_COMPLEX_TYPE);
DisplayType display = virtualContainer.getDisplay();
// TODO: support full polystring -> translations could be defined directly there.
if (display == null || display.getLabel() == null) {
mCtd.setDisplayName("N/A");
} else {
mCtd.setDisplayName(WebComponentUtil.getOrigStringFromPoly(display.getLabel()));
mCtd.setHelp(WebComponentUtil.getOrigStringFromPoly(display.getHelp()));
}
mCtd.setRuntimeSchema(true);
MutablePrismContainerDefinition<?> def = getPrismContext().definitionFactory().createContainerDefinition(VIRTUAL_CONTAINER, mCtd);
def.setMaxOccurs(1);
if (display != null && display.getLabel() != null) {
def.setDisplayName(WebComponentUtil.getOrigStringFromPoly(display.getLabel()));
}
def.setDynamic(true);
def.setRuntimeSchema(true);
ItemWrapperFactory<?, ?, ?> factory = getRegistry().findWrapperFactory(def, null);
if (factory == null) {
LOGGER.warn("Cannot find factory for {}. Skipping wrapper creation.", def);
continue;
}
WrapperContext ctx = context.clone();
ctx.setVirtualItemSpecification(virtualContainer.getItem());
PrismContainer<?> virtualPrismContainer = def.instantiate();
ItemStatus virtualContainerStatus = context.getObjectStatus() != null ? context.getObjectStatus() : ItemStatus.NOT_CHANGED;
ItemWrapper<?, ?> iw = factory.createWrapper(objectValueWrapper, virtualPrismContainer, virtualContainerStatus, ctx);
if (iw == null) {
continue;
}
if (iw instanceof PrismContainerWrapper) {
PrismContainerWrapper<?> cw = (PrismContainerWrapper<?>) iw;
cw.setIdentifier(virtualContainer.getIdentifier());
cw.setVirtual(true);
if (virtualContainer.isExpanded() != null) {
cw.getValues().forEach(vw -> vw.setExpanded(virtualContainer.isExpanded()));
}
}
iw.setVisibleOverwrite(virtualContainer.getVisibility());
objectValueWrapper.addItem(iw);
}
return objectValueWrapper;
}
use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class ItemWrapperFactoryImpl method determineReadOnly.
private boolean determineReadOnly(IW itemWrapper, WrapperContext context) {
Boolean readOnly = context.getReadOnly();
if (readOnly != null) {
LOGGER.trace("Setting {} as readonly because context said so.", itemWrapper);
return readOnly;
}
ItemStatus objectStatus = context.getObjectStatus();
if (ItemStatus.NOT_CHANGED == objectStatus) {
if (!itemWrapper.canModify()) {
LOGGER.trace("Setting {} as readonly because authZ said so.", itemWrapper);
return true;
}
}
return false;
}
use of com.evolveum.midpoint.gui.api.prism.ItemStatus in project midpoint by Evolveum.
the class ItemWrapperFactoryImpl method createWrapper.
@SuppressWarnings("unchecked")
@Override
public IW createWrapper(PrismContainerValueWrapper<?> parent, ItemDefinition<?> def, WrapperContext context) throws SchemaException {
ItemName name = def.getItemName();
I childItem = (I) parent.getNewValue().findItem(name);
ItemStatus status = getStatus(childItem);
if (skipCreateWrapper(def, status, context, childItem == null || CollectionUtils.isEmpty(childItem.getValues()))) {
LOGGER.trace("Skipping creating wrapper for non-existent item. It is not supported for {}", def);
return null;
}
if (childItem == null) {
childItem = (I) parent.getNewValue().findOrCreateItem(name);
}
return createWrapper(parent, childItem, status, context);
}
Aggregations