Skip to content

Commit

Permalink
Simplify ModelController code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 28, 2022
1 parent 5a68a52 commit 96b4c2a
Show file tree
Hide file tree
Showing 20 changed files with 500 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import javax.annotation.PostConstruct;

import com.evolveum.midpoint.model.common.util.AuditHelper;
import com.evolveum.midpoint.model.impl.controller.ModelController;
import com.evolveum.midpoint.model.impl.correlation.CorrelationServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -136,4 +138,6 @@ public static ModelBeans get() {
@Autowired public SynchronizationActionFactory synchronizationActionFactory;
@Autowired public ProjectionContextKeyFactory projectionContextKeyFactory;
@Autowired public ArchetypeManager archetypeManager;
@Autowired public AuditHelper auditHelper;
@Autowired public ModelController modelController;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyIt
| CommunicationException | ConfigurationException | ObjectAlreadyExistsException
| PolicyViolationException | SecurityViolationException e) {
LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
result.recordFatalError("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
throw e;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1938,17 +1938,18 @@ public Map<String, Object> getMessageBodyAsMap(AsyncUpdateMessageType message) t
public <O extends ObjectType> void addRecomputeTrigger(PrismObject<O> object, Long timestamp,
TriggerCustomizer triggerCustomizer)
throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
TriggerType trigger = new TriggerType(prismContext)
TriggerType trigger = new TriggerType()
.handlerUri(RecomputeTriggerHandler.HANDLER_URI)
.timestamp(XmlTypeConverter.createXMLGregorianCalendar(timestamp != null ? timestamp : System.currentTimeMillis()));
if (triggerCustomizer != null) {
triggerCustomizer.customize(trigger);
}
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(object.asObjectable().getClass())
Class<? extends ObjectType> objectType = object.asObjectable().getClass();
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(objectType)
.item(ObjectType.F_TRIGGER).add(trigger)
.asItemDeltas();
repositoryService.modifyObject(object.getCompileTimeClass(), object.getOid(), itemDeltas,
getCurrentResult(CLASS_DOT + "addRecomputeTrigger"));
repositoryService.modifyObject(
objectType, object.getOid(), itemDeltas, getCurrentResult(CLASS_DOT + "addRecomputeTrigger"));
}

@Override
Expand Down Expand Up @@ -2082,7 +2083,7 @@ public void createRecomputeTrigger(Class<? extends ObjectType> type, String oid)
ObjectAlreadyExistsException, ObjectNotFoundException {
OperationResult result = getCurrentResult(MidpointFunctions.class.getName() + ".createRecomputeTrigger");

TriggerType trigger = new TriggerType(prismContext)
TriggerType trigger = new TriggerType()
.handlerUri(RecomputeTriggerHandler.HANDLER_URI)
.timestamp(XmlTypeConverter.createXMLGregorianCalendar());
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ private String determineObjectOid(TriggerHolderSpecification key, OperationResul
private void addTrigger(TriggerHolderSpecification key, long triggerTimestamp, OperationResult result, String oid)
throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
RepositoryService repositoryService = midpointFunctions.getRepositoryService();
PrismContext prismContext = midpointFunctions.getPrismContext();
TriggerType trigger = new TriggerType(prismContext)
TriggerType trigger = new TriggerType()
.handlerUri(RecomputeTriggerHandler.HANDLER_URI)
.timestamp(XmlTypeConverter.createXMLGregorianCalendar(triggerTimestamp));
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(key.getType())
List<ItemDelta<?, ?>> itemDeltas = PrismContext.get().deltaFor(key.getType())
.item(ObjectType.F_TRIGGER).add(trigger)
.asItemDeltas();
repositoryService.modifyObject(key.getType(), oid, itemDeltas, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ private <F extends FocusType, T extends FocusType> Collection<ItemDelta<?,?>> pr
return evaluation.getItemDeltas();
}


private <F extends FocusType> void link(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
private <F extends FocusType> void link(LensContext<F> context, FocusType persona, OperationResult result)
throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta();
PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue();
refValue.setOid(persona.getOid());
Expand All @@ -349,7 +349,8 @@ private <F extends FocusType> void link(LensContext<F> context, FocusType perso
repositoryService.modifyObject(delta.getObjectTypeClass(), delta.getOid(), delta.getModifications(), result);
}

private <F extends FocusType> void unlink(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
private <F extends FocusType> void unlink(LensContext<F> context, FocusType persona, OperationResult result)
throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta();
PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue();
refValue.setOid(persona.getOid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static void recordException(OperationResult result, String message, Thro
// If this is really an error then it should be logged by the invoking code.
LoggingUtils.logExceptionOnDebugLevel(LOGGER, message, e);
result.recordException(message, e);
result.cleanupResult(e);
result.cleanup();
}

public static void recordPartialError(OperationResult result, Throwable e) {
Expand Down Expand Up @@ -629,11 +629,11 @@ public static PrismReferenceValue determineAuditTargetDeltaOps(
}
if (deltaOps.size() == 1) {
ObjectDeltaOperation<? extends ObjectType> deltaOp = deltaOps.iterator().next();
return getAuditTarget(deltaOp.getObjectDelta(), PrismContext.get());
return getAuditTarget(deltaOp.getObjectDelta());
}
for (ObjectDeltaOperation<? extends ObjectType> deltaOp: deltaOps) {
if (!ShadowType.class.isAssignableFrom(deltaOp.getObjectDelta().getObjectTypeClass())) {
return getAuditTarget(deltaOp.getObjectDelta(), PrismContext.get());
return getAuditTarget(deltaOp.getObjectDelta());
}
}
// Several raw operations, all on shadows, no focus ... this should not happen
Expand All @@ -642,18 +642,17 @@ public static PrismReferenceValue determineAuditTargetDeltaOps(
return null;
}

public static PrismReferenceValue determineAuditTarget(Collection<ObjectDelta<? extends ObjectType>> deltas,
PrismContext prismContext) {
public static PrismReferenceValue determineAuditTarget(Collection<ObjectDelta<? extends ObjectType>> deltas) {
if (deltas == null || deltas.isEmpty()) {
return null;
}
if (deltas.size() == 1) {
ObjectDelta<? extends ObjectType> delta = deltas.iterator().next();
return getAuditTarget(delta, prismContext);
return getAuditTarget(delta);
}
for (ObjectDelta<? extends ObjectType> delta: deltas) {
if (!ShadowType.class.isAssignableFrom(delta.getObjectTypeClass())) {
return getAuditTarget(delta, prismContext);
return getAuditTarget(delta);
}
}
// Several raw operations, all on shadows, no focus ... this should not happen
Expand All @@ -662,9 +661,8 @@ public static PrismReferenceValue determineAuditTarget(Collection<ObjectDelta<?
return null;
}

private static PrismReferenceValue getAuditTarget(ObjectDelta<? extends ObjectType> delta,
PrismContext prismContext) {
PrismReferenceValue targetRef = prismContext.itemFactory().createReferenceValue(delta.getOid());
private static PrismReferenceValue getAuditTarget(ObjectDelta<? extends ObjectType> delta) {
PrismReferenceValue targetRef = PrismContext.get().itemFactory().createReferenceValue(delta.getOid());
targetRef.setTargetType(ObjectTypes.getObjectType(delta.getObjectTypeClass()).getTypeQName());
if (delta.isAdd()) {
targetRef.setObject(delta.getObjectToAdd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void expandConfigurationObject(
}

@Override
public CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result) {
public @NotNull CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result) {
return new CapabilityCollectionType();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void testPartialConfiguration(OperationResult parentResult) {
}

@Override
public CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
public @NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
return fetchCapabilities(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,9 @@ void expandConfigurationObject(
*
* EXPERIMENTAL feature.
*
* @return Return supported operations for connector.
* @return Return supported operations for connector.
*/
@Experimental
CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result)
@NotNull CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result)
throws SchemaException, CommunicationException, ConfigurationException, ObjectNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ public void expandConfigurationObject(
}

@Override
public CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult parentResult)
public @NotNull CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult parentResult)
throws SchemaException, CommunicationException, ConfigurationException, ObjectNotFoundException {
OperationResult result = parentResult.subresult(OP_GET_NATIVE_CAPABILITIES)
.addParam("connectorOid", connOid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,15 @@ public void expandResource(@NotNull ResourceType resource, @NotNull OperationRes
connector.discoverConfiguration(result));
}

// @Override
public CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result)
public @NotNull CapabilityCollectionType getNativeCapabilities(@NotNull String connOid, OperationResult result)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException {
try {
ConnectorInstance connInstance = connectorManager.getConnectorInstanceByConnectorOid(connOid, result);
return connInstance.getNativeCapabilities(result);
return connectorManager
.getConnectorInstanceByConnectorOid(connOid, result)
.getNativeCapabilities(result);
} catch (GenericFrameworkException e) {
// Not expected. Transform to system exception
result.recordFatalError("Generic provisioning framework error", e);
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
} catch (CommunicationException | ConfigurationException e) {
result.recordFatalError(e);
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ default void listenForChanges(
/**
* Method create collection of capabilities which connector support.
*
* @return Return supported operations for connector.
* @return Return supported operations for connector.
*/
CapabilityCollectionType getNativeCapabilities(OperationResult result)
@NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result)
throws CommunicationException, GenericFrameworkException, ConfigurationException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public AsynchronousOperationResult deleteObject(ResourceObjectDefinition objectD
}

@Override
public CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
public @NotNull CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
InternalMonitor.recordConnectorOperation("capabilities");
return new CapabilityCollectionType()
.read(new ReadCapabilityType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void testPartialConfiguration(OperationResult parentResult) {
}

@Override
public CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
public @NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
return fetchCapabilities(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void testPartialConfiguration(OperationResult parentResult) {
}

@Override
public CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
public @NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result) throws CommunicationException, GenericFrameworkException, ConfigurationException {
return fetchCapabilities(result);
}

Expand Down Expand Up @@ -292,7 +292,7 @@ public ConnectorOperationalStatus getOperationalStatus() {
}

@Override
public CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
public @NotNull CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
InternalMonitor.recordConnectorOperation("capabilities");
return new CapabilityCollectionType()
.create(new CreateCapabilityType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void listenForChanges(
}

@Override
public CapabilityCollectionType getNativeCapabilities(OperationResult result)
public @NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result)
throws CommunicationException, GenericFrameworkException, ConfigurationException {
return fetchCapabilities(result);
}
Expand All @@ -192,7 +192,7 @@ public ConnectorOperationalStatus getOperationalStatus() {
}

@Override
public CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
public @NotNull CapabilityCollectionType fetchCapabilities(OperationResult parentResult) {
InternalMonitor.recordConnectorOperation("capabilities");
return new CapabilityCollectionType()
.asyncUpdate(new AsyncUpdateCapabilityType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ResourceSchema getRawResourceSchema() {
/**
* Returns parsed capabilities or null if they were not available.
*/
public CapabilityCollectionType getCapabilities() {
public @NotNull CapabilityCollectionType getCapabilities() {
return capabilities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ public void dispose() {
}

@Override
public CapabilityCollectionType getNativeCapabilities(OperationResult result)
public @NotNull CapabilityCollectionType getNativeCapabilities(OperationResult result)
throws CommunicationException, ConfigurationException, GenericFrameworkException {

APIConfiguration apiConfig = connectorInfo.createDefaultAPIConfiguration();
Expand Down

0 comments on commit 96b4c2a

Please sign in to comment.