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