1 |
41699
|
sandro.lab
|
package eu.dnetlib.enabling.is.registry;
|
2 |
|
|
|
3 |
|
|
import javax.xml.xpath.XPathExpressionException;
|
4 |
|
|
|
5 |
|
|
import eu.dnetlib.enabling.is.registry.schema.ValidationException;
|
6 |
|
|
import eu.dnetlib.enabling.is.registry.validation.ProfileValidationStrategy;
|
7 |
|
|
import eu.dnetlib.enabling.is.registry.validation.RegistrationPhase;
|
8 |
|
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
9 |
41734
|
michele.ar
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
10 |
|
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
11 |
42621
|
sandro.lab
|
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
13 |
41699
|
sandro.lab
|
|
14 |
|
|
/**
|
15 |
|
|
* implement the compatibility pending profile policy.
|
16 |
|
|
*
|
17 |
|
|
* <p>
|
18 |
|
|
* pending profiles receive their own special resource kind and are 'moved' to a different collection
|
19 |
|
|
* </p>
|
20 |
|
|
*
|
21 |
|
|
* @author marko
|
22 |
|
|
*
|
23 |
|
|
*/
|
24 |
|
|
public class CompatPendingResourceManagerImpl implements PendingResourceManager, ResourceKindResolver {
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* IS Registry
|
28 |
|
|
*/
|
29 |
|
|
private ISRegistryService isRegistry;
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* This bean resolver
|
33 |
|
|
*/
|
34 |
|
|
private ResourceKindResolver resourceKindResolver;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* used to validate resources w.r.t. a set of defined properties.
|
38 |
|
|
*/
|
39 |
42621
|
sandro.lab
|
@Autowired
|
40 |
41699
|
sandro.lab
|
private ProfileValidationStrategy profileValidationStrategy;
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* {@inheritDoc}
|
44 |
|
|
*
|
45 |
|
|
* @see eu.dnetlib.enabling.is.registry.PendingResourceManager#setPending(eu.dnetlib.enabling.tools.OpaqueResource)
|
46 |
|
|
*/
|
47 |
|
|
@Override
|
48 |
|
|
public void setPending(final OpaqueResource resource, final boolean local) {
|
49 |
|
|
try {
|
50 |
|
|
resource.setResourceKind(getPendingKindForType(resource.getResourceType()));
|
51 |
|
|
|
52 |
|
|
if (!local) {
|
53 |
|
|
isRegistry.deleteProfile(resource.getResourceId());
|
54 |
|
|
final String newId = isRegistry.registerProfile(resource.asString());
|
55 |
|
|
resource.setResourceId(newId);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
} catch (XPathExpressionException e) {
|
59 |
|
|
throw new IllegalStateException(e);
|
60 |
|
|
} catch (ISRegistryException e) {
|
61 |
|
|
throw new IllegalStateException(e);
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* {@inheritDoc}
|
67 |
|
|
*
|
68 |
|
|
* @see eu.dnetlib.enabling.is.registry.PendingResourceManager#setPending(eu.dnetlib.enabling.tools.OpaqueResource)
|
69 |
|
|
*/
|
70 |
|
|
@Override
|
71 |
|
|
public void setPending(final OpaqueResource resource) {
|
72 |
|
|
setPending(resource, false);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* {@inheritDoc}
|
77 |
|
|
*
|
78 |
|
|
* @see eu.dnetlib.enabling.is.registry.PendingResourceManager#setValid(eu.dnetlib.enabling.tools.OpaqueResource)
|
79 |
|
|
*/
|
80 |
|
|
@Override
|
81 |
|
|
public void setValid(final OpaqueResource resource) {
|
82 |
|
|
try {
|
83 |
|
|
if (resource.getResourceKind() != null && resource.getResourceKind().equals(getNormalKindForType(resource.getResourceType()))) { throw new IllegalArgumentException(
|
84 |
|
|
"trying to validate an already valid resource"); }
|
85 |
|
|
|
86 |
|
|
profileValidationStrategy.accept(resource, RegistrationPhase.Validate);
|
87 |
|
|
|
88 |
|
|
resource.setResourceKind(getNormalKindForType(resource.getResourceType()));
|
89 |
|
|
|
90 |
|
|
isRegistry.deleteProfile(resource.getResourceId());
|
91 |
|
|
|
92 |
|
|
final String newId = isRegistry.registerProfile(resource.asString());
|
93 |
|
|
resource.setResourceId(newId);
|
94 |
|
|
|
95 |
|
|
} catch (XPathExpressionException e) {
|
96 |
|
|
throw new IllegalStateException(e);
|
97 |
|
|
} catch (ISRegistryException e) {
|
98 |
|
|
throw new IllegalStateException(e);
|
99 |
|
|
} catch (ValidationException e) {
|
100 |
|
|
throw new IllegalStateException(e);
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
@Override
|
105 |
|
|
public String getNormalKindForType(final String resourceType) throws XPathExpressionException {
|
106 |
|
|
return resourceKindResolver.getNormalKindForType(resourceType);
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
@Override
|
110 |
|
|
public String getPendingKindForType(final String resourceType) throws XPathExpressionException {
|
111 |
|
|
return resourceKindResolver.getPendingKindForType(resourceType);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
public ResourceKindResolver getResourceKindResolver() {
|
115 |
|
|
return resourceKindResolver;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
@Required
|
119 |
|
|
public void setResourceKindResolver(final ResourceKindResolver resourceKindResolver) {
|
120 |
|
|
this.resourceKindResolver = resourceKindResolver;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
public ProfileValidationStrategy getProfileValidationStrategy() {
|
124 |
|
|
return profileValidationStrategy;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
public void setProfileValidationStrategy(final ProfileValidationStrategy profileValidationStrategy) {
|
128 |
|
|
this.profileValidationStrategy = profileValidationStrategy;
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
public ISRegistryService getIsRegistry() {
|
132 |
|
|
return isRegistry;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
@Required
|
136 |
|
|
public void setIsRegistry(final ISRegistryService isRegistry) {
|
137 |
|
|
this.isRegistry = isRegistry;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
}
|