Search in sources :

Example 1 with ApplicationTemplatesListItem

use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem in project identity-api-server by wso2.

the class ServerApplicationManagementService method listApplicationTemplates.

/**
 * List all the application templates of the tenant.
 *
 * @param limit  maximum number of items to be returned.
 * @param offset number of records to skip for pagination.
 * @return ApplicationTemplatesList containing the list of templates.
 */
public ApplicationTemplatesList listApplicationTemplates(Integer limit, Integer offset, SearchContext searchContext) {
    validatePaginationSupport(limit, offset);
    try {
        List<Template> templateList = getTemplateManager().listTemplates(TemplateMgtConstants.TemplateType.APPLICATION_TEMPLATE.toString(), null, null, getSearchCondition(TemplateMgtConstants.TemplateType.APPLICATION_TEMPLATE.toString(), ContextLoader.getTenantDomainFromContext(), searchContext));
        List<ApplicationTemplatesListItem> applicationTemplateList = templateList.stream().map(new TemplateToApplicationTemplateListItem()).collect(Collectors.toList());
        ApplicationTemplatesList applicationTemplates = new ApplicationTemplatesList();
        applicationTemplates.setTemplates(applicationTemplateList);
        return applicationTemplates;
    } catch (TemplateManagementException e) {
        throw handleTemplateManagementException(e, "Error while listing application templates.");
    }
}
Also used : ApplicationTemplatesList(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesList) TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) ApplicationTemplatesListItem(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem) ApplicationTemplateApiModelToTemplate(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.ApplicationTemplateApiModelToTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template) TemplateToApplicationTemplate(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplate) TemplateToApplicationTemplateListItem(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplateListItem)

Example 2 with ApplicationTemplatesListItem

use of org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem in project identity-api-server by wso2.

the class TemplateToApplicationTemplateListItem method apply.

@Override
public ApplicationTemplatesListItem apply(Template template) {
    ApplicationTemplatesListItem listItem = new ApplicationTemplatesListItem();
    listItem.setName(template.getTemplateName());
    listItem.setId(template.getTemplateId());
    listItem.setSelf(getApplicationTemplateLocation(template.getTemplateId()));
    listItem.setDescription(template.getDescription());
    listItem.setImage(template.getImageUrl());
    if (template.getPropertiesMap() != null) {
        template.getPropertiesMap().forEach((key, value) -> {
            if (ApplicationManagementConstants.TemplateProperties.TYPES.equals(key) && StringUtils.isNotBlank(value)) {
                listItem.setTypes(Arrays.asList(value.split(",")));
            }
            if (ApplicationManagementConstants.TemplateProperties.DISPLAY_ORDER.equals(key) && StringUtils.isNotBlank(value)) {
                listItem.setDisplayOrder(Integer.parseInt(value));
            }
            if (ApplicationManagementConstants.TemplateProperties.CATEGORY.equals(key)) {
                if (ApplicationTemplatesListItem.CategoryEnum.VENDOR.value().equals(value)) {
                    listItem.setCategory(ApplicationTemplatesListItem.CategoryEnum.VENDOR);
                } else {
                    listItem.setCategory(ApplicationTemplatesListItem.CategoryEnum.DEFAULT);
                }
            }
            if (ApplicationManagementConstants.TemplateProperties.INBOUND_PROTOCOL.equals(key)) {
                listItem.setAuthenticationProtocol(value);
            }
            if (ApplicationManagementConstants.TemplateProperties.TEMPLATE_GROUP.equals(key)) {
                listItem.setTemplateGroup(value);
            }
        });
    }
    return listItem;
}
Also used : ApplicationTemplatesListItem(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem)

Aggregations

ApplicationTemplatesListItem (org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem)2 ApplicationTemplatesList (org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesList)1 ApplicationTemplateApiModelToTemplate (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.ApplicationTemplateApiModelToTemplate)1 TemplateToApplicationTemplate (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplate)1 TemplateToApplicationTemplateListItem (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplateListItem)1 TemplateManagementException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException)1 Template (org.wso2.carbon.identity.template.mgt.model.Template)1