Search in sources :

Example 1 with UserProfileServiceException

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;
    }
}
Also used : UserProfile(org.apache.airavata.model.user.UserProfile) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 2 with UserProfileServiceException

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;
    }
}
Also used : UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 3 with UserProfileServiceException

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;
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException)

Example 4 with UserProfileServiceException

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());
    }
}
Also used : TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) TSocket(org.apache.thrift.transport.TSocket)

Example 5 with UserProfileServiceException

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;
    }
}
Also used : UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Aggregations

UserProfileServiceException (org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 IamAdminServicesException (org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)4 AuthorizationException (org.apache.airavata.model.error.AuthorizationException)3 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)3 TException (org.apache.thrift.TException)3 UserProfile (org.apache.airavata.model.user.UserProfile)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TMultiplexedProtocol (org.apache.thrift.protocol.TMultiplexedProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 TTransportException (org.apache.thrift.transport.TTransportException)1