Blame view

applications/party/webapp/partymgr/WEB-INF/actions/communication/getPartyEmailFromCommEventInfo.groovy 2.53 KB
c16038356   Anchit Jindal   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  
  import org.ofbiz.base.util.*;
  import org.ofbiz.entity.util.EntityUtil;
  import javolution.util.FastList;
  
  communicationEvent = delegator.findOne("CommunicationEvent", [communicationEventId : parameters.communicationEventId], true);
  
  if (!communicationEvent.note) return;
  nameString = "Sent from: ";
  nameStringIndexValue = communicationEvent.note.indexOf(nameString);
  if (nameStringIndexValue == -1) return;
  int startEmail = nameStringIndexValue + nameString.length();
  int endEmail = communicationEvent.note.indexOf(";", startEmail);
  context.emailAddress = communicationEvent.note.substring(startEmail, endEmail);
  
  nameString = "Sent Name from: ";
  nameStringIndexValue = communicationEvent.note.indexOf(nameString);
  if (nameStringIndexValue == -1) return;
  int startName = nameStringIndexValue + nameString.length();
  int endName = communicationEvent.note.indexOf(";", startName);
  name = communicationEvent.note.substring(startName, endName);
  if (name) {
      counter = 0;
      lastBlank = 0;
      List names = FastList.newInstance();
      while ((nextBlank = name.indexOf(" ", lastBlank)) != -1) {
          names.add(name.substring(lastBlank, nextBlank));
          lastBlank = nextBlank + 1;
      }
      if (lastBlank > 0) {
          names.add(name.substring(lastBlank));
      }
      if (names && names.size() > 0) { //lastname
          context.lastName = names[names.size()-1];
          if (names.size() > 1) { // firstname
              context.firstName = names[0];
          }
          if (names.size() > 2) { // middle name(s)
              context.middleName = "";
              for (counter = 1; counter < names.size()-1; counter++) {
                  context.middleName = context.middleName.concat(names[counter]).concat(" ")
              }
          }
      }  else {
          context.lastName = name;
      }
  }