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;
}
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);
}
}
Aggregations