Search in sources :

Example 1 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getErrorListItemsDTOsFromErrorHandler.

public static List<ErrorListItemDTO> getErrorListItemsDTOsFromErrorHandler(ErrorHandler error) {
    List<ErrorListItemDTO> errorListItemDTOs = new ArrayList<>();
    ErrorListItemDTO dto = new ErrorListItemDTO();
    dto.setCode(error.getErrorCode() + "");
    dto.setMessage(error.getErrorMessage());
    dto.setDescription(error.getErrorDescription());
    errorListItemDTOs.add(dto);
    return errorListItemDTOs;
}
Also used : ArrayList(java.util.ArrayList) ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO)

Example 2 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO in project carbon-apimgt by wso2.

the class ErrorListItemDTOTestCase method testToString.

@Test
public void testToString() throws Exception {
    ErrorListItemDTO errorListItemDTO = new ErrorListItemDTO();
    errorListItemDTO.setCode("900311");
    errorListItemDTO.setMessage("Couldn't Update as API have changes can't be done");
    String result = errorListItemDTO.toString();
    Assert.assertEquals(result, expectedString);
}
Also used : ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO) Test(org.testng.annotations.Test)

Example 3 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getErrorDTOFromErrorListItems.

/**
 * Get the ErrorDTO from a list of ErrorListItemDTOs. The first item in the list is set as the main error.
 *
 * @param errorListItemDTOs A list of ErrorListItemDTO objects
 * @return ErrorDTO from a list of ErrorListItemDTOs
 */
public static ErrorDTO getErrorDTOFromErrorListItems(List<ErrorListItemDTO> errorListItemDTOs) {
    ErrorDTO errorDTO = new ErrorDTO();
    for (int i = 0; i < errorListItemDTOs.size(); i++) {
        if (i == 0) {
            ErrorListItemDTO elementAt0 = errorListItemDTOs.get(0);
            errorDTO.setCode(Long.parseLong(elementAt0.getCode()));
            errorDTO.setMoreInfo("");
            errorDTO.setMessage(elementAt0.getMessage());
            errorDTO.setDescription(elementAt0.getDescription());
        } else {
            org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO errorListItemDTO = new org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO();
            errorListItemDTO.setCode(errorListItemDTOs.get(i).getCode() + "");
            errorListItemDTO.setMessage(errorListItemDTOs.get(i).getMessage());
            errorListItemDTO.setDescription(errorListItemDTOs.get(i).getDescription());
            errorDTO.getError().add(errorListItemDTO);
        }
    }
    return errorDTO;
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO)

Example 4 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getErrorListItemsDTOsFromErrorHandlers.

public static List<ErrorListItemDTO> getErrorListItemsDTOsFromErrorHandlers(List<ErrorHandler> errorHandlers) {
    List<ErrorListItemDTO> errorListItemDTOs = new ArrayList<>();
    for (ErrorHandler handler : errorHandlers) {
        ErrorListItemDTO dto = new ErrorListItemDTO();
        dto.setCode(handler.getErrorCode() + "");
        dto.setMessage(handler.getErrorMessage());
        dto.setDescription(handler.getErrorDescription());
        errorListItemDTOs.add(dto);
    }
    return errorListItemDTOs;
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.api.ErrorHandler) ArrayList(java.util.ArrayList) ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO)

Example 5 with ErrorListItemDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO in project carbon-apimgt by wso2.

the class RestApiUtil method getErrorDTO.

/**
 * Returns a generic errorDTO from a list of Error Handlers
 *
 * @param errorHandlers A List of error handler objects containing the error information
 * @return A generic errorDTO with the specified details
 */
public static ErrorDTO getErrorDTO(List<ErrorHandler> errorHandlers) {
    ErrorDTO errorDTO = new ErrorDTO();
    for (int i = 0; i < errorHandlers.size(); i++) {
        if (i == 0) {
            ErrorHandler elementAt0 = errorHandlers.get(0);
            errorDTO.setCode(elementAt0.getErrorCode());
            errorDTO.setMoreInfo("");
            errorDTO.setMessage(elementAt0.getErrorMessage());
            errorDTO.setDescription(elementAt0.getErrorDescription());
        } else {
            ErrorListItemDTO errorListItemDTO = new ErrorListItemDTO();
            errorListItemDTO.setCode(errorHandlers.get(i).getErrorCode() + "");
            errorListItemDTO.setMessage(errorHandlers.get(i).getErrorMessage());
            errorListItemDTO.setDescription(errorHandlers.get(i).getErrorDescription());
            errorDTO.getError().add(errorListItemDTO);
        }
    }
    return errorDTO;
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.api.ErrorHandler) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ErrorListItemDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO)

Aggregations

ArrayList (java.util.ArrayList)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 ErrorListItemDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorListItemDTO)3 ErrorListItemDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ErrorListItemDTO)3 ErrorHandler (org.wso2.carbon.apimgt.api.ErrorHandler)2 ConstraintViolation (javax.validation.ConstraintViolation)1 Test (org.testng.annotations.Test)1