BrightSide Workbench Full Report + Source Code
org.turro.push.UserPushSubscription Class Reference
Inheritance diagram for org.turro.push.UserPushSubscription:
Collaboration diagram for org.turro.push.UserPushSubscription:

Public Member Functions

 UserPushSubscription ()
 
- Public Member Functions inherited from org.turro.elephant.direct.AbstractDirect
 AbstractDirect ()
 
boolean isRedirectToCurrent ()
 
void setRedirectToCurrent (boolean redirectToCurrent)
 
String createFormAction ()
 
String createPOST (String values)
 
String getAjaxSubmitUrl (String containerId)
 
String getAjaxUrl (String containerId, String values)
 
String getAjaxUrl (String containerId, KeyValueMap values)
 
String getAjaxEvalUrl (KeyValueMap values)
 
String createRightNowURL (String values)
 
String createRightNowURL (KeyValueMap values)
 
String createLinkTo (String link, KeyValueMap values)
 
String createURL ()
 
String createURL (IConstructor constructor, String values)
 
String createURL (IConstructor constructor, String values, int daysValid)
 
String createURL (IConstructor constructor, String values, int daysValid, boolean withDomain)
 
String createURL (IConstructor constructor, IContact recipe, String values, int daysValid, boolean withDomain)
 
String createURL (IConstructor constructor, IContact recipe, KeyValueMap values, int daysValid, boolean withDomain)
 
boolean itsMe (String id)
 
boolean myTurn (HttpServletRequest request)
 
void execute (ServletContext context, HttpServletRequest request, HttpServletResponse response)
 
void execute (IConstructor constructor)
 

Static Public Member Functions

static void pushMessage (String idContact, String payload)
 
static void pushMessage (PushSubscription pushSubscription, String payload)
 
static PushService instance ()
 

Protected Member Functions

String getIdentifier ()
 
void doExecute (IConstructor constructor, KeyValueMap map)
 
- Protected Member Functions inherited from org.turro.elephant.direct.AbstractDirect
String getRedirContext (IConstructor constructor, boolean withDomain)
 
String generateJson (String rootElement, String itemElement, List results)
 
JsonObjectBuilder createJsonItem (String itemElement, Object item)
 
void writeJsonResponse (HttpServletResponse response, String json)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 59 of file UserPushSubscription.java.

Constructor & Destructor Documentation

◆ UserPushSubscription()

org.turro.push.UserPushSubscription.UserPushSubscription ( )

Definition at line 89 of file UserPushSubscription.java.

89  {
90  }

Member Function Documentation

◆ doExecute()

void org.turro.push.UserPushSubscription.doExecute ( IConstructor  constructor,
KeyValueMap  map 
)
protected

Reimplemented from org.turro.elephant.direct.AbstractDirect.

Definition at line 98 of file UserPushSubscription.java.

98  {
99  if(map.containsKey("json")) {
100  JsonReader reader = Json.createReader(new StringReader(map.get("json")));
101  JsonObject subs = reader.readObject();
102  JsonObject keys = subs.getJsonObject("keys");
103  PushSubscription subscription = new PushSubscription();
104  subscription.setContactId(Authentication.getIContact().getId());
105  subscription.setEndpoint(subs.getString("endpoint"));
106  subscription.setPrivateKey(keys.getString("auth"));
107  subscription.setPublicKey(keys.getString("p256dh"));
108  new ElephantPU().saveObject(subscription);
109  pushMessage(subscription, PushMessage.title("Welcome")
110  .message("Successfully subscribed on this device")
111  .click(ElephantContext.getServerUrl("http")).json());
112  }
113  }
static void pushMessage(String idContact, String payload)
Here is the call graph for this function:

◆ getIdentifier()

String org.turro.push.UserPushSubscription.getIdentifier ( )
protected

Reimplemented from org.turro.elephant.direct.AbstractDirect.

Definition at line 93 of file UserPushSubscription.java.

93  {
94  return UserPushSubscription.class.getAnnotation(DirectContent.class).identifier();
95  }

◆ instance()

static PushService org.turro.push.UserPushSubscription.instance ( )
static

Definition at line 132 of file UserPushSubscription.java.

132  {
133  return PUSH_SERVICE.instance(() -> {
134  Security.addProvider(new BouncyCastleProvider());
135  try {
136  return new PushService(
137  ServerKeys.publicKey(),
138  ServerKeys.privateKey(),
139  "mailto:lluis@turro.org");
140  } catch (GeneralSecurityException ex) {
141  Logger.getLogger(UserPushSubscription.class.getName()).log(Level.SEVERE, null, ex);
142  return null;
143  }
144  });
145  }
Here is the call graph for this function:

◆ pushMessage() [1/2]

static void org.turro.push.UserPushSubscription.pushMessage ( PushSubscription  pushSubscription,
String  payload 
)
static

Definition at line 69 of file UserPushSubscription.java.

69  {
70  try {
71  PushService pushService = instance();
72  Subscription.Keys keys = new Subscription.Keys(
73  pushSubscription.getPublicKey(), pushSubscription.getPrivateKey());
74  Subscription subscription = new Subscription(pushSubscription.getEndpoint(), keys);
75  Notification notification = new Notification(subscription, payload);
76  HttpResponse response = pushService.send(notification);
77  if(REMOVE_RESPONSES.contains(response.getCode())) {
78  removeSubscription(pushSubscription);
79  }
80  } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException ex) {
81  Logger.getLogger(UserPushSubscription.class.getName()).log(Level.SEVERE, null, ex);
82  } catch (GeneralSecurityException | IOException | JoseException | ExecutionException | InterruptedException ex) {
83  Logger.getLogger(UserPushSubscription.class.getName()).log(Level.SEVERE, null, ex);
84  }
85  }
Here is the call graph for this function:

◆ pushMessage() [2/2]

static void org.turro.push.UserPushSubscription.pushMessage ( String  idContact,
String  payload 
)
static

Definition at line 63 of file UserPushSubscription.java.

63  {
64  subscriptions(idContact).forEach(pushSubscription -> {
65  pushMessage(pushSubscription, payload);
66  });
67  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: