Browse code

BM-14204 Fix: remove net.bluemind.hsm.unarchall

kladier authored on 08/02/2019 08:16:56
Showing 6 changed files
1 1
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-Manifest-Version: 1.0
2
-Bundle-ManifestVersion: 2
3
-Bundle-Name: net.bluemind.hsm.unarchall
4
-Bundle-SymbolicName: net.bluemind.hsm.unarchall;singleton:=true
5
-Bundle-Version: 1.0.0.qualifier
6
-Bundle-Activator: net.bluemind.hsm.unarchall.Activator
7
-Require-Bundle: org.eclipse.core.runtime,
8
- net.bluemind.slf4j;bundle-version="1.6.4",
9
- net.bluemind.core.client;bundle-version="1.0.0",
10
- net.bluemind.imap;bundle-version="1.0.0",
11
- net.bluemind.core.common;bundle-version="1.0.0",
12
- org.junit;bundle-version="3.8.2"
13
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
14
-Bundle-ActivationPolicy: lazy
15 0
deleted file mode 100644
... ...
@@ -1,4 +0,0 @@
1
-source.. = src/
2
-bin.includes = META-INF/,\
3
-               .,\
4
-               plugin.xml
5 0
deleted file mode 100644
... ...
@@ -1,30 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<?eclipse version="3.4"?>
3
-<plugin>
4
-   <extension
5
-         id="promote"
6
-         name="promote"
7
-         point="org.eclipse.core.runtime.applications">
8
-      <application
9
-            cardinality="singleton-global"
10
-            thread="main"
11
-            visible="true">
12
-         <run
13
-               class="net.bluemind.hsm.unarchall.PromoteApplication">
14
-         </run>
15
-      </application>
16
-   </extension>
17
-   <extension
18
-         id="promote"
19
-         point="org.eclipse.core.runtime.products">
20
-      <product
21
-            application="net.bluemind.hsm.unarchall.promote"
22
-            name="promote">
23
-         <property
24
-               name="appName"
25
-               value="promote">
26
-         </property>
27
-      </product>
28
-   </extension>
29
-
30
-</plugin>
31 0
deleted file mode 100644
... ...
@@ -1,30 +0,0 @@
1
-package net.bluemind.hsm.unarchall;
2
-
3
-import org.osgi.framework.BundleActivator;
4
-import org.osgi.framework.BundleContext;
5
-
6
-public class Activator implements BundleActivator {
7
-
8
-	private static BundleContext context;
9
-
10
-	static BundleContext getContext() {
11
-		return context;
12
-	}
13
-
14
-	/*
15
-	 * (non-Javadoc)
16
-	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
17
-	 */
18
-	public void start(BundleContext bundleContext) throws Exception {
19
-		Activator.context = bundleContext;
20
-	}
21
-
22
-	/*
23
-	 * (non-Javadoc)
24
-	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
25
-	 */
26
-	public void stop(BundleContext bundleContext) throws Exception {
27
-		Activator.context = null;
28
-	}
29
-
30
-}
31 0
deleted file mode 100644
... ...
@@ -1,161 +0,0 @@
1
-package net.bluemind.hsm.unarchall;
2
-
3
-import java.io.FileInputStream;
4
-import java.io.IOException;
5
-import java.util.Map;
6
-import java.util.Properties;
7
-
8
-import junit.framework.TestCase;
9
-import net.bluemind.core.api.AccessToken;
10
-import net.bluemind.core.api.ICore;
11
-import net.bluemind.core.api.ResultList;
12
-import net.bluemind.core.api.fault.AuthFault;
13
-import net.bluemind.core.api.fault.ServerFault;
14
-import net.bluemind.core.api.hsm.TierChangeResult;
15
-import net.bluemind.core.api.user.MailRouting;
16
-import net.bluemind.core.api.user.User;
17
-import net.bluemind.core.api.user.UserQuery;
18
-import net.bluemind.core.client.CoreClient;
19
-import net.bluemind.core.client.TokenHelper;
20
-import net.bluemind.core.client.system.SystemClient;
21
-import net.bluemind.imap.IMAPException;
22
-import net.bluemind.imap.ListInfo;
23
-import net.bluemind.imap.ListResult;
24
-import net.bluemind.imap.NameSpaceInfo;
25
-import net.bluemind.imap.StoreClient;
26
-import net.bluemind.imap.Summary;
27
-
28
-import org.slf4j.Logger;
29
-import org.slf4j.LoggerFactory;
30
-
31
-public class PromoteAllTest extends TestCase {
32
-
33
-	private static final Logger logger = LoggerFactory
34
-			.getLogger(PromoteAllTest.class);
35
-	private ICore core;
36
-	private String imap;
37
-
38
-	public void setUp() throws IOException {
39
-		Properties p = new Properties();
40
-		FileInputStream in = new FileInputStream("/etc/bm/bm.ini");
41
-		p.load(in);
42
-		in.close();
43
-		this.imap = p.getProperty("external-url");
44
-		String extUrl = p.getProperty("external-protocol") + "://" + imap
45
-				+ "/services";
46
-		this.core = CoreClient.newCore(extUrl);
47
-	}
48
-
49
-	public void testPromoteAll() throws IOException, AuthFault, ServerFault,
50
-			IMAPException {
51
-		AccessToken gtok = login();
52
-		UserQuery uq = new UserQuery();
53
-		uq.setArchived(false);
54
-		uq.setSystem(false);
55
-		ResultList<User> users = core.getUser().find(gtok, uq);
56
-		logout(gtok);
57
-		promoteUsers(users);
58
-	}
59
-
60
-	private void promoteUsers(ResultList<User> users) throws AuthFault,
61
-			ServerFault, IMAPException {
62
-		AccessToken gtok;
63
-
64
-		for (User u : users) {
65
-			if ("global.virt".equals(u.getDomain().getName())) {
66
-				continue;
67
-			}
68
-			if (u.getMailRouting() != MailRouting.INTERNAL) {
69
-				continue;
70
-			}
71
-			logger.info("now on {}", u.getReservedBoxName());
72
-			gtok = login();
73
-			AccessToken utok = sudo(gtok, u);
74
-			logout(gtok);
75
-			promoteAll(utok, u);
76
-			logout(utok);
77
-		}
78
-	}
79
-
80
-	private void promoteAll(AccessToken utok, User u) throws IMAPException,
81
-			ServerFault, AuthFault {
82
-		StoreClient sc = new StoreClient(imap, 1143, u.getReservedBoxName(),
83
-				utok.getSessionId());
84
-		sc.login();
85
-		ListResult folders = sc.listAll();
86
-		NameSpaceInfo ni = sc.namespace();
87
-		String shared = ni.getMailShares().get(0);
88
-		String others = ni.getOtherUsers().get(0);
89
-		for (ListInfo li : folders) {
90
-			if (li.isSelectable() && !li.getName().startsWith(shared)
91
-					&& !li.getName().startsWith(others)) {
92
-				sc.select(li.getName());
93
-				logger.info("  [{}] {}", u.getReservedBoxName(), li.getName());
94
-				Map<Integer, Summary> sums = sc.uidFetchSummary("1:*");
95
-				for (Summary s : sums.values()) {
96
-					String hsmId = s.getHeaders().getRawHeader("X-BM_HSM_ID");
97
-					if (hsmId != null) {
98
-						logger.info("     un-archive {}, {}", s.getUid(), hsmId);
99
-						try {
100
-							TierChangeResult tcr = core.getHSM()
101
-									.promoteMessage(utok, li.getName(), hsmId);
102
-							logger.info("     un-archived as {}",
103
-									tcr.getImapUid());
104
-						} catch (ServerFault sf) {
105
-							logger.info("     un-archived fail {} {}",
106
-									s.getUid(), hsmId);
107
-						}
108
-					}
109
-				}
110
-			}
111
-		}
112
-		sc.logout();
113
-	}
114
-
115
-	private AccessToken sudo(AccessToken gtok, User u) throws AuthFault,
116
-			ServerFault {
117
-		SystemClient sys = (SystemClient) core.getSystem();
118
-		return sys.sudo(gtok, u.getReservedBoxName());
119
-	}
120
-
121
-	private void logout(AccessToken gtok) {
122
-		SystemClient sys = (SystemClient) core.getSystem();
123
-		sys.logout(gtok);
124
-	}
125
-
126
-	private AccessToken login() {
127
-		SystemClient sys = (SystemClient) core.getSystem();
128
-		return sys.login("admin0@global.virt",
129
-				TokenHelper.getLocalPermanentSid(), "promote-all");
130
-	}
131
-
132
-	public void testPromote(String[] usersLogin) throws AuthFault, ServerFault,
133
-			IMAPException {
134
-		AccessToken gtok = login();
135
-
136
-		ResultList<User> users = new ResultList<User>();
137
-		for (String userLogin : usersLogin) {
138
-			String[] loginParts = userLogin.split("@");
139
-			if (loginParts.length != 2) {
140
-				logger.error("Invalid user login: " + userLogin);
141
-				continue;
142
-			}
143
-
144
-			UserQuery uq = new UserQuery();
145
-			uq.setArchived(false);
146
-			uq.setSystem(false);
147
-			uq.setLogin(loginParts[0]);
148
-			uq.setDomainName(loginParts[1]);
149
-
150
-			ResultList<User> user = core.getUser().find(gtok, uq);
151
-			if (user.size() != 1) {
152
-				logger.info("User: " + userLogin + " not found !");
153
-			}
154
-
155
-			users.addAll(core.getUser().find(gtok, uq));
156
-		}
157
-
158
-		logout(gtok);
159
-		promoteUsers(users);
160
-	}
161
-}
162 0
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-package net.bluemind.hsm.unarchall;
2
-
3
-import org.eclipse.equinox.app.IApplication;
4
-import org.eclipse.equinox.app.IApplicationContext;
5
-import org.slf4j.Logger;
6
-import org.slf4j.LoggerFactory;
7
-
8
-public class PromoteApplication implements IApplication {
9
-
10
-	private static final Logger logger = LoggerFactory
11
-			.getLogger(PromoteApplication.class);
12
-
13
-	@Override
14
-	public Object start(IApplicationContext context) throws Exception {
15
-		logger.info("Starting promotion of emails...");
16
-		String[] args = (String[]) context.getArguments().get(
17
-				IApplicationContext.APPLICATION_ARGS);
18
-		PromoteAllTest pat = new PromoteAllTest();
19
-		pat.setUp();
20
-		if (args.length == 0) {
21
-			logger.info("Need one of options [all|login1..loginN]");
22
-		} else if (args.length == 1 && args[0].equals("all")) {
23
-			pat.testPromoteAll();
24
-		} else {
25
-			pat.testPromote(args);
26
-		}
27
-		System.exit(0);
28
-		return IApplication.EXIT_OK;
29
-	}
30
-
31
-	@Override
32
-	public void stop() {
33
-		logger.info("Finished.");
34
-		System.exit(0);
35
-	}
36
-
37
-}