List of usage examples for com.mongodb.util JSON parse
public static Object parse(final String jsonString)
Parses a JSON string and returns a corresponding Java object.
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.AuthCodeDAO.java
License:EUPL
private DBObject map(final SameTransientStore<AuthCode> store) { DBObject obj = null;//from w w w. j a v a2 s .co m try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new AuthCodeEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write authN code to DB object", e); } return obj; }
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.ClientAppDAO.java
License:EUPL
private DBObject map(final SameTransientStore<ClientApp> store) { DBObject obj = null;// w ww. j ava2s .c o m try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new ClientAppEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write client app to DB object", e); } return obj; }
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.LinkedInStateDAO.java
License:EUPL
private DBObject map(final SameTransientStore<LinkedInState> store) { DBObject obj = null;//from w ww . j ava 2 s . c o m try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new LinkedInStateEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write access state to DB object", e); } return obj; }
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.PendingUserDAO.java
License:EUPL
private DBObject map(final UserTransientStore<PendingUser> store) { DBObject obj = null;/* w ww . java2 s . c om*/ try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new PendingUserEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write pending user to DB object", e); } return obj; }
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.ResourceOwnerDAO.java
License:EUPL
private DBObject map(final UserTransientStore<ResourceOwner> store) { DBObject obj = null;/*from w w w . jav a2 s .c o m*/ try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new ResourceOwnerEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write resource owner to DB object", e); } return obj; }
From source file:eu.eubrazilcc.lvl.storage.oauth2.dao.TokenDAO.java
License:EUPL
private DBObject map(final SameTransientStore<AccessToken> store) { DBObject obj = null;//ww w . ja v a2s .c om try { obj = (DBObject) JSON.parse(JSON_MAPPER.writeValueAsString(new AccessTokenEntity(store.purge()))); } catch (JsonProcessingException e) { LOGGER.error("Failed to write access token to DB object", e); } return obj; }
From source file:eu.falcon.fusion.ScheduledFusionTask.java
@Scheduled(fixedRate = 50000) public void reportCurrentTime() { System.out.println("The time is now " + dateFormat.format(new Date())); InputStream inputStream;/*w w w .j a va2 s . c om*/ String jsonldToSaveToMongoAndFuseki = ""; //doo rest call try { URL url = new URL("http://localhost:8083"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/ld+json"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); jsonldToSaveToMongoAndFuseki += output; } conn.disconnect(); inputStream = new ByteArrayInputStream(jsonldToSaveToMongoAndFuseki.getBytes(StandardCharsets.UTF_8)); //inputStream = new FileInputStream("/home/eleni/NetBeansProjects/falcon-data-management/fusion/src/main/resources/sensorData.json"); String serviceURI = "http://localhost:3030/ds/data"; //DatasetAccessorFactory factory = null; DatasetAccessor accessor; accessor = DatasetAccessorFactory.createHTTP(serviceURI); Model m = ModelFactory.createDefaultModel(); String base = "http://test-projects.com/"; m.read(inputStream, base, "JSON-LD"); //accessor.putModel(m); accessor.add(m); inputStream.close(); } catch (IOException ex) { Logger.getLogger(FusionApplication.class.getName()).log(Level.SEVERE, null, ex); } DBObject dbObject = (DBObject) JSON.parse(jsonldToSaveToMongoAndFuseki); mongoTemplate.insert(dbObject, "sensorMeasurement"); }
From source file:eu.operando.core.ose.mongo.OspsMongo.java
public boolean storeOsps(String ospId, OSPPrivacyPolicy ospPolicy) { boolean result = true; try {/*w ww . ja v a 2 s .c o m*/ ObjectMapper mapper = new ObjectMapper(); String jsonInString = mapper.writeValueAsString(ospPolicy); Object obj = JSON.parse(jsonInString); DBObject document = (DBObject) obj; ospPSTable.insert(document); } catch (MongoException e) { result = false; e.printStackTrace(); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:eu.operando.core.ose.mongo.RegulationsMongo.java
public boolean updateRegulationD(String regId, PrivacyRegulationInput reg) { boolean result = false; //reg.setRegId(regId); try {//from w w w.j a va 2 s . com ObjectMapper mapper = new ObjectMapper(); String jsonInString = mapper.writeValueAsString(reg); Object obj = JSON.parse(jsonInString); DBObject document = (DBObject) obj; BasicDBObject searchQuery = new BasicDBObject().append("regId", regId); WriteResult wr = regulationTable.update(searchQuery, document); result = wr.isUpdateOfExisting(); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:eu.operando.core.pdb.mongo.UPPMongo.java
public boolean updateUPP(String regId, UserPrivacyPolicy upp) { boolean result = false; //upp.setUserPolicyID(regId); try {//from w w w.j av a 2 s. c om ObjectMapper mapper = new ObjectMapper(); String jsonInString = mapper.writeValueAsString(upp); Object obj = JSON.parse(jsonInString); DBObject document = (DBObject) obj; BasicDBObject searchQuery = new BasicDBObject(); ; try { // searchQuery = new BasicDBObject().append("_id", new ObjectId(regId)); searchQuery.put("userId", regId); } catch (IllegalArgumentException e) { e.printStackTrace(); return result; } WriteResult wr = uppTable.update(searchQuery, document); result = wr.isUpdateOfExisting(); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }