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);
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations