Search in sources :

Example 16 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class CaseTypeUtil method getCase.

public static CaseType getCase(CaseWorkItemType workItem) {
    if (workItem == null) {
        return null;
    }
    @SuppressWarnings({ "unchecked", "raw" }) PrismContainerable<CaseWorkItemType> parent = workItem.asPrismContainerValue().getParent();
    if (!(parent instanceof PrismContainer)) {
        return null;
    }
    PrismValue parentParent = ((PrismContainer<CaseWorkItemType>) parent).getParent();
    if (!(parentParent instanceof PrismObjectValue)) {
        return null;
    }
    @SuppressWarnings({ "unchecked", "raw" }) PrismObjectValue<CaseType> parentParentPov = (PrismObjectValue<CaseType>) parentParent;
    return parentParentPov.asObjectable();
}
Also used : PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 17 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PageReport method finishProcessing.

@Override
public void finishProcessing(AjaxRequestTarget target, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas, boolean returningFromAsync, OperationResult result) {
    if (runReport && !result.isError()) {
        showResult(result);
        PrismObject<ReportType> report;
        if (getObjectModel().getObject().getOid() != null) {
            report = getObjectModel().getObject().getObject();
        } else {
            report = (PrismObject<ReportType>) executedDeltas.iterator().next().getObjectDelta().getObjectToAdd();
        }
        if (hasNotParameters(report.asObjectable())) {
            try {
                Task task = createSimpleTask("run_task");
                getReportManager().runReport(report, null, task, result);
            } catch (Exception ex) {
                result.recordFatalError(ex);
            } finally {
                result.computeStatusIfUnknown();
            }
            showResult(result);
            if (!isKeepDisplayingResults()) {
                redirectBack();
            } else {
                target.add(getFeedbackPanel());
            }
        } else {
            RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(getMainPopupBodyId(), report.asObjectable()) {

                private static final long serialVersionUID = 1L;

                @Override
                public StringResourceModel getTitle() {
                    return createStringResource("PageReport.reportPreview");
                }

                protected void runConfirmPerformed(AjaxRequestTarget target, PrismObject<ReportType> reportType, PrismContainer<ReportParameterType> reportParam) {
                    try {
                        Task task = createSimpleTask("run_task");
                        getReportManager().runReport(reportType, reportParam, task, result);
                    } catch (Exception ex) {
                        result.recordFatalError(ex);
                    } finally {
                        result.computeStatusIfUnknown();
                    }
                    hideMainPopup(target);
                    showResult(result);
                    if (!isKeepDisplayingResults()) {
                        redirectBack();
                    } else {
                        target.add(getFeedbackPanel());
                    }
                }
            };
            showMainPopup(runReportPopupPanel, target);
        }
        this.runReport = false;
    } else if (!isKeepDisplayingResults()) {
        showResult(result);
        redirectBack();
    }
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) RunReportPopupPanel(com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)

Example 18 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PolicyRuleTypeUtil method computePathToRoot.

@SuppressWarnings("unchecked")
private static void computePathToRoot(List<String> path, PrismContainerValue<? extends AbstractPolicyConstraintType> pc) {
    path.add(pc.asContainerable().getName());
    if (pc.getParent() instanceof PrismContainer) {
        PrismContainer<? extends AbstractPolicyConstraintType> container = (PrismContainer<? extends AbstractPolicyConstraintType>) pc.getParent();
        PrismValue containerParentValue = container.getParent();
        if (containerParentValue != null && ((PrismContainerValue) containerParentValue).asContainerable() instanceof AbstractPolicyConstraintType) {
            computePathToRoot(path, ((PrismContainerValue) container.getParent()));
        }
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 19 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PageSelfDashboard method createAssignmentItem.

private AssignmentItemDto createAssignmentItem(PrismObject<UserType> user, PrismContainerValue<AssignmentType> assignment, Task task, OperationResult result) {
    ActivationType activation = assignment.asContainerable().getActivation();
    if (activation != null && activation.getAdministrativeStatus() != null && !activation.getAdministrativeStatus().equals(ActivationStatusType.ENABLED)) {
        return null;
    }
    PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
    if (targetRef == null || targetRef.isEmpty()) {
        // account construction
        PrismContainer construction = assignment.findContainer(AssignmentType.F_CONSTRUCTION);
        String name = null;
        String description = "";
        if (construction.getValue().asContainerable() != null && !construction.isEmpty()) {
            ConstructionType constr = (ConstructionType) construction.getValue().asContainerable();
            if (constr.getResourceRef() != null) {
                ObjectReferenceType resourceRef = constr.getResourceRef();
                PrismObject resource = WebModelServiceUtils.loadObject(ResourceType.class, resourceRef.getOid(), this, task, result);
                name = WebComponentUtil.getName(resource);
                description = constr.getDescription();
            }
        }
        return new AssignmentItemDto(AssignmentEditorDtoType.CONSTRUCTION, name, description, null);
    }
    PrismReferenceValue refValue = targetRef.getValue();
    PrismObject value = refValue.getObject();
    if (value == null) {
        // resolve reference
        value = WebModelServiceUtils.loadObject(ObjectType.class, refValue.getOid(), this, task, result);
    }
    if (value == null) {
        // we couldn't resolve assignment details
        return new AssignmentItemDto(null, null, null, null);
    }
    String name = WebComponentUtil.getDisplayNameOrName(value);
    AssignmentEditorDtoType type = AssignmentEditorDtoType.getType(value.getCompileTimeClass());
    String relation = refValue.getRelation() != null ? refValue.getRelation().getLocalPart() : null;
    return new AssignmentItemDto(type, name, getAssignmentDescription(value), relation);
}
Also used : AssignmentEditorDtoType(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDtoType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) AssignmentItemDto(com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto)

Example 20 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class NoOpTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(NoOpTaskHandler.class.getName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    // would be overwritten when problem is encountered
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    PrismContainer taskExtension = task.getExtension();
    PrismProperty<Integer> delayProp = taskExtension != null ? taskExtension.findProperty(SchemaConstants.NOOP_DELAY_QNAME) : null;
    PrismProperty<Integer> stepsProp = taskExtension != null ? taskExtension.findProperty(SchemaConstants.NOOP_STEPS_QNAME) : null;
    PrismPropertyDefinition delayPropDef = taskManagerImpl.getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.NOOP_DELAY_QNAME);
    PrismPropertyDefinition stepsPropDef = taskManagerImpl.getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.NOOP_STEPS_QNAME);
    try {
        if (delayProp != null)
            delayProp.applyDefinition(delayPropDef);
        if (stepsProp != null)
            stepsProp.applyDefinition(stepsPropDef);
    } catch (SchemaException se) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot apply Prism definition to delay and/or steps property, exiting immediately.", se);
        opResult.recordFatalError("Cannot apply Prism definition to delay and/or steps property, exiting immediately.", se);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    long delay;
    if (delayProp != null && !delayProp.getValues().isEmpty())
        delay = delayProp.getValues().get(0).getValue();
    else
        delay = 0;
    int steps;
    if (stepsProp != null && !stepsProp.getValues().isEmpty())
        steps = stepsProp.getValues().get(0).getValue();
    else
        steps = 1;
    LOGGER.info("NoOpTaskHandler run starting; progress = " + progress + ", steps to be executed = " + steps + ", delay for one step = " + delay + " in task " + task.getName());
    for (int i = 0; i < steps; i++) {
        LOGGER.info("NoOpTaskHandler: executing step " + (i + 1) + " of " + steps + " in task " + task.getName());
        // this strange construction is used to simulate non-interruptible execution of the task
        long sleepUntil = System.currentTimeMillis() + delay;
        for (; ; ) {
            long delta = sleepUntil - System.currentTimeMillis();
            if (delta > 0) {
                try {
                    Thread.sleep(delta);
                } catch (InterruptedException e) {
                }
            } else {
                // we have slept enough
                break;
            }
        }
        progress++;
        try {
            task.setProgressImmediate(progress, opResult);
        } catch (ObjectNotFoundException e) {
            LoggingUtils.logException(LOGGER, "Cannot report progress for task {} because the task does not exist anymore.", e, task);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            break;
        } catch (SchemaException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot report progress for task {} because of schema exception.", e, task);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            break;
        }
        if (!task.canRun()) {
            LOGGER.info("NoOpTaskHandler: got a shutdown request, finishing task " + task.getName());
            break;
        }
    }
    opResult.computeStatusIfUnknown();
    runResult.setProgress(progress);
    LOGGER.info("NoOpTaskHandler run finishing; progress = " + progress + " in task " + task.getName());
    return runResult;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

PrismContainer (com.evolveum.midpoint.prism.PrismContainer)28 PrismObject (com.evolveum.midpoint.prism.PrismObject)12 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 RunReportPopupPanel (com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 Item (com.evolveum.midpoint.prism.Item)4 PrismReference (com.evolveum.midpoint.prism.PrismReference)4 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ArrayList (java.util.ArrayList)4 Task (com.evolveum.midpoint.task.api.Task)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 Containerable (com.evolveum.midpoint.prism.Containerable)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 Referencable (com.evolveum.midpoint.prism.Referencable)2