Search in sources :

Example 16 with DtoTranslationException

use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.

the class RResource method copyFromJAXB.

public static void copyFromJAXB(ResourceType jaxb, RResource repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setConnectorRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getConnectorRef(), repositoryContext.prismContext));
    if (jaxb.getConnector() != null) {
        LOGGER.warn("Connector from resource type won't be saved. It should be translated to connector reference.");
    }
    try {
        if (jaxb.getBusiness() != null) {
            ResourceBusinessConfigurationType business = jaxb.getBusiness();
            repo.getApproverRef().addAll(RUtil.safeListReferenceToSet(business.getApproverRef(), repositoryContext.prismContext, repo, RReferenceOwner.RESOURCE_BUSINESS_CONFIGURATON_APPROVER));
            repo.setAdministrativeState(RUtil.getRepoEnumValue(business.getAdministrativeState(), RResourceAdministrativeState.class));
        }
        if (jaxb.getOperationalState() != null) {
            ROperationalState repoOpState = new ROperationalState();
            ROperationalState.copyFromJAXB(jaxb.getOperationalState(), repoOpState);
            repo.setOperationalState(repoOpState);
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
}
Also used : ROperationalState(com.evolveum.midpoint.repo.sql.data.common.embedded.ROperationalState) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ResourceBusinessConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBusinessConfigurationType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) RResourceAdministrativeState(com.evolveum.midpoint.repo.sql.data.common.enums.RResourceAdministrativeState)

Example 17 with DtoTranslationException

use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.

the class RObjectDeltaOperation method toRepo.

public static RObjectDeltaOperation toRepo(RAuditEventRecord record, ObjectDeltaOperation operation, PrismContext prismContext) throws DtoTranslationException {
    RObjectDeltaOperation auditDelta = new RObjectDeltaOperation();
    auditDelta.setRecord(record);
    try {
        if (operation.getObjectDelta() != null) {
            ObjectDelta delta = operation.getObjectDelta();
            String xmlDelta = DeltaConvertor.toObjectDeltaTypeXml(delta, DeltaConversionOptions.createSerializeReferenceNames());
            auditDelta.setDelta(xmlDelta);
            auditDelta.setDeltaOid(delta.getOid());
            auditDelta.setDeltaType(RUtil.getRepoEnumValue(delta.getChangeType(), RChangeType.class));
        }
        if (operation.getExecutionResult() != null) {
            ItemDefinition def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(SchemaConstantsGenerated.C_OPERATION_RESULT);
            RUtil.copyResultFromJAXB(def, SchemaConstantsGenerated.C_OPERATION_RESULT, operation.getExecutionResult().createOperationResultType(), auditDelta, prismContext);
        }
        auditDelta.setObjectName(RPolyString.toRepo(operation.getObjectName()));
        auditDelta.setResourceOid(operation.getResourceOid());
        auditDelta.setResourceName(RPolyString.toRepo(operation.getResourceName()));
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    return auditDelta;
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RChangeType(com.evolveum.midpoint.repo.sql.data.common.enums.RChangeType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 18 with DtoTranslationException

use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.

the class RObjectDeltaOperation method fromRepo.

public static ObjectDeltaOperation fromRepo(RObjectDeltaOperation operation, PrismContext prismContext) throws DtoTranslationException {
    ObjectDeltaOperation odo = new ObjectDeltaOperation();
    try {
        if (operation.getDelta() != null) {
            ObjectDeltaType delta = prismContext.parserFor(operation.getDelta()).parseRealValue(ObjectDeltaType.class);
            odo.setObjectDelta(DeltaConvertor.createObjectDelta(delta, prismContext));
        }
        if (operation.getFullResult() != null) {
            OperationResultType resultType = prismContext.parserFor(operation.getFullResult()).parseRealValue(OperationResultType.class);
            odo.setExecutionResult(OperationResult.createOperationResult(resultType));
        }
        odo.setObjectName(RPolyString.fromRepo(operation.getObjectName()));
        odo.setResourceOid(operation.getResourceOid());
        odo.setResourceName(RPolyString.fromRepo(operation.getResourceName()));
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    return odo;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 19 with DtoTranslationException

use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.

the class SqlAuditServiceImpl method reindexEntryAttempt.

private void reindexEntryAttempt(AuditEventRecord record) {
    Session session = null;
    try {
        session = baseHelper.beginTransaction();
        RAuditEventRecord reindexed = RAuditEventRecord.toRepo(record, getPrismContext());
        //TODO FIXME temporary hack, merge will eventyually load the object to the session if there isn't one,
        // but in this case we force loading object because of "objectDeltaOperation". There is some problem probably
        // during serializing/deserializing which causes constraint violation on priamry key..
        Object o = session.load(RAuditEventRecord.class, record.getRepoId());
        if (o instanceof RAuditEventRecord) {
            RAuditEventRecord rRecord = (RAuditEventRecord) o;
            rRecord.getChangedItems().clear();
            rRecord.getChangedItems().addAll(reindexed.getChangedItems());
            session.merge(rRecord);
        }
        session.getTransaction().commit();
    } catch (DtoTranslationException ex) {
        baseHelper.handleGeneralCheckedException(ex, session, null);
    } catch (RuntimeException ex) {
        baseHelper.handleGeneralRuntimeException(ex, session, null);
    } finally {
        baseHelper.cleanupSessionAndResult(session, null);
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Session(org.hibernate.Session)

Example 20 with DtoTranslationException

use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.

the class ObjectUpdater method addObjectAttempt.

public <T extends ObjectType> String addObjectAttempt(PrismObject<T> object, RepoAddOptions options, OperationResult result) throws ObjectAlreadyExistsException, SchemaException {
    LOGGER_PERFORMANCE.debug("> add object {}, oid={}, overwrite={}", object.getCompileTimeClass().getSimpleName(), object.getOid(), options.isOverwrite());
    String oid = null;
    Session session = null;
    OrgClosureManager.Context closureContext = null;
    // it is needed to keep the original oid for example for import options. if we do not keep it
    // and it was null it can bring some error because the oid is set when the object contains orgRef
    // or it is org. and by the import we do not know it so it will be trying to delete non-existing object
    String originalOid = object.getOid();
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Object\n{}", object.debugDump());
        }
        ObjectTypeUtil.normalizeAllRelations(object);
        LOGGER.trace("Translating JAXB to data type.");
        PrismIdentifierGenerator.Operation operation = options.isOverwrite() ? PrismIdentifierGenerator.Operation.ADD_WITH_OVERWRITE : PrismIdentifierGenerator.Operation.ADD;
        RObject rObject = createDataObjectFromJAXB(object, operation);
        session = baseHelper.beginTransaction();
        closureContext = closureManager.onBeginTransactionAdd(session, object, options.isOverwrite());
        if (options.isOverwrite()) {
            oid = overwriteAddObjectAttempt(object, rObject, originalOid, session, closureContext, result);
        } else {
            oid = nonOverwriteAddObjectAttempt(object, rObject, originalOid, session, closureContext);
        }
        session.getTransaction().commit();
        LOGGER.trace("Saved object '{}' with oid '{}'", object.getCompileTimeClass().getSimpleName(), oid);
        object.setOid(oid);
    } catch (ConstraintViolationException ex) {
        handleConstraintViolationException(session, ex, result);
        baseHelper.rollbackTransaction(session, ex, result, true);
        LOGGER.debug("Constraint violation occurred (will be rethrown as ObjectAlreadyExistsException).", ex);
        // to the original oid and prevent of unexpected behaviour (e.g. by import with overwrite option)
        if (StringUtils.isEmpty(originalOid)) {
            object.setOid(null);
        }
        String constraintName = ex.getConstraintName();
        // Breaker to avoid long unreadable messages
        if (constraintName != null && constraintName.length() > SqlRepositoryServiceImpl.MAX_CONSTRAINT_NAME_LENGTH) {
            constraintName = null;
        }
        throw new ObjectAlreadyExistsException("Conflicting object already exists" + (constraintName == null ? "" : " (violated constraint '" + constraintName + "')"), ex);
    } catch (ObjectAlreadyExistsException | SchemaException ex) {
        baseHelper.rollbackTransaction(session, ex, result, true);
        throw ex;
    } catch (DtoTranslationException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        cleanupClosureAndSessionAndResult(closureContext, session, result);
    }
    return oid;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Session(org.hibernate.Session)

Aggregations

DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)20 Session (org.hibernate.Session)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 Query (org.hibernate.Query)3 Item (com.evolveum.midpoint.prism.Item)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)2 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)2 Timestamp (java.sql.Timestamp)2 HashSet (java.util.HashSet)2 SQLQuery (org.hibernate.SQLQuery)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)1