Search in sources :

Example 21 with IUserProfile

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

the class TestUserManager method testUpdateUser.

public void testUpdateUser() throws Throwable {
    String username = "UserForTest2";
    Date birthdate = this.steBirthdate(1982, 10, 25);
    MockUser user = this.createUserForTest(username);
    IUserProfile profile = this.createProfile("stefano", "puddu", "spuddu@agiletec.it", birthdate, "it");
    user.setProfile(profile);
    try {
        this._userManager.removeUser(user);
        UserDetails extractedUser = this._userManager.getUser(username);
        assertNull(extractedUser);
        this._userManager.addUser(user);
        extractedUser = this._userManager.getUser(username);
        assertEquals(user.getUsername(), extractedUser.getUsername());
        assertNotNull(extractedUser);
        assertEquals(0, extractedUser.getAuthorizations().size());
        user.setPassword("changedPassword");
        IUserProfile extractedProfile = (IUserProfile) extractedUser.getProfile();
        assertNotNull(extractedProfile);
        MonoTextAttribute emailAttr = (MonoTextAttribute) ((IUserProfile) extractedProfile).getAttribute("email");
        assertEquals("spuddu@agiletec.it", emailAttr.getText());
        emailAttr.setText("agiletectest@gmail.com");
        user.setProfile(extractedProfile);
        this._userManager.updateUser(user);
        this._userManager.changePassword(user.getUsername(), user.getUsername());
        extractedUser = this._userManager.getUser(username);
        assertEquals(user.getUsername(), extractedUser.getUsername());
        extractedUser = this._userManager.getUser(username);
        assertNotNull(extractedUser);
        extractedProfile = (IUserProfile) extractedUser.getProfile();
        MonoTextAttribute extractedEmailAttr = (MonoTextAttribute) ((IUserProfile) extractedProfile).getAttribute("email");
        assertEquals("agiletectest@gmail.com", extractedEmailAttr.getText());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._userManager.removeUser(user);
        UserDetails extractedUser = this._userManager.getUser(username);
        assertNull(extractedUser);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) Date(java.util.Date) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)

Example 22 with IUserProfile

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

the class UserProfileManagerIntegrationTest method createProfile.

private IUserProfile createProfile(String name, String surname, String email, Date birthdate, String language) {
    IUserProfile profile = this._profileManager.getDefaultProfileType();
    MonoTextAttribute nameAttr = (MonoTextAttribute) profile.getAttribute("fullname");
    nameAttr.setText(name + " " + surname);
    MonoTextAttribute emailAttr = (MonoTextAttribute) profile.getAttribute("email");
    emailAttr.setText(email);
    DateAttribute birthdateAttr = (DateAttribute) profile.getAttribute("birthdate");
    birthdateAttr.setDate(birthdate);
    MonoTextAttribute languageAttr = (MonoTextAttribute) profile.getAttribute("language");
    languageAttr.setText(language);
    ((UserProfile) profile).setPublicProfile(true);
    return profile;
}
Also used : UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 23 with IUserProfile

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

the class UserProfileManagerTest method testGetDefaultProfileType.

@Test
public void testGetDefaultProfileType() throws ApsSystemException {
    // @formatter:off
    when(entityTypeFactory.extractEntityType(SystemConstants.DEFAULT_PROFILE_TYPE_CODE, UserProfile.class, configItemName, this.entityTypeDom, userProfileManager.getName(), this.entityDom)).thenReturn(this.createFakeProfile(SystemConstants.DEFAULT_PROFILE_TYPE_CODE));
    // @formatter:on
    IUserProfile userProfile = userProfileManager.getDefaultProfileType();
    assertThat(userProfile, is(not(nullValue())));
    assertThat(userProfile.getAttributeList().size(), is(1));
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) Test(org.junit.Test)

Example 24 with IUserProfile

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

the class CurrentUserProfileAttributeTag method getUserProfile.

@Override
protected IUserProfile getUserProfile() throws Throwable {
    HttpSession session = this.pageContext.getSession();
    UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    if (currentUser == null || currentUser.getUsername().equals(SystemConstants.GUEST_USER_NAME) || null == currentUser.getProfile()) {
        _logger.error("User '{}' : Null user, or guest user or user without profile", currentUser);
        return null;
    }
    return (IUserProfile) currentUser.getProfile();
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HttpSession(javax.servlet.http.HttpSession) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 25 with IUserProfile

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

the class TestUserManager method testAddDeleteUser.

public void testAddDeleteUser() throws Throwable {
    String username = "UserForTest1";
    MockUser user = this.createUserForTest(username);
    Date birthdate = this.steBirthdate(1982, 10, 25);
    IUserProfile profile = this.createProfile("stefano", "puddu", "spuddu@agiletec.it", birthdate, "it");
    user.setProfile(profile);
    try {
        this._userManager.removeUser(user);
        UserDetails extractedUser = this._userManager.getUser(username);
        assertNull(extractedUser);
        this._userManager.addUser(user);
        extractedUser = this._userManager.getUser(username);
        assertEquals(user.getUsername(), extractedUser.getUsername());
        assertNotNull(user.getProfile());
        assertEquals("spuddu@agiletec.it", ((IUserProfile) user.getProfile()).getValue("email"));
    } catch (Throwable t) {
        throw t;
    } finally {
        this._userManager.removeUser(user);
        UserDetails extractedUser = this._userManager.getUser(username);
        assertNull(extractedUser);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) Date(java.util.Date)

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