use of org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException in project airavata by apache.
the class UserProfileServiceHandler method deleteUserProfile.
@Override
@SecurityCheck
public boolean deleteUserProfile(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException {
try {
// find user-profile
UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId);
// delete user
boolean deleteSuccess = userProfileRepository.delete(userId);
logger.info("Delete UserProfile with userId: " + userId + ", " + (deleteSuccess ? "Success!" : "Failed!"));
if (deleteSuccess) {
// delete userProfile at end-places
ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.DELETE, userProfile), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
}
return deleteSuccess;
} catch (Exception e) {
logger.error("Error while deleting user profile", e);
UserProfileServiceException exception = new UserProfileServiceException();
exception.setMessage("Error while deleting user profile. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException in project airavata by apache.
the class UserProfileServiceHandler method updateUserProfile.
@Override
@SecurityCheck
public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException {
try {
// After updating the user profile in the database but before committing the transaction, the
// following will update the user profile in the IAM service also. If the update in the IAM service
// fails then the transaction will be rolled back.
Runnable iamUserProfileUpdater = getIAMUserProfileUpdater(authzToken, userProfile);
if (userProfileRepository.updateUserProfile(userProfile, iamUserProfileUpdater) != null) {
logger.info("Updated UserProfile with userId: " + userProfile.getUserId());
// replicate userProfile at end-places
ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.UPDATE, userProfile), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
return true;
}
return false;
} catch (Exception e) {
logger.error("Error while Updating user profile", e);
UserProfileServiceException exception = new UserProfileServiceException();
exception.setMessage("Error while Updating user profile. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException in project airavata by apache.
the class UserProfileServiceHandler method getIamAdminServicesClient.
private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileServiceException {
try {
final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort());
final String serverHost = ServerSettings.getProfileServiceServerHost();
return ProfileServiceClientFactory.createIamAdminServiceClient(serverHost, serverPort);
} catch (IamAdminServicesException | ApplicationSettingsException e) {
logger.error("Failed to create IAM Admin Services client", e);
UserProfileServiceException ex = new UserProfileServiceException("Failed to create IAM Admin Services client");
throw ex;
}
}
use of org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException in project airavata by apache.
the class ProfileServiceClientFactory method createUserProfileServiceClient.
public static UserProfileService.Client createUserProfileServiceClient(String serverHost, int serverPort) throws UserProfileServiceException {
try {
TTransport transport = new TSocket(serverHost, serverPort);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, profile_user_cpiConstants.USER_PROFILE_CPI_NAME);
return new UserProfileService.Client(multiplexedProtocol);
} catch (TTransportException e) {
throw new UserProfileServiceException(e.getMessage());
}
}
use of org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException in project airavata by apache.
the class UserProfileServiceHandler method addUserProfile.
@Override
@SecurityCheck
public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException {
try {
// Lowercase user id and internal id
userProfile.setUserId(userProfile.getUserId().toLowerCase());
userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + userProfile.getGatewayId());
userProfile = userProfileRepository.updateUserProfile(userProfile, getIAMUserProfileUpdater(authzToken, userProfile));
if (null != userProfile) {
logger.info("Added UserProfile with userId: " + userProfile.getUserId());
// replicate userProfile at end-places
ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.CREATE, userProfile), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
// return userId
return userProfile.getUserId();
} else {
throw new Exception("User creation failed. Please try again.");
}
} catch (Exception e) {
logger.error("Error while creating user profile", e);
UserProfileServiceException exception = new UserProfileServiceException();
exception.setMessage("Error while creating user profile. More info : " + e.getMessage());
throw exception;
}
}
Aggregations