com.evolveum.midpoint.model.controller
Class ModelController

java.lang.Object
  extended by com.evolveum.midpoint.model.controller.ModelController
All Implemented Interfaces:
ModelInteractionService, ModelService

@Component
public class ModelController
extends Object
implements ModelService, ModelInteractionService

This used to be an interface, but it was switched to class for simplicity. I don't expect that the implementation of the controller will be ever replaced. In extreme case the whole Model will be replaced by a different implementation, but not just the controller.

However, the common way to extend the functionality will be the use of hooks that are implemented here.

Great deal of code is copied from the old ModelControllerImpl.

Author:
lazyman, Radovan Semancik

Field Summary
static String ADD_OBJECT_WITH_EXCLUSION
           
static String CHANGE_ACCOUNT
           
static String CLASS_NAME_WITH_DOT
           
static String CREATE_ACCOUNT
           
static String GET_SYSTEM_CONFIGURATION
           
static String MODIFY_OBJECT_WITH_EXCLUSION
           
static String PROCESS_USER_TEMPLATE
           
static String RESOLVE_ACCOUNT_ATTRIBUTES
           
static String RESOLVE_USER_ATTRIBUTES
           
static String SEARCH_OBJECTS_IN_PROVISIONING
           
static String SEARCH_OBJECTS_IN_REPOSITORY
           
static String UPDATE_ACCOUNT
           
 
Fields inherited from interface com.evolveum.midpoint.model.api.ModelService
ADD_OBJECT, ADD_USER, DELETE_OBJECT, DISCOVER_CONNECTORS, EXECUTE_CHANGES, GET_OBJECT, GET_PROPERTY_AVAILABLE_VALUES, IMPORT_ACCOUNTS_FROM_RESOURCE, IMPORT_OBJECTS_FROM_FILE, IMPORT_OBJECTS_FROM_STREAM, LIST_ACCOUNT_SHADOW_OWNER, LIST_OBJECTS, LIST_RESOURCE_OBJECT_SHADOWS, LIST_RESOURCE_OBJECTS, MODIFY_OBJECT, POST_INIT, TEST_RESOURCE
 
Fields inherited from interface com.evolveum.midpoint.model.api.ModelInteractionService
PREVIEW_CHANGES
 
Constructor Summary
ModelController()
           
 
Method Summary
<T extends ObjectType>
String
addObject(PrismObject<T> object, Task task, OperationResult parentResult)
          Deprecated. 
<T extends ObjectType>
int
countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult)
           
<T extends ObjectType>
void
deleteObject(Class<T> clazz, String oid, Task task, OperationResult parentResult)
          Deprecated. 
 Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult)
          Discovers local or remote connectors.
 void executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult parentResult)
           Execute the provided object deltas.
<T extends ObjectType>
PrismObject<T>
getObject(Class<T> clazz, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result)
           Returns object for provided OID.
 ModelObjectResolver getObjectResolver()
           
 void importAccountsFromResource(String resourceOid, QName objectClass, Task task, OperationResult parentResult)
           Import accounts from resource.
 void importObjectsFromFile(File input, ImportOptionsType options, Task task, OperationResult parentResult)
          Import objects from file.
 void importObjectsFromStream(InputStream input, ImportOptionsType options, Task task, OperationResult parentResult)
          Import objects from stream.
 PrismObject<UserType> listAccountShadowOwner(String accountOid, Task task, OperationResult result)
           Returns the User object representing owner of specified account (account shadow).
 List<PrismObject<? extends ResourceObjectShadowType>> listResourceObjects(String resourceOid, QName objectClass, ObjectPaging paging, Task task, OperationResult result)
           Returns all resource objects of specified type that are currently available to the system.
<T extends ResourceObjectShadowType>
List<PrismObject<T>>
listResourceObjectShadows(String resourceOid, Class<T> resourceObjectShadowType, Task task, OperationResult result)
           Search for resource object shadows of a specified type that belong to the specified resource.
<T extends ObjectType>
void
modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, Task task, OperationResult parentResult)
          Deprecated. 
 void postInit(OperationResult parentResult)
          Finish initialization of the model and lower system components (provisioning, repository, etc).
<F extends ObjectType,P extends ObjectType>
ModelContext<F,P>
previewChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult parentResult)
          Computes the most likely changes triggered by the provided delta.
protected  void resolve(PrismObject<?> object, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result)
           
<T extends ObjectType>
List<PrismObject<T>>
searchObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result)
           Search for objects.
 OperationResult testResource(String resourceOid, Task task)
           Test the resource connection and basic resource connector functionality.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME_WITH_DOT

public static final String CLASS_NAME_WITH_DOT

SEARCH_OBJECTS_IN_REPOSITORY

public static final String SEARCH_OBJECTS_IN_REPOSITORY

SEARCH_OBJECTS_IN_PROVISIONING

public static final String SEARCH_OBJECTS_IN_PROVISIONING

ADD_OBJECT_WITH_EXCLUSION

public static final String ADD_OBJECT_WITH_EXCLUSION

MODIFY_OBJECT_WITH_EXCLUSION

public static final String MODIFY_OBJECT_WITH_EXCLUSION

CHANGE_ACCOUNT

public static final String CHANGE_ACCOUNT

GET_SYSTEM_CONFIGURATION

public static final String GET_SYSTEM_CONFIGURATION

RESOLVE_USER_ATTRIBUTES

public static final String RESOLVE_USER_ATTRIBUTES

RESOLVE_ACCOUNT_ATTRIBUTES

public static final String RESOLVE_ACCOUNT_ATTRIBUTES

CREATE_ACCOUNT

public static final String CREATE_ACCOUNT

UPDATE_ACCOUNT

public static final String UPDATE_ACCOUNT

PROCESS_USER_TEMPLATE

public static final String PROCESS_USER_TEMPLATE
Constructor Detail

ModelController

public ModelController()
Method Detail

getObjectResolver

public ModelObjectResolver getObjectResolver()

getObject

public <T extends ObjectType> PrismObject<T> getObject(Class<T> clazz,
                                                       String oid,
                                                       Collection<SelectorOptions<GetOperationOptions>> options,
                                                       Task task,
                                                       OperationResult result)
                                            throws ObjectNotFoundException,
                                                   SchemaException
Description copied from interface: ModelService

Returns object for provided OID.

Must fail if object with the OID does not exists.

Specified by:
getObject in interface ModelService
Parameters:
clazz - (class) of an object to get
oid - OID of the object to get
result - parent OperationResult (in/out)
Returns:
Retrieved object
Throws:
ObjectNotFoundException - requested object does not exist
SchemaException - the object is not schema compliant

resolve

protected void resolve(PrismObject<?> object,
                       Collection<SelectorOptions<GetOperationOptions>> options,
                       Task task,
                       OperationResult result)
                throws SchemaException,
                       ObjectNotFoundException
Throws:
SchemaException
ObjectNotFoundException

executeChanges

public void executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas,
                           ModelExecuteOptions options,
                           Task task,
                           OperationResult parentResult)
                    throws ObjectAlreadyExistsException,
                           ObjectNotFoundException,
                           SchemaException,
                           ExpressionEvaluationException,
                           CommunicationException,
                           ConfigurationException,
                           PolicyViolationException,
                           SecurityViolationException
Description copied from interface: ModelService

Execute the provided object deltas.

The operation executes the provided object deltas. All deltas must relate to analogous objects (e.g. user and linked accounts). The implementation may throw an error if the objects are not analogous. The implementation also implicitly links the objects (mark them to be analogous) if such a link is part of the data model. E.g. the implementation links all accounts to the user if they are passed in a single delta collection. This is especially useful if the account deltas are ADD deltas without OID and therefore cannot be linked explicitly.

There must be no more than one delta for each object. The order of execution is not defined and the implementation is free to determine the correct or most suitable ordering.

The OID provided in ADD deltas may be empty. In that case the OID will be assigned by the implementation and the OIDs will be set in the deltas after the operation is completed.

Execution of ADD deltas should fail if such object already exists (if object with the provided OID already exists). Execution of MODIFY and DELETE deltas should fail if such objects do not exist.

The operation may fail if provided OIDs are in an unusable format for the storage. Generating own OIDs and providing them to this method is not recommended for normal operation.

There are no explicit atomicity guarantees for the operations. Some of the operations may pass, some may fail or even fail partially. The consistency of the data and state are not based on operation atomicity but rather a data model that can "repair" inconsistencies.

The operation may fail if any of the objects to be created or modified does not conform to the underlying schema of the storage system or the schema enforced by the implementation.

Specified by:
executeChanges in interface ModelService
Parameters:
deltas - Collection of object deltas to execute
parentResult - parent OperationResult (in/out)
Throws:
ObjectAlreadyExistsException - object with specified identifiers already exists, cannot add
ObjectNotFoundException - object required to complete the operation was not found (e.g. appropriate connector or resource definition)
SchemaException - error dealing with resource schema, e.g. created object does not conform to schema
ExpressionEvaluationException - evaluation of expression associated with the object has failed
CommunicationException
ConfigurationException
PolicyViolationException - Policy violation was detected during processing of the object
SecurityViolationException

previewChanges

public <F extends ObjectType,P extends ObjectType> ModelContext<F,P> previewChanges(Collection<ObjectDelta<? extends ObjectType>> deltas,
                                                                                    ModelExecuteOptions options,
                                                                                    Task task,
                                                                                    OperationResult parentResult)
                                                                       throws SchemaException,
                                                                              PolicyViolationException,
                                                                              ExpressionEvaluationException,
                                                                              ObjectNotFoundException,
                                                                              ObjectAlreadyExistsException,
                                                                              CommunicationException,
                                                                              ConfigurationException,
                                                                              SecurityViolationException
Description copied from interface: ModelInteractionService
Computes the most likely changes triggered by the provided delta. The delta may be any change of any object, e.g. add of a user or change of a shadow. The resulting context will sort that out to "focus" and "projection" as needed. The supplied delta will be used as a primary change. The resulting context will reflect both this primary change and any resulting secondary changes. The changes are only computed, NOT EXECUTED. It also does not change any state of any repository object or task. Therefore this method is safe to use anytime. However it is reading the data from the repository and possibly also from the resources therefore there is still potential for communication (and other) errors and invocation of this method may not be cheap. However, as no operations are really executed there may be issues with resource dependencies. E.g. identifier that are generated by the resource are not taken into account while recomputing the values. This may also cause errors if some expressions depend on the generated values.

Specified by:
previewChanges in interface ModelInteractionService
Throws:
SchemaException
PolicyViolationException
ExpressionEvaluationException
ObjectNotFoundException
ObjectAlreadyExistsException
CommunicationException
ConfigurationException
SecurityViolationException

addObject

@Deprecated
public <T extends ObjectType> String addObject(PrismObject<T> object,
                                                          Task task,
                                                          OperationResult parentResult)
                 throws ObjectAlreadyExistsException,
                        ObjectNotFoundException,
                        SchemaException,
                        ExpressionEvaluationException,
                        CommunicationException,
                        ConfigurationException,
                        PolicyViolationException,
                        SecurityViolationException
Deprecated. 

Description copied from interface: ModelService

Add new object.

The OID provided in the input message may be empty. In that case the OID will be assigned by the implementation of this method and it will be provided as return value.

This operation should fail if such object already exists (if object with the provided OID already exists).

The operation may fail if provided OID is in an unusable format for the storage. Generating own OIDs and providing them to this method is not recommended for normal operation.

Should be atomic. Should not allow creation of two objects with the same OID (even if created in parallel).

The operation may fail if the object to be created does not conform to the underlying schema of the storage system or the schema enforced by the implementation.

Specified by:
addObject in interface ModelService
Parameters:
object - object to create
parentResult - parent OperationResult (in/out)
Returns:
OID assigned to the created object
Throws:
ObjectAlreadyExistsException - object with specified identifiers already exists, cannot add
ObjectNotFoundException - object required to complete the operation was not found (e.g. appropriate connector or resource definition)
SchemaException - error dealing with resource schema, e.g. created object does not conform to schema
ExpressionEvaluationException - evaluation of expression associated with the object has failed
CommunicationException
ConfigurationException
PolicyViolationException - Policy violation was detected during processing of the object
SecurityViolationException

searchObjects

public <T extends ObjectType> List<PrismObject<T>> searchObjects(Class<T> type,
                                                                 ObjectQuery query,
                                                                 Collection<SelectorOptions<GetOperationOptions>> options,
                                                                 Task task,
                                                                 OperationResult result)
                                                      throws SchemaException,
                                                             ObjectNotFoundException,
                                                             CommunicationException,
                                                             ConfigurationException,
                                                             SecurityViolationException
Description copied from interface: ModelService

Search for objects.

Searches through all object types. Returns a list of objects that match search criteria.

Returns empty list if object type is correct but there are no objects of that type.

Should fail if object type is wrong. Should fail if unknown property is specified in the query.

Specified by:
searchObjects in interface ModelService
query - search query
result - parent OperationResult (in/out)
Returns:
all objects of specified type that match search criteria (subject to paging)
Throws:
SchemaException - unknown property used in search query
ObjectNotFoundException - object required for a search was not found (e.g. resource definition)
CommunicationException - error communicating with the resource
ConfigurationException
SecurityViolationException

countObjects

public <T extends ObjectType> int countObjects(Class<T> type,
                                               ObjectQuery query,
                                               Collection<SelectorOptions<GetOperationOptions>> options,
                                               Task task,
                                               OperationResult parentResult)
                 throws SchemaException,
                        ObjectNotFoundException
Specified by:
countObjects in interface ModelService
Throws:
SchemaException
ObjectNotFoundException

modifyObject

@Deprecated
public <T extends ObjectType> void modifyObject(Class<T> type,
                                                           String oid,
                                                           Collection<? extends ItemDelta> modifications,
                                                           Task task,
                                                           OperationResult parentResult)
                  throws ObjectNotFoundException,
                         SchemaException,
                         ExpressionEvaluationException,
                         CommunicationException,
                         ConfigurationException,
                         ObjectAlreadyExistsException,
                         PolicyViolationException,
                         SecurityViolationException
Deprecated. 

Description copied from interface: ModelService

Modifies object using relative change description.

Must fail if user with provided OID does not exists. Must fail if any of the described changes cannot be applied. Should be atomic.

If two or more modify operations are executed in parallel, the operations should be merged. In case that the operations are in conflict (e.g. one operation adding a value and the other removing the same value), the result is not deterministic.

The operation may fail if the modified object does not conform to the underlying schema of the storage system or the schema enforced by the implementation.

Specified by:
modifyObject in interface ModelService
parentResult - parent OperationResult (in/out)
Throws:
ObjectNotFoundException - specified object does not exist
SchemaException - resulting object would violate the schema
ExpressionEvaluationException - evaluation of expression associated with the object has failed
CommunicationException
ObjectAlreadyExistsException - If the account or another "secondary" object already exists and cannot be created
PolicyViolationException - Policy violation was detected during processing of the object
ConfigurationException
SecurityViolationException

deleteObject

@Deprecated
public <T extends ObjectType> void deleteObject(Class<T> clazz,
                                                           String oid,
                                                           Task task,
                                                           OperationResult parentResult)
                  throws ObjectNotFoundException,
                         ConsistencyViolationException,
                         CommunicationException,
                         SchemaException,
                         ConfigurationException,
                         PolicyViolationException,
                         SecurityViolationException
Deprecated. 

Description copied from interface: ModelService

Deletes object with specified OID.

Must fail if object with specified OID does not exists. Should be atomic.

Specified by:
deleteObject in interface ModelService
oid - OID of object to delete
parentResult - parent OperationResult (in/out)
Throws:
ObjectNotFoundException - specified object does not exist
ConsistencyViolationException - sub-operation failed, cannot delete objects as its deletion would lead to inconsistent state
CommunicationException
ConfigurationException
PolicyViolationException - Policy violation was detected during processing of the object
SchemaException
SecurityViolationException

listAccountShadowOwner

public PrismObject<UserType> listAccountShadowOwner(String accountOid,
                                                    Task task,
                                                    OperationResult result)
                                             throws ObjectNotFoundException
Description copied from interface: ModelService

Returns the User object representing owner of specified account (account shadow).

May return null if there is no owner specified for the account.

Implements the backward "owns" association between account shadow and user. Forward association is implemented by property "account" of user object.

Specified by:
listAccountShadowOwner in interface ModelService
Parameters:
accountOid - OID of the account to look for an owner
result - parent OperationResult (in/out)
Returns:
owner of the account or null
Throws:
ObjectNotFoundException - specified account was not found

listResourceObjectShadows

public <T extends ResourceObjectShadowType> List<PrismObject<T>> listResourceObjectShadows(String resourceOid,
                                                                                           Class<T> resourceObjectShadowType,
                                                                                           Task task,
                                                                                           OperationResult result)
                                                                                throws ObjectNotFoundException
Description copied from interface: ModelService

Search for resource object shadows of a specified type that belong to the specified resource.

Returns a list of such object shadows or empty list if nothing was found.

Returned shadows are "attached", that means they have OID and at they are stored in the repository.

Implements the backward "has" association between resource and resource object shadows. Forward association is implemented by property "resource" of resource object shadow.

TODO: add objectClass to be really usable ?

Specified by:
listResourceObjectShadows in interface ModelService
Type Parameters:
T - specific shadow type (class) to return
Parameters:
resourceOid - OID of the resource that the shadows reside
resourceObjectShadowType - specific shadow type (class) to return
result - parent OperationResult (in/out)
Returns:
list of found shadows
Throws:
ObjectNotFoundException

listResourceObjects

public List<PrismObject<? extends ResourceObjectShadowType>> listResourceObjects(String resourceOid,
                                                                                 QName objectClass,
                                                                                 ObjectPaging paging,
                                                                                 Task task,
                                                                                 OperationResult result)
                                                                          throws SchemaException,
                                                                                 ObjectNotFoundException,
                                                                                 CommunicationException,
                                                                                 ConfigurationException
Description copied from interface: ModelService

Returns all resource objects of specified type that are currently available to the system.

Returns empty list if object type is correct but there are no objects of that type. The operation should fail if object type is wrong (e.g. specified type is not part of resource schema).

This method does NOT use any repository shadow objects for reference or any other business objects in the local repository. It goes directly to the resource. The returned objects (indirectly) comply with the resource schema, but it is returned re-formated in a form of detached shadow object. Although the form is the same as shadow object, this is NOT really a shadow object because it is not stored in the repository (it is detached). It does NOT have OID.

The objects are identified by whatever identification properties/attributes are defined by the resource schema.

The purpose of this operation is diagnostics. It works directly with the resource without the potential problems of underlying implementation. E.g. it may be used to test resource connectivity or correctness of resource setup. It may also be used to reach object types that are not directly supported as "shadows" by the implementation. Therefore this method is not required to implement any form of caching, queuing, reference resolution or any other "smart" algorithm.

Specified by:
listResourceObjects in interface ModelService
Parameters:
resourceOid - OID of the resource to fetch objects from
objectClass - Object class of the objects to fetch
paging - paging specification to limit operation result (optional)
result - parent OperationResult (in/out)
Returns:
resource objects in a form of "detached shadows"
Throws:
SchemaException - error handling resource schema
ObjectNotFoundException - specified resource object does not exist
CommunicationException - error communicating with the resource
ConfigurationException

testResource

public OperationResult testResource(String resourceOid,
                                    Task task)
                             throws ObjectNotFoundException
Description copied from interface: ModelService

Test the resource connection and basic resource connector functionality.

This operation will NOT throw exception in case the resource connection fails. It such case it will indicate the failure in the return message, but the operation itself succeeds. The operations fails only if the provided arguments are wrong, in case of system error, system misconfiguration, etc.

This returns OperationResult instead of taking it as in/out argument. This is different from the other methods. The testResource method is not using OperationResult to track its own execution but rather to track the execution of resource tests (that in fact happen in provisioning).

Specified by:
testResource in interface ModelService
Parameters:
resourceOid - OID of resource to test
Returns:
results of executed tests
Throws:
ObjectNotFoundException - specified object does not exist

importAccountsFromResource

public void importAccountsFromResource(String resourceOid,
                                       QName objectClass,
                                       Task task,
                                       OperationResult parentResult)
                                throws ObjectNotFoundException,
                                       SchemaException
Description copied from interface: ModelService

Import accounts from resource.

Invocation of this method may be switched to background.

TODO: OperationResult

Specified by:
importAccountsFromResource in interface ModelService
Throws:
SchemaException
ObjectNotFoundException

importObjectsFromFile

public void importObjectsFromFile(File input,
                                  ImportOptionsType options,
                                  Task task,
                                  OperationResult parentResult)
Description copied from interface: ModelService
Import objects from file. Invocation of this method may be switched to background.

Specified by:
importObjectsFromFile in interface ModelService

importObjectsFromStream

public void importObjectsFromStream(InputStream input,
                                    ImportOptionsType options,
                                    Task task,
                                    OperationResult parentResult)
Description copied from interface: ModelService
Import objects from stream. Invocation of this method will happen in foreground, as the stream cannot be serialized. The results will be provided in the task.

Specified by:
importObjectsFromStream in interface ModelService

discoverConnectors

public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType,
                                             OperationResult parentResult)
                                      throws CommunicationException
Description copied from interface: ModelService
Discovers local or remote connectors. The operation will try to search for new connectors. It works either on local host (hostType is null) or on a remote host (hostType is not null). All discovered connectors are stored in the repository. It returns connectors that were discovered: those that were not in the repository before invocation of this operation.

Specified by:
discoverConnectors in interface ModelService
Parameters:
hostType - definition of a connector host or null
parentResult - parentResult parent OperationResult (in/out)
Returns:
discovered connectors
Throws:
CommunicationException - error communicating with the connector host

postInit

public void postInit(OperationResult parentResult)
Description copied from interface: ModelService
Finish initialization of the model and lower system components (provisioning, repository, etc). The implementation may execute resource-intensive tasks in this method. All the dependencies should be already constructed, properly wired and initialized. Also logging and other infrastructure should be already set up.

Specified by:
postInit in interface ModelService


Copyright © 2013 evolveum. All Rights Reserved.