Search in sources :

Example 36 with IUserProfile

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

the class UserProfileAction method createNewProfile.

protected String createNewProfile(boolean onlyVoid) {
    String username = this.getUsername();
    String profileTypeCode = this.getProfileTypeCode();
    try {
        String check = this.checkUsername(username, false);
        if (null != check)
            return check;
        this.getUserProfileManager().deleteProfile(username);
        /*
            IUserProfile userProfile = (IUserProfile) this.getUserProfileManager().getProfile(username);
            if (null != userProfile) {
                this.getRequest().getSession().setAttribute(USERPROFILE_ON_SESSION, userProfile);
                return "edit";
            }
			*/
        if (StringUtils.isBlank(profileTypeCode)) {
            String[] args = { profileTypeCode };
            this.addFieldError("profileTypeCode", this.getText("error.newUserProfile.invalidProfileType", args));
            return INPUT;
        }
        IUserProfile prototype = (IUserProfile) this.getUserProfileManager().getEntityPrototype(profileTypeCode);
        if (null == prototype) {
            String[] args = { profileTypeCode };
            this.addFieldError("profileTypeCode", this.getText("error.newUserProfile.invalidProfileType", args));
            return INPUT;
        }
        prototype.setId(this.getUsername());
        this.getUserProfileManager().addProfile(username, prototype);
        if (onlyVoid) {
            this.getRequest().getSession().removeAttribute(USERPROFILE_ON_SESSION);
        } else {
            this.getRequest().getSession().setAttribute(USERPROFILE_ON_SESSION, prototype);
        }
    } catch (Throwable t) {
        _logger.error("error in createNewProfile", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 37 with IUserProfile

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

the class UserProfileAction method view.

@Override
public String view() {
    String username = this.getUsername();
    try {
        String checkUsernameResult = this.checkUsername(username, true);
        if (null != checkUsernameResult)
            return checkUsernameResult;
        IUserProfile userProfile = (IUserProfile) this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            String[] args = { username };
            this.addFieldError("username", this.getText("error.viewUserProfile.userWithoutProfile", args));
            return INPUT;
        }
    } catch (Throwable t) {
        _logger.error("error in view", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 38 with IUserProfile

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

the class TestCurrentUserProfileAction method testValidateProfile.

public void testValidateProfile() throws Throwable {
    this.setUserOnSession("editorCustomers");
    this.initAction("/do/currentuser/profile", "edit");
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    this.initAction("/do/currentuser/profile", "save");
    this.addParameter("Monotext:fullname", "");
    this.addParameter("Monotext:email", "");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);
    ActionSupport action = this.getAction();
    assertEquals(2, action.getFieldErrors().size());
    this.initAction("/do/currentuser/profile", "save");
    this.addParameter("Monotext:fullname", "Ronald Rossi");
    this.addParameter("Monotext:email", "");
    this.addParameter("Date:birthdate", "25/09/1972");
    this.addParameter("Monotext:language", "it");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);
    action = this.getAction();
    assertEquals(1, action.getFieldErrors().size());
    assertEquals(1, ((List<String>) action.getFieldErrors().get("Monotext:email")).size());
    IUserProfile currentUserProfile = (IUserProfile) this.getRequest().getSession().getAttribute(ICurrentUserProfileAction.SESSION_PARAM_NAME_CURRENT_PROFILE);
    assertNotNull(currentUserProfile);
    assertEquals("editorCustomers", currentUserProfile.getUsername());
    assertEquals("Ronald Rossi", currentUserProfile.getValue("fullname"));
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 39 with IUserProfile

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

the class TestCurrentUserProfileAction method testEditProfile_2.

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

Example 40 with IUserProfile

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

the class TestUserProfileAction method testEditProfile_2.

public void testEditProfile_2() throws Throwable {
    this.setUserOnSession("admin");
    this.initAction("/do/userprofile", "edit");
    this.addParameter("username", "editorCustomers");
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    IUserProfile currentUserProfile = (IUserProfile) this.getRequest().getSession().getAttribute(UserProfileAction.USERPROFILE_ON_SESSION);
    assertNotNull(currentUserProfile);
    assertEquals("editorCustomers", 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