Search in sources :

Example 1 with PollAttribute

use of eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollAttribute 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;
}
Also used : PollRequestType(eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollRequestType) PollAttributeType(eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollAttributeType) PollMobileTerminal(eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollMobileTerminal) HttpResponse(org.apache.http.HttpResponse) MobileTerminalAssignQuery(eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalAssignQuery) PollAttribute(eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollAttribute) MobileTerminalAttribute(eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalAttribute) MobileTerminalType(eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalType) Map(java.util.Map)

Aggregations

PollAttribute (eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollAttribute)1 PollAttributeType (eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollAttributeType)1 PollMobileTerminal (eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollMobileTerminal)1 PollRequestType (eu.europa.ec.fisheries.schema.mobileterminal.polltypes.v1.PollRequestType)1 MobileTerminalAssignQuery (eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalAssignQuery)1 MobileTerminalAttribute (eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalAttribute)1 MobileTerminalType (eu.europa.ec.fisheries.schema.mobileterminal.types.v1.MobileTerminalType)1 Map (java.util.Map)1 HttpResponse (org.apache.http.HttpResponse)1