Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 343:542caebea773
Add functionality to get 'oldest' artifact of a collection.'
artifacts/trunk@3037 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 19 Oct 2011 15:55:33 +0000 |
parents | eb8dbfa7125d |
children | f2277458823e |
comparison
equal
deleted
inserted
replaced
342:9a85e0ef6e02 | 343:542caebea773 |
---|---|
765 CallMeta callMeta, | 765 CallMeta callMeta, |
766 Document data | 766 Document data |
767 ) | 767 ) |
768 throws ArtifactDatabaseException | 768 throws ArtifactDatabaseException |
769 { | 769 { |
770 logger.debug("ArtifactDatabaseImpl.createArtifactWithFactory " | |
771 + factoryName); | |
770 ArtifactFactory factory = getArtifactFactory(factoryName); | 772 ArtifactFactory factory = getArtifactFactory(factoryName); |
771 | 773 |
772 if (factory == null) { | 774 if (factory == null) { |
773 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | 775 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); |
774 } | 776 } |
1285 } | 1287 } |
1286 | 1288 |
1287 | 1289 |
1288 // Collection API | 1290 // Collection API |
1289 | 1291 |
1292 public Document getCollectionsMasterArtifact( | |
1293 String collectionId, | |
1294 CallMeta meta) | |
1295 throws ArtifactDatabaseException | |
1296 { | |
1297 Document result = XMLUtils.newDocument(); | |
1298 String masterUUID = backend.getMasterArtifact(collectionId); | |
1299 | |
1300 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
1301 result, | |
1302 ArtifactNamespaceContext.NAMESPACE_URI, | |
1303 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
1304 | |
1305 ArtifactCollectionFactory acf = getArtifactCollectionFactory(); | |
1306 | |
1307 if (acf == null) { | |
1308 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | |
1309 } | |
1310 | |
1311 UserFactory uf = getUserFactory(); | |
1312 if (uf == null) { | |
1313 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | |
1314 } | |
1315 | |
1316 ArtifactCollection c = backend.getCollection( | |
1317 collectionId, acf, uf, context); | |
1318 | |
1319 if (c == null) { | |
1320 logger.warn("No collection found with identifier: " + collectionId); | |
1321 throw new ArtifactDatabaseException(NO_SUCH_COLLECTION); | |
1322 } | |
1323 | |
1324 Element root = ec.create("artifact-collection"); | |
1325 ec.addAttr(root, "name", c.getName(), true); | |
1326 ec.addAttr(root, "uuid", c.identifier(), true); | |
1327 ec.addAttr(root, "ttl", String.valueOf(c.getTTL()), true); | |
1328 | |
1329 Date creationTime = c.getCreationTime(); | |
1330 String creation = creationTime != null | |
1331 ? Long.toString(creationTime.getTime()) | |
1332 : ""; | |
1333 | |
1334 ec.addAttr(root, "creation", creation, true); | |
1335 result.appendChild(root); | |
1336 | |
1337 if (masterUUID == null || masterUUID.length() == 0) { | |
1338 logger.debug("No master for the collection existing."); | |
1339 return result; | |
1340 } | |
1341 | |
1342 Element master = ec.create("artifact"); | |
1343 ec.addAttr(master, "uuid", masterUUID, true); | |
1344 | |
1345 root.appendChild(master); | |
1346 | |
1347 return result; | |
1348 } | |
1349 | |
1290 public Document listCollections(String userId, CallMeta callMeta) | 1350 public Document listCollections(String userId, CallMeta callMeta) |
1291 throws ArtifactDatabaseException | 1351 throws ArtifactDatabaseException |
1292 { | 1352 { |
1293 ArtifactCollectionFactory acf = getArtifactCollectionFactory(); | 1353 ArtifactCollectionFactory acf = getArtifactCollectionFactory(); |
1294 UserFactory uf = getUserFactory(); | 1354 UserFactory uf = getUserFactory(); |