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
|
/*******************************************************************************
* 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.framework.ui.skynet.util.email;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.utility.EmailUtil;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateComposite.TableLoadOption;
import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItem;
import org.eclipse.osee.framework.ui.plugin.xnavigate.XNavigateItemAction;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.UserGroupsCheckTreeDialog;
import org.eclipse.swt.program.Program;
/**
* @author Donald G. Dunne
*/
public class EmailUserGroups extends XNavigateItemAction {
/**
* @param teamDefHoldingVersions Team Definition Artifact that is related to versions or null for popup selection
*/
public EmailUserGroups(XNavigateItem parent) {
super(parent, "Email User Groups", FrameworkImage.EMAIL);
}
public static Set<Artifact> getEmailGroupsAndUserGroups(User user) throws OseeCoreException {
Set<Artifact> artifacts = new HashSet<Artifact>();
for (Artifact art : ArtifactQuery.getArtifactListFromTypeWithInheritence(CoreArtifactTypes.UserGroup,
BranchManager.getCommonBranch(), DeletionFlag.EXCLUDE_DELETED)) {
// Only add group if have read permissions
if (!art.getName().equals("Root Artifact") && AccessControlManager.hasPermission(art, PermissionEnum.READ)) {
artifacts.add(art);
}
}
return artifacts;
}
@Override
public void run(TableLoadOption... tableLoadOptions) {
try {
Set<Artifact> groupOptions = getEmailGroupsAndUserGroups(UserManager.getUser());
UserGroupsCheckTreeDialog dialog = new UserGroupsCheckTreeDialog(groupOptions);
dialog.setTitle("Select Groups to Email");
if (dialog.open() == 0) {
Set<String> emails = new HashSet<String>();
for (Artifact artifact : dialog.getSelection()) {
if (artifact.isOfType(CoreArtifactTypes.UniversalGroup)) {
for (Artifact userArt : artifact.getRelatedArtifacts(CoreRelationTypes.Universal_Grouping__Members)) {
if (userArt instanceof User) {
if (!EmailUtil.isEmailValid((User) userArt)) {
OseeLog.logf(Activator.class, Level.SEVERE, "Invalid email [%s] for user [%s]; skipping",
((User) userArt).getEmail(), userArt);
} else if (((User) userArt).isActive()) {
emails.add(((User) userArt).getEmail());
}
}
}
} else if (artifact.isOfType(CoreArtifactTypes.UserGroup)) {
for (User user : artifact.getRelatedArtifacts(CoreRelationTypes.Users_User, User.class)) {
if (!EmailUtil.isEmailValid(user)) {
OseeLog.logf(Activator.class, Level.SEVERE, "Invalid email [%s] for user [%s]; skipping",
user.getEmail(), user);
} else if (user.isActive()) {
emails.add(user.getEmail());
}
}
}
}
if (emails.isEmpty()) {
AWorkbench.popup("Error", "No emails configured.");
return;
}
String emailStr = org.eclipse.osee.framework.jdk.core.util.Collections.toString(";", emails);
if (emailStr.length() > 2048) {
AWorkbench.popup("Email list too big for auto-open. Emails opened in editor for copy/paste.");
ResultsEditor.open("Email Addresses", "Email Addresses", emailStr);
} else {
Program.launch("mailto:" + emailStr);
}
AWorkbench.popup("Complete", "Configured emails openened in local email client.");
}
} catch (OseeCoreException ex) {
OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
}
}
}
|