Search in sources :

Example 1 with LocalClaimResDTO

use of org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO in project identity-api-server by wso2.

the class ServerClaimManagementService method getLocalClaimResDTO.

private LocalClaimResDTO getLocalClaimResDTO(LocalClaim localClaim) {
    LocalClaimResDTO localClaimResDTO = new LocalClaimResDTO();
    localClaimResDTO.setId(base64EncodeId(localClaim.getClaimURI()));
    localClaimResDTO.setClaimURI(localClaim.getClaimURI());
    localClaimResDTO.setDialectURI(localClaim.getClaimDialectURI());
    Map<String, String> claimProperties = new HashMap<>(localClaim.getClaimProperties());
    String description = claimProperties.remove(PROP_DESCRIPTION);
    localClaimResDTO.setDescription(description);
    if (description == null) {
        localClaimResDTO.setDescription(StringUtils.EMPTY);
    }
    String propDisplayOrder = claimProperties.remove(PROP_DISPLAY_ORDER);
    if (StringUtils.isNumeric(propDisplayOrder)) {
        localClaimResDTO.setDisplayOrder(Integer.valueOf(propDisplayOrder));
    } else {
        localClaimResDTO.setDisplayOrder(0);
    }
    localClaimResDTO.setDisplayName(claimProperties.remove(PROP_DISPLAY_NAME));
    localClaimResDTO.setReadOnly(Boolean.valueOf(claimProperties.remove(PROP_READ_ONLY)));
    String regEx = claimProperties.remove(PROP_REG_EX);
    localClaimResDTO.setRegEx(regEx);
    if (regEx == null) {
        localClaimResDTO.setRegEx(StringUtils.EMPTY);
    }
    localClaimResDTO.setRequired(Boolean.valueOf(claimProperties.remove(PROP_REQUIRED)));
    localClaimResDTO.setSupportedByDefault(Boolean.valueOf(claimProperties.remove(PROP_SUPPORTED_BY_DEFAULT)));
    List<AttributeMappingDTO> attributeMappingDTOs = new ArrayList<>();
    for (AttributeMapping attributeMapping : localClaim.getMappedAttributes()) {
        AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
        attributeMappingDTO.setUserstore(attributeMapping.getUserStoreDomain());
        attributeMappingDTO.setMappedAttribute(attributeMapping.getAttributeName());
        attributeMappingDTOs.add(attributeMappingDTO);
    }
    localClaimResDTO.setAttributeMapping(attributeMappingDTOs);
    localClaimResDTO.setProperties(mapToProperties(claimProperties));
    return localClaimResDTO;
}
Also used : AttributeMappingDTO(org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO) HashMap(java.util.HashMap) LocalClaimResDTO(org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ArrayList(java.util.ArrayList)

Example 2 with LocalClaimResDTO

use of org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO in project identity-api-server by wso2.

the class ServerClaimManagementService method getLocalClaim.

/**
 * Retrieve a local claim.
 *
 * @param claimId claimId.
 * @return Local claim.
 */
public LocalClaimResDTO getLocalClaim(String claimId) {
    try {
        List<LocalClaim> localClaimList = getClaimMetadataManagementService().getLocalClaims(ContextLoader.getTenantDomainFromContext());
        LocalClaim localClaim = extractLocalClaimFromClaimList(base64DecodeId(claimId), localClaimList);
        if (localClaim == null) {
            throw handleClaimManagementClientError(ERROR_CODE_LOCAL_CLAIM_NOT_FOUND, NOT_FOUND, claimId);
        }
        return getLocalClaimResDTO(localClaim);
    } catch (ClaimMetadataException e) {
        throw handleClaimManagementException(e, ERROR_CODE_ERROR_RETRIEVING_LOCAL_CLAIM, claimId);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)1 AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)1 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)1 AttributeMappingDTO (org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO)1 LocalClaimResDTO (org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimResDTO)1