Search in sources :

Example 66 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiCountOverTimeGet.

/**
 * Get list of API count information
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for created user
 * @param request   MSF4J request
 * @return API Count information
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving APIs created over time. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
        return Response.ok().entity(apiCountListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API created over time info";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 67 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.

the class AuthenticatorAPI method redirect.

/**
 * This method provides the DCR application information to the SSO-IS login.
 *
 * @param request Request to call the /login api
 * @return Response - Response object with OAuth data
 */
@OPTIONS
@GET
@Path("/login/{appName}")
@Produces(MediaType.APPLICATION_JSON)
public Response redirect(@Context Request request, @PathParam("appName") String appName) {
    try {
        AuthenticatorService authenticatorService = AuthenticatorAPIFactory.getInstance().getService();
        JsonObject oAuthData = authenticatorService.getAuthenticationConfigurations(appName);
        if (oAuthData.size() == 0) {
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while creating the OAuth application!").build();
        } else {
            return Response.status(Response.Status.OK).entity(oAuthData).build();
        }
    } catch (APIManagementException e) {
        ErrorDTO errorDTO = AuthUtil.getErrorDTO(e.getErrorHandler(), null);
        log.error(e.getMessage(), e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO) JsonObject(com.google.gson.JsonObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) OPTIONS(javax.ws.rs.OPTIONS)

Example 68 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImpl method subscriptionsGet.

/**
 * Retrieve subscriptions
 *
 * @param apiContext Context of the API
 * @param apiVersion API version
 * @param limit      Limit value
 * @return Subscriptions of the API
 * @throws NotFoundException If failed to retrieve subscriptions
 */
@Override
public Response subscriptionsGet(String apiContext, String apiVersion, Integer limit, String accept, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<SubscriptionValidationData> subscriptionsOfApi;
        if (StringUtils.isEmpty(apiContext) || StringUtils.isEmpty(apiVersion)) {
            APIUtils.logDebug("API Context or version is null or empty. Retrieving subscriptions of all APIs", log);
            subscriptionsOfApi = apiMgtAdminService.getAPISubscriptions(limit);
        } else {
            subscriptionsOfApi = apiMgtAdminService.getAPISubscriptionsOfApi(apiContext, apiVersion);
        }
        SubscriptionListDTO subscriptionsList = new SubscriptionListDTO();
        subscriptionsList.setList(MappingUtil.convertToSubscriptionListDto(subscriptionsOfApi));
        return Response.ok(subscriptionsList).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving subscriptions.";
        HashMap<String, String> paramList = new HashMap<String, String>();
        if (!StringUtils.isEmpty(apiContext)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
        }
        if (!StringUtils.isEmpty(apiVersion)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
        }
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO)

Example 69 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.

the class ErrorDTOTestCase method testToString.

@Test
public void testToString() throws Exception {
    ErrorDTO errorDTO = new ErrorDTO();
    errorDTO.setCode((long) 900311);
    errorDTO.setDescription(description);
    errorDTO.setMessage(message);
    String result = errorDTO.toString();
    Assert.assertEquals(result, expectedString);
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Test(org.testng.annotations.Test)

Example 70 with ErrorDTO

use of org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO in project carbon-apimgt by wso2.

the class RestApiUtilTestCase method testGetErrorDTO2.

@Test(description = "Test get Error DTO as String")
public void testGetErrorDTO2() throws Exception {
    ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
    Map<String, String> paramList = new HashMap<>();
    APIManagementException ex = Mockito.mock(APIManagementException.class);
    paramList.put("param1", "test1");
    paramList.put("param2", "test2");
    paramList.put("param3", "test3");
    when(errorHandler.getErrorDescription()).thenReturn("Test Error Description");
    when(ex.getMessage()).thenReturn("Error Message");
    when(errorHandler.getErrorCode()).thenReturn((long) 900300);
    final String expectedErrorDTOString1 = "class ErrorDTO {\n" + "  code: 900300\n" + "  message: Error Message\n" + "  description: Test Error Description\n" + "  moreInfo: {param3=test3, param1=test1, param2=test2}\n" + "  error: []\n" + "}\n";
    final String expectedErrorDTOString2 = "class ErrorDTO {\n" + "  code: 900300\n" + "  message: null\n" + "  description: Test Error Description\n" + "  moreInfo: {param3=test3, param1=test1, param2=test2}\n" + "  error: []\n" + "}\n";
    ErrorDTO errorDTO1 = RestApiUtil.getErrorDTO(errorHandler, (HashMap<String, String>) paramList, ex);
    Assert.assertEquals(errorDTO1.toString(), expectedErrorDTOString1);
    when(ex.getMessage()).thenReturn(null);
    ErrorDTO errorDTO2 = RestApiUtil.getErrorDTO(errorHandler, (HashMap<String, String>) paramList, ex);
    Assert.assertEquals(errorDTO2.toString(), expectedErrorDTOString2);
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)155 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)154 HashMap (java.util.HashMap)106 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)48 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)45 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 Map (java.util.Map)25 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)15 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)15 IOException (java.io.IOException)11 Application (org.wso2.carbon.apimgt.core.models.Application)11 URI (java.net.URI)10 URISyntaxException (java.net.URISyntaxException)10 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)9 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 ArrayList (java.util.ArrayList)6 API (org.wso2.carbon.apimgt.core.models.API)6 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)6 Label (org.wso2.carbon.apimgt.core.models.Label)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.authenticator.dto.ErrorDTO)6