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