Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/MetaDataService.java @ 9232:5030c46d8cb4
Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
Needs to provide the ArtifactDatabase to the builder implementation.
author | gernotbelger |
---|---|
date | Fri, 06 Jul 2018 13:09:54 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
9231:082e8e808902 | 9232:5030c46d8cb4 |
---|---|
13 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 | 14 |
15 import java.util.Map; | 15 import java.util.Map; |
16 import java.util.HashMap; | 16 import java.util.HashMap; |
17 | 17 |
18 import org.dive4elements.artifactdatabase.ArtifactCallContext; | |
19 import org.dive4elements.artifactdatabase.ArtifactDatabaseImpl; | |
18 import org.dive4elements.artifacts.Artifact; | 20 import org.dive4elements.artifacts.Artifact; |
19 import org.dive4elements.artifacts.CallMeta; | 21 import org.dive4elements.artifacts.CallMeta; |
20 import org.dive4elements.artifacts.GlobalContext; | 22 import org.dive4elements.artifacts.GlobalContext; |
21 import org.dive4elements.artifacts.ArtifactDatabase; | 23 import org.dive4elements.artifacts.ArtifactDatabase; |
22 import org.dive4elements.artifacts.ArtifactDatabaseException; | 24 import org.dive4elements.artifacts.ArtifactDatabaseException; |
23 | 25 import org.dive4elements.artifacts.CallContext; |
24 import org.dive4elements.artifacts.common.utils.XMLUtils; | 26 import org.dive4elements.artifacts.common.utils.XMLUtils; |
25 import org.dive4elements.artifacts.common.utils.StringUtils; | 27 import org.dive4elements.artifacts.common.utils.StringUtils; |
26 | 28 |
27 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | 29 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; |
28 | 30 |
95 data, XPATH_OUTS, ArtifactNamespaceContext.INSTANCE); | 97 data, XPATH_OUTS, ArtifactNamespaceContext.INSTANCE); |
96 | 98 |
97 String parameters = XMLUtils.xpathString( | 99 String parameters = XMLUtils.xpathString( |
98 data, XPATH_PARAMETERS, ArtifactNamespaceContext.INSTANCE); | 100 data, XPATH_PARAMETERS, ArtifactNamespaceContext.INSTANCE); |
99 | 101 |
100 return doService( | 102 return doService( artifactId, userId, outs, parameters, globalContext, callMeta); |
101 artifactId, userId, outs, parameters, globalContext); | |
102 } | 103 } |
103 | 104 |
104 | 105 |
105 /** | 106 /** |
106 * Split parameterstring in the form of key1:value1;key2:value2 | 107 * Split parameterstring in the form of key1:value1;key2:value2 |
131 protected Document doService( | 132 protected Document doService( |
132 String artifactId, | 133 String artifactId, |
133 String userId, | 134 String userId, |
134 String outsString, | 135 String outsString, |
135 String parameters, | 136 String parameters, |
136 GlobalContext globalContext | 137 GlobalContext globalContext, |
138 CallMeta callMeta | |
137 ) { | 139 ) { |
138 Document result = XMLUtils.newDocument(); | 140 Document result = XMLUtils.newDocument(); |
139 | 141 |
140 D4EArtifact flysArtifact; | 142 D4EArtifact flysArtifact; |
141 | 143 |
149 if (userId != null && !StringUtils.checkUUID(userId)) { | 151 if (userId != null && !StringUtils.checkUUID(userId)) { |
150 log.warn("'" + userId + "' is not a UUID"); | 152 log.warn("'" + userId + "' is not a UUID"); |
151 return result; | 153 return result; |
152 } | 154 } |
153 | 155 |
156 Object dbObject = (ArtifactDatabase)globalContext.get(ARTIFACT_DATA_BASE_KEY); | |
157 if (!(dbObject instanceof ArtifactDatabase)) { | |
158 log.error("Cannot find artifact database"); | |
159 return result; | |
160 } | |
161 ArtifactDatabaseImpl db = (ArtifactDatabaseImpl)dbObject; | |
162 | |
154 if (artifactId != null) { | 163 if (artifactId != null) { |
155 if (!StringUtils.checkUUID(artifactId)) { | 164 if (!StringUtils.checkUUID(artifactId)) { |
156 log.warn("'" + artifactId + "' is not a UUID"); | 165 log.warn("'" + artifactId + "' is not a UUID"); |
157 return result; | 166 return result; |
158 } | 167 } |
159 | 168 |
160 Object dbObject = | |
161 (ArtifactDatabase)globalContext.get(ARTIFACT_DATA_BASE_KEY); | |
162 | |
163 if (!(dbObject instanceof ArtifactDatabase)) { | |
164 log.error("Cannot find artifact database"); | |
165 return result; | |
166 } | |
167 | |
168 ArtifactDatabase db = (ArtifactDatabase)dbObject; | |
169 | |
170 Artifact artifact; | 169 Artifact artifact; |
171 | 170 |
172 try { | 171 try { |
173 artifact = db.getRawArtifact(artifactId); | 172 artifact = db.getRawArtifact(artifactId); |
174 } | 173 } |
194 | 193 |
195 String [] outs = outsString == null | 194 String [] outs = outsString == null |
196 ? new String [0] | 195 ? new String [0] |
197 : outsString.split("\\s*,\\s*"); | 196 : outsString.split("\\s*,\\s*"); |
198 | 197 |
199 Recommendations rec = Recommendations.getInstance(); | 198 |
200 rec.recommend( | 199 // REMARK: this is an ugly place to do it and should rather be done inside the ArtifactDatabase, from where this service is called. |
201 flysArtifact, userId, outs, data, result); | 200 // REMARK: at the moment we know that this is currently only used to transport the ArtifactDatabase |
202 | 201 final ArtifactCallContext callContext = new ArtifactCallContext(db, CallContext.NOTHING, callMeta, null); |
202 | |
203 final Recommendations rec = Recommendations.getInstance(); | |
204 rec.recommend( flysArtifact, userId, outs, data, result, callContext ); | |
205 | |
206 callContext.postCall(); | |
207 | |
203 return result; | 208 return result; |
204 } | 209 } |
205 } | 210 } |
206 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 211 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |