use of eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollRequestType in project UVMS-Docker by UnionVMS.
the class MobileTerminalTestHelper method createPoll_Helper.
public static Map<String, Object> createPoll_Helper(Asset testAsset) throws Exception {
MobileTerminalType createdMobileTerminalType = createMobileTerminalType();
{
MobileTerminalAssignQuery mobileTerminalAssignQuery = new MobileTerminalAssignQuery();
mobileTerminalAssignQuery.setMobileTerminalId(createdMobileTerminalType.getMobileTerminalId());
mobileTerminalAssignQuery.setConnectId(testAsset.getAssetId().getGuid());
// Assign first
final HttpResponse response = Request.Post(getBaseUrl() + "mobileterminal/rest/mobileterminal/assign?comment=comment").setHeader("Content-Type", "application/json").setHeader("Authorization", getValidJwtToken()).bodyByteArray(writeValueAsString(mobileTerminalAssignQuery).getBytes()).execute().returnResponse();
Map<String, Object> dataMap = checkSuccessResponseReturnMap(response);
}
String comChannelId = createdMobileTerminalType.getChannels().get(0).getGuid();
PollRequestType pollRequestType = new PollRequestType();
pollRequestType.setPollType(PollType.PROGRAM_POLL);
pollRequestType.setUserName("vms_admin_com");
pollRequestType.setComment("Manual poll created by test");
PollMobileTerminal pollMobileTerminal = new PollMobileTerminal();
pollMobileTerminal.setComChannelId(comChannelId);
pollMobileTerminal.setConnectId(testAsset.getAssetId().getGuid());
pollMobileTerminal.setMobileTerminalId(createdMobileTerminalType.getMobileTerminalId().getGuid());
List<MobileTerminalAttribute> mobileTerminalAttributes = createdMobileTerminalType.getAttributes();
List<PollAttribute> pollAttributes = pollRequestType.getAttributes();
for (MobileTerminalAttribute mobileTerminalAttribute : mobileTerminalAttributes) {
String type = mobileTerminalAttribute.getType();
String value = mobileTerminalAttribute.getValue();
PollAttribute pollAttribute = new PollAttribute();
try {
PollAttributeType pollAttributeType = PollAttributeType.valueOf(type);
pollAttribute.setKey(pollAttributeType);
pollAttribute.setValue(value);
pollAttributes.add(pollAttribute);
} catch (RuntimeException rte) {
// ignore
}
}
PollAttribute frequency = new PollAttribute();
PollAttribute startDate = new PollAttribute();
PollAttribute endDate = new PollAttribute();
pollAttributes.add(frequency);
frequency.setKey(PollAttributeType.FREQUENCY);
frequency.setValue("1000");
pollAttributes.add(startDate);
startDate.setKey(PollAttributeType.START_DATE);
startDate.setValue(getDateAsString(2001, Calendar.JANUARY, 7, 1, 7, 23, 45));
pollAttributes.add(endDate);
endDate.setKey(PollAttributeType.END_DATE);
endDate.setValue(getDateAsString(2027, Calendar.DECEMBER, 24, 11, 45, 7, 980));
pollRequestType.getMobileTerminals().add(pollMobileTerminal);
final HttpResponse response = Request.Post(getBaseUrl() + "mobileterminal/rest/poll").setHeader("Content-Type", "application/json").setHeader("Authorization", getValidJwtToken()).bodyByteArray(writeValueAsString(pollRequestType).getBytes()).execute().returnResponse();
Map<String, Object> dataMap = checkSuccessResponseReturnMap(response);
return dataMap;
}
Aggregations