Know How: integrating access control service

Context

This example describes the case in which we want to retrieve all the tickets, “white” (valid) and “black” (invalid) in order to fuel a local access control system.
We suppose we want to retrieve the tickets for an oncoming event, a mega-concert in a stadium hosting more than 50 000 guests.
The example code below is written in Java. Topics about security or implementing a SOAP client in java are left aside.

Retreiving the tickets

    private List<AccessControlListItem> retrieveTickets() throws Exception {
        ExternalAccessControlService service =
            getSoapServiceProxy(ExternalAccessControlService.class);
        String seasonCode = "Saison1";
        // This season code is provided by the SecuTix tenant.
        List<String> productList = Collections.singletonList("OD14");
        // The list of the codes of the products is provided by the Secutix tenant.

        String pagination = null;
        // This string stores a server provided value to allow pagination.
        // If passed to null, all the tickets are sent again.
        long batchSize = 1000;
        // The tickets will be retrieved 1000 by 1000

        List<AccessControlListItem> allTickets = Lists.newArrayList();
        // An array to store the tickets that we
        // retrieve.

        AccessControlListResult res =
            service.exportList(null, ListType.GREY, TicketType.ALL,
                seasonCode, productList, pagination, batchSize);
        // GREY : means the list of tickets retrieved contains valid and invalid tickets.
        // Order matters !
        if (!res.getStatusCode().equals("success")) {
            throw new Exception("Something wrong happened :" + res.getStatusCode() + "/" + res.getStatusDetail());
        }
        List<AccessControlListItem> itemsRetrieved =
            res.getAccessControlListData().getAccessControlListItems();
        allTickets.addAll(itemsRetrieved);
        while (itemsRetrieved.size() == batchSize) {
            pagination = res.getAccessControlListData().getPaginationEnd();
            res =
                service.exportList(null, ListType.GREY, TicketType.ALL,
                    seasonCode, productList, pagination,
                    batchSize);
            if (!res.getStatusCode().equals("success")) {
                throw new Exception("Something wrong happened :" +
                    res.getStatusCode() + "/" + res.getStatusDetail());
            }
            itemsRetrieved = res.getAccessControlListData().getAccessControlListItems();
            allTickets.addAll(itemsRetrieved);
        }
        System.out.println("All the tickets retrieved : " + allTickets);
        return allTickets;
    }

Marking the tickets as controlled

    private void markTicketsAsControlled(List<AccessControlListItem> ticketsToControl) throws Exception {
        ExternalAccessControlService service = getSoapServiceProxy(ExternalAccessControlService.class);
        List<ControlledTicket> controlledTickets = new ArrayList<ControlledTicket>();
        Date controlDate = new Date();
        String acIdentifier = "Control a the gates " + controlDate;
        // Free text to identify a unique session of control.
        String deviceCode = "Turnstyle nb B17a";
        String gateCode = "Gate B17";
        for (AccessControlListItem accessControlListItem : ticketsToControl) {
            ControlledTicket controlled = new ControlledTicket();

            controlled.setAcIdentifier(acIdentifier);
            controlled.setBarcode(accessControlListItem.getBarcode());

            controlled.setControlDate(controlDate);
            controlled.setControlResult(ControlResultEnum.OK);

            controlled.setDeviceCode(deviceCode);

            controlled.setGateCode(gateCode);

            controlledTickets.add(controlled);

        }

        WebMethodResult res = service.importControlledTicket(null, controlledTickets);
        if (!res.getStatusCode().equals("success")) {
            throw new Exception("Something wrong happened :" +
                res.getStatusCode() + "/" + res.getStatusDetail());
        }
    }