use of org.wso2.carbon.humantask.core.engine.commands.Start in project carbon-apimgt by wso2.
the class TierMappingUtil method fromTierListToDTO.
/**
* Converts a List object of Tiers into a DTO
*
* @param tiers a list of Tier objects
* @param limit max number of objects returned
* @param offset starting index
* @return TierListDTO object containing TierDTOs
*/
public static TierListDTO fromTierListToDTO(List<Policy> tiers, String tierLevel, int limit, int offset) {
TierListDTO tierListDTO = new TierListDTO();
List<TierDTO> tierDTOs = tierListDTO.getList();
if (tierDTOs == null) {
tierDTOs = new ArrayList<>();
tierListDTO.setList(tierDTOs);
}
// identifying the proper start and end indexes
int size = tiers.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
Policy tier = tiers.get(i);
tierDTOs.add(fromTierToDTO(tier, tierLevel));
}
tierListDTO.setCount(tierDTOs.size());
return tierListDTO;
}
use of org.wso2.carbon.humantask.core.engine.commands.Start in project carbon-apimgt by wso2.
the class RatingMappingUtil method fromRatingDTOListToRatingListDTO.
/**
* Constructs a RatingListDTO from a list of RatingDTO objects and other information
*
* @param avgRating Average Rating of the API
* @param userRating User Rating for the API
* @param offset starting index
* @param limit maximum number of ratings to return
* @param ratingList List of RatingDTO Objects available for the API
* @return a new RatingLIstDTO object
*/
public static RatingListDTO fromRatingDTOListToRatingListDTO(double avgRating, double userRating, Integer offset, Integer limit, List<RatingDTO> ratingList) {
RatingListDTO ratingListDTO = new RatingListDTO();
List<RatingDTO> ratingDTOs = ratingListDTO.getList();
DecimalFormat decimalFormat = new DecimalFormat("#.#");
ratingListDTO.setAvgRating(String.valueOf(decimalFormat.format(avgRating)));
ratingListDTO.setUserRating(String.valueOf(decimalFormat.format(userRating)));
if (ratingList == null) {
ratingList = new ArrayList<>();
ratingListDTO.setList(ratingList);
}
// add the required range of objects to be returned
int start = offset < ratingList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= ratingList.size() - 1 ? offset + limit - 1 : ratingList.size() - 1;
for (int i = start; i <= end; i++) {
ratingDTOs.add(ratingList.get(i));
}
ratingListDTO.setCount(ratingDTOs.size());
return ratingListDTO;
}
use of org.wso2.carbon.humantask.core.engine.commands.Start in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationsToDTO.
/**
* Converts an Application[] array into a corresponding ApplicationListDTO
*
* @param applications array of Application objects
* @param limit limit parameter
* @param offset starting index
* @return ApplicationListDTO object corresponding to Application[] array
*/
public static ApplicationListDTO fromApplicationsToDTO(List<Application> applications, int limit, int offset) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOs = applicationListDTO.getList();
if (applicationInfoDTOs == null) {
applicationInfoDTOs = new ArrayList<>();
applicationListDTO.setList(applicationInfoDTOs);
}
// identifying the proper start and end indexes
int start = offset < applications.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= applications.size() - 1 ? offset + limit - 1 : applications.size() - 1;
for (int i = start; i <= end; i++) {
applicationInfoDTOs.add(fromApplicationToInfoDTO(applications.get(i)));
}
applicationListDTO.setCount(applicationInfoDTOs.size());
return applicationListDTO;
}
use of org.wso2.carbon.humantask.core.engine.commands.Start 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.humantask.core.engine.commands.Start 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();
}
}
Aggregations