Search in sources :

Example 1 with RepositoryContext

use of com.evolveum.midpoint.repo.sql.data.RepositoryContext in project midpoint by Evolveum.

the class ObjectUpdater method createDataObjectFromJAXB.

public <T extends ObjectType> RObject createDataObjectFromJAXB(PrismObject<T> prismObject, PrismIdentifierGenerator.Operation operation) throws SchemaException {
    PrismIdentifierGenerator generator = new PrismIdentifierGenerator();
    IdGeneratorResult generatorResult = generator.generate(prismObject, operation);
    T object = prismObject.asObjectable();
    RObject rObject;
    Class<? extends RObject> clazz = ClassMapper.getHQLTypeClass(object.getClass());
    try {
        rObject = clazz.newInstance();
        Method method = clazz.getMethod("copyFromJAXB", object.getClass(), clazz, RepositoryContext.class, IdGeneratorResult.class);
        method.invoke(clazz, object, rObject, new RepositoryContext(repositoryService, prismContext), generatorResult);
    } catch (Exception ex) {
        String message = ex.getMessage();
        if (StringUtils.isEmpty(message) && ex.getCause() != null) {
            message = ex.getCause().getMessage();
        }
        throw new SchemaException(message, ex);
    }
    return rObject;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) IdGeneratorResult(com.evolveum.midpoint.repo.sql.util.IdGeneratorResult) PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) Method(java.lang.reflect.Method) SerializationRelatedException(com.evolveum.midpoint.repo.sql.SerializationRelatedException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SQLException(java.sql.SQLException)

Aggregations

SerializationRelatedException (com.evolveum.midpoint.repo.sql.SerializationRelatedException)1 RepositoryContext (com.evolveum.midpoint.repo.sql.data.RepositoryContext)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)1 IdGeneratorResult (com.evolveum.midpoint.repo.sql.util.IdGeneratorResult)1 PrismIdentifierGenerator (com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1