use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class TagsApiServiceImpl method tagsGet.
/**
* Retrieve tags of APIs
*
* @param limit Maximum number of tags to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return A list of qualifying tags as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response tagsGet(Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
TagListDTO tagListDTO = null;
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<Tag> tagList = apiStore.getAllTags();
tagListDTO = TagMappingUtil.fromTagListToDTO(tagList, limit, offset);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving tags";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(tagListDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentListToDTO.
/**
* Wraps a List of Comments to a CommentListDTO
*
* @param commentList list of comments
* @param limit maximum comments to return
* @param offset starting position of the pagination
* @return CommentListDTO
*/
public static CommentListDTO fromCommentListToDTO(List<Comment> commentList, int limit, int offset) {
CommentListDTO commentListDTO = new CommentListDTO();
List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
commentListDTO.setCount(commentList.size());
int start = offset < commentList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= commentList.size() - 1 ? offset + limit - 1 : commentList.size() - 1;
for (int i = start; i <= end; i++) {
listOfCommentDTOs.add(fromCommentToDTO(commentList.get(i)));
}
commentListDTO.setList(listOfCommentDTOs);
return commentListDTO;
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-business-process by wso2.
the class UserSubstitutionService method querySubstitutes.
/**
* Query the substitution records based on substitute, assignee and enabled or disabled.
* Pagination parameters, start, size, sort, order are allowed.
* @return paginated list of substitution info records
*/
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response querySubstitutes() {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
Map<String, String> queryMap = new HashedMap();
for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
String value = uriInfo.getQueryParameters().getFirst(entry.getKey());
if (value != null) {
queryMap.put(entry.getValue(), value);
}
}
// validate the parameters
try {
// replace with tenant aware user names
String tenantAwareUser = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.USER));
queryMap.put(SubstitutionQueryProperties.USER, tenantAwareUser);
String tenantAwareSub = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.SUBSTITUTE));
queryMap.put(SubstitutionQueryProperties.SUBSTITUTE, tenantAwareSub);
if (!isUserAuthorizedForSubstitute(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername())) {
String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (!((queryMap.get(SubstitutionQueryProperties.USER) != null && queryMap.get(SubstitutionQueryProperties.USER).equals(loggedInUser)) || (queryMap.get(SubstitutionQueryProperties.SUBSTITUTE) != null && queryMap.get(SubstitutionQueryProperties.SUBSTITUTE).equals(loggedInUser)))) {
throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
}
}
} catch (UserStoreException e) {
throw new ActivitiException("Error accessing User Store for input validations", e);
}
// validate pagination parameters
validatePaginationParams(queryMap);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<SubstitutesDataModel> dataModelList = UserSubstitutionUtils.querySubstitutions(queryMap, tenantId);
int totalResultCount = UserSubstitutionUtils.getQueryResultCount(queryMap, tenantId);
SubstituteInfoCollectionResponse collectionResponse = new SubstituteInfoCollectionResponse();
collectionResponse.setTotal(totalResultCount);
List<SubstituteInfoResponse> responseList = new ArrayList<>();
for (SubstitutesDataModel subsData : dataModelList) {
SubstituteInfoResponse response = new SubstituteInfoResponse();
response.setEnabled(subsData.isEnabled());
response.setEndTime(subsData.getSubstitutionEnd());
response.setStartTime(subsData.getSubstitutionStart());
response.setSubstitute(subsData.getSubstitute());
response.setAssignee(subsData.getUser());
responseList.add(response);
}
collectionResponse.setSubstituteInfoList(responseList);
collectionResponse.setSize(responseList.size());
String sortType = getSortType(queryMap.get(SubstitutionQueryProperties.SORT));
collectionResponse.setSort(sortType);
collectionResponse.setStart(Integer.parseInt(queryMap.get(SubstitutionQueryProperties.START)));
collectionResponse.setOrder(queryMap.get(SubstitutionQueryProperties.ORDER));
return Response.ok(collectionResponse).build();
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-business-process by wso2.
the class UserSubstitutionUtils method querySubstitutions.
/**
* Query substitution records by given properties.
* Allowed properties: user, substitute, enabled.
* Pagination parameters : start, size, sort, order
* @param propertiesMap
* @return Paginated list of PaginatedSubstitutesDataModel
*/
public static List<SubstitutesDataModel> querySubstitutions(Map<String, String> propertiesMap, int tenantId) {
ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
PaginatedSubstitutesDataModel model = getPaginatedModelFromRequest(propertiesMap, tenantId);
String enabled = propertiesMap.get(SubstitutionQueryProperties.ENABLED);
boolean enabledProvided = false;
if (enabled != null) {
enabledProvided = true;
}
if (!enabledProvided) {
return prepareEndTime(activitiDAO.querySubstituteInfoWithoutEnabled(model));
} else {
return prepareEndTime(activitiDAO.querySubstituteInfo(model));
}
}
use of org.wso2.carbon.apimgt.api.model.Pagination in project charon by wso2.
the class UserResource method getUsersByPost.
@POST
@Path("/.search")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return users according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the users are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid users are found"), @ApiResponse(code = 404, message = "Valid users are not found") })
public Response getUsersByPost(String resourceString) throws FormatNotSupportedException, CharonException {
try {
// obtain the user store manager
UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
// create charon-SCIM user resource manager and hand-over the request.
UserResourceManager userResourceManager = new UserResourceManager();
SCIMResponse scimResponse = userResourceManager.listWithPOST(resourceString, userManager);
return buildResponse(scimResponse);
} catch (CharonException e) {
throw new CharonException(e.getDetail(), e);
}
}
Aggregations