Search in sources :

Example 11 with IUserProfile

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

the class SocialActivityStreamManager method getActionCommentRecords.

@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'ActivityStreamCommentRecords_id_'.concat(#id)")
@CacheableInfo(groups = "'ActivityStreamCommentRecords_cacheGroup'")
public List<ActivityStreamComment> getActionCommentRecords(int id) throws ApsSystemException {
    List<ActivityStreamComment> infos = null;
    try {
        infos = this.getSocialActivityStreamDAO().getActionCommentRecords(id);
        if (null != infos) {
            for (int i = 0; i < infos.size(); i++) {
                ActivityStreamComment comment = infos.get(i);
                String username = comment.getUsername();
                IUserProfile profile = this.getUserProfileManager().getProfile(username);
                String displayName = (null != profile) ? profile.getDisplayName() : username;
                comment.setDisplayName(displayName);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting activity stream like records for stream with id {}", id, t);
        throw new ApsSystemException("Error extracting activity stream like records", t);
    }
    return infos;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ActivityStreamComment(org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment) CacheableInfo(org.entando.entando.aps.system.services.cache.CacheableInfo) CachePut(org.springframework.cache.annotation.CachePut)

Example 12 with IUserProfile

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

the class UserAction method checkUserProfile.

private boolean checkUserProfile(String username, String profileTypeCode) throws ApsSystemException {
    try {
        IUserProfile userProfile = this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            userProfile = (null != profileTypeCode) ? this.getUserProfileManager().getProfileType(profileTypeCode) : null;
            if (null == userProfile) {
                userProfile = this.getUserProfileManager().getDefaultProfileType();
            }
            if (null != userProfile) {
                userProfile.setId(username);
                this.getUserProfileManager().addProfile(username, userProfile);
                return true;
            }
        } else {
            return true;
        }
    } catch (Throwable t) {
        _logger.error("Error adding default profile for user {}", username, t);
        throw new ApsSystemException("Error adding default profile for user " + username, t);
    }
    return false;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 13 with IUserProfile

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

the class UserProfileAction method edit.

@Override
public String edit() {
    String username = this.getUsername();
    try {
        String checkUsernameResult = this.checkUsername(username, false);
        if (null != checkUsernameResult)
            return checkUsernameResult;
        IUserProfile userProfile = (IUserProfile) this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            List<IApsEntity> userProfileTypes = new ArrayList<IApsEntity>();
            userProfileTypes.addAll(this.getUserProfileManager().getEntityPrototypes().values());
            if (userProfileTypes.isEmpty()) {
                throw new RuntimeException("Unexpected error - no one user profile types");
            } else if (userProfileTypes.size() == 1) {
                userProfile = (IUserProfile) userProfileTypes.get(0);
                userProfile.setId(username);
            } else {
                return "chooseType";
            }
        }
        this.getRequest().getSession().setAttribute(USERPROFILE_ON_SESSION, userProfile);
    } catch (Throwable t) {
        _logger.error("error in edit", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 14 with IUserProfile

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

the class TestCurrentUserProfileAction method testEditProfile_1.

public void testEditProfile_1() throws Throwable {
    this.setUserOnSession(USERNAME_FOR_TEST);
    this.initAction("/do/currentuser/profile", "edit");
    String result = this.executeAction();
    assertEquals("currentUserWithoutProfile", result);
    IUserProfile currentUserProfile = (IUserProfile) this.getRequest().getSession().getAttribute(ICurrentUserProfileAction.SESSION_PARAM_NAME_CURRENT_PROFILE);
    assertNull(currentUserProfile);
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 15 with IUserProfile

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

the class TestUserProfileAction method testEditProfile_1.

public void testEditProfile_1() throws Throwable {
    this.setUserOnSession("admin");
    this.initAction("/do/userprofile", "edit");
    this.addParameter("username", USERNAME_FOR_TEST);
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    IUserProfile currentUserProfile = (IUserProfile) this.getRequest().getSession().getAttribute(UserProfileAction.USERPROFILE_ON_SESSION);
    assertNotNull(currentUserProfile);
    assertEquals(USERNAME_FOR_TEST, currentUserProfile.getUsername());
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

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