@@ -1808,7 +1808,7 @@ private String sendDiceInvitation(UserDiceAttributes diceAttributes)
18081808 if (response .getStatusCode () != HttpURLConnection .HTTP_OK ) {
18091809 sendSlackNotification (diceAttributes .getHandle (), "Error happened, please check the logs." );
18101810 throw new APIRuntimeException (HttpURLConnection .HTTP_INTERNAL_ERROR ,
1811- String .format ("Error when calling dice connection api with body. %s %s %d %s" , mapper .writeValueAsString (body ), token , response .getStatusCode (),
1811+ String .format ("Error when calling dice connection api with body. %s %s %d %s" , mapper .writeValueAsString (body ), token ,response .getStatusCode (),
18121812 response .getMessage ()));
18131813 }
18141814 DiceInvitationResponse diceInvitation = new ObjectMapper ().readValue (response .getText (),
@@ -1817,16 +1817,21 @@ private String sendDiceInvitation(UserDiceAttributes diceAttributes)
18171817 }
18181818
18191819 @ POST
1820- @ Path ("/dice-status " )
1820+ @ Path ("/dice-callback " )
18211821 @ Timed
1822- public ApiResponse diceStatus (@ Valid PostPutRequest <DiceStatusRequest > postRequest ,
1822+ public ApiResponse diceStatus (@ Valid PostPutRequest <DiceCallbackRequest > postRequest ,
18231823 @ Context HttpServletRequest request ) {
1824- logger .info (String .format ("Dice status request : %s %s" , postRequest , request ));
1824+ logger .info (String .format ("Dice callback : %s %s" , postRequest , request ));
18251825 if (!diceAuth .isValidAPIKey (request )) {
18261826 throw new APIRuntimeException (SC_FORBIDDEN , "Forbidden" );
18271827 }
1828- checkParam (postRequest );
1829- DiceStatusRequest status = postRequest .getParam ();
1828+
1829+ if (postRequest == null ) {
1830+ return ApiResponseFactory .createResponse (
1831+ createValidationResult (true , "Connection success" ));
1832+ }
1833+
1834+ DiceCallbackRequest status = postRequest .getParam ();
18301835 if (status .getType () == null ) {
18311836 logger .info (String .format ("Dice status missing type: %s %s" , postRequest , request ));
18321837 throw new APIRuntimeException (SC_BAD_REQUEST , String .format (MSG_TEMPLATE_MANDATORY , "type" ));
@@ -1860,6 +1865,47 @@ public ApiResponse diceStatus(@Valid PostPutRequest<DiceStatusRequest> postReque
18601865 return ApiResponseFactory .createResponse ("SUCCESS" );
18611866 }
18621867
1868+ @ POST
1869+ @ Path ("/dice-status" )
1870+ @ Timed
1871+ public ApiResponse diceStatus (@ Valid PostPutRequest <DiceStatusRequest > postRequest ,
1872+ @ Context HttpServletRequest request ) {
1873+ if (!diceAuth .isValidAPIKey (request )) {
1874+ throw new APIRuntimeException (SC_FORBIDDEN , "Forbidden" );
1875+ }
1876+ checkParam (postRequest );
1877+ DiceStatusRequest status = postRequest .getParam ();
1878+ if (status .getEvent () == null ) {
1879+ throw new APIRuntimeException (SC_BAD_REQUEST , String .format (MSG_TEMPLATE_MANDATORY , "event" ));
1880+ }
1881+ if (status .getConnectionId () == null || status .getConnectionId ().isEmpty ()) {
1882+ throw new APIRuntimeException (SC_BAD_REQUEST , String .format (MSG_TEMPLATE_MANDATORY , "connectionId" ));
1883+ }
1884+ logger .info (status );
1885+ switch (status .getEvent ()) {
1886+ case "connection-invitation" :
1887+ handleConnectionCreatedEvent (status .getConnectionId (), status .getEmailId (), status .getShortUrl ());
1888+ break ;
1889+ case "connection-response" :
1890+ handleConnectionAcceptedEvent (status .getConnectionId ());
1891+ break ;
1892+ case "credential-issuance" :
1893+ handleCredentialIssuanceEvent (status .getConnectionId ());
1894+ break ;
1895+ case "connection-declined" :
1896+ handleConnectionDeclinedEvent (status .getConnectionId ());
1897+ break ;
1898+ case "credential-declined" :
1899+ handleCredentialDeclinedEvent (status .getConnectionId ());
1900+ break ;
1901+ default :
1902+ throw new APIRuntimeException (SC_BAD_REQUEST ,
1903+ String .format ("%s is not valid event" , status .getEvent ()));
1904+ }
1905+
1906+ return ApiResponseFactory .createResponse ("SUCCESS" );
1907+ }
1908+
18631909 private void handleConnectionCreatedEvent (String connectionId , String emailId , String shortUrl ) {
18641910 if (emailId == null || emailId .isEmpty ()) {
18651911 throw new APIRuntimeException (SC_BAD_REQUEST , String .format (MSG_TEMPLATE_MANDATORY , "emailId" ));
0 commit comments