use of org.wso2.carbon.apimgt.rest.api.authenticator.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();
}
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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();
}
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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();
}
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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);
}
use of org.wso2.carbon.apimgt.rest.api.authenticator.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);
}
Aggregations