@Override
 public void updateEntity(IApsEntity currentEntity, HttpServletRequest request) {
   IUserProfile profile = (IUserProfile) currentEntity;
   String isPublic = request.getParameter("publicProfile");
   profile.setPublicProfile(null != isPublic);
   super.updateEntity(profile, request);
 }
  public void testSaveProfile() throws Throwable {
    this.setUserOnSession(USERNAME_FOR_TEST);
    this.initAction("/do/jpuserprofile/MyProfile", "new");
    this.addParameter("profileTypeCode", "PFL");
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    try {
      this.initAction("/do/jpuserprofile/MyProfile", "save");
      this.addParameter("Name", "Eugenio");
      this.addParameter("Surname", "Santoboni");
      this.addParameter("email", "*****@*****.**");
      this.addParameter("birthdate", "25/09/1972");
      this.addParameter("language", "it");
      result = this.executeAction();
      assertEquals(Action.SUCCESS, result);

      IUserProfile userProfile = this._profileManager.getProfile("mainEditor");
      assertNotNull(userProfile);
      assertEquals("Amanda", userProfile.getValue("Name"));
    } catch (Throwable t) {
      throw t;
    } finally {
      this._profileManager.deleteProfile(USERNAME_FOR_TEST);
      IUserProfile userProfile = this._profileManager.getProfile(USERNAME_FOR_TEST);
      assertNull(userProfile);
    }
  }
 public void testEditProfile() throws Throwable {
   this.setUserOnSession(USERNAME_FOR_TEST);
   this.initAction("/do/jpuserprofile/MyProfile", "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(USERNAME_FOR_TEST, currentUserProfile.getUsername());
 }
 @Override
 public String createNew() {
   try {
     IUserProfile defaultProfile = this.getUserProfileManager().getDefaultProfileType();
     defaultProfile.disableAttributes(
         JpaddressbookSystemConstants.ATTRIBUTE_DISABLING_CODE_ON_MANAGE_CONTACT);
     Contact contact = new Contact(defaultProfile);
     contact.setOwner(this.getCurrentUser().getUsername());
     this.getRequest().getSession().setAttribute(SESSION_PARAM_NAME_CURRENT_CONTACT, contact);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "createNew");
     return FAILURE;
   }
   return SUCCESS;
 }
 private void sendNewsletterToUser(
     String username,
     List<Content> contents,
     Map<String, List<String>> profileAttributes,
     NewsletterReport newsletterReport) {
   NewsletterConfig config = this.getConfig();
   try {
     UserDetails user = this.getUserManager().getUser(username);
     IUserProfile profile = (IUserProfile) user.getProfile();
     if (profile != null) {
       String eMail = (String) profile.getValue(config.getMailAttrName());
       if (eMail != null && eMail.length() > 0) {
         List<Content> userContents =
             this.extractContentsForUser(
                 user, eMail, contents, profileAttributes, newsletterReport);
         if (userContents.size() > 0) {
           String[] emailAddresses = {eMail};
           String simpleText = this.prepareMailBody(userContents, newsletterReport, false);
           if (config.isAlsoHtml()) {
             String htmlText = this.prepareMailBody(userContents, newsletterReport, true);
             this.getMailManager()
                 .sendMixedMail(
                     simpleText,
                     htmlText,
                     config.getSubject(),
                     null,
                     null,
                     null,
                     emailAddresses,
                     config.getSenderCode());
           } else {
             this.getMailManager()
                 .sendMail(
                     simpleText,
                     config.getSubject(),
                     null,
                     null,
                     emailAddresses,
                     config.getSenderCode());
           }
         }
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "sendNewsletterToUser");
   }
 }
 private List<Content> extractContentsForUser(
     UserDetails user,
     String eMail,
     List<Content> contents,
     Map<String, List<String>> profileAttributes,
     NewsletterReport newsletterReport)
     throws ApsSystemException {
   NewsletterConfig config = this.getConfig();
   List<Content> userContents = new ArrayList<Content>();
   String username = user.getUsername();
   IUserProfile profile = (IUserProfile) user.getProfile();
   if (profile != null) {
     String allContentsAttribute = config.getAllContentsAttributeName();
     boolean allContents = false;
     if (null != allContentsAttribute) {
       Boolean value = (Boolean) profile.getValue(allContentsAttribute);
       allContents = value != null && value.booleanValue();
     }
     List<String> groupNames = this.extractUserGroupNames(user);
     boolean isGroupAdmin = groupNames.contains(Group.ADMINS_GROUP_NAME);
     for (int i = 0; i < contents.size(); i++) {
       Content content = contents.get(i);
       String contentId = content.getId();
       List<String> contentProfileAttributes = profileAttributes.get(contentId);
       ContentReport contentReport = newsletterReport.getContentReport(contentId);
       if (contentReport != null
           && (isGroupAdmin || this.checkUserAllowedOnContent(groupNames, content))) {
         if (allContents) {
           userContents.add(content);
           contentReport.addRecipient(username, eMail);
         } else if (contentProfileAttributes != null && contentProfileAttributes.size() > 0) {
           for (String profileAttrName : contentProfileAttributes) {
             Boolean value = (Boolean) profile.getValue(profileAttrName);
             if (value != null && value.booleanValue()) {
               userContents.add(content);
               contentReport.addRecipient(username, eMail);
               break;
             }
           }
         }
       }
     }
   }
   return userContents;
 }
  public void testValidateProfile() throws Throwable {
    this.setUserOnSession(USERNAME_FOR_TEST);
    this.initAction("/do/jpuserprofile/MyProfile", "new");
    this.addParameter("profileTypeCode", "PFL");
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);

    this.initAction("/do/jpuserprofile/MyProfile", "save");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);

    ActionSupport action = this.getAction();
    assertEquals(5, action.getFieldErrors().size());

    this.initAction("/do/jpuserprofile/MyProfile", "save");
    this.addParameter("Name", "Eugenio");
    this.addParameter("Surname", "Santoboni");
    this.addParameter("email", "");
    this.addParameter("birthdate", "25/09/1972");
    this.addParameter("language", "it");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);

    action = this.getAction();
    assertEquals(1, action.getFieldErrors().size());
    assertEquals(1, ((List<String>) action.getFieldErrors().get("email")).size());

    IUserProfile currentUserProfile =
        (IUserProfile)
            this.getRequest()
                .getSession()
                .getAttribute(ICurrentUserProfileAction.SESSION_PARAM_NAME_CURRENT_PROFILE);
    assertNotNull(currentUserProfile);
    assertEquals(USERNAME_FOR_TEST, currentUserProfile.getUsername());
    assertEquals("Eugenio", currentUserProfile.getValue("Name"));
    assertEquals("Santoboni", currentUserProfile.getValue("Surname"));
  }