Search in sources :

Example 91 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class AbstractRestController method createErrorResponseBuilder.

protected ResponseEntity<?> createErrorResponseBuilder(HttpStatus status, OperationResult result) {
    OperationResultType resultBean;
    if (result != null) {
        result.computeStatusIfUnknown();
        resultBean = result.createOperationResultType();
    } else {
        resultBean = null;
    }
    return status(status).body(resultBean);
}
Also used : OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 92 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class MidpointAbstractProvider method writeTo.

@Override
public void writeTo(T object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    // TODO implement in the standard serializer; also change root name
    QName fakeQName = new QName(PrismConstants.NS_TYPES, "object");
    String serializedForm;
    PrismSerializer<String> serializer = getSerializer().options(SerializationOptions.createSerializeReferenceNames());
    try {
        if (object instanceof ObjectType) {
            ObjectType ot = (ObjectType) object;
            serializedForm = serializer.serialize(ot.asPrismObject());
        } else if (object instanceof PrismObject) {
            serializedForm = serializer.serialize((PrismObject<?>) object);
        } else if (object instanceof OperationResult) {
            Function<LocalizableMessage, String> resolveKeys = msg -> localizationService.translate(msg, Locale.US);
            OperationResultType operationResultType = ((OperationResult) object).createOperationResultType(resolveKeys);
            serializedForm = serializer.serializeAnyData(operationResultType, fakeQName);
        } else {
            serializedForm = serializer.serializeAnyData(object, fakeQName);
        }
        entityStream.write(serializedForm.getBytes(StandardCharsets.UTF_8));
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logException(LOGGER, "Couldn't marshal element to string: {}", e, object);
    }
}
Also used : Arrays(java.util.Arrays) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Trace(com.evolveum.midpoint.util.logging.Trace) LocalizationService(com.evolveum.midpoint.common.LocalizationService) Function(java.util.function.Function) AbstractConfigurableProvider(org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) MediaType(javax.ws.rs.core.MediaType) Locale(java.util.Locale) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) OutputStream(java.io.OutputStream) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) Type(java.lang.reflect.Type) SystemException(com.evolveum.midpoint.util.exception.SystemException) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) QName(javax.xml.namespace.QName) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 93 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class SqlAuditServiceImpl method convertDelta.

private MAuditDelta convertDelta(ObjectDeltaOperation<?> deltaOperation, long recordId) {
    MAuditDelta mAuditDelta = new MAuditDelta();
    mAuditDelta.recordId = recordId;
    try {
        ObjectDelta<? extends ObjectType> delta = deltaOperation.getObjectDelta();
        if (delta != null) {
            DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
            options.setEscapeInvalidCharacters(isEscapingInvalidCharacters(auditConfiguration));
            String serializedDelta = DeltaConvertor.serializeDelta(delta, options, PrismContext.LANG_XML);
            // serializedDelta is transient, needed for changed items later
            mAuditDelta.serializedDelta = serializedDelta;
            mAuditDelta.delta = RUtil.getBytesFromSerializedForm(serializedDelta, sqlConfiguration().isUseZipAudit());
            mAuditDelta.deltaOid = delta.getOid();
            mAuditDelta.deltaType = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(delta.getChangeType(), RChangeType.class));
        }
        OperationResult executionResult = deltaOperation.getExecutionResult();
        if (executionResult != null) {
            OperationResultType jaxb = executionResult.createOperationResultType();
            if (jaxb != null) {
                mAuditDelta.status = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(jaxb.getStatus(), ROperationResultStatus.class));
                // Note that escaping invalid characters and using toString for unsupported types is safe in the
                // context of operation result serialization.
                String full = schemaService.createStringSerializer(PrismContext.LANG_XML).options(SerializationOptions.createEscapeInvalidCharacters().serializeUnsupportedTypesAsString(true)).serializeRealValue(jaxb, SchemaConstantsGenerated.C_OPERATION_RESULT);
                mAuditDelta.fullResult = RUtil.getBytesFromSerializedForm(full, sqlConfiguration().isUseZipAudit());
            }
        }
        mAuditDelta.resourceOid = deltaOperation.getResourceOid();
        if (deltaOperation.getObjectName() != null) {
            mAuditDelta.objectNameOrig = deltaOperation.getObjectName().getOrig();
            mAuditDelta.objectNameNorm = deltaOperation.getObjectName().getNorm();
        }
        if (deltaOperation.getResourceName() != null) {
            mAuditDelta.resourceNameOrig = deltaOperation.getResourceName().getOrig();
            mAuditDelta.resourceNameNorm = deltaOperation.getResourceName().getNorm();
        }
        mAuditDelta.checksum = RUtil.computeChecksum(mAuditDelta.delta, mAuditDelta.fullResult);
    } catch (Exception ex) {
        throw new SystemException("Problem during audit delta conversion", ex);
    }
    return mAuditDelta;
}
Also used : MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 94 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class SqlAuditServiceImpl method convertDelta.

private MAuditDelta convertDelta(ObjectDeltaOperationType deltaOperation, MAuditEventRecord auditRow) {
    MAuditDelta mAuditDelta = new MAuditDelta();
    mAuditDelta.recordId = auditRow.id;
    try {
        ObjectDeltaType delta = deltaOperation.getObjectDelta();
        if (delta != null) {
            DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
            options.setEscapeInvalidCharacters(isEscapingInvalidCharacters(auditConfiguration));
            String serializedDelta = DeltaConvertor.serializeDelta(delta, options, PrismContext.LANG_XML);
            // serializedDelta is transient, needed for changed items later
            mAuditDelta.serializedDelta = serializedDelta;
            mAuditDelta.delta = RUtil.getBytesFromSerializedForm(serializedDelta, sqlConfiguration().isUseZipAudit());
            mAuditDelta.deltaOid = delta.getOid();
            mAuditDelta.deltaType = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(ChangeType.toChangeType(delta.getChangeType()), RChangeType.class));
            for (ItemDeltaType itemDelta : delta.getItemDelta()) {
                ItemPath path = itemDelta.getPath().getItemPath();
                CanonicalItemPath canonical = schemaService.createCanonicalItemPath(path, delta.getObjectType());
                for (int i = 0; i < canonical.size(); i++) {
                    auditRow.addChangedItem(canonical.allUpToIncluding(i).asString());
                }
            }
        }
        OperationResultType executionResult = deltaOperation.getExecutionResult();
        if (executionResult != null) {
            mAuditDelta.status = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(executionResult.getStatus(), ROperationResultStatus.class));
            // Note that escaping invalid characters and using toString for unsupported types is safe in the
            // context of operation result serialization.
            String full = schemaService.createStringSerializer(PrismContext.LANG_XML).options(SerializationOptions.createEscapeInvalidCharacters().serializeUnsupportedTypesAsString(true)).serializeRealValue(executionResult, SchemaConstantsGenerated.C_OPERATION_RESULT);
            mAuditDelta.fullResult = RUtil.getBytesFromSerializedForm(full, sqlConfiguration().isUseZipAudit());
        }
        mAuditDelta.resourceOid = deltaOperation.getResourceOid();
        if (deltaOperation.getObjectName() != null) {
            mAuditDelta.objectNameOrig = deltaOperation.getObjectName().getOrig();
            mAuditDelta.objectNameNorm = deltaOperation.getObjectName().getNorm();
        }
        if (deltaOperation.getResourceName() != null) {
            mAuditDelta.resourceNameOrig = deltaOperation.getResourceName().getOrig();
            mAuditDelta.resourceNameNorm = deltaOperation.getResourceName().getNorm();
        }
        mAuditDelta.checksum = RUtil.computeChecksum(mAuditDelta.delta, mAuditDelta.fullResult);
    } catch (Exception ex) {
        throw new SystemException("Problem during audit delta conversion", ex);
    }
    return mAuditDelta;
}
Also used : MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 95 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSchemaRestService method test030getWrongExtensionSchema.

@Test
public void test030getWrongExtensionSchema() {
    WebClient client = prepareClient();
    when();
    client.path("/wrong-extension");
    client.accept(MediaType.TEXT_PLAIN_TYPE, MediaType.APPLICATION_JSON_TYPE);
    Response response = client.get();
    then();
    assertStatus(response, 400);
    OperationResultType result = response.readEntity(OperationResultType.class);
    assertNotNull("Error result must not be null", result);
    assertFailure("Name must be an xsd schema (.xsd extension expected)", result);
}
Also used : Response(javax.ws.rs.core.Response) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Aggregations

OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)172 Test (org.testng.annotations.Test)106 Holder (javax.xml.ws.Holder)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)75 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)63 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)57 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)56 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)53 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)49 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)47 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)34 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)34 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)32 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)26 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)18 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)18 QName (javax.xml.namespace.QName)18 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)17