5616 |
27 Apr 11 |
nicklas |
1 |
/** |
5616 |
27 Apr 11 |
nicklas |
$Id$ |
5616 |
27 Apr 11 |
nicklas |
3 |
|
5616 |
27 Apr 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5616 |
27 Apr 11 |
nicklas |
5 |
|
5616 |
27 Apr 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5616 |
27 Apr 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5616 |
27 Apr 11 |
nicklas |
8 |
|
5616 |
27 Apr 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5616 |
27 Apr 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5616 |
27 Apr 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5616 |
27 Apr 11 |
nicklas |
of the License, or (at your option) any later version. |
5616 |
27 Apr 11 |
nicklas |
13 |
|
5616 |
27 Apr 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5616 |
27 Apr 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5616 |
27 Apr 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5616 |
27 Apr 11 |
nicklas |
GNU General Public License for more details. |
5616 |
27 Apr 11 |
nicklas |
18 |
|
5616 |
27 Apr 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5616 |
27 Apr 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5616 |
27 Apr 11 |
nicklas |
21 |
*/ |
5616 |
27 Apr 11 |
nicklas |
22 |
package net.sf.basedb.util.extensions.manager.processor; |
5616 |
27 Apr 11 |
nicklas |
23 |
|
5616 |
27 Apr 11 |
nicklas |
24 |
|
5616 |
27 Apr 11 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
5616 |
27 Apr 11 |
nicklas |
26 |
import net.sf.basedb.core.PluginDefinition; |
5616 |
27 Apr 11 |
nicklas |
27 |
import net.sf.basedb.util.extensions.manager.ExtensionsFile.WriteableExtensionsFile; |
5616 |
27 Apr 11 |
nicklas |
28 |
import net.sf.basedb.util.extensions.manager.ExtensionsFile; |
5616 |
27 Apr 11 |
nicklas |
29 |
import net.sf.basedb.util.extensions.manager.ExtensionsFileProcessor; |
5616 |
27 Apr 11 |
nicklas |
30 |
import net.sf.basedb.util.extensions.manager.ExtensionsManager; |
5616 |
27 Apr 11 |
nicklas |
31 |
import net.sf.basedb.util.extensions.manager.ProcessResults; |
5616 |
27 Apr 11 |
nicklas |
32 |
import net.sf.basedb.util.extensions.xml.PluginInfo; |
5616 |
27 Apr 11 |
nicklas |
33 |
|
5616 |
27 Apr 11 |
nicklas |
34 |
/** |
5616 |
27 Apr 11 |
nicklas |
File processor implementation that disables plug-ins. |
5616 |
27 Apr 11 |
nicklas |
36 |
|
5616 |
27 Apr 11 |
nicklas |
@author Nicklas |
5616 |
27 Apr 11 |
nicklas |
@since 3.0 |
5616 |
27 Apr 11 |
nicklas |
@base.modified $Date$ |
5616 |
27 Apr 11 |
nicklas |
40 |
*/ |
5616 |
27 Apr 11 |
nicklas |
41 |
public class DisablePluginsProcessor |
5616 |
27 Apr 11 |
nicklas |
42 |
implements ExtensionsFileProcessor |
5616 |
27 Apr 11 |
nicklas |
43 |
{ |
5616 |
27 Apr 11 |
nicklas |
44 |
|
6444 |
09 Apr 14 |
nicklas |
45 |
private static final org.slf4j.Logger log = |
6444 |
09 Apr 14 |
nicklas |
46 |
org.slf4j.LoggerFactory.getLogger(DisablePluginsProcessor.class); |
5616 |
27 Apr 11 |
nicklas |
47 |
|
5616 |
27 Apr 11 |
nicklas |
48 |
private final DbControl dc; |
5616 |
27 Apr 11 |
nicklas |
49 |
private final ProcessResults results; |
5616 |
27 Apr 11 |
nicklas |
50 |
private int numFiles; |
5616 |
27 Apr 11 |
nicklas |
51 |
private int numError; |
5616 |
27 Apr 11 |
nicklas |
52 |
private int numTotalPlugins; |
5616 |
27 Apr 11 |
nicklas |
53 |
|
5616 |
27 Apr 11 |
nicklas |
54 |
/** |
5616 |
27 Apr 11 |
nicklas |
Create a new processor. |
5616 |
27 Apr 11 |
nicklas |
56 |
|
5616 |
27 Apr 11 |
nicklas |
@param dc DbControl to use for accessing the database |
5616 |
27 Apr 11 |
nicklas |
58 |
*/ |
5616 |
27 Apr 11 |
nicklas |
59 |
public DisablePluginsProcessor(DbControl dc, ProcessResults results) |
5616 |
27 Apr 11 |
nicklas |
60 |
{ |
5616 |
27 Apr 11 |
nicklas |
61 |
this.dc = dc; |
5616 |
27 Apr 11 |
nicklas |
62 |
this.results = results; |
5616 |
27 Apr 11 |
nicklas |
63 |
} |
5616 |
27 Apr 11 |
nicklas |
64 |
|
5616 |
27 Apr 11 |
nicklas |
65 |
/* |
5616 |
27 Apr 11 |
nicklas |
From the ExtensionsFileProcessor interface |
5616 |
27 Apr 11 |
nicklas |
67 |
------------------------------------------ |
5616 |
27 Apr 11 |
nicklas |
68 |
*/ |
5616 |
27 Apr 11 |
nicklas |
69 |
@Override |
5616 |
27 Apr 11 |
nicklas |
70 |
public void begin(ExtensionsManager manager, int numFiles) |
5616 |
27 Apr 11 |
nicklas |
71 |
{ |
5616 |
27 Apr 11 |
nicklas |
72 |
this.numFiles = 0; |
5616 |
27 Apr 11 |
nicklas |
73 |
this.numError = 0; |
5616 |
27 Apr 11 |
nicklas |
74 |
this.numTotalPlugins = 0; |
5616 |
27 Apr 11 |
nicklas |
75 |
} |
5616 |
27 Apr 11 |
nicklas |
76 |
|
5616 |
27 Apr 11 |
nicklas |
77 |
@Override |
5616 |
27 Apr 11 |
nicklas |
78 |
public void processFile(ExtensionsManager manager, WriteableExtensionsFile wFile) |
5616 |
27 Apr 11 |
nicklas |
79 |
{ |
5616 |
27 Apr 11 |
nicklas |
80 |
ExtensionsFile xtFile = wFile.getExtensionsFile(); |
5616 |
27 Apr 11 |
nicklas |
81 |
|
5616 |
27 Apr 11 |
nicklas |
82 |
log.info("Disabling plug-ins in file: " + xtFile); |
5616 |
27 Apr 11 |
nicklas |
83 |
try |
5616 |
27 Apr 11 |
nicklas |
84 |
{ |
5616 |
27 Apr 11 |
nicklas |
85 |
wFile.open(); |
5616 |
27 Apr 11 |
nicklas |
86 |
int num = 0; |
5616 |
27 Apr 11 |
nicklas |
87 |
for (PluginInfo info : xtFile.getObjectsOfClass(PluginInfo.class)) |
5616 |
27 Apr 11 |
nicklas |
88 |
{ |
5616 |
27 Apr 11 |
nicklas |
89 |
if (info.getInternalId() > 0) |
5616 |
27 Apr 11 |
nicklas |
90 |
{ |
5616 |
27 Apr 11 |
nicklas |
91 |
PluginDefinition plugin = PluginDefinition.getById(dc, info.getInternalId()); |
5616 |
27 Apr 11 |
nicklas |
92 |
plugin.setDisabled(true); |
5616 |
27 Apr 11 |
nicklas |
93 |
num++; |
5616 |
27 Apr 11 |
nicklas |
94 |
} |
5616 |
27 Apr 11 |
nicklas |
95 |
} |
5616 |
27 Apr 11 |
nicklas |
96 |
|
5616 |
27 Apr 11 |
nicklas |
97 |
numTotalPlugins += num; |
5616 |
27 Apr 11 |
nicklas |
98 |
numFiles++; |
5616 |
27 Apr 11 |
nicklas |
99 |
if (results != null) |
5616 |
27 Apr 11 |
nicklas |
100 |
{ |
5616 |
27 Apr 11 |
nicklas |
101 |
if (num > 0) results.addMessage(xtFile, num + " plug-in(s) disabled."); |
5616 |
27 Apr 11 |
nicklas |
102 |
} |
5616 |
27 Apr 11 |
nicklas |
103 |
log.info("Disabled " + num + " plug-ins from file: " + xtFile); |
5616 |
27 Apr 11 |
nicklas |
104 |
} |
5616 |
27 Apr 11 |
nicklas |
105 |
catch (Throwable ex) |
5616 |
27 Apr 11 |
nicklas |
106 |
{ |
5616 |
27 Apr 11 |
nicklas |
107 |
wFile.setError(true); |
5616 |
27 Apr 11 |
nicklas |
108 |
numError++; |
5616 |
27 Apr 11 |
nicklas |
109 |
if (results != null) |
5616 |
27 Apr 11 |
nicklas |
110 |
{ |
6379 |
13 Dec 13 |
nicklas |
111 |
results.addErrorMessage(xtFile, "Could not disable plug-ins: " + ex.getClass().getName() + "; " + ex.getMessage()); |
5616 |
27 Apr 11 |
nicklas |
112 |
} |
5616 |
27 Apr 11 |
nicklas |
113 |
log.error("Could not unregister extensions in file: " + xtFile, ex); |
5616 |
27 Apr 11 |
nicklas |
114 |
} |
5616 |
27 Apr 11 |
nicklas |
115 |
finally |
5616 |
27 Apr 11 |
nicklas |
116 |
{ |
5616 |
27 Apr 11 |
nicklas |
117 |
wFile.close(); |
5616 |
27 Apr 11 |
nicklas |
118 |
} |
5616 |
27 Apr 11 |
nicklas |
119 |
} |
5616 |
27 Apr 11 |
nicklas |
120 |
|
5616 |
27 Apr 11 |
nicklas |
121 |
@Override |
5616 |
27 Apr 11 |
nicklas |
122 |
public void done(ExtensionsManager manager) |
5616 |
27 Apr 11 |
nicklas |
123 |
{} |
5616 |
27 Apr 11 |
nicklas |
124 |
|
5616 |
27 Apr 11 |
nicklas |
125 |
@Override |
5616 |
27 Apr 11 |
nicklas |
126 |
public void done(ExtensionsManager manager, Throwable t) |
5616 |
27 Apr 11 |
nicklas |
127 |
{} |
5616 |
27 Apr 11 |
nicklas |
128 |
// ------------------------------------------ |
5616 |
27 Apr 11 |
nicklas |
129 |
|
5616 |
27 Apr 11 |
nicklas |
130 |
public ProcessResults getProcessResults() |
5616 |
27 Apr 11 |
nicklas |
131 |
{ |
5616 |
27 Apr 11 |
nicklas |
132 |
return results; |
5616 |
27 Apr 11 |
nicklas |
133 |
} |
5616 |
27 Apr 11 |
nicklas |
134 |
|
5616 |
27 Apr 11 |
nicklas |
135 |
/** |
5616 |
27 Apr 11 |
nicklas |
Get the number of files that was successfully processed. |
5616 |
27 Apr 11 |
nicklas |
137 |
*/ |
5616 |
27 Apr 11 |
nicklas |
138 |
public int getNumFiles() |
5616 |
27 Apr 11 |
nicklas |
139 |
{ |
5616 |
27 Apr 11 |
nicklas |
140 |
return numFiles; |
5616 |
27 Apr 11 |
nicklas |
141 |
} |
5616 |
27 Apr 11 |
nicklas |
142 |
|
5616 |
27 Apr 11 |
nicklas |
143 |
/** |
5616 |
27 Apr 11 |
nicklas |
Get the number of files that was had an error. |
5616 |
27 Apr 11 |
nicklas |
145 |
*/ |
5616 |
27 Apr 11 |
nicklas |
146 |
public int getNumError() |
5616 |
27 Apr 11 |
nicklas |
147 |
{ |
5616 |
27 Apr 11 |
nicklas |
148 |
return numError; |
5616 |
27 Apr 11 |
nicklas |
149 |
} |
5616 |
27 Apr 11 |
nicklas |
150 |
|
5616 |
27 Apr 11 |
nicklas |
151 |
/** |
5616 |
27 Apr 11 |
nicklas |
Get the total number of plug-in installed or updated |
5616 |
27 Apr 11 |
nicklas |
by the processor. |
5616 |
27 Apr 11 |
nicklas |
154 |
*/ |
5616 |
27 Apr 11 |
nicklas |
155 |
public int getNumPlugins() |
5616 |
27 Apr 11 |
nicklas |
156 |
{ |
5616 |
27 Apr 11 |
nicklas |
157 |
return numTotalPlugins; |
5616 |
27 Apr 11 |
nicklas |
158 |
} |
5616 |
27 Apr 11 |
nicklas |
159 |
|
5616 |
27 Apr 11 |
nicklas |
160 |
} |