Search in sources :

Example 1 with TestMappingResponse

use of org.eclipse.vorto.repository.web.core.dto.mapping.TestMappingResponse in project vorto by eclipse.

the class PayloadMappingController method testMapping.

@PutMapping(value = "/test")
@PreAuthorize("hasAuthority('model_viewer')")
public TestMappingResponse testMapping(@RequestBody TestMappingRequest testRequest) throws Exception {
    Object content = null;
    if (testRequest.getContentType().equals(TestContentType.csv)) {
        content = CSV_DESERIALIZER.deserialize(testRequest.getContent());
    } else {
        content = JSON_DESERIALIZER.deserialize(testRequest.getContent());
    }
    InfomodelValue mappedOutput = mappingService.runTest(testRequest.getSpecification(), content);
    TestMappingResponse response = new TestMappingResponse();
    response.setCanonical(new ObjectMapper().writeValueAsString(mappedOutput.serialize()));
    response.setDitto(new Gson().toJson(org.eclipse.vorto.mapping.targetplatform.ditto.TwinPayloadFactory.toDittoProtocol(mappedOutput, "com.acme:4711")));
    response.setAwsiot(new Gson().toJson(org.eclipse.vorto.mapping.targetplatform.awsiot.TwinPayloadFactory.toShadowUpdateRequest(mappedOutput)));
    response.setReport(mappedOutput.validate());
    return response;
}
Also used : Gson(com.google.gson.Gson) TestMappingResponse(org.eclipse.vorto.repository.web.core.dto.mapping.TestMappingResponse) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Gson (com.google.gson.Gson)1 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)1 TestMappingResponse (org.eclipse.vorto.repository.web.core.dto.mapping.TestMappingResponse)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1