Search in sources :

Example 1 with ModelState

use of com.evolveum.midpoint.model.api.context.ModelState in project midpoint by Evolveum.

the class ModelOperationStatusPanel method initLayout.

protected void initLayout() {
    add(new Label(ID_STATE, new StringResourceModel("ModelOperationStatusPanel.state.${}", new PropertyModel<ModelState>(getModel(), ModelOperationStatusDto.F_STATE))));
    // add(new Label(ID_FOCUS_TYPE, new PropertyModel<String>(getModel(), ModelOperationStatusDto.F_FOCUS_TYPE)));
    // add(new Label(ID_FOCUS_NAME, new PropertyModel<String>(getModel(), ModelOperationStatusDto.F_FOCUS_NAME)));
    ScenePanel deltaPanel = new ScenePanel(ID_PRIMARY_DELTA, new PropertyModel<>(getModel(), ModelOperationStatusDto.F_PRIMARY_DELTA));
    deltaPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject() != null && getModelObject().getPrimaryDelta() != null;
        }
    });
    add(deltaPanel);
}
Also used : ScenePanel(com.evolveum.midpoint.web.component.prism.show.ScenePanel) Label(org.apache.wicket.markup.html.basic.Label) ModelState(com.evolveum.midpoint.model.api.context.ModelState) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 2 with ModelState

use of com.evolveum.midpoint.model.api.context.ModelState in project midpoint by Evolveum.

the class Clockwork method click.

public <F extends ObjectType> HookOperationMode click(LensContext<F> context, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (context.getDebugListener() == null) {
        context.setDebugListener(debugListener);
    }
    try {
        XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
        // We need to determine focus before auditing. Otherwise we will not know user
        // for the accounts (unless there is a specific delta for it).
        // This is ugly, but it is the easiest way now (TODO: cleanup).
        contextLoader.determineFocusContext((LensContext<? extends FocusType>) context, result);
        ModelState state = context.getState();
        if (state == ModelState.INITIAL) {
            if (debugListener != null) {
                debugListener.beforeSync(context);
            }
            metadataManager.applyRequestMetadata(context, now, task, result);
            context.getStats().setRequestTimestamp(now);
            // We need to do this BEFORE projection. If we would do that after projection
            // there will be secondary changes that are not part of the request.
            audit(context, AuditEventStage.REQUEST, task, result);
        }
        boolean recompute = false;
        if (!context.isFresh()) {
            LOGGER.trace("Context is not fresh -- forcing cleanup and recomputation");
            recompute = true;
        } else if (context.getExecutionWave() > context.getProjectionWave()) {
            // should not occur
            LOGGER.warn("Execution wave is greater than projection wave -- forcing cleanup and recomputation");
            recompute = true;
        }
        if (recompute) {
            context.cleanup();
            projector.project(context, "PROJECTOR (" + state + ")", task, result);
        } else if (context.getExecutionWave() == context.getProjectionWave()) {
            LOGGER.trace("Running projector for current execution wave");
            projector.resume(context, "PROJECTOR (" + state + ")", task, result);
        } else {
            LOGGER.trace("Skipping projection because the context is fresh and projection for current wave has already run");
        }
        if (!context.isRequestAuthorized()) {
            authorizeContextRequest(context, task, result);
        }
        LensUtil.traceContext(LOGGER, "CLOCKWORK (" + state + ")", "before processing", true, context, false);
        if (InternalsConfig.consistencyChecks) {
            try {
                context.checkConsistence();
            } catch (IllegalStateException e) {
                throw new IllegalStateException(e.getMessage() + " in clockwork, state=" + state, e);
            }
        }
        if (InternalsConfig.encryptionChecks && !ModelExecuteOptions.isNoCrypt(context.getOptions())) {
            context.checkEncrypted();
        }
        switch(state) {
            case INITIAL:
                processInitialToPrimary(context, task, result);
                break;
            case PRIMARY:
                processPrimaryToSecondary(context, task, result);
                break;
            case SECONDARY:
                processSecondary(context, task, result);
                break;
            case FINAL:
                HookOperationMode mode = processFinal(context, task, result);
                if (debugListener != null) {
                    debugListener.afterSync(context);
                }
                return mode;
        }
        result.recomputeStatus();
        result.cleanupResult();
        return invokeHooks(context, task, result);
    } catch (CommunicationException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException | PolicyViolationException | SchemaException | SecurityViolationException | RuntimeException | ObjectAlreadyExistsException e) {
        processClockworkException(context, e, task, result);
        throw e;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ModelState(com.evolveum.midpoint.model.api.context.ModelState) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 3 with ModelState

use of com.evolveum.midpoint.model.api.context.ModelState in project midpoint by Evolveum.

the class ReportManagerImpl method invoke.

/**
     * Transforms change:
     * 1/ ReportOutputType DELETE to MODIFY some attribute to mark it for deletion.
     * 2/ ReportType ADD and MODIFY should compute jasper design and styles if necessary
     *
     * @param context
     * @param task
     * @param result
     * @return
     * @throws UnsupportedEncodingException 
     */
@Override
public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task task, @NotNull OperationResult parentResult) {
    ModelState state = context.getState();
    if (state != ModelState.FINAL) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("report manager called in state = " + state + ", exiting.");
        }
        return HookOperationMode.FOREGROUND;
    } else {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("report manager called in state = " + state + ", proceeding.");
        }
    }
    boolean relatesToReport = false;
    boolean isDeletion = false;
    PrismObject<?> object = null;
    for (Object o : context.getProjectionContexts()) {
        boolean deletion = false;
        object = ((ModelElementContext<?>) o).getObjectNew();
        if (object == null) {
            deletion = true;
            object = ((ModelElementContext<?>) o).getObjectOld();
        }
        if (object == null) {
            LOGGER.warn("Probably invalid projection context: both old and new objects are null");
        } else if (object.getCompileTimeClass().isAssignableFrom(ReportType.class)) {
            relatesToReport = true;
            isDeletion = deletion;
        }
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("change relates to report: " + relatesToReport + ", is deletion: " + isDeletion);
    }
    if (!relatesToReport) {
        LOGGER.trace("invoke() EXITING: Changes not related to report");
        return HookOperationMode.FOREGROUND;
    }
    if (isDeletion) {
        LOGGER.trace("invoke() EXITING because operation is DELETION");
        return HookOperationMode.FOREGROUND;
    }
    OperationResult result = parentResult.createSubresult(CLASS_NAME_WITH_DOT + "invoke");
    try {
        ReportType reportType = (ReportType) object.asObjectable();
        JasperDesign jasperDesign = null;
        if (reportType.getTemplate() == null) {
            String message = "Report template must not be null";
            LOGGER.error(message);
            result.recordFatalError(message, new SystemException());
        } else //             {
        //            	 PrismSchema reportSchema = null;
        //            	 PrismContainer<ReportConfigurationType> parameterConfiguration = null;  
        //            	 try
        //            	 {
        //            		reportSchema = ReportUtils.getParametersSchema(reportType, prismContext);
        //            		parameterConfiguration = ReportUtils.getParametersContainer(reportType, reportSchema);
        //             		
        //            	 } catch (Exception ex){
        //            		 String message = "Cannot create parameter configuration: " + ex.getMessage();
        //            		 LOGGER.error(message);
        //            		 result.recordFatalError(message, ex);
        //            	 }
        //            	 
        //            	 jasperDesign = ReportUtils.createJasperDesign(reportType, parameterConfiguration, reportSchema) ;
        //            	 LOGGER.trace("create jasper design : {}", jasperDesign);
        //             }
        {
            byte[] reportTemplateBase64 = reportType.getTemplate();
            byte[] reportTemplate = Base64.decodeBase64(reportTemplateBase64);
            InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
            jasperDesign = JRXmlLoader.load(inputStreamJRXML);
            LOGGER.trace("load jasper design : {}", jasperDesign);
        }
        // Compile template
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
        //result.computeStatus();
        result.recordSuccessIfUnknown();
    } catch (JRException ex) {
        String message = "Cannot load or compile jasper report: " + ex.getMessage();
        LOGGER.error(message);
        result.recordFatalError(message, ex);
    }
    return HookOperationMode.FOREGROUND;
}
Also used : JasperDesign(net.sf.jasperreports.engine.design.JasperDesign) JRException(net.sf.jasperreports.engine.JRException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ModelState(com.evolveum.midpoint.model.api.context.ModelState) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JasperReport(net.sf.jasperreports.engine.JasperReport) ByteArrayInputStream(java.io.ByteArrayInputStream) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 4 with ModelState

use of com.evolveum.midpoint.model.api.context.ModelState in project midpoint by Evolveum.

the class SystemConfigurationHandler method invoke.

@Override
public <O extends ObjectType> HookOperationMode invoke(@NotNull ModelContext<O> context, @NotNull Task task, @NotNull OperationResult parentResult) {
    ModelState state = context.getState();
    if (state != ModelState.FINAL) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("sysconfig handler called in state = " + state + ", exiting.");
        }
        return HookOperationMode.FOREGROUND;
    } else {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("sysconfig handler called in state = " + state + ", proceeding.");
        }
    }
    if (context.getFocusClass() != SystemConfigurationType.class) {
        LOGGER.trace("invoke() EXITING: Changes not related to systemConfiguration");
        return HookOperationMode.FOREGROUND;
    }
    ModelContext<SystemConfigurationType> confContext = (ModelContext<SystemConfigurationType>) context;
    ModelElementContext<SystemConfigurationType> focusContext = confContext.getFocusContext();
    // is this config-related change a deletion?
    boolean isDeletion = false;
    PrismObject<SystemConfigurationType> object = focusContext.getObjectNew();
    if (object == null) {
        isDeletion = true;
        object = focusContext.getObjectOld();
    }
    if (object == null) {
        // if the handler would not work because of this, for us to see the reason
        LOGGER.warn("Probably invalid projection context: both old and new objects are null");
    }
    LOGGER.trace("change relates to sysconfig, is deletion: {}", isDeletion);
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "invoke");
    try {
        if (isDeletion) {
            // because the new config (if any) will have version number probably starting at 1 - so to be sure to read it when it comes
            LoggingConfigurationManager.resetCurrentlyUsedVersion();
            LOGGER.trace("invoke() EXITING because operation is DELETION");
            return HookOperationMode.FOREGROUND;
        }
        /*
             * Because we need to know actual version of the system configuration (generated by repo), we have to re-read
             * current configuration. (At this moment, it is already stored there.)
             */
        PrismObject<SystemConfigurationType> config = cacheRepositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result);
        LOGGER.trace("invoke() SystemConfig from repo: {}, ApplyingLoggingConfiguration", config.getVersion());
        SystemConfigurationHolder.setCurrentConfiguration(config.asObjectable());
        SecurityUtil.setRemoteHostAddressHeaders(config.asObjectable());
        applyLoggingConfiguration(ProfilingConfigurationManager.checkSystemProfilingConfiguration(config), config.asObjectable().getVersion(), result);
        cacheRepositoryService.applyFullTextSearchConfiguration(config.asObjectable().getFullTextSearch());
        result.recordSuccessIfUnknown();
    } catch (ObjectNotFoundException e) {
        String message = "Cannot read system configuration because it does not exist in repository: " + e.getMessage();
        LoggingUtils.logException(LOGGER, message, e);
        result.recordFatalError(message, e);
    } catch (SchemaException e) {
        String message = "Cannot read system configuration because of schema exception: " + e.getMessage();
        LoggingUtils.logException(LOGGER, message, e);
        result.recordFatalError(message, e);
    }
    return HookOperationMode.FOREGROUND;
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ModelState(com.evolveum.midpoint.model.api.context.ModelState) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 5 with ModelState

use of com.evolveum.midpoint.model.api.context.ModelState in project midpoint by Evolveum.

the class ClockworkClick method click.

public HookOperationMode click(OperationResult parentResult) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException, ConflictDetectedException {
    if (context.getInspector() == null) {
        context.setInspector(beans.medic.getClockworkInspector());
    }
    OperationResult result = parentResult.subresult(OP_CLICK).addQualifier(context.getOperationQualifier()).addArbitraryObjectAsContext("context", context).addArbitraryObjectAsContext("task", task).build();
    createTraceIfNeeded(result);
    try {
        // We need to determine focus before auditing. Otherwise we will not know user
        // for the accounts (unless there is a specific delta for it).
        // This is ugly, but it is the easiest way now (TODO: cleanup).
        beans.contextLoader.loadFocusContext(context, task, result);
        ModelState state = context.getState();
        if (state == ModelState.INITIAL) {
            beans.medic.clockworkStart(context);
            beans.metadataManager.setRequestMetadataInContext(context, now, task);
            context.getStats().setRequestTimestamp(now);
            context.generateRequestIdentifierIfNeeded();
            // We need to do this BEFORE projection. If we would do that after projection
            // there will be secondary changes that are not part of the request.
            // As for the results: we need also the overall ("Clockwork.run") operation result.
            beans.clockworkAuditHelper.audit(context, AuditEventStage.REQUEST, task, result, parentResult);
        }
        if (state != ModelState.FINAL) {
            projectIfNeeded(result);
        }
        checkIndestructible(result);
        if (!context.isRequestAuthorized()) {
            beans.clockworkAuthorizationHelper.authorizeContextRequest(context, task, result);
        }
        beans.medic.traceContext(LOGGER, "CLOCKWORK (" + state + ")", "before processing", true, context, false);
        context.checkConsistenceIfNeeded();
        context.checkEncryptedIfNeeded();
        return moveStateForward(parentResult, result, state);
    } catch (CommunicationException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException | PolicyViolationException | SchemaException | SecurityViolationException | RuntimeException | Error | ObjectAlreadyExistsException | ConflictDetectedException e) {
        processClockworkException(e, result, parentResult);
        throw e;
    } finally {
        finishTrace(result);
        // Maybe this should be "composite" instead.
        result.computeStatusIfUnknown();
        result.cleanupResultDeeply();
    }
}
Also used : ModelState(com.evolveum.midpoint.model.api.context.ModelState) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

ModelState (com.evolveum.midpoint.model.api.context.ModelState)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 ScenePanel (com.evolveum.midpoint.web.component.prism.show.ScenePanel)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 JRException (net.sf.jasperreports.engine.JRException)1