List of usage examples for com.google.gwt.query.client.plugins.ajax Ajax ajax
public static void ajax(Properties p)
From source file:org.mindinformatics.gwt.domeo.plugins.persistence.annotopia.src.AnnotopiaPersistenceManager.java
License:Apache License
@Override public void retrieveExistingAnnotationSetList(IRetrieveExistingAnnotationSetListHandler handler) { _application.getLogger().debug(this, "Retrieving list of existing annotation sets..."); _application.getProgressPanelContainer() .setProgressMessage("Retrieving list of existing annotation sets from Annotopia..."); try {/* www. j a va 2s. c om*/ Ajax.ajax(Ajax.createSettings().setUrl(URL + "s/annotationset").setHeaders(getAnnotopiaOAuthToken()) .setDataType("json") // txt, json, jsonp, xml .setType("get") // post, get .setData(GQuery.$$("apiKey: " + ApplicationUtils.getAnnotopiaApiKey() + ",outCmd:frame,tgtUrl:" + ((IDomeo) _application).getPersistenceManager().getCurrentResource().getUrl())) // parameters for the query-string .setTimeout(10000).setSuccess(new Function() { // callback to be run if the request success public void f() { IDomeo _domeo = ((IDomeo) _application); JsAnnotopiaSetsResultWrapper wrapper = (JsAnnotopiaSetsResultWrapper) parseJson( getDataProperties().toJsonString()); AnnotopiaConverter unmarshaller = new AnnotopiaConverter(_domeo); List<MAnnotopiaAnnotationSet> sets = unmarshaller.unmarshallAnnotationSetsList(wrapper); _application.getLogger() .debug(this, "Completed Execution of retrieveExistingAnnotationSetList() in " + (System.currentTimeMillis() - ((IDomeo) _application).getDocumentPipelineTimer()) + "ms"); if (sets.size() == 0) { // TODO message no annotation found _application.getLogger().info(this, "No annotation sets found"); _application.getProgressPanelContainer() .setCompletionMessage("No annotation exist for this document"); } else { _application.getProgressPanelContainer().hide(); try { ExistingAnnotationViewerPanel lwp = new ExistingAnnotationViewerPanel( (IDomeo) _application, sets); new EnhancedGlassPanel((IDomeo) _application, lwp, lwp.getTitle(), false, false, false); } catch (Exception e) { _application.getLogger().exception(this, "Exeption in visualizing existing annotation"); } } } }).setError(new Function() { // callback to be run if the request fails public void f() { _application.getLogger().exception(this, "Couldn't complete existing annotation sets list retrieval process"); _application.getProgressPanelContainer().setErrorMessage( "Couldn't complete existing annotation sets list retrieval process"); } })); } catch (Exception e) { _application.getLogger().exception(this, "Couldn't complete existing annotation sets list retireval"); } }
From source file:org.mindinformatics.gwt.domeo.plugins.persistence.annotopia.src.AnnotopiaPersistenceManager.java
License:Apache License
@Override public void retrieveExistingAnnotationSets(List<String> urls, IRetrieveExistingAnnotationSetHandler handler) { _application.getLogger().debug(this, "Retrieving requested annotation sets..."); _application.getProgressPanelContainer() .setProgressMessage("Retrieving requested annotation sets from Annotopia..."); for (String url : urls) { try {/*from ww w. ja v a2 s . com*/ Ajax.ajax(Ajax.createSettings().setUrl(url).setHeaders(getAnnotopiaOAuthToken()).setDataType("json") // txt, json, jsonp, xml .setType("get") // post, get .setData(GQuery.$$("apiKey: " + ApplicationUtils.getAnnotopiaApiKey() + ",outCmd:frame")) // parameters for the query-string .setTimeout(10000).setSuccess(new Function() { // callback to be run if the request success public void f() { IDomeo _domeo = ((IDomeo) _application); JsAnnotopiaAnnotationSetGraph wrapper = (JsAnnotopiaAnnotationSetGraph) parseJson( getDataProperties().toJsonString()); AnnotopiaConverter unmarshaller = new AnnotopiaConverter(_domeo); MAnnotationSet set = unmarshaller.unmarshallAnnotationSet(wrapper, true); if (set == null) { // TODO message no annotation found _application.getLogger().info(this, "No annotation set found"); _application.getProgressPanelContainer() .setCompletionMessage("Annotation Set not found"); } else { ((AnnotationPersistenceManager) _domeo.getPersistenceManager()) .loadAnnotationSet(set); _application.getProgressPanelContainer().hide(); _application.getLogger().debug(this, "Completed Execution of retrieveExistingAnnotationSets() in " + (System.currentTimeMillis() - ((IDomeo) _application).getDocumentPipelineTimer()) + "ms"); _domeo.refreshAllComponents(); } } }).setError(new Function() { // callback to be run if the request fails public void f() { _application.getLogger().exception(this, "Couldn't complete existing annotation sets list retrieval process"); _application.getProgressPanelContainer().setErrorMessage( "Couldn't complete existing annotation sets list retrieval process"); } })); } catch (Exception e) { _application.getLogger().exception(this, "Couldn't complete existing annotation sets list retrieval"); } } }
From source file:org.mindinformatics.gwt.domeo.plugins.persistence.annotopia.src.AnnotopiaPersistenceManager.java
License:Apache License
@Override public void saveAnnotation() { _application.getLogger().debug(this, "Saving modified annotation sets..."); _application.getProgressPanelContainer() .setProgressMessage("Saving modified annotation sets to Annotopia..."); ArrayList<MAnnotationSet> setToSerialize = new ArrayList<MAnnotationSet>(); for (MAnnotationSet set : ((IDomeo) _application).getAnnotationPersistenceManager() .getAllDiscussionSets()) {/*w ww .j a va 2 s . co m*/ if (set.getHasChanged() && set.getAnnotations().size() > 0) setToSerialize.add(set); } for (MAnnotationSet set : ((IDomeo) _application).getAnnotationPersistenceManager().getAllUserSets()) { if (set.getHasChanged() && set.getAnnotations().size() > 0) setToSerialize.add(set); } AnnotopiaSerializerManager manager = AnnotopiaSerializerManager.getInstance((IDomeo) _application); for (MAnnotationSet annotationSet : setToSerialize) { final String operation = (annotationSet.getVersionNumber() == null || annotationSet.getVersionNumber().isEmpty()) ? "post" : "put"; JsUtils.JsUtilsImpl utils = new JsUtils.JsUtilsImpl(); Properties v = utils.parseJSON("{\"apiKey\":\"" + ApplicationUtils.getAnnotopiaApiKey() + "\",\"outCmd\":\"frame\",\"set\":" + manager.serialize(annotationSet).toString() + "}"); try { Ajax.ajax(Ajax.createSettings().setUrl(URL + "s/annotationset").setHeaders(getAnnotopiaOAuthToken()) .setDataType("json") // txt, json, jsonp, xml */ .setType(operation) // post, get .setData(v) // parameters for the query-string setData(GQuery.$$("apiKey: testkey, set: " + value)) .setTimeout(10000).setSuccess(new Function() { // callback to be run if the request success public void f() { IDomeo _domeo = ((IDomeo) _application); JsAnnotopiaSetResultWrapper wrapper = (JsAnnotopiaSetResultWrapper) parseJson( getDataProperties().toJsonString()); AnnotopiaConverter unmarshaller = new AnnotopiaConverter(_domeo); MAnnotationSet set = unmarshaller .unmarshallAnnotationSet(wrapper.getResult().getSet().get(0), false); if (set == null) { // TODO message no annotation found _application.getLogger().exception(this, "Annotation set not saved correctly"); _application.getProgressPanelContainer() .setErrorMessage("Annotation set not saved correctly"); } else { MAnnotationSet currentSet = null; if (operation.equals("post")) currentSet = _domeo.getPersistenceManager() .getAnnotationSetById(set.getPreviousVersion()); else currentSet = _domeo.getPersistenceManager() .getAnnotationSetById(set.getIndividualUri()); currentSet.setIndividualUri(set.getIndividualUri()); _application.getLogger().info(this, "Setting Set id to " + currentSet.getIndividualUri()); currentSet.setLastSavedOn(set.getLastSavedOn()); currentSet.setVersionNumber(set.getVersionNumber()); currentSet.setPreviousVersion(set.getPreviousVersion()); currentSet.setHasChanged(false); _application.getLogger().info(this, "Set: " + currentSet.getIndividualUri()); for (MAnnotation annotation : set.getAnnotations()) { _application.getLogger().info(this, "Annotation " + annotation.getPreviousVersion()); for (MAnnotation currentAnnotation : currentSet.getAnnotations()) { _application.getLogger().info(this, "Matching " + currentAnnotation.getIndividualUri()); if (currentAnnotation.getIndividualUri() .equals(annotation.getPreviousVersion())) { _application.getLogger().info(this, "Matched"); currentAnnotation.setIndividualUri(annotation.getIndividualUri()); currentAnnotation.setLastSavedOn(annotation.getLastSavedOn()); currentAnnotation.setVersionNumber(annotation.getVersionNumber()); currentAnnotation .setPreviousVersion(annotation.getPreviousVersion()); currentAnnotation.setHasChanged(false); // TODO: Assumes one target currentAnnotation.getSelector() .setUri(annotation.getSelector().getUri()); break; } } } _application.getProgressPanelContainer().hide(); _application.getLogger().debug(this, "Completed saving of Annotation Set in " + (System.currentTimeMillis() - ((IDomeo) _application).getDocumentPipelineTimer()) + "ms"); } } }).setError(new Function() { // callback to be run if the request fails public void f() { Window.alert("There was an error " + getDataObject()); _application.getLogger().exception(this, "Couldn't complete existing annotation sets list saving"); _application.getProgressPanelContainer() .setErrorMessage("Couldn't complete existing annotation sets list saving"); } })); } catch (Exception e) { _application.getLogger().exception(this, "Couldn't complete existing annotation sets list saving"); } } }