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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations