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
|
/*******************************************************************************
* Copyright (c) 2013 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.orcs.account.admin.internal;
import java.util.Date;
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.SubscriptionGroup;
import org.eclipse.osee.account.rest.model.AccountWebPreferences;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.type.ResultSetTransform.Function;
import org.eclipse.osee.framework.jdk.core.type.ResultSets;
import org.eclipse.osee.orcs.data.ArtifactReadable;
/**
* @author Roberto E. Escobar
*/
public class AccountFactory {
private final Function<String, ArtifactReadable, Account> function1 = new ArtifactToAccount();
private final Function<String, ArtifactReadable, AccountPreferences> function2 = new ArtifactToAccountPreferences();
private final Function<String, ArtifactReadable, SubscriptionGroup> function3 =
new ArtifactToAccountSubscriptionGroup();
public ResultSet<Account> newAccountResultSet(ResultSet<ArtifactReadable> results) {
return ResultSets.transform(results, function1);
}
public ResultSet<AccountPreferences> newAccountPreferencesResultSet(ResultSet<ArtifactReadable> results) {
return ResultSets.transform(results, function2);
}
public Account newAccount(ArtifactReadable artifact) {
AccountPreferences preferences = newAccountPreferences(artifact);
AccountWebPreferences webPreferences = newAccountWebPreferences(artifact);
return new AccountArtifact(artifact.getGuid(), artifact, preferences, webPreferences);
}
public AccountPreferences newAccountPreferences(ArtifactReadable artifact) {
String id = artifact.getGuid();
return new AccountPreferencesArtifact(id, artifact);
}
public AccountWebPreferences newAccountWebPreferences(ArtifactReadable artifact) {
String webPreferencesJson = artifact.getSoleAttributeAsString(CoreAttributeTypes.WebPreferences, "{}");
return new AccountWebPreferences(webPreferencesJson, artifact.getName());
}
private class ArtifactToAccount implements Function<String, ArtifactReadable, Account> {
@Override
public Account apply(ArtifactReadable source) {
return newAccount(source);
}
}
private class ArtifactToAccountPreferences implements Function<String, ArtifactReadable, AccountPreferences> {
@Override
public AccountPreferences apply(ArtifactReadable source) {
return newAccountPreferences(source);
}
}
public AccountSession newAccountSession(long accountId, String sessionToken, String accessedFrom, String accessDetails) {
Date currentDate = new Date();
return newAccountSession(accountId, sessionToken, currentDate, currentDate, accessedFrom, accessDetails);
}
public AccountSession newAccountSession(long accountId, String sessionToken, Date createdOn, Date lastAccessedOn, String accessedFrom, String accessDetails) {
AccountSessionImpl session = new AccountSessionImpl();
session.setAccountId(accountId);
session.setSessionToken(sessionToken);
session.setCreatedOn(createdOn);
session.setLastAccessedOn(lastAccessedOn);
session.setAccessDetails(accessDetails);
session.setAccessedFrom(accessedFrom);
return session;
}
public SubscriptionGroup newAccountSubscriptionGroup(ArtifactReadable source) {
return new AccountSubscriptionGroupImpl(source.getGuid(), source);
}
public ResultSet<SubscriptionGroup> newAccountSubscriptionGroupResultSet(ResultSet<ArtifactReadable> results) {
return ResultSets.transform(results, function3);
}
private class ArtifactToAccountSubscriptionGroup implements Function<String, ArtifactReadable, SubscriptionGroup> {
@Override
public SubscriptionGroup apply(ArtifactReadable source) {
return newAccountSubscriptionGroup(source);
}
}
}
|