Search in sources :

Example 31 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ModelEvent method getFocusDeltas.

public List<ObjectDelta<FocusType>> getFocusDeltas() {
    List<ObjectDelta<FocusType>> retval = new ArrayList<>();
    Class c = modelContext.getFocusClass();
    if (c != null && FocusType.class.isAssignableFrom(c)) {
        for (Object o : getFocusExecutedDeltas()) {
            ObjectDeltaOperation objectDeltaOperation = (ObjectDeltaOperation) o;
            retval.add(objectDeltaOperation.getObjectDelta());
        }
    }
    return retval;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 32 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AuditController method getObjectFromLastEvent.

private <O extends ObjectType> PrismObject<O> getObjectFromLastEvent(PrismObject<O> object, List<AuditEventRecord> changeTrail, String eventIdentifier) {
    if (changeTrail.isEmpty()) {
        return object;
    }
    AuditEventRecord lastEvent = changeTrail.remove(changeTrail.size() - 1);
    if (!eventIdentifier.equals(lastEvent.getEventIdentifier())) {
        throw new IllegalStateException("Wrong last event identifier, expected " + eventIdentifier + " but was " + lastEvent.getEventIdentifier());
    }
    Collection<ObjectDeltaOperation<? extends ObjectType>> lastEventDeltasOperations = lastEvent.getDeltas();
    for (ObjectDeltaOperation<? extends ObjectType> lastEventDeltasOperation : lastEventDeltasOperations) {
        ObjectDelta<O> objectDelta = (ObjectDelta<O>) lastEventDeltasOperation.getObjectDelta();
        if (!isApplicable(lastEventDeltasOperation, object, lastEvent)) {
            continue;
        }
        if (objectDelta.isAdd()) {
            // We are lucky. This is object add, so we have complete object there. No need to roll back
            // the operations.
            PrismObject<O> objectToAdd = objectDelta.getObjectToAdd();
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Taking object from add delta in last event {}:\n{}", lastEvent.getEventIdentifier(), objectToAdd.debugDump(1));
            }
            return objectToAdd;
        }
    }
    return null;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 33 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ImportReportPopupPanel method importConfirmPerformed.

private void importConfirmPerformed(AjaxRequestTarget target, Model<String> nameModel, Model<String> fileStringImport) {
    String dataName;
    if (nameModel == null || StringUtils.isEmpty(nameModel.getObject())) {
        dataName = getModelObject().getName().getOrig() + "-IMPORT " + getDataTime();
    } else {
        dataName = nameModel.getObject();
    }
    // Create new file
    MidPointApplication application = getPageBase().getMidpointApplication();
    WebApplicationConfiguration config = application.getWebApplicationConfiguration();
    String midpointHome = System.getProperty(MidpointConfiguration.MIDPOINT_HOME_PROPERTY);
    File importDir = new File(midpointHome, "import");
    if (!importDir.exists() || !importDir.isDirectory()) {
        if (!importDir.mkdir()) {
            LOGGER.error("Couldn't create import dir {}", importDir);
            FeedbackAlerts feedback = getFeedbackPanel();
            feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportDir", importDir).getString());
            target.add(feedback);
            return;
        }
    }
    FileUpload uploadedFile = getUploadedFile();
    if (uploadedFile == null && StringUtils.isEmpty(fileStringImport.getObject())) {
        LOGGER.error("Please upload file for import");
        FeedbackAlerts feedback = getFeedbackPanel();
        feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.uploadFile", importDir).getString());
        target.add(feedback);
        return;
    }
    String newFilePath;
    if (uploadedFile != null) {
        String fileName = FilenameUtils.removeExtension(uploadedFile.getClientFileName()) + " " + getDataTime() + "." + FilenameUtils.getExtension(uploadedFile.getClientFileName());
        File newFile = new File(importDir, fileName);
        // Check new file, delete if it already exists
        if (newFile.exists()) {
            newFile.delete();
        }
        try {
            newFile.createNewFile();
            FileUtils.copyInputStreamToFile(uploadedFile.getInputStream(), newFile);
            newFilePath = newFile.getAbsolutePath();
        } catch (IOException e) {
            LOGGER.error("Couldn't create new file " + newFile.getAbsolutePath(), e);
            FeedbackAlerts feedback = getFeedbackPanel();
            feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportFile", newFile.getAbsolutePath()).getString());
            target.add(feedback);
            return;
        }
    } else {
        newFilePath = new File(importDir, dataName).getAbsolutePath();
        try {
            Files.write(Paths.get(newFilePath), fileStringImport.getObject().getBytes());
        } catch (IOException e) {
            LOGGER.error("Couldn't create new file " + newFilePath, e);
            FeedbackAlerts feedback = getFeedbackPanel();
            feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportFile", newFilePath).getString());
            target.add(feedback);
            return;
        }
    }
    ReportDataType reportImportData = null;
    try {
        @NotNull PrismObject<ReportDataType> prismObject = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ReportDataType.class).instantiate();
        reportImportData = prismObject.asObjectable();
    } catch (SchemaException e) {
        LOGGER.error("Couldn't instantiate new Report Data from definition", e);
        FeedbackAlerts feedback = getFeedbackPanel();
        feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createInstantiateReportData").getString());
        target.add(feedback);
        return;
    }
    reportImportData.setName(new PolyStringType(dataName));
    reportImportData.setFilePath(newFilePath);
    ObjectReferenceType reportRef = new ObjectReferenceType();
    reportRef.setType(ReportType.COMPLEX_TYPE);
    reportRef.setOid(getModelObject().getOid());
    reportImportData.setReportRef(reportRef);
    Collection<ObjectDelta<? extends ObjectType>> deltas = Collections.singleton(reportImportData.asPrismObject().createAddDelta());
    Task task = getPageBase().createSimpleTask(OPERATION_CREATE_REPORT_DATA);
    try {
        Collection<ObjectDeltaOperation<? extends ObjectType>> retDeltas = getPageBase().getModelService().executeChanges(deltas, null, task, task.getResult());
        reportImportData = (ReportDataType) retDeltas.iterator().next().getObjectDelta().getObjectToAdd().asObjectable();
    } catch (ObjectAlreadyExistsException e) {
        LOGGER.error("Report Data with name " + dataName + " already exists", e);
        FeedbackAlerts feedback = getFeedbackPanel();
        feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.importReportDataAlreadyExists", dataName).getString());
        target.add(feedback);
        return;
    } catch (Exception e) {
        LOGGER.error("Couldn't create new Report Data with name " + dataName, e);
        FeedbackAlerts feedback = getFeedbackPanel();
        feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportReportData", dataName).getString());
        target.add(feedback);
        return;
    }
    importConfirmPerformed(target, reportImportData);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) IOException(java.io.IOException) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) FeedbackAlerts(com.evolveum.midpoint.web.component.message.FeedbackAlerts) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 34 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChangesSync.

private void executeChangesSync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    try {
        MidPointApplication application = MidPointApplication.get();
        if (previewOnly) {
            ModelInteractionService service = application.getModelInteractionService();
            ModelContext previewResult = service.previewChanges(deltas, options, task, result);
            reporter.setPreviewResult(previewResult);
        } else {
            ModelService service = application.getModel();
            Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
            reporter.setObjectDeltaOperation(executedDeltas);
        }
        result.computeStatusIfUnknown();
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
        if (!result.isFatalError()) {
            // just to be sure the exception is recorded into the result
            result.recordFatalError(e.getMessage(), e);
        }
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommonException(com.evolveum.midpoint.util.exception.CommonException) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 35 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AbstractPageObjectDetails method saveOrPreviewPerformed.

// private ObjectDelta<O> delta;
public Collection<ObjectDeltaOperation<? extends ObjectType>> saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly, Task task) {
    PrismObjectWrapper<O> objectWrapper = getModelWrapperObject();
    LOGGER.debug("Saving object {}", objectWrapper);
    if (task == null) {
        task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
    }
    ExecuteChangeOptionsDto options = getExecuteChangesOptionsDto();
    Collection<ObjectDelta<? extends ObjectType>> deltas;
    try {
        deltas = objectDetailsModels.collectDeltas(result);
        checkValidationErrors(target, objectDetailsModels.getValidationErrors());
    } catch (Throwable ex) {
        result.recordFatalError(getString("pageAdminObjectDetails.message.cantCreateObject"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Create Object failed", ex);
        showResult(result);
        target.add(getFeedbackPanel());
        return null;
    }
    LOGGER.trace("returning from saveOrPreviewPerformed");
    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = executeChanges(deltas, previewOnly, options, task, result, target);
    postProcessResult(result, executedDeltas, target);
    return executedDeltas;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ExecuteChangeOptionsDto(com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 Task (com.evolveum.midpoint.task.api.Task)12 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)11 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ModelService (com.evolveum.midpoint.model.api.ModelService)3 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2