Search in sources :

Example 1 with IdentityProviderTemplateListResponse

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse in project identity-api-server by wso2.

the class ServerIdpManagementService method createIDPTemplateListResponse.

/**
 * Create the IDP template list response.
 *
 * @param templateInfoList  List of IDP templates.
 * @param offset            Offset.
 * @param limit             Limit.
 * @param filter            IDP template filter.
 * @return {@link IdentityProviderTemplateListResponse}
 */
private IdentityProviderTemplateListResponse createIDPTemplateListResponse(List<Template> templateInfoList, Integer offset, Integer limit, String filter) {
    IdentityProviderTemplateListResponse idpTemplateListResponse = new IdentityProviderTemplateListResponse();
    if (!CollectionUtils.isEmpty(templateInfoList)) {
        List<IdentityProviderTemplateListItem> idpTemplates = new ArrayList<>();
        for (Template idpTemplate : templateInfoList) {
            IdentityProviderTemplateListItem idpTemplateListItem = new IdentityProviderTemplateListItem();
            idpTemplateListItem.setId(idpTemplate.getTemplateId());
            idpTemplateListItem.setDescription(idpTemplate.getDescription());
            idpTemplateListItem.setName(idpTemplate.getTemplateName());
            idpTemplateListItem.setImage(idpTemplate.getImageUrl());
            idpTemplateListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + IDP_TEMPLATE_PATH_COMPONENT + "/%s", idpTemplate.getTemplateId())).toString());
            if (idpTemplate.getPropertiesMap().containsKey(PROP_CATEGORY)) {
                if (IdentityProviderTemplateListItem.CategoryEnum.CUSTOM.toString().equals(idpTemplate.getPropertiesMap().get(PROP_CATEGORY))) {
                    idpTemplateListItem.setCategory(IdentityProviderTemplateListItem.CategoryEnum.CUSTOM);
                } else {
                    idpTemplateListItem.setCategory(IdentityProviderTemplateListItem.CategoryEnum.DEFAULT);
                }
            }
            if (idpTemplate.getPropertiesMap().containsKey(PROP_DISPLAY_ORDER)) {
                idpTemplateListItem.setDisplayOrder(Integer.valueOf(idpTemplate.getPropertiesMap().get(PROP_DISPLAY_ORDER)));
            }
            if ((idpTemplate.getPropertiesMap().containsKey(PROP_SERVICES)) && (idpTemplate.getPropertiesMap().get(PROP_SERVICES) != null)) {
                idpTemplateListItem.setServices(Arrays.asList(idpTemplate.getPropertiesMap().get(PROP_SERVICES).split(",")));
            }
            idpTemplates.add(idpTemplateListItem);
        }
        idpTemplateListResponse.setTemplates(idpTemplates);
        idpTemplateListResponse.setCount(idpTemplates.size());
    } else {
        idpTemplateListResponse.setCount(0);
    }
    limit = (limit == null) ? Integer.valueOf(0) : limit;
    offset = (offset == null) ? Integer.valueOf(0) : offset;
    idpTemplateListResponse.setTotalResults(templateInfoList.size());
    idpTemplateListResponse.setStartIndex(offset + 1);
    idpTemplateListResponse.setLinks(createLinks(V1_API_PATH_COMPONENT + IDP_TEMPLATE_PATH_COMPONENT, limit, offset, templateInfoList.size(), filter));
    return idpTemplateListResponse;
}
Also used : IdentityProviderTemplateListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse) ArrayList(java.util.ArrayList) IdentityProviderTemplateListItem(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListItem) IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Example 2 with IdentityProviderTemplateListResponse

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse in project identity-api-server by wso2.

the class ServerIdpManagementService method getIDPTemplates.

/**
 * Retrieve the list of IDP templates.
 *
 * @param limit         Items per page.
 * @param offset        Offset.
 * @param searchContext Search Criteria. E.g. filter="name" sw "google" and "category" eq "DEFAULT"
 * @return List of identity templates.
 */
public IdentityProviderTemplateListResponse getIDPTemplates(Integer limit, Integer offset, SearchContext searchContext) {
    try {
        TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
        List<Template> templateList = templateManager.listTemplates(TemplateMgtConstants.TemplateType.IDP_TEMPLATE.toString(), limit, offset, getSearchCondition(TemplateMgtConstants.TemplateType.IDP_TEMPLATE.toString(), ContextLoader.getTenantDomainFromContext(), searchContext));
        return createIDPTemplateListResponse(templateList, offset, limit, searchContext.getSearchExpression());
    } catch (TemplateManagementException e) {
        throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_IDP_TEMPLATES, null);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager) IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Aggregations

IdentityProviderTemplate (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate)2 Template (org.wso2.carbon.identity.template.mgt.model.Template)2 ArrayList (java.util.ArrayList)1 IdentityProviderTemplateListItem (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListItem)1 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)1 TemplateManager (org.wso2.carbon.identity.template.mgt.TemplateManager)1 TemplateManagementException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException)1