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 5, 2021
1 parent e76a3ae commit e8eb54a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
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 @@ -83,7 +84,7 @@ public OperationResultStatus queryOperationStatus(String asynchronousOperationRe


@Override
protected String createTicketAdd(PrismObject<? extends ShadowType> object, OperationResult result) throws CommunicationException,
protected String createTicketAdd(PrismObject<? extends ShadowType> object, Task task, OperationResult result) throws CommunicationException,
GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
DummyItsm itsm = DummyItsm.getInstance();
String identifier;
Expand All @@ -103,7 +104,7 @@ protected String createTicketAdd(PrismObject<? extends ShadowType> object, Opera
@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 CommunicationException, GenericFrameworkException,
SchemaException, ObjectAlreadyExistsException, ConfigurationException {
DummyItsm itsm = DummyItsm.getInstance();
Expand All @@ -124,7 +125,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 @@ -69,18 +70,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, OperationResult result) throws CommunicationException,
protected abstract String createTicketAdd(PrismObject<? extends ShadowType> object, 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 @@ -97,7 +98,7 @@ public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObj

try {

ticketIdentifier = createTicketAdd(object, result);
ticketIdentifier = createTicketAdd(object, reporter.getTask(), result);

} catch (CommunicationException | GenericFrameworkException | SchemaException |
ObjectAlreadyExistsException | ConfigurationException | RuntimeException | Error e) {
Expand Down Expand Up @@ -134,7 +135,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 @@ -168,7 +175,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 @@ -131,7 +132,7 @@ public TaskManager getTaskManager() {
}

@Override
protected String createTicketAdd(PrismObject<? extends ShadowType> object, OperationResult result) throws SchemaException,
protected String createTicketAdd(PrismObject<? extends ShadowType> object, 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 @@ -144,14 +145,14 @@ protected String createTicketAdd(PrismObject<? extends ShadowType> object, Opera
}
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.debugDumpLazily(changes, 1));
if (InternalsConfig.isSanityChecks()) {
if (MiscUtil.hasDuplicates(changes)) {
Expand All @@ -169,13 +170,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 @@ -191,7 +192,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 @@ -200,7 +201,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 @@ -284,6 +285,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 e8eb54a

Please sign in to comment.