Search in sources :

Example 51 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageCaseWorkItem method loadCaseIfNecessary.

private CaseType loadCaseIfNecessary() {
    if (caseModel.isLoaded()) {
        return caseModel.getObject();
    }
    Task task = createSimpleTask(OPERATION_LOAD_CASE);
    OperationResult result = task.getResult();
    CaseType caseInstance = null;
    try {
        PrismObject<CaseType> caseObject = // optionsBuilder.build(),
        WebModelServiceUtils.loadObject(// optionsBuilder.build(),
        CaseType.class, // optionsBuilder.build(),
        workItemId.getCaseOid(), // optionsBuilder.build(),
        null, PageCaseWorkItem.this, task, result);
        caseInstance = caseObject.asObjectable();
        result.recordSuccessIfUnknown();
    } catch (RestartResponseException e) {
        // already processed
        throw e;
    } catch (NullPointerException ex) {
        result.recordFatalError(getString("PageCaseWorkItem.couldNotGetCase"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get case because it does not exist. (It might have been already completed or deleted.)", ex);
    } catch (RuntimeException ex) {
        result.recordFatalError(getString("PageCaseWorkItem.couldNotGetCase.runtime"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get case.", ex);
    }
    showResult(result, false);
    if (!result.isSuccess()) {
        throw redirectBackViaRestartResponseException();
    }
    return caseInstance;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 52 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageDebugDownloadBehaviour method initFile.

@Override
protected File initFile() {
    PageBase page = getPage();
    OperationResult result = new OperationResult(OPERATION_CREATE_DOWNLOAD_FILE);
    MidPointApplication application = page.getMidpointApplication();
    WebApplicationConfiguration config = application.getWebApplicationConfiguration();
    File folder = new File(config.getExportFolder());
    if (!folder.exists() || !folder.isDirectory()) {
        folder.mkdir();
    }
    String suffix = isUseZip() ? "zip" : "xml";
    String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_m_s"));
    String fileName = "ExportedData_" + getType().getSimpleName() + "_" + currentTime + "." + suffix;
    File file = new File(folder, fileName);
    LOGGER.debug("Creating file '{}'.", file.getAbsolutePath());
    try (Writer writer = createWriter(file)) {
        LOGGER.debug("Exporting objects.");
        dumpHeader(writer);
        dumpObjectsToStream(writer, result);
        dumpFooter(writer);
        LOGGER.debug("Export finished.");
        result.recomputeStatus();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't init download link", ex);
        result.recordFatalError(getPage().createStringResource("PageDebugDownloadBehaviour.message.initFile.fatalError").getString(), ex);
    }
    if (!WebComponentUtil.isSuccessOrHandledError(result)) {
        page.showResult(result);
        page.getSession().error(page.getString("pageDebugList.message.createFileException"));
        LOGGER.debug("Removing file '{}'.", file.getAbsolutePath());
        Files.remove(file);
        throw new RestartResponseException(PageDebugList.class);
    }
    return file;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) RestartResponseException(org.apache.wicket.RestartResponseException) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) File(org.apache.wicket.util.file.File) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 53 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class ObjectDataProvider method internalSize.

@Override
protected int internalSize() {
    LOGGER.trace("begin::internalSize()");
    int count = 0;
    OperationResult result = new OperationResult(OPERATION_COUNT_OBJECTS);
    try {
        Task task = getPageBase().createSimpleTask(OPERATION_COUNT_OBJECTS);
        count = getModel().countObjects(getType(), getQuery(), getOptionsToUse(), task, result);
    } catch (Exception ex) {
        result.recordFatalError(getPageBase().createStringResource("ObjectDataProvider.message.countObjects.fatalError").getString(), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count objects", ex);
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!WebComponentUtil.isSuccessOrHandledError(result) && !OperationResultStatus.NOT_APPLICABLE.equals(result.getStatus())) {
        getPageBase().showResult(result);
        throw new RestartResponseException(PageError.class);
    }
    LOGGER.trace("end::internalSize(): {}", count);
    return count;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 54 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageSelfRegistration method prepareUserToSave.

private UserType prepareUserToSave(Task task, OperationResult result) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    SelfRegistrationDto selfRegistrationConfiguration = getSelfRegistrationConfiguration();
    UserType userType = getUserModel().getObject();
    UserType userToSave = userType.clone();
    if (!isCustomFormDefined()) {
        applyPassword(userToSave);
        if (selfRegistrationConfiguration.getRequiredLifecycleState() != null) {
            String userLifecycle = userToSave.getLifecycleState();
            if (!selfRegistrationConfiguration.getRequiredLifecycleState().equals(userLifecycle)) {
                LOGGER.error("Registration not allowed for a user {} -> Unsatisfied Configuration for required lifecycle, expected {} but was {}", userToSave.getEmailAddress() != null ? userToSave.getEmailAddress() : userToSave, selfRegistrationConfiguration.getRequiredLifecycleState(), userLifecycle);
                getSession().error(createStringResource("PageSelfRegistration.registration.failed.unsatisfied.registration.configuration").getString());
                throw new RestartResponseException(this);
            }
        }
    } else {
        try {
            userToSave = getDynamicFormPanel().getObject().asObjectable().clone();
        } catch (SchemaException e) {
            LoggingUtils.logException(LOGGER, "Failed to construct delta " + e.getMessage(), e);
            throw new RestartResponseException(this);
        }
    }
    // CredentialsType credentials =
    applyNonce(userToSave, selfRegistrationConfiguration.getNoncePolicy(), task, result);
    // userToSave.setCredentials(credentials);
    if (selfRegistrationConfiguration.getInitialLifecycleState() != null) {
        LOGGER.trace("Setting initial lifecycle state of registered user to {}", selfRegistrationConfiguration.getInitialLifecycleState());
        userToSave.setLifecycleState(selfRegistrationConfiguration.getInitialLifecycleState());
    }
    try {
        getPrismContext().adopt(userToSave);
    } catch (SchemaException e) {
    // nothing to do, try without it
    }
    return userToSave;
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException)

Example 55 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageSelfRegistration method createUserModel.

private UserType createUserModel(String userOid) {
    if (userOid == null) {
        LOGGER.trace("Registration process for new user started");
        return instantiateUser();
    }
    PrismObject<UserType> result = runPrivileged(new Producer<PrismObject<UserType>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public PrismObject<UserType> run() {
            LOGGER.trace("Loading preregistered user with oid {}.", userOid);
            Task task = createAnonymousTask(OPERATION_LOAD_USER);
            OperationResult result = new OperationResult(OPERATION_LOAD_USER);
            PrismObject<UserType> user = WebModelServiceUtils.loadObject(UserType.class, userOid, PageSelfRegistration.this, task, result);
            result.computeStatus();
            return user;
        }
    });
    if (result == null) {
        LOGGER.error("Failed to load preregistered user");
        getSession().error(createStringResource("PageSelfRegistration.invalid.registration.link").getString());
        throw new RestartResponseException(PageLogin.class);
    }
    return result.asObjectable();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

RestartResponseException (org.apache.wicket.RestartResponseException)73 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 Task (com.evolveum.midpoint.task.api.Task)27 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)20 ArrayList (java.util.ArrayList)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 CommonException (com.evolveum.midpoint.util.exception.CommonException)8 SecurityPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)5 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)5 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 PageError (com.evolveum.midpoint.web.page.error.PageError)5 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 Collection (java.util.Collection)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 IModel (org.apache.wicket.model.IModel)4 StringValue (org.apache.wicket.util.string.StringValue)4