Optimize your device reservation

It may happen that a device gets reserved, but then the user who reserved it uses a free device instead. This, effectively, blocks two devices: the reserved one and the one the reserving user is actually using. The following simple class helps you deal with this problem. You only need to put it in a deployment tool like Jenkins. This will trigger it in cycles to clear the unused reservations every hour, two hours, and so on (as per your configuration).

The PerfectoReservationOptimizer.jar you need to add to your project is available here. Following is the simple code you need to run in java to delete the unused reservations. The startTime/endTime should be in milliseconds from midnight, January 1, 1970 ( Epoch/Unix Time).

Copy
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.json.simple.parser.ParseException;
import org.xml.sax.SAXException;

import com.perfecto.reservation.PerfectoReservationActivity;

public class DeleteDeviceReservation {
    
    static String cloudName = "partners.perfectomobile.com";

    static String securityToken = "iA6ICJLc1BUWU1zZHBSZ21LXzk4OGZwaUx6cWsxdWpZMnduZG5SQU50ejgyVHBNIn0.eyJqdGkiOiIxNTRiMjI3My1hOGE0LTQ1YzItYjNjOS0wYTcxNjUzZjI3NzYiLCJleHAiOjAsIm5iZiI6MCwiaWF0IjoxNTc1NjE1NjE0LCJpc3MiOiJodHRwczovL2F1dGgucGVyZmVjdG9tb2JpbGUuY29tL2F1dGgvcmVhbG1zL3BhcnRuZXJzLXBlcmZlY3RvbW9iaWxlLWNvbSIsImF1ZCI6Im9mZmxpbmUtdG9rZW4tZ2VuZXJhdG9yIiwic3ViIjoiNWE5OGU5NmMtYmU2Zi00YTk3LTg2ZDMtMWNjZmY0NWQyYjE4IiwidHlwIjoiT2ZmbGluZSIsImF6cCI6Im9mZmxpbmUtdG9rZW4tZ2VuZXJhdG9yIiwibm9uY2UiOiI3MjYxMjdmYS00ZjZhLTRiN2EtYjY5My0xY2YwMTVhMjZlNTQiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiJlMTNhOThiYi1mOGJmLTRlYzEtYTRmMy02MzhmYjEwMDA0YzgiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19fQ.aKzGsr4cFJ9Q_bYXGEyuI9-Lg335Jh5Qw_kkImgIoSRR2_OhEN8zf52r6AxHgajhYMDVy_B9uVkcyMXStBis4ZIm8s14hFESmsayWLfk3bmF3g9QR6IGMq51ud-81sXj4pWVHvIXirU8LQcVfUtmcj5Q0xTj8F6IulBTdtXbKznsO0D-gj_damwySTIAEXG2V9lE5kiwUu1uMNl_WaPaN9uqLNWb-T0VEEZLj6BjPhI5-SB3JapFx_sEkNgXuLDHbnJ7QS5ZGo4F8dUfI5aekfAvojODwbWhYNRL0xS26JEXJGdnWYcCBmmAVea2mKBVSxSQmN8tFIY7ijoMacmuuQ";
     
public static void main(String args[] ) throws Exception, IOException, ParserConfigurationException, SAXException, ParseException{
        
    PerfectoReservationActivity activity = new PerfectoReservationActivity(cloudName, securityToken);

    //Either set time for inactive to release the reservations. If not set, 31 minutes is default
    activity.setTimings(32);
    
    activity.deleteUnusedReservations();
           
}
    
}