List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:com.google.iosched.model.DataExtractor.java
License:Open Source License
public JsonArray extractVideoSessions(JsonDataSources sources) { videoSessionsById = new HashMap<String, JsonObject>(); if (categoryToTagMap == null) { throw new IllegalStateException("You need to extract tags before attempting to extract video sessions"); }/* www. j a va2 s . co m*/ if (speakersById == null) { throw new IllegalStateException( "You need to extract speakers before attempting to extract video sessions"); } JsonArray result = new JsonArray(); JsonDataSource source = sources.getSource(VendorAPISource.MainTypes.topics.name()); if (source != null) { for (JsonObject origin : source) { if (!isVideoSession(origin)) { continue; } if (isHiddenSession(origin)) { // Sessions with a "Hidden from schedule" flag should be ignored continue; } JsonObject dest = new JsonObject(); JsonPrimitive vid = setVideoForVideoSession(origin, dest); JsonElement id = get(origin, VendorAPISource.Topics.id); // video library id must be the Youtube video id set(vid, dest, OutputJsonKeys.VideoLibrary.id); set(origin, VendorAPISource.Topics.title, dest, OutputJsonKeys.VideoLibrary.title, null); set(origin, VendorAPISource.Topics.description, dest, OutputJsonKeys.VideoLibrary.desc, null); set(new JsonPrimitive(Config.CONFERENCE_YEAR), dest, OutputJsonKeys.VideoLibrary.year); JsonElement videoTopic = null; JsonArray categories = origin.getAsJsonArray(VendorAPISource.Topics.categoryids.name()); for (JsonElement category : categories) { JsonObject tag = categoryToTagMap.get(category.getAsString()); if (tag != null) { if (isHashtag(tag)) { videoTopic = get(tag, OutputJsonKeys.Tags.name); // by definition, the first tag that can be a hashtag (usually a TOPIC) is considered the video tag break; } } } if (videoTopic != null) { set(videoTopic, dest, OutputJsonKeys.VideoLibrary.topic); } // Concatenate speakers: JsonArray speakers = getAsArray(origin, VendorAPISource.Topics.speakerids); StringBuilder sb = new StringBuilder(); if (speakers != null) for (int i = 0; i < speakers.size(); i++) { String speakerId = speakers.get(i).getAsString(); usedSpeakers.add(speakerId); JsonObject speaker = speakersById.get(speakerId); if (speaker != null) { sb.append(get(speaker, OutputJsonKeys.Speakers.name).getAsString()); if (i < speakers.size() - 1) sb.append(", "); } } set(new JsonPrimitive(sb.toString()), dest, OutputJsonKeys.VideoLibrary.speakers); videoSessionsById.put(id.getAsString(), dest); result.add(dest); } } return result; }
From source file:com.google.iosched.model.DataExtractor.java
License:Open Source License
private boolean isVideoSession(JsonObject sessionObj) { JsonArray tags = sessionObj.getAsJsonArray(VendorAPISource.Topics.categoryids.name()); for (JsonElement category : tags) { if (Config.VIDEO_CATEGORY.equals(category.getAsString())) { return true; }/*from w w w. j a va 2 s. c o m*/ } return false; }
From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
public JsonArray extractSessions(JsonDataSources sources) { if (videoSessionsById == null) { throw new IllegalStateException( "You need to extract video sessions before attempting to extract sessions"); }/*ww w. j a va 2 s. co m*/ if (categoryToTagMap == null) { throw new IllegalStateException("You need to extract tags before attempting to extract sessions"); } JsonArray result = new JsonArray(); JsonDataSource source = sources.getSource(InputJsonKeys.VendorAPISource.MainTypes.topics.name()); if (source != null) { for (JsonObject origin : source) { if (isVideoSession(origin)) { // Sessions with the Video tag are processed as video library content continue; } if (isHiddenSession(origin)) { // Sessions with a "Hidden from schedule" flag should be ignored continue; } JsonElement title = get(origin, InputJsonKeys.VendorAPISource.Topics.title); // Since the CMS returns an empty keynote as a session, we need to ignore it if (title != null && title.isJsonPrimitive() && "keynote".equalsIgnoreCase(title.getAsString())) { continue; } JsonObject dest = new JsonObject(); // Some sessions require a special ID, so we replace it here... if (title != null && title.isJsonPrimitive() && "after hours".equalsIgnoreCase(title.getAsString())) { set(new JsonPrimitive("__afterhours__"), dest, OutputJsonKeys.Sessions.id); } else { set(origin, InputJsonKeys.VendorAPISource.Topics.id, dest, OutputJsonKeys.Sessions.id); } set(origin, InputJsonKeys.VendorAPISource.Topics.id, dest, OutputJsonKeys.Sessions.url, Converters.SESSION_URL); set(origin, InputJsonKeys.VendorAPISource.Topics.title, dest, OutputJsonKeys.Sessions.title, obfuscate ? Converters.OBFUSCATE : null); set(origin, InputJsonKeys.VendorAPISource.Topics.description, dest, OutputJsonKeys.Sessions.description, obfuscate ? Converters.OBFUSCATE : null); set(origin, InputJsonKeys.VendorAPISource.Topics.start, dest, OutputJsonKeys.Sessions.startTimestamp, Converters.DATETIME); set(origin, InputJsonKeys.VendorAPISource.Topics.finish, dest, OutputJsonKeys.Sessions.endTimestamp, Converters.DATETIME); set(new JsonPrimitive(isFeatured(origin)), dest, OutputJsonKeys.Sessions.isFeatured); JsonElement documents = get(origin, InputJsonKeys.VendorAPISource.Topics.documents); if (documents != null && documents.isJsonArray() && documents.getAsJsonArray().size() > 0) { // Note that the input for SessionPhotoURL is the entity ID. We simply ignore the original // photo URL, because that will be processed by an offline cron script, resizing the // photos and saving them to a known location with the entity ID as its base name. set(origin, InputJsonKeys.VendorAPISource.Topics.id, dest, OutputJsonKeys.Sessions.photoUrl, Converters.SESSION_PHOTO_URL); } setVideoPropertiesInSession(origin, dest); setRelatedContent(origin, dest); JsonElement mainTag = null; JsonElement hashtag = null; JsonElement mainTagColor = null; JsonArray categories = origin .getAsJsonArray(InputJsonKeys.VendorAPISource.Topics.categoryids.name()); JsonArray tags = new JsonArray(); for (JsonElement category : categories) { JsonObject tag = categoryToTagMap.get(category.getAsString()); if (tag != null) { JsonElement tagName = get(tag, OutputJsonKeys.Tags.tag); tags.add(tagName); usedTags.add(tagName.getAsString()); if (mainTag == null) { // check if the tag is from a "default" category. For example, if THEME is the default // category, all sessions will have a "mainTag" property set to the first tag of type THEME JsonElement tagCategory = get(tag, OutputJsonKeys.Tags.category); // THEME, TYPE or TOPIC if (tagCategory.equals(mainCategory)) { mainTag = tagName; mainTagColor = get(tag, OutputJsonKeys.Tags.color); } if (hashtag == null && isHashtag(tag)) { hashtag = get(tag, OutputJsonKeys.Tags.hashtag); if (hashtag == null || hashtag.getAsString() == null || hashtag.getAsString().isEmpty()) { // If no hashtag set in the tagsconf file, we will convert the tagname to find one: hashtag = new JsonPrimitive( get(tag, OutputJsonKeys.Tags.name, Converters.TAG_NAME).getAsString() .toLowerCase()); } } } } } set(tags, dest, OutputJsonKeys.Sessions.tags); if (mainTag != null) { set(mainTag, dest, OutputJsonKeys.Sessions.mainTag); } if (mainTagColor != null) { set(mainTagColor, dest, OutputJsonKeys.Sessions.color); } if (hashtag != null) { set(hashtag, dest, OutputJsonKeys.Sessions.hashtag); } JsonArray speakers = getAsArray(origin, InputJsonKeys.VendorAPISource.Topics.speakerids); if (speakers != null) for (JsonElement speaker : speakers) { String speakerId = speaker.getAsString(); usedSpeakers.add(speakerId); } set(speakers, dest, OutputJsonKeys.Sessions.speakers); JsonArray sessions = origin.getAsJsonArray(InputJsonKeys.VendorAPISource.Topics.sessions.name()); if (sessions != null && sessions.size() > 0) { String roomId = get(sessions.get(0).getAsJsonObject(), InputJsonKeys.VendorAPISource.Sessions.roomid).getAsString(); roomId = Config.ROOM_MAPPING.getRoomId(roomId); set(new JsonPrimitive(roomId), dest, OutputJsonKeys.Sessions.room); // captions URL is set based on the session room, so keep it here. String captionsURL = Config.ROOM_MAPPING.getCaptions(roomId); if (captionsURL != null) { set(new JsonPrimitive(captionsURL), dest, OutputJsonKeys.Sessions.captionsUrl); } } if (Config.DEBUG_FIX_DATA) { DebugDataExtractorHelper.changeSession(dest, usedTags); } result.add(dest); } } return result; }
From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
public JsonArray extractVideoSessions(JsonDataSources sources) { videoSessionsById = new HashMap<String, JsonObject>(); if (categoryToTagMap == null) { throw new IllegalStateException("You need to extract tags before attempting to extract video sessions"); }//from ww w. j a v a2s . c o m if (speakersById == null) { throw new IllegalStateException( "You need to extract speakers before attempting to extract video sessions"); } JsonArray result = new JsonArray(); JsonDataSource source = sources.getSource(InputJsonKeys.VendorAPISource.MainTypes.topics.name()); if (source != null) { for (JsonObject origin : source) { if (!isVideoSession(origin)) { continue; } if (isHiddenSession(origin)) { // Sessions with a "Hidden from schedule" flag should be ignored continue; } JsonObject dest = new JsonObject(); JsonPrimitive vid = setVideoForVideoSession(origin, dest); JsonElement id = get(origin, InputJsonKeys.VendorAPISource.Topics.id); // video library id must be the Youtube video id set(vid, dest, OutputJsonKeys.VideoLibrary.id); set(origin, InputJsonKeys.VendorAPISource.Topics.title, dest, OutputJsonKeys.VideoLibrary.title, obfuscate ? Converters.OBFUSCATE : null); set(origin, InputJsonKeys.VendorAPISource.Topics.description, dest, OutputJsonKeys.VideoLibrary.desc, obfuscate ? Converters.OBFUSCATE : null); set(new JsonPrimitive(Config.CONFERENCE_YEAR), dest, OutputJsonKeys.VideoLibrary.year); JsonElement videoTopic = null; JsonArray categories = origin .getAsJsonArray(InputJsonKeys.VendorAPISource.Topics.categoryids.name()); for (JsonElement category : categories) { JsonObject tag = categoryToTagMap.get(category.getAsString()); if (tag != null) { if (isHashtag(tag)) { videoTopic = get(tag, OutputJsonKeys.Tags.name); // by definition, the first tag that can be a hashtag (usually a TOPIC) is considered the video tag break; } } } if (videoTopic != null) { set(videoTopic, dest, OutputJsonKeys.VideoLibrary.topic); } // Concatenate speakers: JsonArray speakers = getAsArray(origin, InputJsonKeys.VendorAPISource.Topics.speakerids); StringBuilder sb = new StringBuilder(); if (speakers != null) for (int i = 0; i < speakers.size(); i++) { String speakerId = speakers.get(i).getAsString(); usedSpeakers.add(speakerId); JsonObject speaker = speakersById.get(speakerId); if (speaker != null) { sb.append(get(speaker, OutputJsonKeys.Speakers.name).getAsString()); if (i < speakers.size() - 1) sb.append(", "); } } set(new JsonPrimitive(sb.toString()), dest, OutputJsonKeys.VideoLibrary.speakers); videoSessionsById.put(id.getAsString(), dest); result.add(dest); } } return result; }
From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
private boolean isVideoSession(JsonObject sessionObj) { JsonArray tags = sessionObj.getAsJsonArray(InputJsonKeys.VendorAPISource.Topics.categoryids.name()); for (JsonElement category : tags) { if (Config.VIDEO_CATEGORY.equals(category.getAsString())) { return true; }//from w w w . jav a 2 s . c o m } return false; }
From source file:com.graphiq.kettle.jobentries.slack.SlackBotDialog.java
License:Apache License
/** * This method is called by Spoon when the user opens the settings dialog of the job entry. * It should open the dialog and return only once the dialog has been closed by the user. * * If the user confirms the dialog, the meta object (passed in the constructor) must * be updated to reflect the new job entry settings. The changed flag of the meta object must * reflect whether the job entry configuration was changed by the dialog. * * If the user cancels the dialog, the meta object must not be updated, and its changed flag * must remain unaltered./*from w w w.j av a 2s. c o m*/ * * The open() method must return the met object of the job entry after the user has confirmed the dialog, * or null if the user cancelled the dialog. */ public JobEntryInterface open() { // SWT code for setting up the dialog Shell parent = getParent(); Display display = parent.getDisplay(); shell = new Shell(parent, props.getJobsDialogStyle()); props.setLook(shell); JobDialog.setShellImage(shell, meta); // save the job entry's changed flag changed = meta.hasChanged(); // The ModifyListener used on all controls. It will update the meta object to // indicate that changes are being made. ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { meta.setChanged(); } }; // ------------------------------------------------------- // // SWT code for building the actual settings dialog // // ------------------------------------------------------- // FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "SlackBot.Shell.Title") + SlackBotDialog.STEP_VERSION); int middle = props.getMiddlePct(); int margin = Const.MARGIN; //Start building UI elements // Job entry name line Label wlName = new Label(shell, SWT.RIGHT); wlName.setText(BaseMessages.getString(PKG, "SlackBot.StepNameLabel")); props.setLook(wlName); FormData fdlName = new FormData(); fdlName.left = new FormAttachment(0, 0); fdlName.right = new FormAttachment(middle, 0); fdlName.top = new FormAttachment(0, margin); wlName.setLayoutData(fdlName); wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wName); wName.addModifyListener(lsMod); FormData fdName = new FormData(); fdName.left = new FormAttachment(middle, 0); fdName.top = new FormAttachment(0, margin); fdName.right = new FormAttachment(100, 0); wName.setLayoutData(fdName); // Separator Line Label separator1 = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); FormData fdSeparator1 = new FormData(); fdSeparator1.left = new FormAttachment(0, margin); fdSeparator1.top = new FormAttachment(wlName, margin * 3); fdSeparator1.right = new FormAttachment(100, 0); separator1.setLayoutData(fdSeparator1); props.setLook(separator1); selectionAdapter = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { meta.setChanged(); } }; /* * Recipient Group */ recipientGroup = new Group(shell, SWT.SHADOW_NONE); recipientGroup.setText(BaseMessages.getString(PKG, "SlackBot.MessageSettings")); props.setLook(recipientGroup); recipientGroupForm = new FormData(); recipientGroupForm.left = new FormAttachment(0, 0); recipientGroupForm.right = new FormAttachment(100, 0); recipientGroupForm.top = new FormAttachment(separator1, margin * 2); GridLayout recipientGrid = new GridLayout(); recipientGrid.numColumns = 2; recipientGroup.setLayout(recipientGrid); recipientGroup.setLayoutData(recipientGroupForm); // token wlToken = new Label(recipientGroup, SWT.RIGHT); wlToken.setText(BaseMessages.getString(PKG, "SlackBot.Token")); wlToken.setToolTipText(BaseMessages.getString(PKG, "SlackBot.TokenTip")); fdlToken = new GridData(); fdlToken.horizontalAlignment = GridData.END; wlToken.setLayoutData(fdlToken); wToken = new TextVar(jobMeta, recipientGroup, SWT.SINGLE | SWT.LEFT); props.setLook(wToken); wToken.addModifyListener(lsMod); fdToken = new GridData(); fdToken.horizontalAlignment = GridData.FILL; fdToken.grabExcessHorizontalSpace = true; wToken.setLayoutData(fdToken); /* * channel update button */ wlUpdate = new Label(recipientGroup, SWT.RIGHT); wlUpdate.setText(BaseMessages.getString(PKG, "SlackBot.UpdateChannel")); wlUpdate.setToolTipText(BaseMessages.getString(PKG, "SlackBot.UpdateChannelTip")); fdlUpdate = new GridData(); fdlUpdate.horizontalAlignment = GridData.END; wlUpdate.setLayoutData(fdlUpdate); wUpdate = new Button(recipientGroup, SWT.PUSH); wUpdate.setText("Update"); fdUpdate = new GridData(); fdUpdate.horizontalAlignment = GridData.FILL; fdUpdate.grabExcessHorizontalSpace = true; wUpdate.setLayoutData(fdUpdate); // post type wlPostType = new Label(recipientGroup, SWT.RIGHT); wlPostType.setText(BaseMessages.getString(PKG, "SlackBot.PostType")); wlPostType.setToolTipText(BaseMessages.getString(PKG, "SlackBot.PostTypeTip")); fdlPostType = new GridData(); fdlPostType.horizontalAlignment = GridData.FILL; wlPostType.setLayoutData(fdlPostType); wPostType = new CCombo(recipientGroup, SWT.READ_ONLY); props.setLook(wPostType); wPostType.addModifyListener(lsMod); fdPostType = new GridData(); fdPostType.horizontalAlignment = GridData.FILL; fdPostType.grabExcessHorizontalSpace = true; wPostType.setLayoutData(fdPostType); wPostType.add("Channel"); wPostType.add("Group"); // room name drop down wlChannel = new Label(recipientGroup, SWT.RIGHT); wlChannel.setText(BaseMessages.getString(PKG, "SlackBot.RoomName")); wlChannel.setToolTipText(BaseMessages.getString(PKG, "SlackBot.RoomNameTip")); fdlChannel = new GridData(); fdlChannel.horizontalAlignment = GridData.FILL; wlChannel.setLayoutData(fdlChannel); wChannel = new CCombo(recipientGroup, SWT.DROP_DOWN); props.setLook(wChannel); wChannel.addModifyListener(lsMod); fdChannel = new GridData(); fdChannel.horizontalAlignment = GridData.FILL; fdChannel.grabExcessHorizontalSpace = true; wChannel.setLayoutData(fdChannel); // Bot Name wlBotName = new Label(recipientGroup, SWT.RIGHT); wlBotName.setText(BaseMessages.getString(PKG, "SlackBot.BotName")); wlBotName.setToolTipText(BaseMessages.getString(PKG, "SlackBot.BotNameTip")); fdlBotName = new GridData(); fdlBotName.horizontalAlignment = GridData.END; wlBotName.setLayoutData(fdlBotName); wBotName = new TextVar(jobMeta, recipientGroup, SWT.SINGLE | SWT.LEFT); props.setLook(wBotName); wBotName.addModifyListener(lsMod); fdBotName = new GridData(); fdBotName.horizontalAlignment = GridData.FILL; fdBotName.grabExcessHorizontalSpace = true; wBotName.setLayoutData(fdBotName); // bot icon drop down wlBotIcon = new Label(recipientGroup, SWT.RIGHT); wlBotIcon.setText(BaseMessages.getString(PKG, "SlackBot.BotIcon")); wlBotIcon.setToolTipText(BaseMessages.getString(PKG, "SlackBot.BotIconTip")); fdlBotIcon = new GridData(); fdlBotIcon.horizontalAlignment = GridData.FILL; wlBotIcon.setLayoutData(fdlBotIcon); wBotIcon = new CCombo(recipientGroup, SWT.DROP_DOWN); props.setLook(wBotIcon); wBotIcon.addModifyListener(lsMod); fdBotIcon = new GridData(); fdBotIcon.horizontalAlignment = GridData.FILL; fdBotIcon.grabExcessHorizontalSpace = true; wBotIcon.setLayoutData(fdBotIcon); /* * Message section */ contentGroup = new Group(shell, SWT.SHADOW_NONE); contentGroup.setText(BaseMessages.getString(PKG, "SlackBot.Message")); props.setLook(contentGroup); contentGroupForm = new FormData(); contentGroupForm.left = new FormAttachment(0, 0); contentGroupForm.right = new FormAttachment(100, 0); contentGroupForm.top = new FormAttachment(recipientGroup, margin * 3); FormLayout contentLayout = new FormLayout(); contentGroup.setLayout(contentLayout); contentGroup.setLayoutData(contentGroupForm); Composite textComposite = new Composite(contentGroup, SWT.NONE); FormLayout textCompositeLayout = new FormLayout(); textCompositeLayoutForm = new FormData(); textCompositeLayoutForm.left = new FormAttachment(0, 0); textCompositeLayoutForm.right = new FormAttachment(100, 0); textCompositeLayoutForm.top = new FormAttachment(0, margin); textComposite.setLayout(textCompositeLayout); textComposite.setLayoutData(textCompositeLayoutForm); standardSuccessButton = new Button(contentGroup, SWT.RADIO); standardSuccessButton.setSelection(false); standardSuccessButton.setSize(100, standardSuccessButton.getSize().y); standardSuccessButtonForm = new FormData(); standardSuccessButtonForm.left = new FormAttachment(0, 0); standardSuccessButtonForm.right = new FormAttachment(10, 0); standardSuccessButtonForm.top = new FormAttachment(0, margin + 2); standardSuccessButton.setLayoutData(standardSuccessButtonForm); standardSuccessLabel = new Label(contentGroup, SWT.LEFT); standardSuccessLabel.setText(BaseMessages.getString(PKG, "SlackBot.Success")); standardSuccessLabel.setToolTipText(BaseMessages.getString(PKG, "SlackBot.StandardSuccess")); standardSuccessLabelForm = new FormData(); standardSuccessLabelForm.left = new FormAttachment(10, 0); standardSuccessLabelForm.right = new FormAttachment(100, 0); standardSuccessLabelForm.top = new FormAttachment(0, margin + 2); standardSuccessLabel.setLayoutData(standardSuccessLabelForm); standardFailureButton = new Button(contentGroup, SWT.RADIO); standardFailureButton.setSelection(true); standardFailureButton.setSize(100, standardFailureButton.getSize().y); standardFailureButtonForm = new FormData(); standardFailureButtonForm.left = new FormAttachment(0, 0); standardFailureButtonForm.right = new FormAttachment(10, 0); standardFailureButtonForm.top = new FormAttachment(standardSuccessLabel, margin); standardFailureButton.setLayoutData(standardFailureButtonForm); standardFailureLabel = new Label(contentGroup, SWT.LEFT); standardFailureLabel.setText(BaseMessages.getString(PKG, "SlackBot.Failure")); standardFailureLabel.setToolTipText(BaseMessages.getString(PKG, "SlackBot.StandardFailure")); standardFailureLabelForm = new FormData(); standardFailureLabelForm.left = new FormAttachment(10, 0); standardFailureLabelForm.right = new FormAttachment(100, 0); standardFailureLabelForm.top = new FormAttachment(standardSuccessLabel, margin); standardFailureLabel.setLayoutData(standardFailureLabelForm); customMessageButton = new Button(contentGroup, SWT.RADIO); customMessageButton.setSelection(false); customMessageButton.setSize(100, customMessageButton.getSize().y); customMessageButtonForm = new FormData(); customMessageButtonForm.left = new FormAttachment(0, 0); customMessageButtonForm.right = new FormAttachment(10, 0); customMessageButtonForm.top = new FormAttachment(standardFailureLabel, margin); customMessageButton.setLayoutData(customMessageButtonForm); Listener lsCustom = new Listener() { public void handleEvent(Event e) { setDialogStatus(true); } }; Listener lsStock = new Listener() { public void handleEvent(Event e) { setDialogStatus(false); } }; customMessageButton.addListener(SWT.Selection, lsCustom); customMessageButton.addSelectionListener(selectionAdapter); standardFailureButton.addListener(SWT.Selection, lsStock); standardFailureButton.addSelectionListener(selectionAdapter); standardSuccessButton.addListener(SWT.Selection, lsStock); standardSuccessButton.addSelectionListener(selectionAdapter); wUpdate.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { List<String> vars = jobMeta.getUsedVariables(); SlackConnection slack = new SlackConnection(meta.environmentSubstitute(wToken.getText())); if (!slack.getAuthStatus()) { throw new ConnectException(BaseMessages.getString(PKG, "SlackBot.ConnectionError")); } int roomType; String listName; if (wPostType.getText() == null) { roomType = SlackConnection.CHANNEL; listName = "channels"; } else if (wPostType.getText().equals("Group")) { roomType = SlackConnection.GROUP; listName = "groups"; } else { roomType = SlackConnection.CHANNEL; listName = "channels"; } String result = slack.getRoomList(roomType); JsonElement parsed = new JsonParser().parse(result); JsonObject jObject = parsed.getAsJsonObject(); String status = jObject.get("ok").toString(); if (!status.equals("true")) { new ConnectException(BaseMessages.getString(PKG, "SlackBot.ConnectionErrorList")); } JsonArray jarray = jObject.getAsJsonArray(listName); List<String> options = new LinkedList<String>(); Iterator<JsonElement> jelement = jarray.iterator(); while (jelement.hasNext()) { options.add(jelement.next().getAsJsonObject().get("name").getAsString()); } wChannel.setItems(options.toArray(new String[options.size()])); } catch (Exception ex) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setText(BaseMessages.getString(PKG, "SlackBot.ConnectionError.Title")); mb.setMessage(BaseMessages.getString(PKG, "SlackBot.ConnectionError.Message")); mb.open(); } } }); customMessageLabel = new Label(contentGroup, SWT.LEFT); customMessageLabel.setText(BaseMessages.getString(PKG, "SlackBot.Custom")); customMessageLabel.setToolTipText(BaseMessages.getString(PKG, "SlackBot.CustomTip")); customMessageLabelForm = new FormData(); customMessageLabelForm.left = new FormAttachment(10, 0); customMessageLabelForm.right = new FormAttachment(100, 0); customMessageLabelForm.top = new FormAttachment(standardFailureLabel, margin); customMessageLabel.setLayoutData(customMessageLabelForm); // Separator Line between checkboxes and custom message input Label separator2 = new Label(contentGroup, SWT.HORIZONTAL | SWT.SEPARATOR); FormData fdSeparator2 = new FormData(); fdSeparator2.left = new FormAttachment(0, margin); fdSeparator2.top = new FormAttachment(customMessageLabel, margin); fdSeparator2.right = new FormAttachment(100, 0); separator2.setLayoutData(fdSeparator2); props.setLook(separator2); customTextLabel = new Label(contentGroup, SWT.LEFT); customTextLabel.setText(BaseMessages.getString(PKG, "SlackBot.CustomMsgLabel")); customTextLabelForm = new FormData(); customTextLabelForm.left = new FormAttachment(0, 0); customTextLabelForm.right = new FormAttachment(100, 0); customTextLabelForm.top = new FormAttachment(separator2, margin); customTextLabel.setLayoutData(customTextLabelForm); customTextInput = new Text(contentGroup, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); props.setLook(customTextInput); customTextInput.addModifyListener(lsMod); customTextInputForm = new FormData(); customTextInputForm.left = new FormAttachment(0, 0); customTextInputForm.right = new FormAttachment(100, 0); customTextInputForm.top = new FormAttachment(customTextLabel, margin); customTextInputForm.bottom = new FormAttachment(customTextLabel, 150); customTextInput.setLayoutData(customTextInputForm); customTextInput.addKeyListener(new ControlSpaceKeyAdapter(jobMeta, customTextInput)); /* * Ok and Cancel buttons */ Button wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); Button wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); // at the bottom BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, null); // Add listeners Listener lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; Listener lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; wCancel.addListener(SWT.Selection, lsCancel); wOK.addListener(SWT.Selection, lsOK); // default listener (for hitting "enter") SelectionAdapter lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wName.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window and cancel the dialog properly shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); // populate the dialog with the values from the meta object populateDialog(); // restore the changed flag to original value, as the modify listeners fire during dialog population meta.setChanged(changed); // restore dialog size and placement, or set default size if none saved yet BaseStepDialog.setSize(shell, 100, 100, false); // open dialog and enter event loop shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } // at this point the dialog has closed, so either ok() or cancel() have been executed return meta; }
From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Apache License
private List<DisbursementData> fetchDisbursementData(final JsonObject command) { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command); List<DisbursementData> disbursementDatas = new ArrayList<>(); if (command.has(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .getAsJsonArray(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { int i = 0; do {//ww w . j av a 2 s . c om final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); LocalDate expectedDisbursementDate = null; BigDecimal principal = null; if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); } if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } disbursementDatas .add(new DisbursementData(null, expectedDisbursementDate, null, principal, null, null)); i++; } while (i < disbursementDataArray.size()); } } return disbursementDatas; }
From source file:com.gst.portfolio.loanaccount.service.LoanUtilService.java
License:Apache License
public List<LoanDisbursementDetails> fetchDisbursementData(final JsonObject command) { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command); List<LoanDisbursementDetails> disbursementDatas = new ArrayList<>(); if (command.has(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .getAsJsonArray(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { int i = 0; do {/*w w w . j a v a 2 s . c o m*/ final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); Date expectedDisbursementDate = null; Date actualDisbursementDate = null; BigDecimal principal = null; if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); if (date != null) { expectedDisbursementDate = date.toDate(); } } if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } disbursementDatas.add(new LoanDisbursementDetails(expectedDisbursementDate, actualDisbursementDate, principal)); i++; } while (i < disbursementDataArray.size()); } } return disbursementDatas; }
From source file:com.gullakh.gullakhandroidapp.GoogleCardsMediaActivity.java
License:Apache License
public JSONObject parse(String jsonLine) { String result = null;//w w w . j av a 2 s.c o m JsonElement jelement = new JsonParser().parse(jsonLine); JsonObject jobject = jelement.getAsJsonObject(); JSONObject jsonObject2 = new JSONObject(); JsonArray jarray = jobject.getAsJsonArray("result"); Log.d(" jobject is2", String.valueOf(jarray)); for (int i = 0; i < jarray.size(); i++) { jobject = jarray.get(i).getAsJsonObject(); Log.d(" jobject is", String.valueOf(jobject)); result = jobject.get("bankid").toString(); Log.d(" result is", result); for (int i2 = 0; i2 < high_cibil.size(); i2++) { if (high_cibil.get(i2).equals(result)) { jobject.remove(String.valueOf(jobject)); } else { try { jsonObject2.put("result", jobject); } catch (JSONException e) { Log.d("exception is", String.valueOf(e)); e.printStackTrace(); } } } } return jsonObject2; }
From source file:com.headswilllol.mineflat.gui.GuiParser.java
License:Open Source License
private static GuiElement parseElement(String id, JsonObject json, Optional<GuiElement> parent) { GuiElement element = null; // only remains null if this element can't be parsed int height;//from ww w . jav a2 s . com if (json.has("height")) { if (json.get("height").getAsString().endsWith("%")) { // height is defined as percentage of parent height height = (int) (Integer.parseInt(json.get("height").getAsString().replace("%", "")) / 100f * (parent.isPresent() ? parent.get().getSize().getY() : Display.getHeight())); } else { // height is standard pixel count height = json.get("height").getAsInt(); } } else { if (parent.isPresent()) { height = parent.get().getSize().getY(); // use parent element height } else { height = Display.getHeight(); // default to full window height } } if (height < 0) height = Display.getHeight() + height; int width; if (json.has("width")) { if (json.get("width").getAsString().endsWith("%")) { // width is defined as percentage of parent height width = (int) (Integer.parseInt(json.get("width").getAsString().replace("%", "")) / 100f * (parent.isPresent() ? parent.get().getSize().getX() : Display.getWidth())); } else { // width is standard pixel count width = json.get("width").getAsInt(); } } else if (json.has("type") && json.get("type").getAsString().equalsIgnoreCase("text") && json.has("text")) { width = GraphicsHandler.getStringLength(json.get("text").getAsString(), height); } else { if (parent.isPresent()) { width = parent.get().getSize().getX(); // use parent element width } else { width = Display.getWidth(); // default to full window width } } if (width < 0) width = Display.getWidth() + width; int x = 0; // default to x=0 (relative to parent) if (json.has("x")) { String jsonX = json.get("x").getAsString(); if (jsonX.equalsIgnoreCase("center")) { x = Integer.MAX_VALUE; } else x = Integer.parseInt(jsonX); } if (x < 0) // position is relative to right x = (parent.isPresent() ? parent.get().getSize().getX() : Display.getWidth()) + x; int y = json.has("y") ? json.get("y").getAsInt() : 0; // if not present, default to y=0 (relative to parent) if (y < 0) // position is relative to bottom y = (parent.isPresent() ? parent.get().getSize().getY() : Display.getHeight()) + y; Vector4f color = json.has("color") ? MiscUtil.hexToRGBA(json.get("color").getAsString()) : // use defined color MiscUtil.hexToRGBA("#FFF0"); // default to white transparent String text = json.has("text") ? json.get("text").getAsString() : ""; // default to empty string Class<?> handlerClass = null; if (json.has("handlerClass")) { try { handlerClass = Class.forName(json.get("handlerClass").getAsString()); } catch (ClassNotFoundException ex) { System.err.println("Cannot resolve handler class for element " + id + "!"); ex.printStackTrace(); } } else if (parent.isPresent()) handlerClass = parent.get().getHandlerClass().isPresent() ? parent.get().getHandlerClass().get() : null; if (json.has("type")) { String type = json.get("type").getAsString(); switch (type) { // check defined type case "text": // text element // instantiate the new TextElement element = new TextElement(id, new Vector2i(x, y), text, height, json.has("shadow") && json.get("shadow").getAsBoolean()); break; case "button": // button element Vector4f hover = MiscUtil.hexToRGBA(json.get("hoverColor").getAsString()); if (handlerClass != null) { if (json.has("handlerMethod")) { String mName = json.get("handlerMethod").getAsString(); JsonArray params = json.getAsJsonArray("handlerParams"); try { Method m = handlerClass.getMethod(mName); //TODO: params element = new Button(id, new Vector2i(x, y), new Vector2i(width, height), text, color, hover, m); } catch (NoSuchMethodException ex) { System.err.println("Failed to access handler method " + mName + " for element " + id); } } else System.err.println("No handler method for element " + id + "!"); } else { System.err.println("No handler class for element " + id + "!"); } break; case "panel": // container element element = new GuiElement(id, new Vector2i(x, y), new Vector2i(width, height), color); break; default: // unrecognized element, ignore it System.err.println("Unrecognized element type \"" + type + "\""); // default to container element element = new GuiElement(id, new Vector2i(x, y), new Vector2i(width, height), color); break; } } else { // default to container element element = new GuiElement(id, new Vector2i(x, y), new Vector2i(width, height), color); } if (element != null) { if (x == Integer.MAX_VALUE) elementsToCenter.add(element); element.setHandlerClass(handlerClass); for (Map.Entry<String, JsonElement> e : json.entrySet()) { // iterate subelements if (e.getValue().isJsonObject()) { // assert it's not a value for the current element // recursively parse subelements element.addChild( parseElement(e.getKey(), e.getValue().getAsJsonObject(), Optional.of(element))); } } } return element; }