comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 273:22a90706d32d

Enables the artifact server to set the TTL of a specific collection via REST call. artifacts/trunk@2070 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 07 Jun 2011 16:27:47 +0000
parents d9a99b28a847
children e92d5944fe4b
comparison
equal deleted inserted replaced
272:2ce31a9414ff 273:22a90706d32d
219 * XPath to figure out the attributes for an artifact that is put into a 219 * XPath to figure out the attributes for an artifact that is put into a
220 * collection. 220 * collection.
221 */ 221 */
222 public static final String XPATH_COLLECTION_ITEM_ATTRIBUTE = 222 public static final String XPATH_COLLECTION_ITEM_ATTRIBUTE =
223 "/art:action/art:type/art:artifact/art:attribute"; 223 "/art:action/art:type/art:artifact/art:attribute";
224
225 /**
226 * XPath to figure out the time to live value for setting a new TTL.
227 */
228 public static final String XPATH_COLLECTION_TTL =
229 "/art:action/art:type/art:ttl/@value";
224 230
225 231
226 /** 232 /**
227 * This inner class allows the deferral of writing the output 233 * This inner class allows the deferral of writing the output
228 * of the artifact's out() call. 234 * of the artifact's out() call.
1483 result.appendChild(root); 1489 result.appendChild(root);
1484 1490
1485 return result; 1491 return result;
1486 } 1492 }
1487 1493
1494 public Document setCollectionTTL(String uuid, Document doc, CallMeta meta)
1495 throws ArtifactDatabaseException
1496 {
1497 Document result = XMLUtils.newDocument();
1498 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
1499 result,
1500 ArtifactNamespaceContext.NAMESPACE_URI,
1501 ArtifactNamespaceContext.NAMESPACE_PREFIX);
1502
1503 Element root = ec.create("result");
1504 result.appendChild(root);
1505
1506 String tmp = XMLUtils.xpathString(
1507 doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE);
1508
1509 logger.info("Set TTL of artifact collection '" + uuid + "' to: " + tmp);
1510
1511 if (tmp == null || tmp.length() == 0) {
1512 logger.warn("No ttl for this collection specified.");
1513 root.setTextContent(OPERATION_FAILURE);
1514
1515 return result;
1516 }
1517
1518 Long ttl = null;
1519 if ((tmp = tmp.toUpperCase()).equals("INF")) {
1520 ttl = null;
1521 }
1522 else if (tmp.equals("DEFAULT")) {
1523 ArtifactCollectionFactory acf = getArtifactCollectionFactory();
1524 ttl = acf.timeToLiveUntouched(null, context);
1525 }
1526 else {
1527 try {
1528 ttl = Long.valueOf(tmp);
1529
1530 if (ttl < 0) {
1531 throw new NumberFormatException("Negative value.");
1532 }
1533 }
1534 catch (NumberFormatException nfe) {
1535 logger.error("Could not determine TTL", nfe);
1536 root.setTextContent(OPERATION_FAILURE);
1537 return result;
1538 }
1539 }
1540
1541 boolean success = backend.setCollectionTTL(uuid, ttl);
1542 root.setTextContent(success ? OPERATION_SUCCESSFUL: OPERATION_FAILURE);
1543
1544 return result;
1545 }
1546
1488 public DeferredOutput outCollection( 1547 public DeferredOutput outCollection(
1489 String collectionId, 1548 String collectionId,
1490 Document format, 1549 Document format,
1491 CallMeta callMeta) 1550 CallMeta callMeta)
1492 throws ArtifactDatabaseException 1551 throws ArtifactDatabaseException

http://dive4elements.wald.intevation.org