Search in sources :

Example 21 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)

Example 22 with DtoTranslationException

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

the class ROperationalState method fromJaxb.

public static void fromJaxb(OperationalStateType jaxb, ROperationalState repo) throws DtoTranslationException {
    Objects.requireNonNull(repo, "Repo object must not be null.");
    Objects.requireNonNull(jaxb, "JAXB object must not be null.");
    try {
        if (jaxb.getLastAvailabilityStatus() != null) {
            repo.setLastAvailabilityStatus(RUtil.getRepoEnumValue(jaxb.getLastAvailabilityStatus(), RAvailabilityStatus.class));
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) RAvailabilityStatus(com.evolveum.midpoint.repo.sql.data.common.enums.RAvailabilityStatus) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 23 with DtoTranslationException

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

the class ActivationMapper method map.

@Override
public RActivation map(ActivationType input, MapperContext context) {
    try {
        RActivation ractivation = new RActivation();
        RActivation.fromJaxb(input, ractivation);
        return ractivation;
    } catch (DtoTranslationException ex) {
        throw new SystemException("Couldn't translate activation to entity", ex);
    }
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) RActivation(com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation)

Example 24 with DtoTranslationException

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

the class CaseWorkItemMapper method map.

@Override
public RCaseWorkItem map(CaseWorkItemType input, MapperContext context) {
    RCase owner = (RCase) context.getOwner();
    RCaseWorkItem item;
    try {
        item = RCaseWorkItem.toRepo(owner, input, context.getRepositoryContext());
    } catch (DtoTranslationException ex) {
        throw new SystemException("Couldn't translate CaseWorkItemType to entity", ex);
    }
    return item;
}
Also used : RCase(com.evolveum.midpoint.repo.sql.data.common.RCase) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) RCaseWorkItem(com.evolveum.midpoint.repo.sql.data.common.container.RCaseWorkItem) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 25 with DtoTranslationException

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

the class RResource method copyFromJAXB.

// dynamically called
public static void copyFromJAXB(ResourceType jaxb, RResource repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    copyAssignmentHolderInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setConnectorRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getConnectorRef(), repositoryContext.relationRegistry));
    try {
        if (jaxb.getBusiness() != null) {
            ResourceBusinessConfigurationType business = jaxb.getBusiness();
            repo.getApproverRef().addAll(RUtil.toRObjectReferenceSet(business.getApproverRef(), repo, RReferenceType.RESOURCE_BUSINESS_CONFIGURATION_APPROVER, repositoryContext.relationRegistry));
            repo.setAdministrativeState(RUtil.getRepoEnumValue(business.getAdministrativeState(), RResourceAdministrativeState.class));
        }
        if (jaxb.getOperationalState() != null) {
            ROperationalState repoOpState = new ROperationalState();
            ROperationalState.fromJaxb(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)

Aggregations

DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)30 SystemException (com.evolveum.midpoint.util.exception.SystemException)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 Session (org.hibernate.Session)7 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)6 Item (com.evolveum.midpoint.prism.Item)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 RAnyConverter (com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter)2 RAnyValue (com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue)2 ROperationalState (com.evolveum.midpoint.repo.sql.data.common.embedded.ROperationalState)2 RAvailabilityStatus (com.evolveum.midpoint.repo.sql.data.common.enums.RAvailabilityStatus)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)2 PrismIdentifierGenerator (com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator)2 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)2 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)2