use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class GatewayUtils method generateApplicationList.
public static ApplicationListDTO generateApplicationList(List<Application> applicationList, SubscriptionDataStore subscriptionDataStore) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOList = new ArrayList<>();
for (Application application : applicationList) {
ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO().id(application.getId()).name(application.getName()).policy(application.getPolicy()).attributes(application.getAttributes()).subName(application.getSubName()).uuid(application.getUUID()).tokenType(application.getTokenType()).keys(convertToApplicationKeyMapping(application.getId(), subscriptionDataStore));
applicationInfoDTOList.add(applicationInfoDTO);
}
applicationListDTO.setList(applicationInfoDTOList);
applicationListDTO.setCount(applicationInfoDTOList.size());
return applicationListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
/**
* Retrieves all the applications that the user has access to
*
* @param groupId group Id
* @param query search condition
* @param limit max number of objects returns
* @param offset starting index
* @param ifNoneMatch If-None-Match header value
* @return Response object containing resulted applications
*/
@Override
public Response applicationsGet(String groupId, String query, String sortBy, String sortOrder, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DEFAULT_SORT_ORDER;
sortBy = sortBy != null ? ApplicationMappingUtil.getApplicationSortByField(sortBy) : APIConstants.APPLICATION_NAME;
query = query == null ? "" : query;
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
String username = RestApiCommonUtil.getLoggedInUsername();
// todo: Do a second level filtering for the incoming group ID.
// todo: eg: use case is when there are lots of applications which is accessible to his group "g1", he wants to see
// todo: what are the applications shared to group "g2" among them.
groupId = RestApiUtil.getLoggedInUserGroupId();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
Subscriber subscriber = new Subscriber(username);
Application[] applications;
applications = apiConsumer.getApplicationsWithPagination(new Subscriber(username), groupId, offset, limit, query, sortBy, sortOrder, organization);
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
int applicationCount = apiMgtDAO.getAllApplicationCount(subscriber, groupId, query);
applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(applications);
ApplicationMappingUtil.setPaginationParamsWithSortParams(applicationListDTO, groupId, limit, offset, applicationCount, sortOrder, sortBy.toLowerCase());
return Response.ok().entity(applicationListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.rootCauseMessageMatches(e, "start index seems to be greater than the limit count")) {
// this is not an error of the user as he does not know the total number of applications available.
// Thus sends an empty response
applicationListDTO.setCount(0);
applicationListDTO.setPagination(new PaginationDTO());
return Response.ok().entity(applicationListDTO).build();
} else {
String errorMessage = "Error while retrieving Applications";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
@Override
public Response applicationsGet(String user, Integer limit, Integer offset, String accept, String applicationName, String tenantDomain, String sortBy, String sortOrder, MessageContext messageContext) {
// To store the initial value of the user (specially if it is null or empty)
String givenUser = user;
// if no username provided user associated with access token will be used
if (user == null || StringUtils.isEmpty(user)) {
user = RestApiCommonUtil.getLoggedInUsername();
givenUser = StringUtils.EMPTY;
}
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DEFAULT_SORT_ORDER;
sortBy = getApplicationsSortByField(sortBy);
applicationName = applicationName != null ? applicationName : StringUtils.EMPTY;
ApplicationListDTO applicationListDTO;
try {
Application[] allMatchedApps;
boolean migrationMode = Boolean.getBoolean(RestApiConstants.MIGRATION_MODE);
int allApplicationsCount = 0;
if (!migrationMode) {
// normal non-migration flow
if (!MultitenantUtils.getTenantDomain(user).equals(RestApiCommonUtil.getLoggedInUserTenantDomain())) {
String errorMsg = "User " + user + " is not available for the current tenant domain";
log.error(errorMsg);
return Response.status(Response.Status.FORBIDDEN).entity(errorMsg).build();
}
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(user);
// If no user is passed, get the applications for the tenant (not only for the user)
APIAdmin apiAdmin = new APIAdminImpl();
int tenantId = APIUtil.getTenantId(user);
allMatchedApps = apiAdmin.getApplicationsWithPagination(user, givenUser, tenantId, limit, offset, applicationName, sortBy, sortOrder);
allApplicationsCount = apiAdmin.getApplicationsCount(tenantId, givenUser, applicationName);
} else {
// flow at migration process
if (StringUtils.isEmpty(tenantDomain)) {
tenantDomain = MultitenantUtils.getTenantDomain(user);
}
RestApiUtil.handleMigrationSpecificPermissionViolations(tenantDomain, RestApiCommonUtil.getLoggedInUsername());
APIAdmin apiAdmin = new APIAdminImpl();
allMatchedApps = apiAdmin.getAllApplicationsOfTenantForMigration(tenantDomain);
}
applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(allMatchedApps);
ApplicationMappingUtil.setPaginationParams(applicationListDTO, limit, offset, allApplicationsCount);
return Response.ok().entity(applicationListDTO).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving applications of the user " + user, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationListDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationsToDTO.
public static ApplicationListDTO fromApplicationsToDTO(Application[] applications) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOs = applicationListDTO.getList();
if (applicationInfoDTOs == null) {
applicationInfoDTOs = new ArrayList<>();
applicationListDTO.setList(applicationInfoDTOs);
}
for (Application application : applications) {
applicationInfoDTOs.add(fromApplicationToInfoDTO(application));
}
applicationListDTO.setCount(applicationInfoDTOs.size());
return applicationListDTO;
}
Aggregations