Search in sources :

Example 1 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project hive by apache.

the class ExecutionController method testLog.

@RequestMapping(value = "/testLog", method = RequestMethod.POST)
@ResponseBody
public TestLogResponse testLog(@RequestBody TestLogRequest logsRequest, BindingResult result) {
    String testHandle = logsRequest.getTestHandle();
    Test testExecution = mTests.get(testHandle);
    if (result.hasErrors() || Strings.nullToEmpty(logsRequest.getTestHandle()).trim().isEmpty() || testExecution == null || logsRequest.getLength() > MAX_READ_SIZE) {
        return new TestLogResponse(Status.illegalArgument());
    }
    File outputFile = testExecution.getOutputFile();
    if (outputFile == null || logsRequest.getOffset() > outputFile.length()) {
        return new TestLogResponse(Status.illegalArgument());
    }
    RandomAccessFile fileHandle = null;
    try {
        fileHandle = new RandomAccessFile(outputFile, "r");
        long offset = logsRequest.getOffset();
        fileHandle.seek(offset);
        int readLength = 0;
        if (offset < fileHandle.length()) {
            readLength = (int) Math.min(fileHandle.length() - offset, logsRequest.getLength());
        }
        byte[] buffer = new byte[readLength];
        fileHandle.readFully(buffer);
        offset += readLength;
        return new TestLogResponse(Status.ok(), offset, new String(buffer, Charsets.UTF_8));
    } catch (IOException e) {
        LOG.info("Unexpected IO error reading " + testExecution.getOutputFile(), e);
        return new TestLogResponse(Status.internalError(e.getMessage()));
    } finally {
        if (fileHandle != null) {
            try {
                fileHandle.close();
            } catch (IOException e) {
                LOG.warn("Error closing " + outputFile, e);
            }
        }
    }
}
Also used : TestLogResponse(org.apache.hive.ptest.api.response.TestLogResponse) RandomAccessFile(java.io.RandomAccessFile) PTest(org.apache.hive.ptest.execution.PTest) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project hive by apache.

the class ExecutionController method testStatus.

@RequestMapping(value = "/testStatus", method = RequestMethod.POST)
@ResponseBody
public TestStatusResponse testStatus(@RequestBody TestStopRequest stopRequest, BindingResult result) {
    String testHandle = stopRequest.getTestHandle();
    Test test = mTests.get(testHandle);
    if (result.hasErrors() || Strings.nullToEmpty(stopRequest.getTestHandle()).trim().isEmpty() || test == null) {
        return new TestStatusResponse(Status.illegalArgument());
    }
    return new TestStatusResponse(Status.ok(), test.toTestStatus());
}
Also used : PTest(org.apache.hive.ptest.execution.PTest) TestStatusResponse(org.apache.hive.ptest.api.response.TestStatusResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project hive by apache.

the class ExecutionController method testStop.

@RequestMapping(value = "/testStop", method = RequestMethod.POST)
@ResponseBody
public TestStopResponse testStop(@RequestBody TestStopRequest stopRequest, BindingResult result) {
    String testHandle = stopRequest.getTestHandle();
    Test test = mTests.get(testHandle);
    if (result.hasErrors() || Strings.nullToEmpty(stopRequest.getTestHandle()).trim().isEmpty() || test == null) {
        return new TestStopResponse(Status.illegalArgument());
    }
    test.setStopRequested(true);
    return new TestStopResponse(Status.ok());
}
Also used : TestStopResponse(org.apache.hive.ptest.api.response.TestStopResponse) PTest(org.apache.hive.ptest.execution.PTest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project head by mifos.

the class CenterRESTController method getCenterChargesByNumber.

@RequestMapping(value = "center/num-{globalCustNum}/charges", method = RequestMethod.GET)
@ResponseBody
public CustomerChargesDetailsDto getCenterChargesByNumber(@PathVariable String globalCustNum) {
    CenterBO centerBO = customerDao.findCenterBySystemId(globalCustNum);
    CustomerChargesDetailsDto centerCharges = centerServiceFacade.retrieveChargesDetails(centerBO.getCustomerId());
    centerCharges.addActivities(centerServiceFacade.retrieveRecentActivities(centerBO.getCustomerId(), 3));
    return centerCharges;
}
Also used : CustomerChargesDetailsDto(org.mifos.dto.domain.CustomerChargesDetailsDto) CenterBO(org.mifos.customers.center.business.CenterBO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project head by mifos.

the class CollectionSheetRESTController method saveCollectionSheet.

@RequestMapping(value = "/collectionsheet/save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveCollectionSheet(@RequestBody JSONSaveCollectionsheet request) throws Throwable {
    Map<String, Object> map = new HashMap<String, Object>();
    ObjectMapper om = createObjectMapper();
    List<InvalidSaveCollectionSheetReason> reasons = new ArrayList<InvalidSaveCollectionSheetReason>();
    CollectionSheetErrorsDto errors = null;
    SaveCollectionSheetDto saveCollectionSheetDto = null;
    try {
        saveCollectionSheetDto = om.readValue(request.getJson(), SaveCollectionSheetDto.class);
    } catch (JsonMappingException e) {
        if (e.getCause() instanceof SaveCollectionSheetException) {
            reasons.addAll(((SaveCollectionSheetException) e.getCause()).getInvalidSaveCollectionSheetReasons());
        } else {
            throw e.getCause();
        }
    }
    if (saveCollectionSheetDto != null) {
        try {
            errors = collectionSheetServiceFacade.saveCollectionSheet(saveCollectionSheetDto);
            map.put("errors", errors != null ? errors.getErrorText() : null);
        } catch (MifosRuntimeException e) {
            map.put("errors", e.getMessage());
        }
    }
    map.put("invalidCollectionSheet", reasons);
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SaveCollectionSheetDto(org.mifos.application.servicefacade.SaveCollectionSheetDto) InvalidSaveCollectionSheetReason(org.mifos.application.servicefacade.InvalidSaveCollectionSheetReason) SaveCollectionSheetException(org.mifos.application.servicefacade.SaveCollectionSheetException) CollectionSheetErrorsDto(org.mifos.application.servicefacade.CollectionSheetErrorsDto) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) MifosRuntimeException(org.mifos.core.MifosRuntimeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2017 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1720 HashMap (java.util.HashMap)460 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)212 IOException (java.io.IOException)207 JSONObject (com.alibaba.fastjson.JSONObject)201 ApiOperation (io.swagger.annotations.ApiOperation)176 ArrayList (java.util.ArrayList)172 Map (java.util.Map)172 GetMapping (org.springframework.web.bind.annotation.GetMapping)114 ResponseEntity (org.springframework.http.ResponseEntity)104 ApiRest (build.dream.common.api.ApiRest)101 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)101 AuthPassport (com.ngtesting.platform.util.AuthPassport)99 PostMapping (org.springframework.web.bind.annotation.PostMapping)97 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)90 Date (java.util.Date)81 UserVo (com.ngtesting.platform.vo.UserVo)78 LogDetail (com.bc.pmpheep.annotation.LogDetail)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)65