Search in sources :

Example 1 with PreferenceSearchAttribute

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method getConfigPreference.

/**
 * Get governance connector properties according to the search attribute.
 *
 * @param preferenceSearchAttribute Governance connector details.
 * @return Governance connector properties for the given connector or properties.
 */
public List<PreferenceResp> getConfigPreference(List<PreferenceSearchAttribute> preferenceSearchAttribute) {
    IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    List<PreferenceResp> preferenceRespList = new ArrayList<>();
    for (PreferenceSearchAttribute prefSearchAttr : preferenceSearchAttribute) {
        String connectorName = prefSearchAttr.getConnectorName();
        List<String> expectedProperties = prefSearchAttr.getProperties();
        Property[] properties;
        try {
            ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName);
            if (connectorConfig == null) {
                throw handleBadRequestError(GovernanceConstants.ErrorMessage.ERROR_CODE_INCORRECT_CONNECTOR_NAME, connectorName);
            }
            properties = connectorConfig.getProperties();
            PreferenceResp preferenceResp = buildPreferenceRespDTO(connectorName, properties, expectedProperties);
            preferenceRespList.add(preferenceResp);
        } catch (IdentityGovernanceException e) {
            GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR_PREFERENCES;
            Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
            throw handleException(e, errorEnum, status);
        }
    }
    return preferenceRespList;
}
Also used : PreferenceSearchAttribute(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute) ConnectorConfig(org.wso2.carbon.identity.governance.bean.ConnectorConfig) ArrayList(java.util.ArrayList) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException) PreferenceResp(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) Property(org.wso2.carbon.identity.application.common.model.Property)

Aggregations

ArrayList (java.util.ArrayList)1 PreferenceResp (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp)1 PreferenceSearchAttribute (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute)1 Property (org.wso2.carbon.identity.application.common.model.Property)1 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)1 IdentityGovernanceService (org.wso2.carbon.identity.governance.IdentityGovernanceService)1 ConnectorConfig (org.wso2.carbon.identity.governance.bean.ConnectorConfig)1