Search in sources :

Example 1 with PatchDocument

use of org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument in project identity-api-server by wso2.

the class ServerUserStoreService method buildUserStoreForPatch.

private UserStoreDTO buildUserStoreForPatch(String domainId, List<PatchDocument> patchDocuments) {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    UserStoreDTO userStoreDTO;
    try {
        userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
        PropertyDTO[] propertyDTOS = userStoreDTO.getProperties();
        for (PatchDocument patchDocument : patchDocuments) {
            String path = patchDocument.getPath();
            String value = patchDocument.getValue();
            if (StringUtils.isBlank(path)) {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
            if (path.startsWith(UserStoreConstants.USER_STORE_PROPERTIES)) {
                String propName = extractPropertyName(path);
                if (StringUtils.isNotEmpty(propName)) {
                    for (PropertyDTO propertyDTO : propertyDTOS) {
                        if (propName.equals(propertyDTO.getName())) {
                            propertyDTO.setValue(value);
                        }
                    }
                }
            } else if (path.equals(UserStoreConstants.USER_STORE_DESCRIPTION)) {
                userStoreDTO.setDescription(value);
            } else {
                throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
            }
        }
        userStoreDTO.setProperties(propertyDTOS);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
    return userStoreDTO;
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO) PatchDocument(org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument)

Aggregations

PatchDocument (org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument)1 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)1 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)1 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)1 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)1