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();
}
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();
}
}
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()));
}
}
}
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);
}
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;
}
Aggregations