Skip to content

Commit

Permalink
Added temp API for testing FRI-646 - Need to be reverted when testing…
Browse files Browse the repository at this point in the history
… done
  • Loading branch information
QuyenLy87 committed Apr 17, 2023
1 parent 9f369a5 commit 7b20c9c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface PublishService {
void publishAdHocFile(ReleaseCenter releaseCenter, InputStream inputStream, String originalFilename, long size, boolean publishComponentIds) throws BusinessServiceException;

boolean exists(ReleaseCenter releaseCenter, String previouslyPublishedPackageName);

void testSendingMessage(String codeSystem, String releaseEffectiveDate, String importDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ public boolean exists(final ReleaseCenter releaseCenter, final String targetFile
return exists;
}

@Override
public void testSendingMessage(String codeSystem, String releaseEffectiveDate, String importDate) {
// Send notification via JMS
LOGGER.info("Sending message");
executorService.submit(() -> {
try {
Map payload = new HashMap();
payload.put("codeSystemShortName", codeSystem);
payload.put("effectiveDate", releaseEffectiveDate);
payload.put("importDate", importDate);
messagingHelper.publish(releasePublishDestination, payload, null, messageTimeToLiveSeconds);
} catch (JsonProcessingException | JMSException e) {
LOGGER.error("Failed to send PUBLISHED status to {}", releasePublishDestination);
}
});
}

// Publish extracted entries in a directory of the same name
private void publishExtractedVersionOfPackage(final String publishFilePath, final InputStream fileStream) throws IOException {
String zipExtractPath = publishFilePath.replace(".zip", S3PathHelper.SEPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.ihtsdo.buildcloud.core.entity.ReleaseCenter;
import org.ihtsdo.buildcloud.core.service.PublishService;
import org.ihtsdo.buildcloud.core.service.PublishServiceImpl;
import org.ihtsdo.buildcloud.core.service.TermServerService;
import org.ihtsdo.buildcloud.rest.security.IsAuthenticatedAsAdminOrReleaseManager;
import org.ihtsdo.otf.rest.client.terminologyserver.pojo.CodeSystem;
import org.ihtsdo.otf.rest.exception.BusinessServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Controller
@Tag(name = "Code Systems", description = "-")
Expand All @@ -28,6 +38,9 @@ public class CodeSystemController {
@Autowired
private TermServerService termServerService;

@Autowired
private PublishService publishService;

@GetMapping
@Operation(summary = "List code systems",
description = "List all code systems")
Expand All @@ -43,4 +56,17 @@ public ResponseEntity listCodeSystems(HttpServletRequest request) {
return new ResponseEntity(codeSystems, HttpStatus.OK);
}

private static final Logger LOGGER = LoggerFactory.getLogger(CodeSystemController.class);

@PostMapping(value = "/send-published-message")
@ResponseBody
public ResponseEntity<Object> publishReleaseCenterPackage(@RequestBody Map<String, String> requestBody, HttpServletRequest request) {
LOGGER.info("Recieved request: {}", requestBody);
String codeSystem = requestBody.get("codeSystem");
String effectiveDate = requestBody.get("effectiveDate");
String importDate = requestBody.get("importDate");
publishService.testSendingMessage(codeSystem, effectiveDate, importDate);
return new ResponseEntity<>(HttpStatus.CREATED);
}

}

0 comments on commit 7b20c9c

Please sign in to comment.