Search in sources :

Example 26 with IUserProfile

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

the class UserProfileManagerIntegrationTest method testAddProfile.

public void testAddProfile() throws Throwable {
    String username = "admin";
    Date birthdate = this.getBirthdate(1982, 10, 25);
    IUserProfile profile = this.createProfile("stefano", "puddu", "spuddu@agiletec.it", birthdate, "it");
    try {
        this._profileManager.addProfile("admin", profile);
        IUserProfile added = this._profileManager.getProfile(username);
        assertEquals("spuddu@agiletec.it", added.getValue("email"));
        assertEquals(username, added.getUsername());
        MonoTextAttribute emailAttr = (MonoTextAttribute) ((IUserProfile) profile).getAttribute("email");
        emailAttr.setText("agiletectest@gmail.com");
        this._profileManager.updateProfile(profile.getUsername(), profile);
        IUserProfile updated = this._profileManager.getProfile(username);
        assertEquals("agiletectest@gmail.com", updated.getValue("email"));
        assertEquals(username, added.getUsername());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._profileManager.deleteProfile(username);
        assertNull(this._profileManager.getProfile(username));
    }
}
Also used : 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 27 with IUserProfile

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

the class UserProfileManagerTest method testAddProfile.

@Test
public void testAddProfile() 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();
    String name = "Jack_Bower";
    MonoTextAttribute attribute = (MonoTextAttribute) userProfile.getAttribute("Name");
    attribute.setText(name);
    this.userProfileManager.addProfile(name, userProfile);
    assertThat(userProfile.getId(), is(name));
    Mockito.verify(userProfileDAO, Mockito.times(1)).addEntity(userProfile);
    Mockito.verify(notifyManager, Mockito.times(1)).publishEvent(Mockito.any(ProfileChangedEvent.class));
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ProfileChangedEvent(org.entando.entando.aps.system.services.userprofile.event.ProfileChangedEvent) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) Test(org.junit.Test)

Example 28 with IUserProfile

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

the class UserProfileDAO method buildUpdateEntityStatement.

@Override
protected void buildUpdateEntityStatement(IApsEntity entity, PreparedStatement stat) throws Throwable {
    IUserProfile profile = (IUserProfile) entity;
    stat.setString(1, profile.getTypeCode());
    stat.setString(2, profile.getXML());
    if (profile.isPublicProfile()) {
        stat.setInt(3, 1);
    } else {
        stat.setInt(3, 0);
    }
    stat.setString(4, profile.getUsername());
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 29 with IUserProfile

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

the class ApiUserProfileInterface method getUserProfiles.

public List<String> getUserProfiles(Properties properties) throws Throwable {
    List<String> usernames = null;
    try {
        String userProfileType = properties.getProperty("typeCode");
        IUserProfile prototype = (IUserProfile) this.getUserProfileManager().getEntityPrototype(userProfileType);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile Type '" + userProfileType + "' does not exist", Response.Status.CONFLICT);
        }
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String filtersParam = properties.getProperty("filters");
        BaseFilterUtils filterUtils = new BaseFilterUtils();
        EntitySearchFilter[] filters = filterUtils.getFilters(prototype, filtersParam, langCode);
        usernames = this.getUserProfileManager().searchId(userProfileType, filters);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error searching usernames", t);
        // ApsSystemUtils.logThrowable(t, this, "getUserProfiles");
        throw new ApsSystemException("Error searching usernames", t);
    }
    return usernames;
}
Also used : BaseFilterUtils(com.agiletec.aps.system.common.entity.helper.BaseFilterUtils) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 30 with IUserProfile

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

the class ApiUserProfileInterface method deleteUserProfile.

public void deleteUserProfile(Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String username = properties.getProperty("username");
        IUserProfile userProfile = this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
        }
        this.getUserProfileManager().deleteProfile(username);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting user Profile", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteUserProfile");
        throw new ApsSystemException("Error deleting user Profile", t);
    }
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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