Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7774710df63dd758f7164db990d4d41b62bc5772 (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
/*******************************************************************************
 * Copyright (c) 2014 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.account.rest.internal;

import org.eclipse.osee.account.admin.Account;
import org.eclipse.osee.account.admin.AccountPreferences;
import org.eclipse.osee.account.admin.AccountSession;
import org.eclipse.osee.account.admin.Subscription;
import org.eclipse.osee.account.admin.SubscriptionGroup;
import org.eclipse.osee.account.rest.model.AccountActiveData;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
import org.eclipse.osee.account.rest.model.AccountPreferencesData;
import org.eclipse.osee.account.rest.model.AccountSessionData;
import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.account.rest.model.SubscriptionData;
import org.eclipse.osee.account.rest.model.SubscriptionGroupData;
import org.eclipse.osee.framework.jdk.core.type.OseePrincipal;

/**
 * @author Roberto E. Escobar
 */
public final class AccountDataUtil {

   private AccountDataUtil() {
      // Utility class
   }

   public static AccountSessionDetailsData asAccountAccessData(AccountSession session) {
      AccountSessionDetailsData data = new AccountSessionDetailsData();
      data.setAccountId(session.getAccountId());
      data.setAccessDetails(session.getAccessDetails());
      data.setAccessedFrom(session.getAccessedFrom());
      data.setCreatedOn(session.getCreatedOn());
      data.setLastAccessedOn(session.getLastAccessedOn());
      return data;
   }

   public static AccountSessionData asSessionData(AccountSession session) {
      AccountSessionData data = new AccountSessionData();
      data.setAccountId(session.getAccountId());
      data.setToken(session.getSessionToken());
      return data;
   }

   public static AccountDetailsData asAccountDetailsData(Account account) {
      AccountDetailsData data = new AccountDetailsData();
      fillData(account, data);
      AccountPreferencesData preferences = asAccountPreferencesData(account.getPreferences());
      data.setPreferences(preferences);
      return data;
   }

   public static AccountInfoData asAccountData(Account account) {
      AccountInfoData data = new AccountInfoData();
      fillData(account, data);
      return data;
   }

   private static void fillData(Account account, AccountInfoData data) {
      data.setAccountId(account.getId());
      data.setGuid(account.getGuid());
      data.setName(account.getName());
      data.setEmail(account.getEmail());
      data.setUserName(account.getUserName());
      data.setActive(account.isActive());
   }

   public static AccountPreferencesData asAccountPreferencesData(AccountPreferences preferences) {
      AccountPreferencesData data = new AccountPreferencesData();
      data.setId(preferences.getId());
      data.setMap(preferences.asMap());
      return data;
   }

   public static AccountActiveData asAccountActiveData(Account account) {
      AccountActiveData data = new AccountActiveData();
      data.setAccountId(account.getId());
      data.setGuid(account.getGuid());
      data.setActive(account.isActive());
      return data;
   }

   public static SubscriptionData asAccountSubscriptionData(Subscription subscription) {
      SubscriptionData data = new SubscriptionData();
      data.setGuid(subscription.getGuid());
      data.setName(subscription.getName());
      data.setActive(subscription.isActive());
      data.setAccountName(subscription.getAccountName());
      return data;
   }

   public static SubscriptionGroupData asSubscriptionGroupData(SubscriptionGroup src) {
      SubscriptionGroupData data = new SubscriptionGroupData();
      data.setGuid(src.getGuid());
      data.setName(src.getName());
      data.setId(src.getId());
      return data;
   }

   public static AccountInfoData asAccountInfoData(OseePrincipal principal) {
      AccountInfoData toReturn = new AccountInfoData();
      toReturn.setAccountId(principal.getGuid());
      toReturn.setActive(principal.isActive());
      toReturn.setEmail(principal.getEmailAddress());
      toReturn.setName(principal.getName());
      toReturn.setUserName(principal.getUserName());
      toReturn.setGuid(principal.getOseeGuid());
      toReturn.setRoles(principal.getRoles());
      return toReturn;
   }

}

Back to the top