Beispiel #1
0
 public void update() {
   try {
     // Check if the user has a client object created and create one if not yet exist
     if (this.mySettingsProgram.getContactInfo().getOWNER() == null) {
       // Check which client type is "Person", but we are assuming it's called "Person" and not by
       // other similar names
       ClientType personClientType = clientService.getClientTypeByName("Person");
       ClientUserAssignment newClientAssignment =
           clientService.registerClientForUser(
               userContainer.getUser(), personClientType.getOBJECTID());
       Client newclient = newClientAssignment.getSOURCE();
       this.mySettingsProgram.getContactInfo().setOWNER(newclient);
     }
     this.clientService.updateClientContact(mySettingsProgram.getContactInfo());
     FacesMessenger.setFacesMessage(
         this.formName,
         FacesMessage.SEVERITY_FATAL,
         "Your contact details has been updated!",
         null);
   } catch (DBConnectionException ex) {
     FacesMessenger.setFacesMessage(
         this.formName,
         FacesMessage.SEVERITY_ERROR,
         "Could not connect to DB!",
         "Please contact administrators.");
   } catch (Exception ex) {
     FacesMessenger.setFacesMessage(
         this.formName,
         FacesMessage.SEVERITY_ERROR,
         ex.getClass().getSimpleName(),
         ex.getMessage());
   }
 }
Beispiel #2
0
  public void initContactInfo() throws DBConnectionException, Exception {
    if (!userContainer.isLoggedIn() || userContainer.getUser() == null) {
      // This will most likely not happen in production, hence we don't really have to handle it
      throw new RuntimeException(
          "You are not logged in and you cannot execute any functionalities on this page.");
    }

    // Retrieve the contact info for this particular user
    this.setContactInfo(clientService.getContactInfoForUser(userContainer.getUser().getOBJECTID()));

    // You don't want a nullpointerexception on your page!
    // This is the temporary solution, may or may not be the best.
    if (getContactInfo() == null) {
      ContactInfo newContactInfo = new ContactInfo();

      // Get the user's clientid
      Client thisClient =
          clientService.getClientByAssignedUser(userContainer.getUser().getOBJECTID());
      newContactInfo.setOWNER(thisClient); // May be null at this point of time
      setContactInfo(newContactInfo);
    }
  }