Search in sources :

Example 1 with ContainerStatus

use of com.evolveum.midpoint.web.component.prism.ContainerStatus in project midpoint by Evolveum.

the class PageAdminObjectDetails method loadObjectWrapper.

protected ObjectWrapper<O> loadObjectWrapper(PrismObject<O> objectToEdit) {
    Task task = createSimpleTask(OPERATION_LOAD_OBJECT);
    OperationResult result = task.getResult();
    PrismObject<O> object = null;
    Collection<SelectorOptions<GetOperationOptions>> loadOptions = null;
    try {
        if (!isEditingFocus()) {
            if (objectToEdit == null) {
                LOGGER.trace("Loading object: New object (creating)");
                O focusType = createNewObject();
                getMidpointApplication().getPrismContext().adopt(focusType);
                object = (PrismObject<O>) focusType.asPrismObject();
            } else {
                LOGGER.trace("Loading object: New object (supplied): {}", objectToEdit);
                object = objectToEdit;
            }
        } else {
            loadOptions = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
            String focusOid = getObjectOidParameter();
            object = WebModelServiceUtils.loadObject(getCompileTimeClass(), focusOid, loadOptions, this, task, result);
            LOGGER.trace("Loading object: Existing object (loadled): {} -> {}", focusOid, object);
        }
        result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get object.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
    }
    showResult(result, false);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Loaded object:\n{}", object.debugDump());
    }
    if (object == null) {
        if (isEditingFocus()) {
            getSession().error(getString("pageAdminFocus.message.cantEditFocus"));
        } else {
            getSession().error(getString("pageAdminFocus.message.cantNewFocus"));
        }
        throw new RestartResponseException(getRestartResponsePage());
    }
    ContainerStatus status = isEditingFocus() ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
    ObjectWrapper<O> wrapper;
    ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
    try {
        wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, status, task);
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user", ex);
        wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, null, null, status, false);
    }
    wrapper.setLoadOptions(loadOptions);
    showResult(wrapper.getResult(), false);
    loadParentOrgs(wrapper, task, result);
    wrapper.setShowEmpty(!isEditingFocus());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Loaded focus wrapper:\n{}", wrapper.debugDump());
    }
    return wrapper;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ContainerStatus(com.evolveum.midpoint.web.component.prism.ContainerStatus) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 2 with ContainerStatus

use of com.evolveum.midpoint.web.component.prism.ContainerStatus in project midpoint by Evolveum.

the class PageMyPasswordQuestions method loadUserWrapper.

private ObjectWrapper loadUserWrapper(PrismObject<UserType> userToEdit) {
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    PrismObject<UserType> user = null;
    Task task = createSimpleTask(OPERATION_LOAD_USER);
    try {
        Collection options = SelectorOptions.createCollection(UserType.F_CREDENTIALS, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
        user = getModelService().getObject(UserType.class, SecurityUtils.getPrincipalUser().getOid(), options, task, result);
        result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user PageMyQuestions", ex);
    }
    showResult(result, false);
    if (user == null) {
        throw new RestartResponseException(PageDashboard.class);
    }
    ContainerStatus status = ContainerStatus.MODIFYING;
    ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
    ObjectWrapper wrapper;
    try {
        wrapper = owf.createObjectWrapper("pageMyPasswordQuestions.userDetails", null, user, status, task);
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user", ex);
        wrapper = owf.createObjectWrapper("pageMyPasswordQuestions.userDetails", null, user, null, null, status, false);
    }
    //        ObjectWrapper wrapper = new ObjectWrapper("pageUser.userDetails", null, user, status);
    showResult(wrapper.getResult(), false);
    return wrapper;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ContainerStatus(com.evolveum.midpoint.web.component.prism.ContainerStatus) RestartResponseException(org.apache.wicket.RestartResponseException) Collection(java.util.Collection) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException)

Example 3 with ContainerStatus

use of com.evolveum.midpoint.web.component.prism.ContainerStatus in project midpoint by Evolveum.

the class PrismContainerValueWrapperImpl method getChildContainers.

@Override
public List<PrismContainerDefinition<C>> getChildContainers() throws SchemaException {
    List<PrismContainerDefinition<C>> childContainers = new ArrayList<>();
    for (ItemDefinition<?> def : getContainerDefinition().getDefinitions()) {
        if (!(def instanceof PrismContainerDefinition)) {
            continue;
        }
        @SuppressWarnings("unchecked") PrismContainerDefinition<C> containerDef = (PrismContainerDefinition<C>) def;
        ContainerStatus objectStatus = findObjectStatus();
        boolean allowed = false;
        switch(objectStatus) {
            case ADDING:
                allowed = containerDef.canAdd();
                break;
            case MODIFYING:
            case DELETING:
                allowed = containerDef.canModify();
        }
        // do not allow to add already existing singel value container
        if (containerDef.isSingleValue() && findContainer(containerDef.getItemName()) != null) {
            allowed = false;
        }
        if (allowed) {
            childContainers.add(containerDef);
        }
    }
    return childContainers;
}
Also used : ContainerStatus(com.evolveum.midpoint.web.component.prism.ContainerStatus)

Aggregations

ContainerStatus (com.evolveum.midpoint.web.component.prism.ContainerStatus)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 ObjectWrapperFactory (com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 AuthorizationException (com.evolveum.midpoint.util.exception.AuthorizationException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ObjectWrapper (com.evolveum.midpoint.web.component.prism.ObjectWrapper)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Collection (java.util.Collection)1