diff --git a/management/src/main/java/eu/nebulous/resource/discovery/registration/RegistrationRequestProcessor.java b/management/src/main/java/eu/nebulous/resource/discovery/registration/RegistrationRequestProcessor.java index c41ba46..8f96a88 100644 --- a/management/src/main/java/eu/nebulous/resource/discovery/registration/RegistrationRequestProcessor.java +++ b/management/src/main/java/eu/nebulous/resource/discovery/registration/RegistrationRequestProcessor.java @@ -249,6 +249,7 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess private void processResponse(@NonNull Map response) { String requestId = response.getOrDefault("requestId", "").toString().trim(); + String reference = response.getOrDefault("reference", "").toString().trim(); String status = response.getOrDefault("status", "").toString().trim(); String deviceIpAddress = response.getOrDefault("deviceIpAddress", "").toString().trim(); long timestamp = Long.parseLong(response.getOrDefault("timestamp", "-1").toString().trim()); @@ -266,18 +267,27 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess registrationRequest.setStatus(newStatus); String ipAddress = registrationRequest.getDevice().getIpAddress(); + boolean isError = false; if (StringUtils.equals(ipAddress, deviceIpAddress)) { - log.warn("processResponse: Device IP address do not match with that in request: id={}, ip-address={} != {}", - requestId, ipAddress, deviceIpAddress); - return; + String mesg = String.format("Device IP address do not match with that in request: id=%s, ip-address=%s != %s", requestId, ipAddress, deviceIpAddress); + log.warn("processResponse: {}", mesg); + registrationRequest.getMessages().add(mesg); + isError = true; } if (timestamp < registrationRequest.getRequestDate().toEpochMilli()) { - log.warn("processResponse: Response timestamp is older than Request's date: id={}, timestamp={} < {}", - requestId, timestamp, registrationRequest.getRequestDate()); - return; + String mesg = String.format("Response timestamp is older than Request's date: id=%s, timestamp=%d < %s", requestId, timestamp, registrationRequest.getRequestDate()); + log.warn("processResponse: {}", mesg); + registrationRequest.getMessages().add(mesg); + isError = true; } if (! "SUCCESS".equals(status)) { - log.warn("processResponse: Request status is not SUCCESS: id={}, timestamp={}, status={}", requestId, timestamp, status); + String mesg = String.format("Request status is not SUCCESS: id=%s, timestamp=%d, status=%s", requestId, timestamp, status); + log.warn("processResponse: {}", mesg); + registrationRequest.getMessages().add(mesg); + isError = true; + } + if (isError) { + registrationRequestService.update(registrationRequest); return; } @@ -307,6 +317,12 @@ public class RegistrationRequestProcessor implements IRegistrationRequestProcess requestId, timestamp, processedDevInfo); registrationRequest.getDevice().setDeviceInfo(processedDevInfo); + // Set node reference (meaningful only in case of Onboarding) + if (StringUtils.isNotBlank(reference) && currStatus==RegistrationRequestStatus.ONBOARDING_REQUESTED) { + registrationRequest.setNodeReference(reference.trim()); + } + + // Set new status if (currStatus==RegistrationRequestStatus.DATA_COLLECTION_REQUESTED) registrationRequest.setStatus(RegistrationRequestStatus.PENDING_AUTHORIZATION); if (currStatus==RegistrationRequestStatus.ONBOARDING_REQUESTED) diff --git a/management/src/main/java/eu/nebulous/resource/discovery/registration/model/ArchivedRegistrationRequest.java b/management/src/main/java/eu/nebulous/resource/discovery/registration/model/ArchivedRegistrationRequest.java index de2f02c..c98ba4b 100644 --- a/management/src/main/java/eu/nebulous/resource/discovery/registration/model/ArchivedRegistrationRequest.java +++ b/management/src/main/java/eu/nebulous/resource/discovery/registration/model/ArchivedRegistrationRequest.java @@ -15,6 +15,8 @@ public class ArchivedRegistrationRequest extends RegistrationRequest { archivedRequest.setArchiveDate(registrationRequest.getArchiveDate()); archivedRequest.setStatus(registrationRequest.getStatus()); archivedRequest.setHistory(registrationRequest.getHistory()); + archivedRequest.setNodeReference(registrationRequest.getNodeReference()); + archivedRequest.getMessages().addAll(registrationRequest.getMessages()); return archivedRequest; } @@ -28,6 +30,8 @@ public class ArchivedRegistrationRequest extends RegistrationRequest { .archiveDate(this.getArchiveDate()) .status(this.getStatus()) .history(this.getHistory()) + .nodeReference(this.getNodeReference()) + .messages(this.getMessages()) .build(); } } diff --git a/management/src/main/java/eu/nebulous/resource/discovery/registration/model/RegistrationRequest.java b/management/src/main/java/eu/nebulous/resource/discovery/registration/model/RegistrationRequest.java index f5dc8e6..0286b84 100644 --- a/management/src/main/java/eu/nebulous/resource/discovery/registration/model/RegistrationRequest.java +++ b/management/src/main/java/eu/nebulous/resource/discovery/registration/model/RegistrationRequest.java @@ -1,12 +1,15 @@ package eu.nebulous.resource.discovery.registration.model; +import lombok.AccessLevel; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import java.time.Instant; +import java.util.ArrayList; import java.util.List; @Data @@ -23,4 +26,7 @@ public class RegistrationRequest { private Instant archiveDate; private RegistrationRequestStatus status; private List history; + private String nodeReference; + @Setter(AccessLevel.NONE) + private List messages = new ArrayList<>(); } diff --git a/management/src/main/resources/static/freebees_webdesign_6/archived-view.html b/management/src/main/resources/static/freebees_webdesign_6/archived-view.html index 40fed5f..58b85db 100644 --- a/management/src/main/resources/static/freebees_webdesign_6/archived-view.html +++ b/management/src/main/resources/static/freebees_webdesign_6/archived-view.html @@ -108,6 +108,17 @@ function updateFormData(data) { } else { $(`[id="request#device#deviceInfo"]`).val( '' ).attr( 'rows', 2 ); } + + // Update messages field + if (data.messages) { + var valStr = data.messages.join('\n').trim(); + var rows = data.messages.length; + if (rows<2) rows = 2; + if (rows>50) rows = 50; + $(`[id="request#messages"]`).val( valStr ).attr( 'rows', rows ); + } else { + $(`[id="request#messages"]`).val( '' ).attr( 'rows', 2 ); + } } function flattenObject(ob) { @@ -202,6 +213,13 @@ function flattenObject(ob) { + +
+ +
+ +
+
@@ -230,6 +248,13 @@ function flattenObject(ob) {
+ +
+ +
+ +
+
Device details
diff --git a/management/src/main/resources/static/freebees_webdesign_6/request-edit.html b/management/src/main/resources/static/freebees_webdesign_6/request-edit.html index 0060323..0e3210d 100644 --- a/management/src/main/resources/static/freebees_webdesign_6/request-edit.html +++ b/management/src/main/resources/static/freebees_webdesign_6/request-edit.html @@ -110,6 +110,17 @@ function updateFormData(data) { } else { $(`[id="request#device#deviceInfo"]`).val( '' ).attr( 'rows', 2 ); } + + // Update messages field + if (data.messages) { + var valStr = data.messages.join('\n').trim(); + var rows = data.messages.length; + if (rows<2) rows = 2; + if (rows>50) rows = 50; + $(`[id="request#messages"]`).val( valStr ).attr( 'rows', rows ); + } else { + $(`[id="request#messages"]`).val( '' ).attr( 'rows', 2 ); + } } function flattenObject(ob) { @@ -215,6 +226,11 @@ function saveRequestInfo() { if (deviceInfo==='') deviceInfo = '{}'; root['device']['deviceInfo'] = JSON.parse( deviceInfo ); + // Fix messages + var messages = $(`[id="request#messages"]`).val().trim(); + if (messages==='') messages = ''; + root['messages'] = messages.split(/\r\n|\r|\n/); + // Check request Id if (requestId!=='' && requestId!==root.id) { alert('Request id has been modified!'); @@ -335,6 +351,13 @@ function sendRequestData(requestData) {
+ +
+ +
+ +
+
@@ -356,6 +379,13 @@ function sendRequestData(requestData) {
+ +
+ +
+ +
+
Device details