Skip to content

Commit

Permalink
Merge pull request #7 from sergeByishimo/develop
Browse files Browse the repository at this point in the history
feat: Linkedin Connector - Meeds-io/MIPs#141
  • Loading branch information
plamarque authored Sep 18, 2024
2 parents 3fcd195 + caf33c0 commit 3f977bd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.linkedin.gamification.rest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.exoplatform.services.listener.ListenerService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.HashMap;
import java.util.Map;

import static io.meeds.linkedin.gamification.utils.Utils.*;

@RestController
@RequestMapping("/linkedin/webhook")
@Tag(name = "webhooks", description = "An endpoint to receive linkedin webhooks")
public class LinkedInWebhookController {

private static final Log LOG = ExoLogger.getLogger(LinkedInWebhookController.class);

@Autowired
private ListenerService listenerService;

@PostMapping
@Operation(summary = "Project webhook for Remote LinkedIn connector.", description = "Project webhook for Remote LinkedIn connector.", method = "POST")
@ApiResponse(responseCode = "200", description = "Ok")
@ApiResponse(responseCode = "509", description = "Internal Server Error")
public ResponseEntity<Object> linkedInEvent(
@Parameter(required = true) @RequestParam("senderId") String senderId,
@Parameter(required = true) @RequestParam("receiverId") String receiverId,
@Parameter(required = true) @RequestParam("ruleTitle") String ruleTitle
) {
try {
try {

// String eventDetails = "{" + PROJECT_ID + ": " + event.getProjectId() + ", " + LANGUAGE_ID + ": " + event.getLanguageId()
// + ", " + MUST_BE_HUMAN + ": " + event.isMustBeHuman() + ", " + DIRECTORY_ID + ": " + event.getDirectoryId() + "}";

Map<String, String> gam = new HashMap<>();
gam.put("senderId", senderId);
gam.put("receiverId", receiverId);
gam.put("objectId", "");
gam.put("objectType", "");
// gam.put("eventDetails", eventDetails);

gam.put("ruleTitle", ruleTitle);

listenerService.broadcast(GAMIFICATION_GENERIC_EVENT, gam, "");
LOG.info("LinkedIn action {} broadcast for user {}", ruleTitle, senderId);

} catch (Exception e) {
LOG.error("Cannot broadcast linkedIn event", e);
}

return ResponseEntity.status(HttpStatus.OK).build();
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public class Utils {
public static final String LINKEDIN_CONNECTION_ERROR = "linkedin.connectionError";
public static final String LINKEDIN_VERSION = "202405";
public static final String LINKEDIN_PROTOCOL_VERSION = "2.0.0";

public static final String GAMIFICATION_GENERIC_EVENT = "exo.gamification.generic.action";

public static final String GAMIFICATION_CANCEL_EVENT = "gamification.cancel.event.action";

}

0 comments on commit 3f977bd

Please sign in to comment.