Remove unnecessary JsonProperty annotations (#2296)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -187,14 +188,10 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
protected DmfDownloadAndUpdateRequest createDownloadAndUpdateRequest(
|
||||
final Target target, final Long actionId,
|
||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
final DmfDownloadAndUpdateRequest request = new DmfDownloadAndUpdateRequest();
|
||||
request.setActionId(actionId);
|
||||
request.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
|
||||
if (softwareModules != null) {
|
||||
softwareModules.entrySet().forEach(entry -> request.addSoftwareModule(convertToAmqpSoftwareModule(target, entry)));
|
||||
}
|
||||
return request;
|
||||
return new DmfDownloadAndUpdateRequest(
|
||||
actionId,
|
||||
systemSecurityContext.runAsSystem(target::getSecurityToken),
|
||||
convertToAmqpSoftwareModules(target, softwareModules));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,9 +261,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
return;
|
||||
}
|
||||
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest();
|
||||
actionRequest.setActionId(actionId);
|
||||
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest(actionId);
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
actionRequest,
|
||||
createConnectorMessagePropertiesEvent(tenant, controllerId, EventTopic.CANCEL_DOWNLOAD));
|
||||
@@ -275,25 +270,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
protected DmfTarget convertToDmfTarget(final Target target, final Long actionId) {
|
||||
final DmfTarget dmfTarget = new DmfTarget();
|
||||
dmfTarget.setActionId(actionId);
|
||||
dmfTarget.setControllerId(target.getControllerId());
|
||||
dmfTarget.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
return dmfTarget;
|
||||
return new DmfTarget(actionId, target.getControllerId(), systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
}
|
||||
|
||||
protected DmfConfirmRequest createConfirmRequest(
|
||||
final Target target, final Long actionId, final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
final DmfConfirmRequest request = new DmfConfirmRequest();
|
||||
request.setActionId(actionId);
|
||||
request.setTargetSecurityToken(systemSecurityContext.runAsSystem(target::getSecurityToken));
|
||||
|
||||
//Software modules can be filtered in the future exposing only the needed.
|
||||
if (softwareModules != null) {
|
||||
softwareModules.entrySet().forEach(entry ->
|
||||
request.addSoftwareModule(convertToAmqpSoftwareModule(target, entry)));
|
||||
}
|
||||
return request;
|
||||
return new DmfConfirmRequest(
|
||||
actionId,
|
||||
systemSecurityContext.runAsSystem(target::getSecurityToken),
|
||||
convertToAmqpSoftwareModules(target, softwareModules));
|
||||
}
|
||||
|
||||
void sendMultiActionRequestToTarget(
|
||||
@@ -304,18 +289,21 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
return;
|
||||
}
|
||||
|
||||
final DmfMultiActionRequest multiActionRequest = new DmfMultiActionRequest();
|
||||
actions.forEach(action -> {
|
||||
final DmfActionRequest actionRequest = createDmfActionRequest(
|
||||
target, action,
|
||||
action.getDistributionSet().getModules().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), module -> {
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = getSoftwareModuleMetaData.apply(module);
|
||||
return softwareModuleMetadata == null ? Collections.emptyList() : softwareModuleMetadata;
|
||||
})));
|
||||
final int weight = deploymentManagement.getWeightConsideringDefault(action);
|
||||
multiActionRequest.addElement(getEventTypeForAction(action), actionRequest, weight);
|
||||
});
|
||||
final DmfMultiActionRequest multiActionRequest = new DmfMultiActionRequest(
|
||||
actions.stream()
|
||||
.map(action -> {
|
||||
final DmfActionRequest actionRequest = createDmfActionRequest(
|
||||
target, action,
|
||||
action.getDistributionSet().getModules().stream()
|
||||
.collect(Collectors.toMap(Function.identity(), module -> {
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = getSoftwareModuleMetaData.apply(
|
||||
module);
|
||||
return softwareModuleMetadata == null ? Collections.emptyList() : softwareModuleMetadata;
|
||||
})));
|
||||
final int weight = deploymentManagement.getWeightConsideringDefault(action);
|
||||
return new DmfMultiActionRequest.DmfMultiActionElement(getEventTypeForAction(action), actionRequest, weight);
|
||||
})
|
||||
.toList());
|
||||
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
multiActionRequest,
|
||||
@@ -323,12 +311,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
amqpSenderService.sendMessage(message, targetAddress);
|
||||
}
|
||||
|
||||
private static DmfActionRequest createPlainActionRequest(final Action action) {
|
||||
final DmfActionRequest actionRequest = new DmfActionRequest();
|
||||
actionRequest.setActionId(action.getId());
|
||||
return actionRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the type of event depending on whether the action is a DOWNLOAD_ONLY action or if it has a valid maintenance window
|
||||
* available or not based on defined maintenance schedule. In case of no maintenance schedule or if there is a valid window available,
|
||||
@@ -488,7 +470,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Target target, final Action action,
|
||||
final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
return createPlainActionRequest(action);
|
||||
return new DmfActionRequest(action.getId());
|
||||
} else if (action.isWaitingConfirmation()) {
|
||||
return createConfirmRequest(target, action.getId(), softwareModules);
|
||||
}
|
||||
@@ -553,21 +535,24 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
amqpSenderService.sendMessage(message, URI.create(targetAddress));
|
||||
}
|
||||
|
||||
private List<DmfSoftwareModule> convertToAmqpSoftwareModules(
|
||||
final Target target, final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules) {
|
||||
return Optional.ofNullable(softwareModules)
|
||||
.map(Map::entrySet)
|
||||
.map(Set::stream)
|
||||
.map(stream -> stream.map(entry -> convertToAmqpSoftwareModule(target, entry)).toList())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private DmfSoftwareModule convertToAmqpSoftwareModule(
|
||||
final Target target,
|
||||
final Entry<SoftwareModule, List<SoftwareModuleMetadata>> entry) {
|
||||
final DmfSoftwareModule amqpSoftwareModule = new DmfSoftwareModule();
|
||||
amqpSoftwareModule.setModuleId(entry.getKey().getId());
|
||||
amqpSoftwareModule.setModuleType(entry.getKey().getType().getKey());
|
||||
amqpSoftwareModule.setModuleVersion(entry.getKey().getVersion());
|
||||
amqpSoftwareModule.setEncrypted(entry.getKey().isEncrypted() ? Boolean.TRUE : null);
|
||||
amqpSoftwareModule.setArtifacts(convertArtifacts(target, entry.getKey().getArtifacts()));
|
||||
|
||||
if (!CollectionUtils.isEmpty(entry.getValue())) {
|
||||
amqpSoftwareModule.setMetadata(convertMetadata(entry.getValue()));
|
||||
}
|
||||
|
||||
return amqpSoftwareModule;
|
||||
final Target target, final Entry<SoftwareModule, List<SoftwareModuleMetadata>> entry) {
|
||||
return new DmfSoftwareModule(
|
||||
entry.getKey().getId(),
|
||||
entry.getKey().getType().getKey(),
|
||||
entry.getKey().getVersion(),
|
||||
entry.getKey().isEncrypted() ? Boolean.TRUE : null,
|
||||
convertArtifacts(target, entry.getKey().getArtifacts()),
|
||||
CollectionUtils.isEmpty(entry.getValue()) ? null :convertMetadata(entry.getValue()));
|
||||
}
|
||||
|
||||
private List<DmfMetadata> convertMetadata(final List<SoftwareModuleMetadata> metadata) {
|
||||
@@ -584,24 +569,22 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) {
|
||||
final DmfArtifact artifact = new DmfArtifact();
|
||||
|
||||
final TenantMetaData tenantMetadata = systemManagement.getTenantMetadataWithoutDetails();
|
||||
artifact.setUrls(artifactUrlHandler
|
||||
.getUrls(new URLPlaceholder(
|
||||
tenantMetadata.getTenant(), tenantMetadata.getId(), target.getControllerId(), target.getId(),
|
||||
new SoftwareData(
|
||||
localArtifact.getSoftwareModule().getId(), localArtifact.getFilename(), localArtifact.getId(),
|
||||
localArtifact.getSha1Hash())),
|
||||
ApiType.DMF)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef)));
|
||||
|
||||
artifact.setFilename(localArtifact.getFilename());
|
||||
artifact.setHashes(new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()));
|
||||
artifact.setSize(localArtifact.getSize());
|
||||
artifact.setLastModified(localArtifact.getLastModifiedAt());
|
||||
return artifact;
|
||||
return new DmfArtifact(
|
||||
localArtifact.getFilename(),
|
||||
new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()),
|
||||
localArtifact.getSize(),
|
||||
localArtifact.getLastModifiedAt(),
|
||||
artifactUrlHandler
|
||||
.getUrls(new URLPlaceholder(
|
||||
tenantMetadata.getTenant(), tenantMetadata.getId(), target.getControllerId(), target.getId(),
|
||||
new SoftwareData(
|
||||
localArtifact.getSoftwareModule().getId(), localArtifact.getFilename(), localArtifact.getId(),
|
||||
localArtifact.getSha1Hash())),
|
||||
ApiType.DMF)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ArtifactUrl::getProtocol, ArtifactUrl::getRef))
|
||||
);
|
||||
}
|
||||
|
||||
private Map<SoftwareModule, List<SoftwareModuleMetadata>> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) {
|
||||
@@ -622,18 +605,16 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
.map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId()))
|
||||
.toList();
|
||||
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest();
|
||||
batchRequest.setTimestamp(System.currentTimeMillis());
|
||||
batchRequest.addTargets(dmfTargets);
|
||||
|
||||
// due to the fact that all targets in a batch use the same set of
|
||||
// software modules we don't generate
|
||||
// target-specific urls
|
||||
// due to the fact that all targets in a batch use the same set of software modules we don't generate target-specific urls
|
||||
final Target firstTarget = targets.get(0);
|
||||
if (modules != null) {
|
||||
modules.entrySet().forEach(entry ->
|
||||
batchRequest.addSoftwareModule(convertToAmqpSoftwareModule(firstTarget, entry)));
|
||||
}
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest(
|
||||
System.currentTimeMillis(),
|
||||
dmfTargets,
|
||||
Optional.ofNullable(modules)
|
||||
.map(Map::entrySet)
|
||||
.map(Set::stream)
|
||||
.map(stream -> stream.map(entry -> convertToAmqpSoftwareModule(firstTarget, entry)).toList())
|
||||
.orElse(null));
|
||||
|
||||
// we use only the first action when constructing message as Tenant and action type are the same
|
||||
// since all actions have the same trigger
|
||||
|
||||
@@ -454,17 +454,16 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
|
||||
final Action updatedAction;
|
||||
if (actionUpdateStatus.getActionStatus() == DmfActionStatus.CONFIRMED) {
|
||||
updatedAction = confirmationManagement.confirmAction(action.getId(),
|
||||
actionUpdateStatus.getCode().orElse(null), messages);
|
||||
updatedAction = confirmationManagement.confirmAction(action.getId(), actionUpdateStatus.getCode(), messages);
|
||||
} else if (actionUpdateStatus.getActionStatus() == DmfActionStatus.DENIED) {
|
||||
updatedAction = confirmationManagement.denyAction(action.getId(), actionUpdateStatus.getCode().orElse(null), messages);
|
||||
updatedAction = confirmationManagement.denyAction(action.getId(), actionUpdateStatus.getCode(), messages);
|
||||
} else {
|
||||
final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status).messages(messages);
|
||||
actionUpdateStatus.getCode().ifPresent(code -> {
|
||||
Optional.ofNullable(actionUpdateStatus.getCode()).ifPresent(code -> {
|
||||
actionStatus.code(code);
|
||||
actionStatus.message("Device reported status code: " + code);
|
||||
});
|
||||
updatedAction = ((Status.CANCELED == status) || (Status.CANCEL_REJECTED == status))
|
||||
updatedAction = Status.CANCELED == status || Status.CANCEL_REJECTED == status
|
||||
? controllerManagement.addCancelActionStatus(actionStatus)
|
||||
: controllerManagement.addUpdateActionStatus(actionStatus);
|
||||
}
|
||||
|
||||
@@ -174,8 +174,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setName(knownThingName);
|
||||
final DmfCreateThing payload = new DmfCreateThing(knownThingName, null, null);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -190,8 +189,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingTypeName = "TargetTypeName";
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setType(knownThingTypeName);
|
||||
final DmfCreateThing payload = new DmfCreateThing(null, knownThingTypeName, null);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -215,12 +213,9 @@ class AmqpMessageHandlerServiceTest {
|
||||
void createThingWithAttributes() {
|
||||
final String knownThingId = "4";
|
||||
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
final DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
final DmfCreateThing payload = new DmfCreateThing(null, null, attributeUpdate);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -235,14 +230,9 @@ class AmqpMessageHandlerServiceTest {
|
||||
final String knownThingId = "5";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
attributeUpdate.setMode(DmfUpdateMode.REPLACE);
|
||||
|
||||
final DmfCreateThing payload = new DmfCreateThing();
|
||||
payload.setName(knownThingName);
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate(
|
||||
Map.of("testKey1", "testValue1", "testKey2", "testValue2"), DmfUpdateMode.REPLACE);
|
||||
final DmfCreateThing payload = new DmfCreateThing(knownThingName, null, attributeUpdate);
|
||||
|
||||
processThingCreatedMessage(knownThingId, payload);
|
||||
|
||||
@@ -259,9 +249,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
final DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
final Message message = createMessage(attributeUpdate, messageProperties);
|
||||
|
||||
@@ -281,9 +269,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_ATTRIBUTES");
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().put("testKey1", "testValue1");
|
||||
attributeUpdate.getAttributes().put("testKey2", "testValue2");
|
||||
DmfAttributeUpdate attributeUpdate = dmfAttributeUpdate();
|
||||
|
||||
when(controllerManagementMock.updateControllerAttributes(targetIdCaptor.capture(), attributesCaptor.capture(),
|
||||
modeCaptor.capture())).thenReturn(null);
|
||||
@@ -296,27 +282,36 @@ class AmqpMessageHandlerServiceTest {
|
||||
assertThingAttributesModeCapturedField(null);
|
||||
|
||||
// send a message which specifies update mode MERGE
|
||||
attributeUpdate.setMode(DmfUpdateMode.MERGE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.MERGE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.MERGE);
|
||||
|
||||
// send a message which specifies update mode REPLACE
|
||||
attributeUpdate.setMode(DmfUpdateMode.REPLACE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.REPLACE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.REPLACE);
|
||||
|
||||
// send a message which specifies update mode REMOVE
|
||||
attributeUpdate.setMode(DmfUpdateMode.REMOVE);
|
||||
attributeUpdate = dmfAttributeUpdate(DmfUpdateMode.REMOVE);
|
||||
message = createMessage(attributeUpdate, messageProperties);
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
// verify that the update mode is converted and forwarded as expected
|
||||
assertThingAttributesModeCapturedField(UpdateMode.REMOVE);
|
||||
}
|
||||
|
||||
private static DmfAttributeUpdate dmfAttributeUpdate() {
|
||||
return dmfAttributeUpdate(null);
|
||||
}
|
||||
|
||||
private static DmfAttributeUpdate dmfAttributeUpdate(final DmfUpdateMode mode) {
|
||||
return new DmfAttributeUpdate(
|
||||
Map.of("testKey1", "testValue1", "testKey2", "testValue2"), mode);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a thing without a 'reply to' header in message.")
|
||||
void createThingWithoutReplyTo() {
|
||||
@@ -470,7 +465,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
@Test
|
||||
@Description("Test feedback code is persisted in messages when provided with DmfActionUpdateStatus")
|
||||
void feedBackCodeIsPersistedInMessages() throws IllegalAccessException {
|
||||
|
||||
// Mock
|
||||
final Action action = createActionWithTarget(22L);
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
@@ -483,23 +477,22 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
|
||||
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(23L, DmfActionStatus.RUNNING);
|
||||
actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2));
|
||||
actionUpdateStatus.setCode(12);
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(
|
||||
23L, DmfActionStatus.RUNNING, null, 2L, null, 12);
|
||||
|
||||
final Message message = createMessage(actionUpdateStatus, messageProperties);
|
||||
|
||||
// test
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
|
||||
final ArgumentCaptor<ActionStatusCreate> actionPropertiesCaptor = ArgumentCaptor
|
||||
.forClass(ActionStatusCreate.class);
|
||||
final ArgumentCaptor<ActionStatusCreate> actionPropertiesCaptor = ArgumentCaptor.forClass(ActionStatusCreate.class);
|
||||
|
||||
verify(controllerManagementMock, times(1)).addUpdateActionStatus(actionPropertiesCaptor.capture());
|
||||
|
||||
final JpaActionStatus jpaActionStatus = (JpaActionStatus) actionPropertiesCaptor.getValue().build();
|
||||
assertThat(jpaActionStatus.getCode()).as("Action status for reported code is missing").contains(12);
|
||||
assertThat(jpaActionStatus.getMessages()).as("Action status message for reported code is missing")
|
||||
assertThat(jpaActionStatus.getMessages())
|
||||
.as("Action status message for reported code is missing")
|
||||
.contains("Device reported status code: 12");
|
||||
}
|
||||
|
||||
@@ -542,10 +535,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_AUTO_CONFIRM");
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation();
|
||||
autoConfirmation.setEnabled(true);
|
||||
autoConfirmation.setInitiator(initiator);
|
||||
autoConfirmation.setRemark(remark);
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation(true, initiator, remark);
|
||||
|
||||
final Message message = createMessage(autoConfirmation, messageProperties);
|
||||
|
||||
@@ -569,7 +559,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "UPDATE_AUTO_CONFIRM");
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation();
|
||||
final DmfAutoConfirmation autoConfirmation = new DmfAutoConfirmation(false, null, null);
|
||||
|
||||
final Message message = createMessage(autoConfirmation, messageProperties);
|
||||
|
||||
@@ -649,9 +639,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
}
|
||||
|
||||
private DmfActionUpdateStatus createActionUpdateStatus(final DmfActionStatus status, final Long id) {
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(id, status);
|
||||
actionUpdateStatus.setSoftwareModuleId(Long.valueOf(2));
|
||||
return actionUpdateStatus;
|
||||
return new DmfActionUpdateStatus(id, status, null, 2L, null, null);
|
||||
}
|
||||
|
||||
private MessageProperties createMessageProperties(final MessageType type) {
|
||||
|
||||
@@ -13,6 +13,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
@@ -100,12 +102,7 @@ class BaseAmqpServiceTest {
|
||||
}
|
||||
|
||||
private DmfActionUpdateStatus createActionStatus() {
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING);
|
||||
actionUpdateStatus.setCode(2);
|
||||
actionUpdateStatus.setSoftwareModuleId(2L);
|
||||
actionUpdateStatus.addMessage("Message 1");
|
||||
actionUpdateStatus.addMessage("Message 2");
|
||||
return actionUpdateStatus;
|
||||
return new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING, null, 2L, List.of("Message 1", "Message 2"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -306,14 +306,9 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
DmfCreateThing payload = null;
|
||||
if (!StringUtils.isEmpty(name) || !CollectionUtils.isEmpty(attributes)) {
|
||||
payload = new DmfCreateThing();
|
||||
payload.setName(name);
|
||||
|
||||
if (!CollectionUtils.isEmpty(attributes)) {
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
attributeUpdate.getAttributes().putAll(attributes);
|
||||
payload.setAttributeUpdate(attributeUpdate);
|
||||
}
|
||||
payload = new DmfCreateThing(
|
||||
name, null,
|
||||
CollectionUtils.isEmpty(attributes) ? null : new DmfAttributeUpdate(attributes, null));
|
||||
}
|
||||
|
||||
return createMessage(payload, messageProperties);
|
||||
@@ -330,7 +325,8 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
protected void createAndSendActionStatusUpdateMessage(final String target, final long actionId,
|
||||
final DmfActionStatus status) {
|
||||
final DmfActionUpdateStatus dmfActionUpdateStatus = new DmfActionUpdateStatus(actionId, status, System.currentTimeMillis());
|
||||
final DmfActionUpdateStatus dmfActionUpdateStatus = new DmfActionUpdateStatus(
|
||||
actionId, status, System.currentTimeMillis(), null, null, null);
|
||||
|
||||
final Message eventMessage = createUpdateActionEventMessage(dmfActionUpdateStatus);
|
||||
eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.THING_ID, target);
|
||||
|
||||
@@ -729,9 +729,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
|
||||
// setup
|
||||
registerAndAssertTargetWithExistingTenant(controllerId);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put("test1", "testA");
|
||||
controllerAttribute.getAttributes().put("test2", "testB");
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate(
|
||||
Map.of("test1", "testA", "test2", "testB"), null);
|
||||
final Message createUpdateAttributesMessage = createUpdateAttributesMessage(null, TENANT_EXIST,
|
||||
controllerAttribute);
|
||||
createUpdateAttributesMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID);
|
||||
@@ -741,7 +740,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
|
||||
// verify
|
||||
verifyOneDeadLetterMessage();
|
||||
final DmfAttributeUpdate controllerAttributeEmpty = new DmfAttributeUpdate();
|
||||
final DmfAttributeUpdate controllerAttributeEmpty = new DmfAttributeUpdate(null, null);
|
||||
assertUpdateAttributes(controllerId, controllerAttributeEmpty.getAttributes());
|
||||
}
|
||||
|
||||
@@ -754,11 +753,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
void updateAttributesWithWrongBody() {
|
||||
// setup
|
||||
registerAndAssertTargetWithExistingTenant(UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put("test1", "testA");
|
||||
controllerAttribute.getAttributes().put("test2", "testB");
|
||||
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(
|
||||
UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody( UPDATE_ATTR_TEST_CONTROLLER_ID);
|
||||
|
||||
// test
|
||||
getDmfClient().send(createUpdateAttributesMessageWrongBody);
|
||||
@@ -1051,9 +1046,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
removeAttributes.put("k1", "foo");
|
||||
removeAttributes.put("k3", "bar");
|
||||
|
||||
final DmfAttributeUpdate remove = new DmfAttributeUpdate();
|
||||
remove.setMode(DmfUpdateMode.REMOVE);
|
||||
remove.getAttributes().putAll(removeAttributes);
|
||||
final DmfAttributeUpdate remove = new DmfAttributeUpdate(removeAttributes, DmfUpdateMode.REMOVE);
|
||||
sendUpdateAttributeMessage(remove);
|
||||
|
||||
// validate
|
||||
@@ -1071,9 +1064,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
mergeAttributes.put("k1", "v1_modified_again");
|
||||
mergeAttributes.put("k4", "v4");
|
||||
|
||||
final DmfAttributeUpdate merge = new DmfAttributeUpdate();
|
||||
merge.setMode(DmfUpdateMode.MERGE);
|
||||
merge.getAttributes().putAll(mergeAttributes);
|
||||
final DmfAttributeUpdate merge = new DmfAttributeUpdate(mergeAttributes, DmfUpdateMode.MERGE);
|
||||
sendUpdateAttributeMessage(merge);
|
||||
|
||||
// validate
|
||||
@@ -1091,9 +1082,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
expectedAttributes.put("k2", "v2");
|
||||
expectedAttributes.put("k3", "v3");
|
||||
|
||||
final DmfAttributeUpdate replace = new DmfAttributeUpdate();
|
||||
replace.setMode(DmfUpdateMode.REPLACE);
|
||||
replace.getAttributes().putAll(expectedAttributes);
|
||||
final DmfAttributeUpdate replace = new DmfAttributeUpdate(expectedAttributes, DmfUpdateMode.REPLACE);
|
||||
sendUpdateAttributeMessage(replace);
|
||||
|
||||
// validate
|
||||
@@ -1107,8 +1096,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
expectedAttributes.put("k0", "v0");
|
||||
expectedAttributes.put("k1", "v1");
|
||||
|
||||
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate();
|
||||
defaultUpdate.getAttributes().putAll(expectedAttributes);
|
||||
final DmfAttributeUpdate defaultUpdate = new DmfAttributeUpdate(expectedAttributes, null);
|
||||
sendUpdateAttributeMessage(defaultUpdate);
|
||||
|
||||
// validate
|
||||
@@ -1135,10 +1123,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
}
|
||||
|
||||
private void sendUpdateAttributesMessageWithGivenAttributes(final String key, final String value) {
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate();
|
||||
controllerAttribute.getAttributes().put(key, value);
|
||||
final Message message = createUpdateAttributesMessage(UPDATE_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST,
|
||||
controllerAttribute);
|
||||
final DmfAttributeUpdate controllerAttribute = new DmfAttributeUpdate(Map.of(key, value), null);
|
||||
final Message message = createUpdateAttributesMessage(UPDATE_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST, controllerAttribute);
|
||||
getDmfClient().send(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -23,6 +24,10 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfActionRequest {
|
||||
|
||||
@JsonProperty
|
||||
private Long actionId;
|
||||
private final Long actionId;
|
||||
|
||||
@JsonCreator
|
||||
public DmfActionRequest(@JsonProperty("actionId") final Long actionId) {
|
||||
this.actionId = actionId;
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* JSON representation of action update status.
|
||||
@@ -35,31 +30,28 @@ public class DmfActionUpdateStatus {
|
||||
private final Long actionId;
|
||||
private final DmfActionStatus actionStatus;
|
||||
private final long timestamp;
|
||||
private final Long softwareModuleId;
|
||||
private final List<String> message;
|
||||
private final Integer code;
|
||||
|
||||
@JsonProperty
|
||||
private Long softwareModuleId;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@JsonProperty
|
||||
private List<String> message;
|
||||
|
||||
@JsonProperty
|
||||
private Integer code;
|
||||
|
||||
public DmfActionUpdateStatus(@JsonProperty(value = "actionId", required = true) final Long actionId,
|
||||
@JsonProperty(value = "actionStatus", required = true) final DmfActionStatus actionStatus, @JsonProperty(value = "timestamp") final Long timestamp) {
|
||||
@JsonCreator
|
||||
public DmfActionUpdateStatus(
|
||||
@JsonProperty(value = "actionId", required = true) final Long actionId,
|
||||
@JsonProperty(value = "actionStatus", required = true) final DmfActionStatus actionStatus,
|
||||
@JsonProperty(value = "timestamp") final Long timestamp,
|
||||
@JsonProperty("softwareModuleId") final Long softwareModuleId,
|
||||
@JsonProperty("message") final List<String> message,
|
||||
@JsonProperty("code") final Integer code) {
|
||||
this.actionId = actionId;
|
||||
this.actionStatus = actionStatus;
|
||||
this.timestamp = timestamp != null ? timestamp : System.currentTimeMillis();
|
||||
this.softwareModuleId = softwareModuleId;
|
||||
this.message = message;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DmfActionUpdateStatus(final Long actionId, final DmfActionStatus actionStatus) {
|
||||
this(actionId, actionStatus, null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Optional<Integer> getCode() {
|
||||
return Optional.ofNullable(code);
|
||||
this(actionId, actionStatus, null, null, null, 0);
|
||||
}
|
||||
|
||||
public List<String> getMessage() {
|
||||
@@ -69,25 +61,4 @@ public class DmfActionUpdateStatus {
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean addMessage(final String message) {
|
||||
if (this.message == null) {
|
||||
this.message = new ArrayList<>();
|
||||
}
|
||||
|
||||
return this.message.add(message);
|
||||
}
|
||||
|
||||
public boolean addMessage(final Collection<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (message == null) {
|
||||
message = new ArrayList<>(messages);
|
||||
return true;
|
||||
}
|
||||
|
||||
return message.addAll(messages);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.dmf.json.model;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -26,22 +27,23 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfArtifact {
|
||||
|
||||
@JsonProperty
|
||||
private String filename;
|
||||
@JsonProperty
|
||||
private DmfArtifactHash hashes;
|
||||
@JsonProperty
|
||||
private long size;
|
||||
@JsonProperty
|
||||
private long lastModified;
|
||||
@JsonProperty
|
||||
private Map<String, String> urls;
|
||||
private final String filename;
|
||||
private final DmfArtifactHash hashes;
|
||||
private final long size;
|
||||
private final long lastModified;
|
||||
private final Map<String, String> urls;
|
||||
|
||||
public Map<String, String> getUrls() {
|
||||
if (urls == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableMap(urls);
|
||||
@JsonCreator
|
||||
public DmfArtifact(
|
||||
@JsonProperty("filename") final String filename,
|
||||
@JsonProperty("hashes") final DmfArtifactHash hashes,
|
||||
@JsonProperty("size") final long size,
|
||||
@JsonProperty("lastModified") final long lastModified,
|
||||
@JsonProperty("urls") final Map<String, String> urls) {
|
||||
this.filename = filename;
|
||||
this.hashes = hashes;
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
this.urls = urls == null ? Collections.emptyMap() : Collections.unmodifiableMap(urls);
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,8 @@ import lombok.Data;
|
||||
@Data
|
||||
public class DmfArtifactHash {
|
||||
|
||||
@JsonProperty
|
||||
private String sha1;
|
||||
@JsonProperty
|
||||
private String md5;
|
||||
private final String sha1;
|
||||
private final String md5;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -26,9 +27,14 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfAttributeUpdate {
|
||||
|
||||
@JsonProperty
|
||||
private final Map<String, String> attributes = new HashMap<>();
|
||||
private final Map<String, String> attributes;
|
||||
private final DmfUpdateMode mode;
|
||||
|
||||
@JsonProperty
|
||||
private DmfUpdateMode mode;
|
||||
@JsonCreator
|
||||
public DmfAttributeUpdate(
|
||||
@JsonProperty("attributes") final Map<String, String> attributes,
|
||||
@JsonProperty("mode") final DmfUpdateMode mode) {
|
||||
this.attributes = attributes == null ? Collections.emptyMap() : attributes;
|
||||
this.mode = mode;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -23,10 +24,17 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfAutoConfirmation {
|
||||
|
||||
@JsonProperty
|
||||
private boolean enabled;
|
||||
@JsonProperty
|
||||
private String initiator;
|
||||
@JsonProperty
|
||||
private String remark;
|
||||
private final boolean enabled;
|
||||
private final String initiator;
|
||||
private final String remark;
|
||||
|
||||
@JsonCreator
|
||||
public DmfAutoConfirmation(
|
||||
@JsonProperty("enabled") final boolean enabled,
|
||||
@JsonProperty("initiator") final String initiator,
|
||||
@JsonProperty("remark") final String remark) {
|
||||
this.enabled = enabled;
|
||||
this.initiator = initiator;
|
||||
this.remark = remark;
|
||||
}
|
||||
}
|
||||
@@ -17,78 +17,28 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* JSON representation of batch download and update request.
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfBatchDownloadAndUpdateRequest {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonProperty
|
||||
private Long timestamp;
|
||||
private final Long timestamp;
|
||||
private final List<DmfTarget> targets;
|
||||
private final List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
@JsonProperty
|
||||
private List<DmfTarget> targets;
|
||||
|
||||
@JsonProperty
|
||||
private List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
public List<DmfSoftwareModule> getSoftwareModules() {
|
||||
if (softwareModules == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Software module.
|
||||
*
|
||||
* @param createSoftwareModule the module
|
||||
*/
|
||||
public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
|
||||
if (softwareModules == null) {
|
||||
softwareModules = new ArrayList<>();
|
||||
}
|
||||
|
||||
softwareModules.add(createSoftwareModule);
|
||||
}
|
||||
|
||||
public List<DmfTarget> getTargets() {
|
||||
if (targets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Target.
|
||||
*
|
||||
* @param target the target
|
||||
*/
|
||||
public void addTarget(final DmfTarget target) {
|
||||
if (targets == null) {
|
||||
targets = new ArrayList<>();
|
||||
}
|
||||
|
||||
targets.add(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple Targets.
|
||||
*
|
||||
* @param targets the target
|
||||
*/
|
||||
public void addTargets(final List<DmfTarget> targets) {
|
||||
if (this.targets == null) {
|
||||
this.targets = new ArrayList<>();
|
||||
}
|
||||
this.targets.addAll(targets);
|
||||
public DmfBatchDownloadAndUpdateRequest(
|
||||
@JsonProperty("timestamp") final Long timestamp,
|
||||
@JsonProperty("targets") final List<DmfTarget> targets,
|
||||
@JsonProperty("softwareModules") final List<DmfSoftwareModule> softwareModules) {
|
||||
this.timestamp = timestamp;
|
||||
this.targets = targets == null ? Collections.emptyList() : targets;
|
||||
this.softwareModules = softwareModules == null ? Collections.emptyList() : Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
}
|
||||
@@ -9,33 +9,41 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* JSON representation of confirm request.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfConfirmRequest extends DmfActionRequest {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonProperty
|
||||
private String targetSecurityToken;
|
||||
private final String targetSecurityToken;
|
||||
private final List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
@JsonProperty
|
||||
private List<DmfSoftwareModule> softwareModules;
|
||||
@JsonCreator
|
||||
public DmfConfirmRequest(
|
||||
@JsonProperty("actionId") final Long actionId,
|
||||
@JsonProperty("targetSecurityToken") final String targetSecurityToken,
|
||||
@JsonProperty("softwareModules") final List<DmfSoftwareModule> softwareModules) {
|
||||
super(actionId);
|
||||
this.targetSecurityToken = targetSecurityToken;
|
||||
this.softwareModules = softwareModules;
|
||||
}
|
||||
|
||||
public List<DmfSoftwareModule> getSoftwareModules() {
|
||||
if (softwareModules == null) {
|
||||
@@ -44,18 +52,4 @@ public class DmfConfirmRequest extends DmfActionRequest {
|
||||
|
||||
return Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Software module.
|
||||
*
|
||||
* @param createSoftwareModule the module
|
||||
*/
|
||||
public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
|
||||
if (softwareModules == null) {
|
||||
softwareModules = new ArrayList<>();
|
||||
}
|
||||
|
||||
softwareModules.add(createSoftwareModule);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -23,12 +24,17 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfCreateThing {
|
||||
|
||||
@JsonProperty
|
||||
private String name;
|
||||
private final String name;
|
||||
private final String type;
|
||||
private final DmfAttributeUpdate attributeUpdate;
|
||||
|
||||
@JsonProperty
|
||||
private String type;
|
||||
|
||||
@JsonProperty
|
||||
private DmfAttributeUpdate attributeUpdate;
|
||||
@JsonCreator
|
||||
public DmfCreateThing(
|
||||
@JsonProperty("name") final String name,
|
||||
@JsonProperty("type") final String type,
|
||||
@JsonProperty("attributeUpdate") final DmfAttributeUpdate attributeUpdate) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.attributeUpdate = attributeUpdate;
|
||||
}
|
||||
}
|
||||
@@ -13,43 +13,35 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* JSON representation of download and update request.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@JsonProperty
|
||||
private String targetSecurityToken;
|
||||
private final String targetSecurityToken;
|
||||
private final List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
@JsonProperty
|
||||
private List<DmfSoftwareModule> softwareModules;
|
||||
|
||||
public List<DmfSoftwareModule> getSoftwareModules() {
|
||||
if (softwareModules == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
|
||||
public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
|
||||
if (softwareModules == null) {
|
||||
softwareModules = new ArrayList<>();
|
||||
}
|
||||
|
||||
softwareModules.add(createSoftwareModule);
|
||||
@JsonCreator
|
||||
public DmfDownloadAndUpdateRequest(
|
||||
@JsonProperty("actionId") final Long actionId,
|
||||
@JsonProperty("targetSecurityToken") final String targetSecurityToken,
|
||||
@JsonProperty("softwareModules") final List<DmfSoftwareModule> softwareModules) {
|
||||
super(actionId);
|
||||
this.targetSecurityToken = targetSecurityToken;
|
||||
this.softwareModules = softwareModules == null ? Collections.emptyList() : Collections.unmodifiableList(softwareModules);
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,7 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfMetadata {
|
||||
|
||||
@JsonProperty
|
||||
private final String key;
|
||||
|
||||
@JsonProperty
|
||||
private final String value;
|
||||
|
||||
@JsonCreator
|
||||
|
||||
@@ -22,18 +22,16 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
||||
|
||||
/**
|
||||
* JSON representation of a multi-action request.
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfMultiActionRequest {
|
||||
|
||||
private List<DmfMultiActionElement> elements;
|
||||
private final List<DmfMultiActionElement> elements;
|
||||
|
||||
@JsonCreator
|
||||
public DmfMultiActionRequest(final List<DmfMultiActionElement> elements) {
|
||||
@@ -45,41 +43,28 @@ public class DmfMultiActionRequest {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void addElement(final DmfMultiActionElement element) {
|
||||
if (elements == null) {
|
||||
elements = new ArrayList<>();
|
||||
}
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
public void addElement(final EventTopic topic, final DmfActionRequest action, final int weight) {
|
||||
final DmfMultiActionElement element = new DmfMultiActionElement();
|
||||
element.setTopic(topic);
|
||||
element.setAction(action);
|
||||
element.setWeight(weight);
|
||||
addElement(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an element within a {@link DmfMultiActionRequest}.
|
||||
*/
|
||||
@Data
|
||||
public static class DmfMultiActionElement {
|
||||
|
||||
@JsonProperty
|
||||
private EventTopic topic;
|
||||
private final EventTopic topic;
|
||||
private final DmfActionRequest action;
|
||||
private final int weight;
|
||||
|
||||
@JsonProperty
|
||||
private DmfActionRequest action;
|
||||
|
||||
@JsonProperty
|
||||
private int weight;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "topic", defaultImpl = DmfActionRequest.class)
|
||||
@JsonSubTypes({ @Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD"),
|
||||
@Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD_AND_INSTALL") })
|
||||
public void setAction(final DmfActionRequest action) {
|
||||
@JsonCreator
|
||||
public DmfMultiActionElement(
|
||||
@JsonProperty("topic") final EventTopic topic,
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "topic", defaultImpl = DmfActionRequest.class)
|
||||
@JsonSubTypes({
|
||||
@Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD"),
|
||||
@Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD_AND_INSTALL") })
|
||||
@JsonProperty("action") final DmfActionRequest action,
|
||||
@JsonProperty("weight") final int weight) {
|
||||
this.topic = topic;
|
||||
this.action = action;
|
||||
this.weight = weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.dmf.json.model;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -26,30 +27,26 @@ import lombok.Data;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfSoftwareModule {
|
||||
|
||||
@JsonProperty
|
||||
private Long moduleId;
|
||||
@JsonProperty
|
||||
private String moduleType;
|
||||
@JsonProperty
|
||||
private String moduleVersion;
|
||||
@JsonProperty
|
||||
private Boolean encrypted;
|
||||
@JsonProperty
|
||||
private List<DmfArtifact> artifacts;
|
||||
@JsonProperty
|
||||
private List<DmfMetadata> metadata;
|
||||
private final Long moduleId;
|
||||
private final String moduleType;
|
||||
private final String moduleVersion;
|
||||
private final Boolean encrypted;
|
||||
private final List<DmfArtifact> artifacts;
|
||||
private final List<DmfMetadata> metadata;
|
||||
|
||||
public List<DmfArtifact> getArtifacts() {
|
||||
if (artifacts == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(artifacts);
|
||||
}
|
||||
|
||||
public void setMetadata(final List<DmfMetadata> metadata) {
|
||||
if (metadata != null && !metadata.isEmpty()) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
@JsonCreator
|
||||
public DmfSoftwareModule(
|
||||
@JsonProperty("moduleId") final Long moduleId,
|
||||
@JsonProperty("moduleType") final String moduleType,
|
||||
@JsonProperty("moduleVersion") final String moduleVersion,
|
||||
@JsonProperty("encrypted") final Boolean encrypted,
|
||||
@JsonProperty("artifacts") final List<DmfArtifact> artifacts,
|
||||
@JsonProperty("metadata") final List<DmfMetadata> metadata) {
|
||||
this.moduleId = moduleId;
|
||||
this.moduleType = moduleType;
|
||||
this.moduleVersion = moduleVersion;
|
||||
this.encrypted = encrypted;
|
||||
this.artifacts = artifacts == null ? Collections.emptyList() : Collections.unmodifiableList(artifacts);
|
||||
this.metadata = metadata == null || metadata.isEmpty() ? null : metadata;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.dmf.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -24,11 +25,18 @@ import lombok.ToString;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DmfTarget {
|
||||
|
||||
@JsonProperty
|
||||
private Long actionId;
|
||||
@JsonProperty
|
||||
private String controllerId;
|
||||
private final Long actionId;
|
||||
private final String controllerId;
|
||||
@ToString.Exclude
|
||||
@JsonProperty
|
||||
private String targetSecurityToken;
|
||||
private final String targetSecurityToken;
|
||||
|
||||
@JsonCreator
|
||||
public DmfTarget(
|
||||
@JsonProperty("actionId") final Long actionId,
|
||||
@JsonProperty("controllerId") final String controllerId,
|
||||
@JsonProperty("targetSecurityToken") final String targetSecurityToken) {
|
||||
this.actionId = actionId;
|
||||
this.controllerId = controllerId;
|
||||
this.targetSecurityToken = targetSecurityToken;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user