Skip to main content
summaryrefslogtreecommitdiffstats
blob: 46377fde16ef46f009dc319cdc3e8c9e021d40b9 (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ats.core.review.role;

import java.text.NumberFormat;
import java.util.logging.Level;
import org.eclipse.osee.ats.core.internal.Activator;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.AXml;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.UserManager;

/**
 * @author Donald G. Dunne
 */
public class UserRole {

   private Role role = Role.Reviewer;
   private User user;
   private Double hoursSpent = null;
   private String guid = GUID.create();
   private Boolean completed = false;

   public UserRole() throws OseeCoreException {
      this(Role.Reviewer, UserManager.getUser(), null, false);
   }

   public UserRole(Role role, User user) {
      this(role, user, 0.0, false);
   }

   public UserRole(Role role, User user, Double hoursSpent, Boolean completed) {
      this.role = role;
      this.user = user;
      this.hoursSpent = hoursSpent;
      this.completed = completed;
   }

   public UserRole(String xml) {
      fromXml(xml);
   }

   public void update(UserRole dItem) throws OseeCoreException {
      fromXml(dItem.toXml());
   }

   public String toXml() throws OseeCoreException {
      StringBuffer sb = new StringBuffer();
      sb.append(AXml.addTagData("role", role.name()));
      sb.append(AXml.addTagData("userId", user.getUserId()));
      sb.append(AXml.addTagData("hoursSpent", hoursSpent == null ? "" : String.valueOf(hoursSpent)));
      sb.append(AXml.addTagData("completed", String.valueOf(completed)));
      sb.append(AXml.addTagData("guid", guid));
      return sb.toString();
   }

   public void fromXml(String xml) {
      try {
         this.role = Role.valueOf(AXml.getTagData(xml, "role"));
         this.user = UserManager.getUserByUserId(AXml.getTagData(xml, "userId"));
         String hoursSpent = AXml.getTagData(xml, "hoursSpent");
         if (Strings.isValid(hoursSpent)) {
            this.hoursSpent = NumberFormat.getInstance().parse(hoursSpent).doubleValue();
         } else {
            this.hoursSpent = null;
         }
         String completedStr = AXml.getTagData(xml, "completed");
         if (Strings.isValid(completedStr)) {
            this.completed = completedStr.equals("true");
         } else {
            this.completed = false;
         }
         this.guid = AXml.getTagData(xml, "guid");
      } catch (Exception ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
   }

   @Override
   public boolean equals(Object obj) {
      if (obj instanceof UserRole) {
         UserRole userRole = (UserRole) obj;
         return userRole.getGuid().equals(getGuid());
      }
      return false;
   }

   @Override
   public int hashCode() {
      return getGuid().hashCode();
   }

   @Override
   public String toString() {
      return role + " - " + user + " - " + hoursSpent + " - " + (completed ? "Completed" : "InWork");
   }

   /**
    * @return the role
    */
   public Role getRole() {
      return role;
   }

   /**
    * @param role the role to set
    */
   public void setRole(Role role) {
      this.role = role;
   }

   /**
    * @return the user
    */
   public User getUser() {
      return user;
   }

   /**
    * @param user the user to set
    */
   public void setUser(User user) {
      this.user = user;
   }

   /**
    * @return the hoursSpent
    */
   public Double getHoursSpent() {
      return hoursSpent;
   }

   public String getHoursSpentStr() {
      return hoursSpent == null ? "" : AtsUtilCore.doubleToI18nString(hoursSpent, true);
   }

   /**
    * @param hoursSpent the hoursSpent to set
    */
   public void setHoursSpent(Double hoursSpent) {
      this.hoursSpent = hoursSpent;
   }

   /**
    * @return the guid
    */
   public String getGuid() {
      return guid;
   }

   /**
    * @param guid the guid to set
    */
   public void setGuid(String guid) {
      this.guid = guid;
   }

   /**
    * @return the completed
    */
   public boolean isCompleted() {
      return completed;
   }

   /**
    * @param completed the completed to set
    */
   public void setCompleted(boolean completed) {
      this.completed = completed;
   }

}

Back to the top