5616 |
27 Apr 11 |
nicklas |
1 |
/** |
5616 |
27 Apr 11 |
nicklas |
$Id: ValidAndNewOrModifiedFilter.java 5607 2011-04-15 07:52:28Z nicklas $ |
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.filter; |
5616 |
27 Apr 11 |
nicklas |
23 |
|
5616 |
27 Apr 11 |
nicklas |
24 |
import java.io.File; |
5616 |
27 Apr 11 |
nicklas |
25 |
|
5616 |
27 Apr 11 |
nicklas |
26 |
import net.sf.basedb.util.extensions.manager.ExtensionsFile; |
5616 |
27 Apr 11 |
nicklas |
27 |
import net.sf.basedb.util.extensions.manager.Settings; |
5616 |
27 Apr 11 |
nicklas |
28 |
import net.sf.basedb.util.filter.Filter; |
5616 |
27 Apr 11 |
nicklas |
29 |
|
5616 |
27 Apr 11 |
nicklas |
30 |
/** |
5616 |
27 Apr 11 |
nicklas |
Filter implementation for extension files that |
5616 |
27 Apr 11 |
nicklas |
allow installed files to pass. A {@link Settings} |
5616 |
27 Apr 11 |
nicklas |
object is used to keep track of which files are |
5616 |
27 Apr 11 |
nicklas |
installed and not. |
5616 |
27 Apr 11 |
nicklas |
35 |
|
5616 |
27 Apr 11 |
nicklas |
@author Nicklas |
5616 |
27 Apr 11 |
nicklas |
@since 3.0 |
5616 |
27 Apr 11 |
nicklas |
@base.modified $Date: 2011-04-15 09:52:28 +0200 (fr, 15 apr 2011) $ |
5616 |
27 Apr 11 |
nicklas |
39 |
*/ |
5616 |
27 Apr 11 |
nicklas |
40 |
public class InstalledFilter |
5616 |
27 Apr 11 |
nicklas |
41 |
implements Filter<ExtensionsFile> |
5616 |
27 Apr 11 |
nicklas |
42 |
{ |
5616 |
27 Apr 11 |
nicklas |
43 |
|
6444 |
09 Apr 14 |
nicklas |
44 |
private static final org.slf4j.Logger log = |
6444 |
09 Apr 14 |
nicklas |
45 |
org.slf4j.LoggerFactory.getLogger(InstalledFilter.class); |
5616 |
27 Apr 11 |
nicklas |
46 |
|
5616 |
27 Apr 11 |
nicklas |
47 |
private final Settings settings; |
5616 |
27 Apr 11 |
nicklas |
48 |
private final Filter<ExtensionsFile> parent; |
5616 |
27 Apr 11 |
nicklas |
49 |
|
5616 |
27 Apr 11 |
nicklas |
50 |
/** |
5616 |
27 Apr 11 |
nicklas |
Create a new filter. |
5616 |
27 Apr 11 |
nicklas |
@param settings The settings object to use when checking if a file is installed or not |
5616 |
27 Apr 11 |
nicklas |
53 |
*/ |
5616 |
27 Apr 11 |
nicklas |
54 |
public InstalledFilter(Settings settings) |
5616 |
27 Apr 11 |
nicklas |
55 |
{ |
5616 |
27 Apr 11 |
nicklas |
56 |
this(settings, null); |
5616 |
27 Apr 11 |
nicklas |
57 |
} |
5616 |
27 Apr 11 |
nicklas |
58 |
|
5616 |
27 Apr 11 |
nicklas |
59 |
/** |
5616 |
27 Apr 11 |
nicklas |
Create a new filter with an optional chained parent filted. |
5616 |
27 Apr 11 |
nicklas |
@param settings The settings object to use when checking if a file is installed or not |
5616 |
27 Apr 11 |
nicklas |
@param parent An optional parent filter that will also be checked |
5616 |
27 Apr 11 |
nicklas |
63 |
*/ |
5616 |
27 Apr 11 |
nicklas |
64 |
public InstalledFilter(Settings settings, Filter<ExtensionsFile> parent) |
5616 |
27 Apr 11 |
nicklas |
65 |
{ |
5616 |
27 Apr 11 |
nicklas |
66 |
this.settings = settings; |
5616 |
27 Apr 11 |
nicklas |
67 |
this.parent = parent; |
5616 |
27 Apr 11 |
nicklas |
68 |
} |
5616 |
27 Apr 11 |
nicklas |
69 |
|
5616 |
27 Apr 11 |
nicklas |
70 |
/* |
5616 |
27 Apr 11 |
nicklas |
From the Filter interface |
5616 |
27 Apr 11 |
nicklas |
72 |
------------------------- |
5616 |
27 Apr 11 |
nicklas |
73 |
*/ |
5616 |
27 Apr 11 |
nicklas |
74 |
@Override |
5616 |
27 Apr 11 |
nicklas |
75 |
public boolean evaluate(ExtensionsFile xtFile) |
5616 |
27 Apr 11 |
nicklas |
76 |
{ |
5616 |
27 Apr 11 |
nicklas |
77 |
if (parent != null && !parent.evaluate(xtFile)) |
5616 |
27 Apr 11 |
nicklas |
78 |
{ |
5616 |
27 Apr 11 |
nicklas |
79 |
return false; |
5616 |
27 Apr 11 |
nicklas |
80 |
} |
5616 |
27 Apr 11 |
nicklas |
81 |
File file = xtFile.getFile(); |
5616 |
27 Apr 11 |
nicklas |
82 |
if (file != null && !settings.isInstalledFile(file)) |
5616 |
27 Apr 11 |
nicklas |
83 |
{ |
5616 |
27 Apr 11 |
nicklas |
84 |
log.info("File is not installed (skipping): " + xtFile); |
5616 |
27 Apr 11 |
nicklas |
85 |
return false; |
5616 |
27 Apr 11 |
nicklas |
86 |
} |
6520 |
18 Aug 14 |
nicklas |
87 |
if (!xtFile.isValid() || xtFile.hasError()) |
6520 |
18 Aug 14 |
nicklas |
88 |
{ |
6520 |
18 Aug 14 |
nicklas |
// Do not install files with errors |
6520 |
18 Aug 14 |
nicklas |
90 |
return false; |
6520 |
18 Aug 14 |
nicklas |
91 |
} |
5616 |
27 Apr 11 |
nicklas |
92 |
return true; |
5616 |
27 Apr 11 |
nicklas |
93 |
} |
5616 |
27 Apr 11 |
nicklas |
94 |
// ------------------------- |
5616 |
27 Apr 11 |
nicklas |
95 |
|
5616 |
27 Apr 11 |
nicklas |
96 |
|
5616 |
27 Apr 11 |
nicklas |
97 |
} |