use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class RAuditEventRecord method fromRepo.
public static AuditEventRecord fromRepo(RAuditEventRecord repo, PrismContext prismContext) throws DtoTranslationException {
AuditEventRecord audit = new AuditEventRecord();
audit.setChannel(repo.getChannel());
audit.setEventIdentifier(repo.getEventIdentifier());
if (repo.getEventStage() != null) {
audit.setEventStage(repo.getEventStage().getStage());
}
if (repo.getEventType() != null) {
audit.setEventType(repo.getEventType().getType());
}
audit.setHostIdentifier(repo.getHostIdentifier());
audit.setRemoteHostAddress(repo.getRemoteHostAddress());
audit.setNodeIdentifier(repo.getNodeIdentifier());
audit.setMessage(repo.getMessage());
if (repo.getOutcome() != null) {
audit.setOutcome(repo.getOutcome().getStatus());
}
audit.setParameter(repo.getParameter());
audit.setResult(repo.getResult());
audit.setSessionIdentifier(repo.getSessionIdentifier());
audit.setTaskIdentifier(repo.getTaskIdentifier());
audit.setTaskOID(repo.getTaskOID());
if (repo.getTimestamp() != null) {
audit.setTimestamp(repo.getTimestamp().getTime());
}
List<ObjectDeltaOperation> odos = new ArrayList<>();
for (RObjectDeltaOperation rodo : repo.getDeltas()) {
try {
ObjectDeltaOperation odo = RObjectDeltaOperation.fromRepo(rodo, prismContext);
if (odo != null) {
odos.add(odo);
}
} catch (Exception ex) {
// TODO: for now thi is OK, if we cannot parse detla, just skipp
// it.. Have to be resolved later;
}
}
audit.getDeltas().addAll((Collection) odos);
for (RAuditPropertyValue rPropertyValue : repo.getPropertyValues()) {
audit.addPropertyValue(rPropertyValue.getName(), rPropertyValue.getValue());
}
for (RAuditReferenceValue rRefValue : repo.getReferenceValues()) {
audit.addReferenceValue(rRefValue.getName(), rRefValue.fromRepo());
}
audit.setRepoId(repo.getId());
return audit;
// initiator, target, targetOwner
}
use of com.evolveum.midpoint.repo.sql.util.DtoTranslationException in project midpoint by Evolveum.
the class RConnector method copyFromJAXB.
public static void copyFromJAXB(ConnectorType jaxb, RConnector repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
repo.setConnectorBundle(jaxb.getConnectorBundle());
repo.setConnectorType(jaxb.getConnectorType());
repo.setConnectorVersion(jaxb.getConnectorVersion());
repo.setFramework(jaxb.getFramework());
repo.setConnectorHostRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getConnectorHostRef(), repositoryContext.prismContext));
if (jaxb.getConnectorHost() != null) {
LOGGER.warn("Connector host from connector type won't be saved. It should be " + "translated to connector host reference.");
}
try {
repo.setTargetSystemType(RUtil.listToSet(jaxb.getTargetSystemType()));
} 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 SqlAuditServiceImpl method auditAttempt.
private void auditAttempt(AuditEventRecord record) {
Session session = null;
try {
session = baseHelper.beginTransaction();
RAuditEventRecord newRecord = RAuditEventRecord.toRepo(record, getPrismContext());
session.save(newRecord);
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 RAssignmentExtension method copyFromJAXB.
private static void copyFromJAXB(PrismContainerValue containerValue, RAssignmentExtension repo, RAssignmentExtensionType type, RepositoryContext repositoryContext) throws DtoTranslationException {
RAnyConverter converter = new RAnyConverter(repositoryContext.prismContext);
Set<RAnyValue> values = new HashSet<RAnyValue>();
try {
List<Item<?, ?>> items = containerValue.getItems();
for (Item item : items) {
values.addAll(converter.convertToRValue(item, true));
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
for (RAnyValue value : values) {
((RAExtValue) value).setAnyContainer(repo);
((RAExtValue) value).setExtensionType(type);
if (value instanceof RAExtDate) {
repo.getDates().add((RAExtDate) value);
} else if (value instanceof RAExtLong) {
repo.getLongs().add((RAExtLong) value);
} else if (value instanceof RAExtReference) {
repo.getReferences().add((RAExtReference) value);
} else if (value instanceof RAExtString) {
repo.getStrings().add((RAExtString) value);
} else if (value instanceof RAExtPolyString) {
repo.getPolys().add((RAExtPolyString) value);
} else if (value instanceof RAExtBoolean) {
repo.getBooleans().add((RAExtBoolean) 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 RAnyConverter method convertToRValue.
//todo assignment parameter really messed up this method, proper interfaces must be introduced later [lazyman]
public Set<RAnyValue> convertToRValue(Item item, boolean assignment) throws DtoTranslationException {
Validate.notNull(item, "Object for converting must not be null.");
Validate.notNull(item.getDefinition(), "Item '" + item.getElementName() + "' without definition can't be saved.");
ItemDefinition definition = item.getDefinition();
Set<RAnyValue> rValues = new HashSet<>();
if (!isIndexed(definition, prismContext)) {
return rValues;
}
try {
RAnyValue rValue;
List<PrismValue> values = item.getValues();
for (PrismValue value : values) {
if (value instanceof PrismPropertyValue) {
PrismPropertyValue propertyValue = (PrismPropertyValue) value;
//todo omg, do something with this!!! [lazyman]
switch(getValueType(definition.getTypeName())) {
case BOOLEAN:
{
Boolean repoValue = extractValue(propertyValue, Boolean.class);
if (assignment) {
rValue = new RAExtBoolean(repoValue);
} else {
rValue = new ROExtBoolean(repoValue);
}
break;
}
case LONG:
{
Long repoValue = extractValue(propertyValue, Long.class);
if (assignment) {
rValue = new RAExtLong(repoValue);
} else {
rValue = new ROExtLong(repoValue);
}
break;
}
case DATE:
{
Timestamp repoValue = extractValue(propertyValue, Timestamp.class);
if (assignment) {
rValue = new RAExtDate(repoValue);
} else {
rValue = new ROExtDate(repoValue);
}
break;
}
case POLY_STRING:
{
PolyString repoValue = extractValue(propertyValue, PolyString.class);
if (assignment) {
rValue = new RAExtPolyString(repoValue);
} else {
rValue = new ROExtPolyString(repoValue);
}
break;
}
case STRING:
default:
{
String repoValue = extractValue(propertyValue, String.class);
if (assignment) {
rValue = new RAExtString(repoValue);
} else {
rValue = new ROExtString(repoValue);
}
}
}
} else if (value instanceof PrismReferenceValue) {
if (assignment) {
PrismReferenceValue referenceValue = (PrismReferenceValue) value;
rValue = RAExtReference.createReference(referenceValue);
} else {
PrismReferenceValue referenceValue = (PrismReferenceValue) value;
rValue = ROExtReference.createReference(referenceValue);
}
} else if (value == null) {
// shouldn't occur anyway
continue;
} else {
// shouldn't get here because if isIndexed test above
throw new AssertionError("Wrong value type: " + value);
}
rValue.setName(RUtil.qnameToString(definition.getName()));
rValue.setType(RUtil.qnameToString(definition.getTypeName()));
rValue.setValueType(getValueType(value.getParent()));
rValue.setDynamic(definition.isDynamic());
rValues.add(rValue);
}
} catch (Exception ex) {
throw new DtoTranslationException("Exception when translating " + item + ": " + ex.getMessage(), ex);
}
return rValues;
}
Aggregations