Search in sources :

Example 31 with IUserProfile

use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.

the class ApiUserProfileInterface method updateUserProfile.

public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String username = jaxbUserProfile.getId();
        if (null == this.getUserProfileManager().getProfile(username)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
        }
        IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
        if (null == profilePrototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
        }
        IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
        List<ApiError> errors = this.validate(userProfile);
        if (errors.size() > 0) {
            response.addErrors(errors);
            response.setResult(IResponseBuilder.FAILURE, null);
            return response;
        }
        this.getUserProfileManager().updateProfile(username, userProfile);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating user profile", t);
        // ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
        throw new ApsSystemException("Error updating user profile", t);
    }
    return response;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 32 with IUserProfile

use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.

the class UserAvatarAction method extractGravatar.

protected String extractGravatar() {
    try {
        IUserProfile profile = this.getUserProfile();
        if (null == profile) {
            return this.extractDefaultAvatarStream();
        }
        String email = (String) profile.getValueByRole(SystemConstants.USER_PROFILE_ATTRIBUTE_ROLE_MAIL);
        if (null == email) {
            return this.extractDefaultAvatarStream();
        }
        URL url = new URL(this.createGravatarUri(email));
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        this.setInputStream(conn.getInputStream());
    } catch (FileNotFoundException fnfe) {
        _logger.info("avatar not available", fnfe);
        return this.extractDefaultAvatarStream();
    } catch (Throwable t) {
        _logger.error("error in returnAvatarStream", t);
        return this.extractDefaultAvatarStream();
    }
    return SUCCESS;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL)

Example 33 with IUserProfile

use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.

the class CurrentAvatarAction method getUserProfile.

@Override
protected IUserProfile getUserProfile() throws ApsSystemException {
    UserDetails currentUser = super.getCurrentUser();
    IUserProfile profile = (null != currentUser && null != currentUser.getProfile()) ? (IUserProfile) currentUser.getProfile() : null;
    return profile;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 34 with IUserProfile

use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.

the class CurrentUserProfileAction method save.

@Override
public String save() {
    try {
        IUserProfile profile = this.getUserProfile();
        if (profile == null) {
            return FAILURE;
        }
        UserDetails user = this.getCurrentUser();
        ((AbstractUser) user).setProfile(profile);
        if (null == this.getUserProfileManager().getProfile(user.getUsername())) {
            this.getUserProfileManager().addProfile(user.getUsername(), profile);
        } else {
            this.getUserProfileManager().updateProfile(user.getUsername(), profile);
        }
        this.getRequest().getSession().removeAttribute(SESSION_PARAM_NAME_CURRENT_PROFILE);
        this.addActionMessage(this.getText("message.profileUpdated"));
    } catch (Throwable t) {
        _logger.error("error in save", t);
        // ApsSystemUtils.logThrowable(t, this, "save");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) AbstractUser(com.agiletec.aps.system.services.user.AbstractUser)

Example 35 with IUserProfile

use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.

the class UserProfileAction method save.

@Override
public String save() {
    try {
        IUserProfile userProfile = (IUserProfile) this.getApsEntity();
        String username = userProfile.getUsername();
        if (null == this.getUserProfileManager().getProfile(userProfile.getUsername())) {
            this.getUserProfileManager().addProfile(username, userProfile);
        } else {
            this.getUserProfileManager().updateProfile(username, userProfile);
        }
        UserDetails currentUser = super.getCurrentUser();
        if (null != currentUser && currentUser.getUsername().equals(username) && (currentUser instanceof AbstractUser)) {
            ((AbstractUser) currentUser).setProfile(userProfile);
        }
    } catch (Throwable t) {
        _logger.error("error in save", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) AbstractUser(com.agiletec.aps.system.services.user.AbstractUser)

Aggregations

IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)42 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 UserDetails (com.agiletec.aps.system.services.user.UserDetails)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)5 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)3 AbstractUser (com.agiletec.aps.system.services.user.AbstractUser)3 Date (java.util.Date)3 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)3 CacheableInfo (org.entando.entando.aps.system.services.cache.CacheableInfo)3 CachePut (org.springframework.cache.annotation.CachePut)3 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)2 ActionSupport (com.opensymphony.xwork2.ActionSupport)2 ArrayList (java.util.ArrayList)2 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)2 Test (org.junit.Test)2 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)1 BaseFilterUtils (com.agiletec.aps.system.common.entity.helper.BaseFilterUtils)1 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1