use of org.wso2.carbon.identity.mgt.dto.UserChallengesSetDTO in project carbon-identity-framework by wso2.
the class UserIdentityManagementAdminService method getAllPromotedUserChallenge.
/**
* get all promoted user challenges
*
* @return array of user challenges
* @throws IdentityMgtServiceException if fails
*/
public UserChallengesSetDTO[] getAllPromotedUserChallenge() throws IdentityMgtServiceException {
ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
List<UserChallengesSetDTO> challengeQuestionSetDTOs = new ArrayList<UserChallengesSetDTO>();
List<ChallengeQuestionDTO> questionDTOs = null;
try {
questionDTOs = processor.getAllChallengeQuestions();
} catch (IdentityException e) {
log.error("Error while loading user challenges", e);
throw new IdentityMgtServiceException("Error while loading user challenges");
}
Map<String, List<UserChallengesDTO>> listMap = new HashMap<String, List<UserChallengesDTO>>();
for (ChallengeQuestionDTO dto : questionDTOs) {
List<UserChallengesDTO> dtoList = listMap.get(dto.getQuestionSetId());
if (dtoList == null) {
dtoList = new ArrayList<UserChallengesDTO>();
}
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
userChallengesDTO.setId(dto.getQuestionSetId());
userChallengesDTO.setQuestion(dto.getQuestion());
userChallengesDTO.setOrder(dto.getOrder());
dtoList.add(userChallengesDTO);
listMap.put(dto.getQuestionSetId(), dtoList);
}
for (Map.Entry<String, List<UserChallengesDTO>> listEntry : listMap.entrySet()) {
UserChallengesSetDTO dto = new UserChallengesSetDTO();
dto.setId(listEntry.getKey());
List<UserChallengesDTO> dtoList = listEntry.getValue();
dto.setChallengesDTOs(dtoList.toArray(new UserChallengesDTO[dtoList.size()]));
challengeQuestionSetDTOs.add(dto);
}
return challengeQuestionSetDTOs.toArray(new UserChallengesSetDTO[challengeQuestionSetDTOs.size()]);
}
Aggregations