Search in sources :

Example 11 with DtoTranslationException

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
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 12 with DtoTranslationException

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);
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 13 with DtoTranslationException

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);
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) Session(org.hibernate.Session)

Example 14 with DtoTranslationException

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());
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) Item(com.evolveum.midpoint.prism.Item) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) HashSet(java.util.HashSet)

Example 15 with DtoTranslationException

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;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Timestamp(java.sql.Timestamp) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

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