Search in sources :

Example 1 with UserChallengesSetDTO

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()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) UserChallengesDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesDTO) HashMap(java.util.HashMap) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) ArrayList(java.util.ArrayList) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) UserChallengesSetDTO(org.wso2.carbon.identity.mgt.dto.UserChallengesSetDTO)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IdentityException (org.wso2.carbon.identity.base.IdentityException)1 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)1 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)1 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)1 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)1 UserChallengesSetDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesSetDTO)1