use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class ApiUserProfileInterface method updateUserProfile.
public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = jaxbUserProfile.getId();
if (null == this.getUserProfileManager().getProfile(username)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
}
IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
if (null == profilePrototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
}
IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
List<ApiError> errors = this.validate(userProfile);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
this.getUserProfileManager().updateProfile(username, userProfile);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating user profile", t);
// ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
throw new ApsSystemException("Error updating user profile", t);
}
return response;
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class UserAvatarAction method extractGravatar.
protected String extractGravatar() {
try {
IUserProfile profile = this.getUserProfile();
if (null == profile) {
return this.extractDefaultAvatarStream();
}
String email = (String) profile.getValueByRole(SystemConstants.USER_PROFILE_ATTRIBUTE_ROLE_MAIL);
if (null == email) {
return this.extractDefaultAvatarStream();
}
URL url = new URL(this.createGravatarUri(email));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
this.setInputStream(conn.getInputStream());
} catch (FileNotFoundException fnfe) {
_logger.info("avatar not available", fnfe);
return this.extractDefaultAvatarStream();
} catch (Throwable t) {
_logger.error("error in returnAvatarStream", t);
return this.extractDefaultAvatarStream();
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class CurrentAvatarAction method getUserProfile.
@Override
protected IUserProfile getUserProfile() throws ApsSystemException {
UserDetails currentUser = super.getCurrentUser();
IUserProfile profile = (null != currentUser && null != currentUser.getProfile()) ? (IUserProfile) currentUser.getProfile() : null;
return profile;
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class CurrentUserProfileAction method save.
@Override
public String save() {
try {
IUserProfile profile = this.getUserProfile();
if (profile == null) {
return FAILURE;
}
UserDetails user = this.getCurrentUser();
((AbstractUser) user).setProfile(profile);
if (null == this.getUserProfileManager().getProfile(user.getUsername())) {
this.getUserProfileManager().addProfile(user.getUsername(), profile);
} else {
this.getUserProfileManager().updateProfile(user.getUsername(), profile);
}
this.getRequest().getSession().removeAttribute(SESSION_PARAM_NAME_CURRENT_PROFILE);
this.addActionMessage(this.getText("message.profileUpdated"));
} catch (Throwable t) {
_logger.error("error in save", t);
// ApsSystemUtils.logThrowable(t, this, "save");
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class UserProfileAction method save.
@Override
public String save() {
try {
IUserProfile userProfile = (IUserProfile) this.getApsEntity();
String username = userProfile.getUsername();
if (null == this.getUserProfileManager().getProfile(userProfile.getUsername())) {
this.getUserProfileManager().addProfile(username, userProfile);
} else {
this.getUserProfileManager().updateProfile(username, userProfile);
}
UserDetails currentUser = super.getCurrentUser();
if (null != currentUser && currentUser.getUsername().equals(username) && (currentUser instanceof AbstractUser)) {
((AbstractUser) currentUser).setProfile(userProfile);
}
} catch (Throwable t) {
_logger.error("error in save", t);
return FAILURE;
}
return SUCCESS;
}
Aggregations