/** * The subscription has been approved by a node owner. The subscription is now active so the * subscriber is now allowed to get event notifications. */ void approved() { if (state == State.subscribed) { // Do nothing return; } state = State.subscribed; if (savedToDB) { // Update the subscription in the backend store PubSubPersistenceManager.saveSubscription(service, node, this, false); } // Send last published item (if node is leaf node and subscription status is ok) if (node.isSendItemSubscribe() && isActive()) { PublishedItem lastItem = node.getLastPublishedItem(); if (lastItem != null) { sendLastPublishedItem(lastItem); } } }
void configure(DataForm options) { List<String> values; String booleanValue; boolean wasUsingPresence = !presenceStates.isEmpty(); // Remove this field from the form options.removeField("FORM_TYPE"); // Process and remove specific collection node fields FormField collectionField = options.getField("pubsub#subscription_type"); if (collectionField != null) { values = collectionField.getValues(); if (values.size() > 0) { type = Type.valueOf(values.get(0)); } options.removeField("pubsub#subscription_type"); } collectionField = options.getField("pubsub#subscription_depth"); if (collectionField != null) { values = collectionField.getValues(); depth = "all".equals(values.get(0)) ? 0 : 1; options.removeField("pubsub#subscription_depth"); } // If there are more fields in the form then process them and set that // the subscription has been configured for (FormField field : options.getFields()) { boolean fieldExists = true; if ("pubsub#deliver".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); deliverNotifications = "1".equals(booleanValue); } else if ("pubsub#digest".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); usingDigest = "1".equals(booleanValue); } else if ("pubsub#digest_frequency".equals(field.getVariable())) { values = field.getValues(); digestFrequency = values.size() > 0 ? Integer.parseInt(values.get(0)) : 86400000; } else if ("pubsub#expire".equals(field.getVariable())) { values = field.getValues(); synchronized (dateFormat) { try { expire = dateFormat.parse(values.get(0)); } catch (ParseException e) { Log.error("Error parsing date", e); } } } else if ("pubsub#include_body".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); includingBody = "1".equals(booleanValue); } else if ("pubsub#show-values".equals(field.getVariable())) { // Get the new list of presence states for which an entity wants to // receive notifications presenceStates = new ArrayList<String>(); for (String value : field.getValues()) { try { presenceStates.add(value); } catch (Exception e) { // Do nothing } } } else if ("x-pubsub#keywords".equals(field.getVariable())) { values = field.getValues(); keyword = values.isEmpty() ? null : values.get(0); } else { fieldExists = false; } if (fieldExists) { // Subscription has been configured so set the next state if (node.getAccessModel().isAuthorizationRequired() && !node.isAdmin(owner)) { state = State.pending; } else { state = State.subscribed; } } } if (savedToDB) { // Update the subscription in the backend store PubSubPersistenceManager.saveSubscription(service, node, this, false); } // Check if the service needs to subscribe or unsubscribe from the owner presence if (!node.isPresenceBasedDelivery() && wasUsingPresence != !presenceStates.isEmpty()) { if (presenceStates.isEmpty()) { service.presenceSubscriptionNotRequired(node, owner); } else { service.presenceSubscriptionRequired(node, owner); } } }