Skip to content

Commit

Permalink
fix for setting requested by to caseType of manual connector ticket (…
Browse files Browse the repository at this point in the history
…MID-7238)
  • Loading branch information
skublik committed Nov 8, 2021
1 parent 04d5625 commit aa2f153
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
Expand Down Expand Up @@ -85,7 +86,7 @@ public OperationResultStatus queryOperationStatus(String asynchronousOperationRe

@Override
protected String createTicketAdd(PrismObject<? extends ShadowType> object,
Collection<Operation> additionalOperations, OperationResult result) throws CommunicationException,
Collection<Operation> additionalOperations, Task task, OperationResult result) throws CommunicationException,
GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
DummyItsm itsm = DummyItsm.getInstance();
String identifier;
Expand All @@ -105,7 +106,7 @@ protected String createTicketAdd(PrismObject<? extends ShadowType> object,
@Override
protected String createTicketModify(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers,
String resourceOid, Collection<Operation> changes, OperationResult result)
String resourceOid, Collection<Operation> changes, Task task, OperationResult result)
throws ObjectNotFoundException, CommunicationException, GenericFrameworkException,
SchemaException, ObjectAlreadyExistsException, ConfigurationException {
DummyItsm itsm = DummyItsm.getInstance();
Expand All @@ -126,7 +127,7 @@ protected String createTicketModify(ObjectClassComplexTypeDefinition objectClass
@Override
protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers,
String resourceOid, OperationResult result) throws ObjectNotFoundException,
String resourceOid, Task task, OperationResult result) throws ObjectNotFoundException,
CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
DummyItsm itsm = DummyItsm.getInstance();
String identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus;
import com.evolveum.midpoint.task.api.StateReporter;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -73,18 +74,18 @@ public abstract class AbstractManualConnectorInstance extends AbstractManagedCon
// Operations to be implemented in the subclasses. These operations create the tickets.

protected abstract String createTicketAdd(PrismObject<? extends ShadowType> object,
Collection<Operation> additionalOperations, OperationResult result) throws CommunicationException,
Collection<Operation> additionalOperations, Task task, OperationResult result) throws CommunicationException,
GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException;

protected abstract String createTicketModify(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, Collection<Operation> changes,
OperationResult result) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException,
ObjectAlreadyExistsException, ConfigurationException;
Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException,
SchemaException, ObjectAlreadyExistsException, ConfigurationException;

protected abstract String createTicketDelete(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, OperationResult result)
throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException,
ConfigurationException;
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid,
Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException,
SchemaException, ConfigurationException;

@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(
Expand All @@ -100,9 +101,7 @@ public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObj
InternalMonitor.recordConnectorModification("add");

try {

ticketIdentifier = createTicketAdd(object, additionalOperations, result);

ticketIdentifier = createTicketAdd(object, additionalOperations, reporter.getTask(), result);
} catch (CommunicationException | GenericFrameworkException | SchemaException |
ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
result.recordFatalError(e);
Expand Down Expand Up @@ -138,7 +137,13 @@ public AsynchronousOperationReturnValue<Collection<PropertyModificationOperation

try {

ticketIdentifier = createTicketModify(identification.getObjectClassDefinition(), shadow, identification.getAllIdentifiers(), reporter.getResourceOid(), changes, result);
ticketIdentifier = createTicketModify(
identification.getObjectClassDefinition(),
shadow, identification.getAllIdentifiers(),
reporter.getResourceOid(),
changes,
reporter.getTask(),
result);

} catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException |
ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
Expand Down Expand Up @@ -172,7 +177,7 @@ public AsynchronousOperationResult deleteObject(ObjectClassComplexTypeDefinition

try {

ticketIdentifier = createTicketDelete(objectClass, shadow, identifiers, reporter.getResourceOid(), result);
ticketIdentifier = createTicketDelete(objectClass, shadow, identifiers, reporter.getResourceOid(), reporter.getTask(), result);

} catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException |
ConfigurationException | RuntimeException | Error e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.OidUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.task.api.TaskManagerAware;
import com.evolveum.midpoint.util.DebugUtil;
Expand Down Expand Up @@ -128,8 +129,8 @@ public TaskManager getTaskManager() {
}

@Override
protected String createTicketAdd(PrismObject<? extends ShadowType> object,
Collection<Operation> additionalOperations, OperationResult result) throws SchemaException,
protected String createTicketAdd(PrismObject<? extends ShadowType> object, Collection<Operation> additionalOperations,
Task task, OperationResult result) throws SchemaException,
ObjectAlreadyExistsException {
LOGGER.debug("Creating case to add account\n{}", object.debugDump(1));
ObjectDelta<? extends ShadowType> objectDelta = DeltaFactory.Object.createAddDelta(object);
Expand All @@ -142,14 +143,14 @@ protected String createTicketAdd(PrismObject<? extends ShadowType> object,
}
String description = "Please create resource account: "+shadowName;
PrismObject<CaseType> aCase = addCase("create", description, ShadowUtil.getResourceOid(object.asObjectable()),
shadowName, null, objectDeltaType, result);
shadowName, null, objectDeltaType, task, result);
return aCase.getOid();
}

@Override
protected String createTicketModify(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, Collection<Operation> changes,
OperationResult result) throws SchemaException, ObjectAlreadyExistsException {
Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException {
LOGGER.debug("Creating case to modify account {}:\n{}", identifiers, DebugUtil.debugDump(changes, 1));
if (InternalsConfig.isSanityChecks()) {
if (MiscUtil.hasDuplicates(changes)) {
Expand All @@ -167,13 +168,13 @@ protected String createTicketModify(ObjectClassComplexTypeDefinition objectClass
String shadowName = shadow.getName().toString();
String description = "Please modify resource account: "+shadowName;
PrismObject<CaseType> aCase = addCase("modify", description, resourceOid, shadowName,
shadow.getOid(), objectDeltaType, result);
shadow.getOid(), objectDeltaType, task, result);
return aCase.getOid();
}

@Override
protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass,
PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, OperationResult result)
protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass, PrismObject<ShadowType> shadow,
Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, Task task, OperationResult result)
throws SchemaException {
LOGGER.debug("Creating case to delete account {}", identifiers);
String shadowName = shadow.getName().toString();
Expand All @@ -189,7 +190,7 @@ protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass
objectDeltaType.getItemDelta().add(itemDeltaType);
PrismObject<CaseType> aCase;
try {
aCase = addCase("delete", description, resourceOid, shadowName, shadow.getOid(), objectDeltaType, result);
aCase = addCase("delete", description, resourceOid, shadowName, shadow.getOid(), objectDeltaType, task, result);
} catch (ObjectAlreadyExistsException e) {
// should not happen
throw new SystemException(e.getMessage(), e);
Expand All @@ -198,7 +199,7 @@ protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass
}

private PrismObject<CaseType> addCase(String operation, String description, String resourceOid, String shadowName, String shadowOid,
ObjectDeltaType objectDelta, OperationResult result) throws SchemaException, ObjectAlreadyExistsException {
ObjectDeltaType objectDelta, Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException {
PrismObject<CaseType> aCase = getPrismContext().createObject(CaseType.class);
CaseType caseType = aCase.asObjectable();

Expand Down Expand Up @@ -258,6 +259,10 @@ private PrismObject<CaseType> addCase(String operation, String description, Stri

caseType.setTargetRef(new ObjectReferenceType().oid(shadowOid).targetName(shadowName).type(ShadowType.COMPLEX_TYPE));

if (task != null) {
caseType.setRequestorRef(task.getOwnerRef());
}

caseType.beginManualProvisioningContext()
.beginPendingOperation()
.type(PendingOperationTypeType.MANUAL)
Expand Down

0 comments on commit aa2f153

Please sign in to comment.