use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class DeleteTaskHandler method runInternal.
public <O extends ObjectType> TaskRunResult runInternal(Task task) {
LOGGER.trace("Delete task run starting ({})", task);
long startTimestamp = System.currentTimeMillis();
OperationResult opResult = new OperationResult("DeleteTask.run");
opResult.setStatus(OperationResultStatus.IN_PROGRESS);
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
opResult.setSummarizeErrors(true);
opResult.setSummarizePartialErrors(true);
opResult.setSummarizeSuccesses(true);
QueryType queryType;
PrismProperty<QueryType> objectQueryPrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
if (objectQueryPrismProperty != null && objectQueryPrismProperty.getRealValue() != null) {
queryType = objectQueryPrismProperty.getRealValue();
} else {
// For "foolproofness" reasons we really require a query. Even if it is "ALL" query.
LOGGER.error("No query parameter in {}", task);
opResult.recordFatalError("No query parameter in " + task);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
Class<O> objectType;
QName objectTypeName;
PrismProperty<QName> objectTypePrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
if (objectTypePrismProperty != null && objectTypePrismProperty.getRealValue() != null) {
objectTypeName = objectTypePrismProperty.getRealValue();
objectType = (Class<O>) ObjectTypes.getObjectTypeFromTypeQName(objectTypeName).getClassDefinition();
} else {
LOGGER.error("No object type parameter in {}", task);
opResult.recordFatalError("No object type parameter in " + task);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
ObjectQuery query;
try {
query = QueryJaxbConvertor.createObjectQuery(objectType, queryType, prismContext);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Using object query from the task: {}", query.debugDump());
}
} catch (SchemaException ex) {
LOGGER.error("Schema error while creating a search filter: {}", new Object[] { ex.getMessage(), ex });
opResult.recordFatalError("Schema error while creating a search filter: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
boolean optionRaw = true;
PrismProperty<Boolean> optionRawPrismProperty = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_OPTION_RAW);
if (optionRawPrismProperty != null && optionRawPrismProperty.getRealValue() != null && !optionRawPrismProperty.getRealValue()) {
optionRaw = false;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Deleting {}, raw={} using query:\n{}", new Object[] { objectType.getSimpleName(), optionRaw, query.debugDump() });
}
// TODO
boolean countObjectsOnStart = true;
long progress = 0;
Integer maxSize = 100;
ObjectPaging paging = ObjectPaging.createPaging(0, maxSize);
query.setPaging(paging);
query.setAllowPartialResults(true);
Collection<SelectorOptions<GetOperationOptions>> searchOptions = null;
ModelExecuteOptions execOptions = null;
if (optionRaw) {
searchOptions = SelectorOptions.createCollection(GetOperationOptions.createRaw());
execOptions = ModelExecuteOptions.createRaw();
}
try {
// counting objects can be within try-catch block, because the handling is similar to handling errors within searchIterative
Long expectedTotal = null;
if (countObjectsOnStart) {
Integer expectedTotalInt = modelService.countObjects(objectType, query, searchOptions, task, opResult);
LOGGER.trace("Expecting {} objects to be deleted", expectedTotal);
if (expectedTotalInt != null) {
// conversion would fail on null
expectedTotal = (long) expectedTotalInt;
}
}
runResult.setProgress(progress);
task.setProgress(progress);
if (expectedTotal != null) {
task.setExpectedTotal(expectedTotal);
}
try {
task.savePendingModifications(opResult);
} catch (ObjectAlreadyExistsException e) {
// other exceptions are handled in the outer try block
throw new IllegalStateException("Unexpected ObjectAlreadyExistsException when updating task progress/expectedTotal", e);
}
long progressLastUpdated = 0;
SearchResultList<PrismObject<O>> objects;
while (true) {
objects = modelService.searchObjects(objectType, query, searchOptions, task, opResult);
if (objects.isEmpty()) {
break;
}
int skipped = 0;
for (PrismObject<O> object : objects) {
if (!optionRaw && ShadowType.class.isAssignableFrom(objectType) && Boolean.TRUE == ((ShadowType) (object.asObjectable())).isProtectedObject()) {
LOGGER.debug("Skipping delete of protected object {}", object);
skipped++;
continue;
}
ObjectDelta<?> delta = ObjectDelta.createDeleteDelta(objectType, object.getOid(), prismContext);
String objectName = PolyString.getOrig(object.getName());
String objectDisplayName = StatisticsUtil.getDisplayName(object);
String objectOid = object.getOid();
task.recordIterativeOperationStart(objectName, objectDisplayName, objectTypeName, objectOid);
long objectDeletionStarted = System.currentTimeMillis();
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), execOptions, task, opResult);
task.recordIterativeOperationEnd(objectName, objectDisplayName, objectTypeName, objectOid, objectDeletionStarted, null);
} catch (Throwable t) {
task.recordIterativeOperationEnd(objectName, objectDisplayName, objectTypeName, objectOid, objectDeletionStarted, t);
// TODO we don't want to continue processing if an error occurs?
throw t;
}
progress++;
task.setProgressTransient(progress);
if (System.currentTimeMillis() - progressLastUpdated > PROGRESS_UPDATE_INTERVAL) {
task.setProgress(progress);
updateState(task);
progressLastUpdated = System.currentTimeMillis();
}
}
opResult.summarize();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Search returned {} objects, {} skipped, progress: {}, result:\n{}", new Object[] { objects.size(), skipped, progress, opResult.debugDump() });
}
if (objects.size() == skipped) {
break;
}
}
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
LOGGER.error("{}", new Object[] { e.getMessage(), e });
opResult.recordFatalError("Object not found " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (CommunicationException e) {
LOGGER.error("{}", new Object[] { e.getMessage(), e });
opResult.recordFatalError("Object not found " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
}
runResult.setProgress(progress);
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
opResult.summarize();
opResult.recordSuccess();
long wallTime = System.currentTimeMillis() - startTimestamp;
String finishMessage = "Finished delete (" + task + "). ";
String statistics = "Processed " + progress + " objects in " + wallTime / 1000 + " seconds.";
if (progress > 0) {
statistics += " Wall clock time average: " + ((float) wallTime / (float) progress) + " milliseconds";
}
opResult.createSubresult(DeleteTaskHandler.class.getName() + ".statistics").recordStatus(OperationResultStatus.SUCCESS, statistics);
LOGGER.info(finishMessage + statistics);
LOGGER.trace("Run finished (task {}, run result {})", new Object[] { task, runResult });
return runResult;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class AbstractModelImplementationIntegrationTest method addFocusModificationToContext.
protected <O extends ObjectType> ObjectDelta<O> addFocusModificationToContext(LensContext<O> context, File file) throws JAXBException, SchemaException, IOException {
ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(file, ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<O> focusDelta = DeltaConvertor.createObjectDelta(modElement, context.getFocusClass(), prismContext);
return addFocusDeltaToContext(context, focusDelta);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class TriggerScannerTaskHandler method fireTriggers.
private void fireTriggers(AbstractScannerResultHandler<ObjectType> handler, PrismObject<ObjectType> object, Task workerTask, Task coordinatorTask, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ObjectAlreadyExistsException, ConfigurationException, PolicyViolationException, SecurityViolationException {
PrismContainer<TriggerType> triggerContainer = object.findContainer(F_TRIGGER);
if (triggerContainer == null) {
LOGGER.warn("Strange thing, attempt to fire triggers on {}, but it does not have trigger container", object);
} else {
List<PrismContainerValue<TriggerType>> triggerCVals = triggerContainer.getValues();
if (triggerCVals.isEmpty()) {
LOGGER.warn("Strange thing, attempt to fire triggers on {}, but it does not have any triggers in trigger container", object);
} else {
LOGGER.trace("Firing triggers for {} ({} triggers)", object, triggerCVals.size());
List<TriggerType> triggers = getSortedTriggers(triggerCVals);
for (TriggerType trigger : triggers) {
XMLGregorianCalendar timestamp = trigger.getTimestamp();
if (timestamp == null) {
LOGGER.warn("Trigger without a timestamp in {}", object);
} else {
if (isHot(handler, timestamp)) {
fireTrigger(trigger, object, triggerContainer.getDefinition(), workerTask, coordinatorTask, result);
} else {
LOGGER.trace("Trigger {} is not hot (timestamp={}, thisScanTimestamp={}, lastScanTimestamp={})", trigger, timestamp, handler.getThisScanTimestamp(), handler.getLastScanTimestamp());
}
}
}
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class TriggerScannerTaskHandler method removeTrigger.
private void removeTrigger(PrismObject<ObjectType> object, PrismContainerValue<TriggerType> triggerCVal, Task task, PrismContainerDefinition<TriggerType> triggerContainerDef) {
ContainerDelta<TriggerType> triggerDelta = triggerContainerDef.createEmptyDelta(new ItemPath(F_TRIGGER));
triggerDelta.addValuesToDelete(triggerCVal.clone());
Collection<? extends ItemDelta> modifications = MiscSchemaUtil.createCollection(triggerDelta);
// This is detached result. It will not take part of the task result. We do not really care.
OperationResult result = new OperationResult(TriggerScannerTaskHandler.class.getName() + ".removeTrigger");
try {
repositoryService.modifyObject(object.getCompileTimeClass(), object.getOid(), modifications, result);
result.computeStatus();
task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
} catch (ObjectNotFoundException e) {
// Object is gone. Ergo there are no triggers left. Ergo the trigger was removed.
// Ergo this is not really an error.
task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
LOGGER.trace("Unable to remove trigger from {}: {} (but this is probably OK)", object, e.getMessage(), e);
} catch (SchemaException | ObjectAlreadyExistsException e) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
LOGGER.error("Unable to remove trigger from {}: {}", object, e.getMessage(), e);
} catch (Throwable t) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
throw t;
} finally {
// maybe OK (absolute correctness is not quite important here)
task.markObjectActionExecutedBoundary();
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class ValueChoosePanel method replaceIfEmpty.
protected void replaceIfEmpty(ObjectType object) {
ObjectReferenceType ort = ObjectTypeUtil.createObjectRef(object);
ort.setTargetName(object.getName());
getModel().setObject((T) ort.asReferenceValue());
}
Aggregations