1 |
41699
|
sandro.lab
|
package eu.dnetlib.enabling.is.registry.validation;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
|
5 |
|
|
import eu.dnetlib.enabling.is.registry.schema.ValidationException;
|
6 |
|
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
7 |
42621
|
sandro.lab
|
import org.springframework.beans.factory.annotation.Autowired;
|
8 |
41699
|
sandro.lab
|
|
9 |
|
|
/**
|
10 |
|
|
* ProfileValidationStrategy iterates all the profile validators,
|
11 |
|
|
* once a suitable validator is found, it's called to accept or
|
12 |
|
|
* reject the given resource.
|
13 |
|
|
*
|
14 |
|
|
* @author claudio
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
public class ProfileValidationStrategy {
|
18 |
42621
|
sandro.lab
|
|
19 |
|
|
@Autowired
|
20 |
41699
|
sandro.lab
|
private List<ProfileValidator> profileValidators;
|
21 |
|
|
|
22 |
|
|
public boolean accept(OpaqueResource resource, RegistrationPhase phase) throws ValidationException {
|
23 |
|
|
for(ProfileValidator validator : profileValidators) {
|
24 |
|
|
if (validator.handle(resource, phase)) {
|
25 |
|
|
if (validator.accept(resource))
|
26 |
|
|
return true;
|
27 |
|
|
else throw new ValidationException("Cannot validate the given resource: " + resource.asString());
|
28 |
|
|
}
|
29 |
|
|
}
|
30 |
|
|
// if no validator handles the resource
|
31 |
|
|
return true;
|
32 |
|
|
}
|
33 |
|
|
}
|