Skip to content

Commit

Permalink
Added support for deletion of Simulated Processed Result Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Feb 3, 2023
1 parent 9adb4e8 commit 3befabc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ private SimulationDefinitionType findDefinitionById(@NotNull String id) throws C
* If they exist, they were probably left there from the previously suspended (and now resumed) execution.
*/
void deleteTransactionIfPresent(String simulationResultOid, String transactionId, OperationResult result) {
// TODO implement
try {
repository.deleteSimulatedProcessedObjects(simulationResultOid, transactionId, result);
} catch (SchemaException | ObjectNotFoundException e) {
throw new SystemException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ interface ModificationsSupplier<T extends ObjectType> {


@Experimental
default ModifyObjectResult<SimulationResultType> deleteSimulatedProcessedObjects(String oid, @Nullable String transactionId, OperationResult parentResult) {
default ModifyObjectResult<SimulationResultType> deleteSimulatedProcessedObjects(String oid, @Nullable String transactionId, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
throw new UnsupportedOperationException("Not supported yet");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public <T extends ObjectType> String addObject(@NotNull PrismObject<T> object, R
return modificationOpHandler.addObject(object, options, parentResult);
}

@Override
@NotNull
public <T extends ObjectType> ModifyObjectResult<T> modifyObject(
@NotNull Class<T> type, @NotNull String oid, @NotNull Collection<? extends ItemDelta<?, ?>> modifications,
Expand Down Expand Up @@ -219,6 +220,12 @@ public <T extends ObjectType> ModifyObjectResult<T> modifyObject(
type, oid, getOptions, modificationsSupplier, modifyOptions, parentResult);
}

@Override
public ModifyObjectResult<SimulationResultType> deleteSimulatedProcessedObjects(String oid,
@Nullable String transactionId, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
return repositoryService.deleteSimulatedProcessedObjects(oid, transactionId, parentResult);
}

@NotNull
@Override
public <T extends ObjectType> DeleteObjectResult deleteObject(Class<T> type, String oid, OperationResult parentResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReferenceMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.simulation.QProcessedObject;
import com.evolveum.midpoint.repo.sqale.qmodel.simulation.QProcessedObjectMapping;
import com.evolveum.midpoint.repo.sqale.update.AddObjectContext;
import com.evolveum.midpoint.repo.sqale.update.RootUpdateContext;
import com.evolveum.midpoint.repo.sqlbase.*;
Expand Down Expand Up @@ -743,6 +745,34 @@ private void logTraceModifications(@NotNull Collection<? extends ItemDelta<?, ?>
}
}

@Override
public ModifyObjectResult<SimulationResultType> deleteSimulatedProcessedObjects(String oid,
@Nullable String transactionId, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
// Should we select
var operationResult = parentResult.createSubresult("deleteSimulatedProcessedObjects");
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
RootUpdateContext<SimulationResultType, QObject<MObject>, MObject> update = prepareUpdateContext(jdbcSession, SimulationResultType.class, SqaleUtils.oidToUuidMandatory(oid));


QProcessedObject alias = QProcessedObjectMapping.getProcessedObjectMapping().defaultAlias();
jdbcSession.newDelete(alias)
.where(alias.ownerOid.eq(SqaleUtils.oidToUuidMandatory(oid))
.and(alias.transactionId.eq(transactionId))
)
.execute();
update.finishExecutionOwn();
jdbcSession.commit();
return new ModifyObjectResult<>(update.getPrismObject(), update.getPrismObject(), Collections.emptyList());
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
recordFatalError(operationResult, t);
throw t;
} finally {
operationResult.close();
}
}

@Override
public @NotNull <T extends ObjectType> DeleteObjectResult deleteObject(
Class<T> type, String oid, OperationResult parentResult)
Expand Down

0 comments on commit 3befabc

Please sign in to comment.