Ejemplo n.º 1
0
 public String insertProfile(Profile profile) throws SQLException {
   String r = "New profile inserted!";
   if (this.getProfileID(profile) == -1) {
     try {
       // creates a SQL Statement object in order to execute the SQL insert command
       stmt = conn.createStatement();
       // String login = (firstName, lastName, password)).createLogin();
       if (profile.getEmail() != null) {
         stmt.execute(
             "INSERT INTO Profiles (FirstName, LastName, Login, Password, Email, IsAdmin) "
                 + "VALUES ('"
                 + profile.getFirstName()
                 + "', '"
                 + profile.getLastName()
                 + "', "
                 + "'"
                 + profile.getLogin()
                 + "', '"
                 + profile.getPassword()
                 + "', "
                 + "'"
                 + profile.getEmail()
                 + "', "
                 + profile.isAdmin()
                 + ")");
       } else {
         stmt.execute(
             "INSERT INTO Profiles (FirstName, LastName, Login, Password, IsAdmin) "
                 + "VALUES ('"
                 + profile.getFirstName()
                 + "', '"
                 + profile.getLastName()
                 + "', "
                 + "'"
                 + profile.getLogin()
                 + "', '"
                 + profile.getPassword()
                 + "', "
                 + profile.isAdmin()
                 + ") ");
       }
       stmt.close();
       // System.out.println("Requête executée");
     } catch (SQLException e) {
       // System.err.println(e.toString());
       r = e.toString();
       throw e;
     }
   }
   return r;
 }
  private void createNotification(
      Profile profile, UGCAudit currentAudit, Map<String, Profile> actionOwnersCache) {
    if (currentAudit.getProfileId() != null
        && !currentAudit.getProfileId().equalsIgnoreCase("anonymous")) {
      Notification notification = new Notification();
      // ACTION of the current JOB
      notification.setAction(profile.getSubscriptions().getAction());

      notification.setCreatedDate(new Date());
      notification.setRow(currentAudit.getRow());

      // FORMAT of the current JOB
      notification.setFormat(profile.getSubscriptions().getFormat());

      // FORMAT of the current JOB
      notification.setFrequency(profile.getSubscriptions().getFrequency());
      notification.setSubscriberUsername(profile.getUserName());

      notification.setSubscriberEmail(profile.getEmail());
      notification.setSubscriberId(profile.getId());
      notification.setTransmitedStatus(TransmittedStatus.PENDING);

      notification.setEvent(
          createEvent(currentAudit, getActionAuditOwner(actionOwnersCache, currentAudit)));

      this.notificationRepository.save(notification);
    }
  }
  private Profile getActionAuditOwner(
      Map<String, Profile> actionOwnersCache, UGCAudit currentAudit) {
    Profile p = actionOwnersCache.get(currentAudit.getProfileId());
    if (p == null) {
      Profile currentProfile =
          this.profileRepository.findOne(new ObjectId(currentAudit.getProfileId()));
      p = new Profile();
      if (currentProfile != null) {
        p.setUserName(currentProfile.getUserName());
        p.setTenantName(currentProfile.getTenantName());
        p.setEmail(currentProfile.getEmail());
        p.setId(currentProfile.getId());
      }
      actionOwnersCache.put(currentAudit.getProfileId(), p);
    }

    return p;
  }