use of com.ibm.commons.util.io.json.JsonJavaObject 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();
}
}
use of com.ibm.commons.util.io.json.JsonJavaObject in project org.openntf.nsfodp by OpenNTF.
the class StockComponentsServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setBufferSize(0);
// $NON-NLS-1$ //$NON-NLS-2$
resp.setHeader("Content-Type", "text/json");
ServletOutputStream os = resp.getOutputStream();
try {
if (componentInfo == null) {
SharableRegistryImpl facesRegistry = new SharableRegistryImpl(getClass().getPackage().getName());
// $NON-NLS-1$
List<Object> libraries = ExtensionManager.findServices((List<Object>) null, LibraryServiceLoader.class, "com.ibm.xsp.Library");
libraries.stream().filter(lib -> lib instanceof XspLibrary).map(XspLibrary.class::cast).map(lib -> new LibraryWrapper(lib.getLibraryId(), lib)).map(wrapper -> {
SimpleRegistryProvider provider = new SimpleRegistryProvider();
provider.init(wrapper);
return provider;
}).map(XspRegistryProvider::getRegistry).forEach(facesRegistry::addDepend);
facesRegistry.refreshReferences();
componentInfo = new JsonJavaObject();
JsonArray defs = new JsonJavaArray();
facesRegistry.findComponentDefs().stream().filter(FacesComponentDefinition::isTag).map(def -> {
try {
JsonObject defObj = new JsonJavaObject();
// $NON-NLS-1$
defObj.putJsonProperty("namespaceUri", def.getNamespaceUri());
// $NON-NLS-1$
defObj.putJsonProperty("tagName", def.getTagName());
// $NON-NLS-1$
defObj.putJsonProperty("class", def.getJavaClass().getName());
// $NON-NLS-1$
defObj.putJsonProperty("since", def.getSince());
// $NON-NLS-1$
defObj.putJsonProperty("defaultPrefix", def.getFirstDefaultPrefix());
// $NON-NLS-1$
defObj.putJsonProperty("componentFamily", def.getComponentFamily());
// $NON-NLS-1$
defObj.putJsonProperty("componentType", def.getComponentType());
// $NON-NLS-1$
defObj.putJsonProperty("id", def.getId());
JsonArray facetNames = new JsonJavaArray();
for (String facetName : def.getFacetNames()) {
facetNames.add(facetName);
}
// $NON-NLS-1$
defObj.putJsonProperty("facetNames", facetNames);
FacesProperty defaultProp = def.getDefaultFacesProperty();
if (defaultProp != null) {
JsonObject defaultPropObj = new JsonJavaObject();
// $NON-NLS-1$
defaultPropObj.putJsonProperty("name", defaultProp.getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("since", defaultProp.getSince());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("class", defaultProp.getJavaClass().getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("required", defaultProp.isRequired());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("attribute", defaultProp.isAttribute());
}
JsonArray properties = new JsonJavaArray();
for (String propName : def.getPropertyNames()) {
FacesProperty prop = def.getProperty(propName);
JsonObject propObj = new JsonJavaObject();
// $NON-NLS-1$
propObj.putJsonProperty("name", propName);
// $NON-NLS-1$
propObj.putJsonProperty("class", prop.getJavaClass().getName());
// $NON-NLS-1$
propObj.putJsonProperty("since", prop.getSince());
// $NON-NLS-1$
propObj.putJsonProperty("required", prop.isRequired());
// $NON-NLS-1$
propObj.putJsonProperty("attribute", prop.isAttribute());
properties.add(propObj);
}
// $NON-NLS-1$
defObj.putJsonProperty("properties", properties);
return defObj;
} catch (JsonException e) {
throw new RuntimeException(e);
}
}).forEach(defObj -> {
try {
defs.add(defObj);
} catch (JsonException e) {
throw new RuntimeException(e);
}
});
// $NON-NLS-1$
componentInfo.putJsonProperty("components", defs);
}
os.print(JsonGenerator.toJson(JsonJavaFactory.instance, componentInfo, false));
} catch (Throwable e) {
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(baos);
e.printStackTrace(out);
out.flush();
os.println(baos.toString());
}
}
Aggregations