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));
}
}
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));
}
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());
}
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;
}
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);
}
}
Aggregations