Search in sources :

Example 1 with JsonJavaFactory

use of com.ibm.commons.util.io.json.JsonJavaFactory in project org.openntf.domino by OpenNTF.

the class EngageDataInitializer method loadData.

@SuppressWarnings({ "unchecked", "unused" })
public void loadData(final org.openntf.domino.Session s, final FramedTransactionalGraph<DGraph> framedGraph) {
    HashMap<String, Location> locs = new HashMap<String, Location>();
    HashMap<String, Track> tracks = new HashMap<String, Track>();
    HashMap<String, String> trackLkup = new HashMap<String, String>();
    trackLkup.put("Special", "Sp");
    trackLkup.put("Strategy/Deployment", "Str");
    trackLkup.put("Administration", "Adm");
    trackLkup.put("Development", "Dev");
    trackLkup.put("Business", "Bus");
    trackLkup.put("Commercial", "Comm");
    try {
        String urlData = readUrl("http://xceed.be/engage.nsf/api/data/collections/name/BLUG_ViewSessions?start=0&count=100");
        JsonJavaFactory factory = JsonJavaFactory.instanceEx;
        ArrayList<JsonJavaObject> jsonData = (ArrayList<JsonJavaObject>) JsonParser.fromJson(factory, urlData);
        SimpleDateFormat sdf = new SimpleDateFormat();
        for (JsonJavaObject obj : jsonData) {
            String locKey = obj.getAsString("session_room");
            Location loc = framedGraph.addVertex(locKey, Location.class);
            if (Strings.isBlankString(loc.getName())) {
                loc.setName(locKey);
            }
            String trackKey = obj.getAsString("session_track");
            Track track = framedGraph.addVertex(trackLkup.get(trackKey), Track.class);
            if (Strings.isBlankString(track.getTitle())) {
                track.setTitle(trackLkup.get(trackKey));
                track.setDescription(trackKey);
            }
            // DO DATES
            String actualDate = obj.getAsString("session_date");
            String manipulated = actualDate.substring(0, 10) + " " + actualDate.substring(11, 19);
            Date startDate = DATE_FORMAT.parse(manipulated);
            String startTime = obj.getAsString("session_time1");
            String endTime = obj.getAsString("session_time2");
            Calendar startCal = Calendar.getInstance();
            startCal.setTime(startDate);
            startCal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(startTime.substring(0, 2)));
            startCal.set(Calendar.MINUTE, Integer.parseInt(startTime.substring(3, 5)));
            startCal.set(Calendar.SECOND, 0);
            startCal.set(Calendar.MILLISECOND, 0);
            Calendar endCal = Calendar.getInstance();
            endCal.setTime(startDate);
            endCal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(endTime.substring(0, 2)));
            endCal.set(Calendar.MINUTE, Integer.parseInt(endTime.substring(3, 5)));
            endCal.set(Calendar.SECOND, 0);
            endCal.set(Calendar.MILLISECOND, 0);
            String tsKey = sdf.format(startCal.getTime()) + " - " + sdf.format(endCal.getTime());
            TimeSlot ts = framedGraph.addVertex(tsKey, TimeSlot.class);
            ts.setStartTime(startCal);
            ts.setEndTime(endCal);
            String code = obj.getAsString("session_nr");
            Presentation sess = framedGraph.addVertex(code, Presentation.class);
            sess.setTitle(obj.getAsString("session_title"));
            sess.setDescription(obj.getAsString("session_abstract"));
            sess.setStatus(Event.Status.CONFIRMED);
            sess.setSessionId(code);
            System.out.println("Assigning location - " + locKey + " to session " + obj.getAsString("session_title"));
            sess.addLocation(loc);
            track.addIncludesSession(sess);
            ts.addEvent(sess);
            for (int i = 1; i < 6; i++) {
                String suffix = "";
                if (i > 1) {
                    suffix = Integer.toString(i);
                }
                String speaker = obj.getAsString("speaker_name" + suffix);
                if ("".equals(speaker)) {
                    break;
                }
                String speakerName = speaker;
                String organization = obj.getAsString("speaker_org" + suffix);
                Attendee att = framedGraph.addVertex(null, Attendee.class);
                System.out.println(speaker);
                int sep = speakerName.indexOf(" ");
                if (sep > -1) {
                    String firstName = speakerName.substring(0, sep);
                    String lastName = speakerName.substring(sep + 1, speakerName.length());
                    att.setFirstName(firstName);
                    att.setLastName(lastName);
                } else {
                    att.setFirstName(speakerName);
                }
                att.setTwitterId(obj.getAsString("speaker_twitter" + suffix));
                att.setUrl(obj.getAsString("speaker_photourl" + suffix));
                if (!"".equals(organization)) {
                    Group org = framedGraph.addVertex(organization, Group.class);
                    org.setName(organization);
                    org.setType(Group.Type.COMPANY);
                    org.addMember(att);
                }
                sess.addPresentedBy(att);
                sess.addAttendingAttendee(att);
                sess.addPlansToAttend(att);
            }
        }
        framedGraph.commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JsonJavaFactory(com.ibm.commons.util.io.json.JsonJavaFactory) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

JsonJavaFactory (com.ibm.commons.util.io.json.JsonJavaFactory)1 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1