use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class RAnyConverter method convertFromRValue.
public void convertFromRValue(RAnyValue value, PrismContainerValue any) throws DtoTranslationException {
Validate.notNull(value, "Value for converting must not be null.");
Validate.notNull(any, "Parent prism container value must not be null.");
try {
Item<?, ?> item = any.findOrCreateItem(RUtil.stringToQName(value.getName()), value.getValueType().getItemClass());
if (item == null) {
throw new DtoTranslationException("Couldn't create item for value '" + value.getName() + "'.");
}
addValueToItem(value, item);
} catch (Exception ex) {
if (ex instanceof DtoTranslationException) {
throw (DtoTranslationException) ex;
}
throw new DtoTranslationException(ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class AuditTest method getAuditEventRecord.
private AuditEventRecord getAuditEventRecord(int expectedCount, int index) {
Session session = getFactory().openSession();
try {
session.beginTransaction();
Query query = session.createQuery("from " + RAuditEventRecord.class.getSimpleName() + " order by id");
List<RAuditEventRecord> records = query.list();
assertEquals(expectedCount, records.size());
AuditEventRecord eventRecord = RAuditEventRecord.fromRepo(records.get(index), prismContext);
session.getTransaction().commit();
return eventRecord;
} catch (DtoTranslationException e) {
throw new SystemException(e);
} finally {
session.close();
}
}
use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class RObject method copyFromJAXB.
public static void copyFromJAXB(PrismContainerValue containerValue, RObject repo, RepositoryContext repositoryContext, RObjectExtensionType ownerType) throws DtoTranslationException {
RAnyConverter converter = new RAnyConverter(repositoryContext.prismContext);
Set<RAnyValue> values = new HashSet<RAnyValue>();
try {
List<Item<?, ?>> items = containerValue.getItems();
//TODO: is this ehought??should we try items without definitions??
if (items != null) {
for (Item item : items) {
values.addAll(converter.convertToRValue(item, false));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
for (RAnyValue value : values) {
ROExtValue ex = (ROExtValue) value;
ex.setOwner(repo);
ex.setOwnerType(ownerType);
if (value instanceof ROExtDate) {
repo.getDates().add(value);
} else if (value instanceof ROExtLong) {
repo.getLongs().add(value);
} else if (value instanceof ROExtReference) {
repo.getReferences().add(value);
} else if (value instanceof ROExtString) {
repo.getStrings().add(value);
} else if (value instanceof ROExtPolyString) {
repo.getPolys().add(value);
} else if (value instanceof ROExtBoolean) {
repo.getBooleans().add(value);
}
}
repo.setStringsCount((short) repo.getStrings().size());
repo.setDatesCount((short) repo.getDates().size());
repo.setPolysCount((short) repo.getPolys().size());
repo.setReferencesCount((short) repo.getReferences().size());
repo.setLongsCount((short) repo.getLongs().size());
repo.setBooleansCount((short) repo.getBooleans().size());
}
use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class SqlAuditServiceImpl method listRecordsIterativeAttempt.
private void listRecordsIterativeAttempt(String query, Map<String, Object> params, AuditResultHandler handler) {
Session session = null;
int count = 0;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("List records attempt\n query: {}\n params:\n{}", query, DebugUtil.debugDump(params, 2));
}
try {
session = baseHelper.beginReadOnlyTransaction();
Query q;
if (StringUtils.isBlank(query)) {
query = "from RAuditEventRecord as aer where 1=1 order by aer.timestamp desc";
q = session.createQuery(query);
setParametersToQuery(q, params);
} else {
q = session.createQuery(query);
setParametersToQuery(q, params);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("List records attempt\n processed query: {}", q);
}
ScrollableResults resultList = q.scroll();
while (resultList.next()) {
Object o = resultList.get(0);
if (!(o instanceof RAuditEventRecord)) {
throw new DtoTranslationException("Unexpected object in result set. Expected audit record, but got " + o.getClass().getSimpleName());
}
RAuditEventRecord raudit = (RAuditEventRecord) o;
AuditEventRecord audit = RAuditEventRecord.fromRepo(raudit, getPrismContext());
// TODO what if original name (in audit log) differs from the current one (in repo) ?
audit.setInitiator(resolve(session, raudit.getInitiatorOid(), raudit.getInitiatorName(), RObjectType.USER));
audit.setTarget(resolve(session, raudit.getTargetOid(), raudit.getTargetName(), raudit.getTargetType()));
audit.setTargetOwner(resolve(session, raudit.getTargetOwnerOid(), raudit.getTargetOwnerName(), RObjectType.USER));
count++;
if (!handler.handle(audit)) {
LOGGER.trace("Skipping handling of objects after {} was handled. ", audit);
break;
}
}
session.getTransaction().commit();
} catch (DtoTranslationException | SchemaException ex) {
baseHelper.handleGeneralCheckedException(ex, session, null);
} catch (RuntimeException ex) {
baseHelper.handleGeneralRuntimeException(ex, session, null);
} finally {
baseHelper.cleanupSessionAndResult(session, null);
}
LOGGER.trace("List records iterative attempt processed {} records", count);
}
use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class RAuditEventRecord method toRepo.
public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
Validate.notNull(record, "Audit event record must not be null.");
Validate.notNull(prismContext, "Prism context must not be null.");
RAuditEventRecord repo = new RAuditEventRecord();
if (record.getRepoId() != null) {
repo.setId(record.getRepoId());
}
repo.setChannel(record.getChannel());
if (record.getTimestamp() != null) {
repo.setTimestamp(new Timestamp(record.getTimestamp()));
}
repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
repo.setSessionIdentifier(record.getSessionIdentifier());
repo.setEventIdentifier(record.getEventIdentifier());
repo.setHostIdentifier(record.getHostIdentifier());
repo.setRemoteHostAddress(record.getRemoteHostAddress());
repo.setNodeIdentifier(record.getNodeIdentifier());
repo.setParameter(record.getParameter());
repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
if (record.getOutcome() != null) {
repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
}
repo.setTaskIdentifier(record.getTaskIdentifier());
repo.setTaskOID(record.getTaskOID());
repo.setResult(record.getResult());
try {
if (record.getTarget() != null) {
PrismReferenceValue target = record.getTarget();
repo.setTargetName(getOrigName(target));
repo.setTargetOid(target.getOid());
repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
}
if (record.getTargetOwner() != null) {
PrismObject targetOwner = record.getTargetOwner();
repo.setTargetOwnerName(getOrigName(targetOwner));
repo.setTargetOwnerOid(targetOwner.getOid());
}
if (record.getInitiator() != null) {
PrismObject<UserType> initiator = record.getInitiator();
repo.setInitiatorName(getOrigName(initiator));
repo.setInitiatorOid(initiator.getOid());
}
for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
if (delta == null) {
continue;
}
ObjectDelta<?> objectDelta = delta.getObjectDelta();
for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
ItemPath path = itemDelta.getPath();
if (path != null) {
// TODO what if empty?
CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
for (int i = 0; i < canonical.size(); i++) {
RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
repo.getChangedItems().add(changedItem);
}
}
}
RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
rDelta.setTransient(true);
rDelta.setRecord(repo);
repo.getDeltas().add(rDelta);
}
for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
for (String propertyValue : propertyEntry.getValue()) {
repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
}
}
for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return repo;
}
Aggregations