This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 91ee328e997104398bde6d49176c7c19089c990c Author: lahiruj <[email protected]> AuthorDate: Wed Oct 8 15:37:17 2025 -0400 handle AMIE data project creation events --- .../java/org/apache/custos/amie/AmiePoller.java | 2 +- .../amie/handler/DataProjectCreateHandler.java | 87 ++++++++++++++++++++++ .../amie/handler/RequestProjectCreateHandler.java | 16 +++- .../custos/amie/worker/ProcessingEventWorker.java | 2 +- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/AmiePoller.java b/amie-decoder/src/main/java/org/apache/custos/amie/AmiePoller.java index 0efbdb597..fc7dc718c 100644 --- a/amie-decoder/src/main/java/org/apache/custos/amie/AmiePoller.java +++ b/amie-decoder/src/main/java/org/apache/custos/amie/AmiePoller.java @@ -57,7 +57,7 @@ public class AmiePoller { } - @Scheduled(fixedDelayString = "${app.amie.scheduler.poll-delay}") + @Scheduled(fixedDelayString = "#{T(org.springframework.boot.convert.DurationStyle).detectAndParse('${app.amie.scheduler.poll-delay}').toMillis()}") @Transactional public void pollForPackets() { LOGGER.info("Polling for new AMIE packets..."); diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataProjectCreateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataProjectCreateHandler.java new file mode 100644 index 000000000..0d30d7451 --- /dev/null +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/DataProjectCreateHandler.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.custos.amie.handler; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.custos.amie.client.AmieClient; +import org.apache.custos.amie.model.PacketEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * Handles 'data_project_create' (DPC) and sends 'inform_transaction_complete' (ITC). + */ +@Component +public class DataProjectCreateHandler implements PacketHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(DataProjectCreateHandler.class); + + private final AmieClient amieClient; + + public DataProjectCreateHandler(AmieClient amieClient) { + this.amieClient = amieClient; + } + + @Override + public String supportsType() { + return "data_project_create"; + } + + @Override + public void handle(JsonNode packetJson, PacketEntity packetEntity) { + LOGGER.info("Starting 'data_project_create' handler for packet amie_id [{}].", packetEntity.getAmieId()); + + JsonNode body = packetJson.path("body"); + String projectId = body.path("ProjectID").asText(); + String personId = body.path("PersonID").asText(); + JsonNode dnList = body.path("DnList"); + + Assert.hasText(projectId, "'ProjectID' must not be empty."); + Assert.hasText(personId, "'PersonID' must not be empty."); + LOGGER.info("Packet validated. ProjectID: [{}], PersonID: [{}].", projectId, personId); + + // TODO update the local DB with the dnList against to the user's profile + if (dnList.isArray() && !dnList.isEmpty()) { + LOGGER.info("Received DnList for user [{}].", personId); + // TODO - userService.updateUserDnList(personId, dnList); + } + sendSuccessReply(packetEntity.getAmieId()); + } + + private void sendSuccessReply(long packetRecId) { + Map<String, Object> reply = new HashMap<>(); + Map<String, Object> itcBody = new HashMap<>(); + + itcBody.put("StatusCode", "Success"); + itcBody.put("DetailCode", 1); + itcBody.put("Message", "Transaction completed successfully by handler."); + + reply.put("type", "inform_transaction_complete"); + reply.put("body", itcBody); + + amieClient.replyToPacket(packetRecId, reply); + + LOGGER.info("Successfully sent 'inform_transaction_complete' for packet_rec_id [{}].", packetRecId); + } +} \ No newline at end of file diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectCreateHandler.java b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectCreateHandler.java index 3841a2a89..10154cde4 100644 --- a/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectCreateHandler.java +++ b/amie-decoder/src/main/java/org/apache/custos/amie/handler/RequestProjectCreateHandler.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; /** * Handles 'request_project_create' (RPC) by replying with 'notify_project_create' (NPC). @@ -68,6 +69,10 @@ public class RequestProjectCreateHandler implements PacketHandler { String pfosNumber = body.path("PfosNumber").asText(""); String piGlobalID = body.path("PiGlobalID").asText(""); + // TODO handle for failures + String piFirstName = body.path("PiFirstName").asText(""); + String piLastName = body.path("PiLastName").asText(""); + // ResourceList will have only one resource (According to AMIE documentation) List<Object> resourceList = new ArrayList<>(); JsonNode rl = body.path("ResourceList"); @@ -80,6 +85,10 @@ public class RequestProjectCreateHandler implements PacketHandler { // TODO - Derive a local project identifier String localProjectId = deriveLocalProjectId(grantNumber); + // TODO - Derive the following two from COmange registry + String piPersonID = UUID.randomUUID().toString(); + String piRemoteSiteLogin = (piFirstName.charAt(0) + piLastName).toLowerCase(); + // Build the NPC reply body Map<String, Object> replyBody = new HashMap<>(); Map<String, Object> npc = new HashMap<>(); @@ -89,9 +98,14 @@ public class RequestProjectCreateHandler implements PacketHandler { npc.put("EndDate", endDate); npc.put("RecordID", recordId); npc.put("ProjectID", localProjectId); - npc.put("PiOrgCode", piOrgCode); npc.put("PfosNumber", pfosNumber); + + npc.put("PiOrgCode", piOrgCode); npc.put("PiGlobalID", piGlobalID); + npc.put("PiPersonID", piPersonID); + npc.put("PiOrgCode", piOrgCode); + npc.put("PiRemoteSiteLogin", piRemoteSiteLogin); + if (!resourceList.isEmpty()) { npc.put("ResourceList", resourceList); } diff --git a/amie-decoder/src/main/java/org/apache/custos/amie/worker/ProcessingEventWorker.java b/amie-decoder/src/main/java/org/apache/custos/amie/worker/ProcessingEventWorker.java index 22edb13bd..39745bb6c 100644 --- a/amie-decoder/src/main/java/org/apache/custos/amie/worker/ProcessingEventWorker.java +++ b/amie-decoder/src/main/java/org/apache/custos/amie/worker/ProcessingEventWorker.java @@ -66,7 +66,7 @@ public class ProcessingEventWorker { /** * Runs on a fixed delay, checks for NEW events, and processes them one by one. */ - @Scheduled(fixedDelayString = "${app.amie.scheduler.worker-delay}") + @Scheduled(fixedDelayString = "#{T(org.springframework.boot.convert.DurationStyle).detectAndParse('${app.amie.scheduler.worker-delay}').toMillis()}") @Transactional public void processPendingEvents() { try (var eventStream = eventRepo.findTop50ByStatusOrderByCreatedAtAsc(ProcessingStatus.NEW)) {
