@Test(expected = ServerException.class) public void assessmentStoreTest_05() throws Exception { List<String> questIds = new ArrayList<>(); questIds.add("A127"); questIds.add("A126"); List<String> properties = new ArrayList<>(); properties.add("body1"); Map<String, Object> itemsMap = assessmentStore.getItems(questIds, properties); }
public Map<String, Object> getItems(List<String> identifiers, List<String> properties) { TelemetryManager.log("Bulk Get Items for identifiers: " + identifiers + " | Properties: " + properties); Session session = CassandraConnector.getSession(); List<String> propertiesTofetch = new ArrayList<String>(properties); assessmentExternalBlobProperties.stream().forEach(x -> { if(propertiesTofetch.contains(x)) { propertiesTofetch.add("blobAsText(" + x + ") as " + x); propertiesTofetch.remove(x); } }); if(!propertiesTofetch.contains("question_id")) propertiesTofetch.add("question_id"); String query = getSelectStatement(identifiers, propertiesTofetch); try { PreparedStatement ps = session.prepare(query); BoundStatement bound = new BoundStatement(ps); ResultSet rs = session.execute(bound); Map<String, Object> itemsMap = new HashMap<>(); if (null != rs) { while (rs.iterator().hasNext()) { Row row = rs.iterator().next(); Map<String, Object> propertyMap = new HashMap<String, Object>(); properties.forEach(prop -> propertyMap.put((String) prop, row.getString(prop))); itemsMap.put(row.getString("question_id"), propertyMap); } return itemsMap; } } catch (Exception e) { TelemetryManager.error("Error! Executing get items: " + e.getMessage(), e); throw new ServerException(CassandraConnectorStoreParam.ERR_SERVER_ERROR.name(), "Error fetching items from cassandra."); } return null; }
AssessmentStore { public Map<String, Object> getItems(List<String> identifiers, List<String> properties) { TelemetryManager.log("Bulk Get Items for identifiers: " + identifiers + " | Properties: " + properties); Session session = CassandraConnector.getSession(); List<String> propertiesTofetch = new ArrayList<String>(properties); assessmentExternalBlobProperties.stream().forEach(x -> { if(propertiesTofetch.contains(x)) { propertiesTofetch.add("blobAsText(" + x + ") as " + x); propertiesTofetch.remove(x); } }); if(!propertiesTofetch.contains("question_id")) propertiesTofetch.add("question_id"); String query = getSelectStatement(identifiers, propertiesTofetch); try { PreparedStatement ps = session.prepare(query); BoundStatement bound = new BoundStatement(ps); ResultSet rs = session.execute(bound); Map<String, Object> itemsMap = new HashMap<>(); if (null != rs) { while (rs.iterator().hasNext()) { Row row = rs.iterator().next(); Map<String, Object> propertyMap = new HashMap<String, Object>(); properties.forEach(prop -> propertyMap.put((String) prop, row.getString(prop))); itemsMap.put(row.getString("question_id"), propertyMap); } return itemsMap; } } catch (Exception e) { TelemetryManager.error("Error! Executing get items: " + e.getMessage(), e); throw new ServerException(CassandraConnectorStoreParam.ERR_SERVER_ERROR.name(), "Error fetching items from cassandra."); } return null; } }
AssessmentStore { public Map<String, Object> getItems(List<String> identifiers, List<String> properties) { TelemetryManager.log("Bulk Get Items for identifiers: " + identifiers + " | Properties: " + properties); Session session = CassandraConnector.getSession(); List<String> propertiesTofetch = new ArrayList<String>(properties); assessmentExternalBlobProperties.stream().forEach(x -> { if(propertiesTofetch.contains(x)) { propertiesTofetch.add("blobAsText(" + x + ") as " + x); propertiesTofetch.remove(x); } }); if(!propertiesTofetch.contains("question_id")) propertiesTofetch.add("question_id"); String query = getSelectStatement(identifiers, propertiesTofetch); try { PreparedStatement ps = session.prepare(query); BoundStatement bound = new BoundStatement(ps); ResultSet rs = session.execute(bound); Map<String, Object> itemsMap = new HashMap<>(); if (null != rs) { while (rs.iterator().hasNext()) { Row row = rs.iterator().next(); Map<String, Object> propertyMap = new HashMap<String, Object>(); properties.forEach(prop -> propertyMap.put((String) prop, row.getString(prop))); itemsMap.put(row.getString("question_id"), propertyMap); } return itemsMap; } } catch (Exception e) { TelemetryManager.error("Error! Executing get items: " + e.getMessage(), e); throw new ServerException(CassandraConnectorStoreParam.ERR_SERVER_ERROR.name(), "Error fetching items from cassandra."); } return null; } AssessmentStore(); }
AssessmentStore { public Map<String, Object> getItems(List<String> identifiers, List<String> properties) { TelemetryManager.log("Bulk Get Items for identifiers: " + identifiers + " | Properties: " + properties); Session session = CassandraConnector.getSession(); List<String> propertiesTofetch = new ArrayList<String>(properties); assessmentExternalBlobProperties.stream().forEach(x -> { if(propertiesTofetch.contains(x)) { propertiesTofetch.add("blobAsText(" + x + ") as " + x); propertiesTofetch.remove(x); } }); if(!propertiesTofetch.contains("question_id")) propertiesTofetch.add("question_id"); String query = getSelectStatement(identifiers, propertiesTofetch); try { PreparedStatement ps = session.prepare(query); BoundStatement bound = new BoundStatement(ps); ResultSet rs = session.execute(bound); Map<String, Object> itemsMap = new HashMap<>(); if (null != rs) { while (rs.iterator().hasNext()) { Row row = rs.iterator().next(); Map<String, Object> propertyMap = new HashMap<String, Object>(); properties.forEach(prop -> propertyMap.put((String) prop, row.getString(prop))); itemsMap.put(row.getString("question_id"), propertyMap); } return itemsMap; } } catch (Exception e) { TelemetryManager.error("Error! Executing get items: " + e.getMessage(), e); throw new ServerException(CassandraConnectorStoreParam.ERR_SERVER_ERROR.name(), "Error fetching items from cassandra."); } return null; } AssessmentStore(); void save(String questionId, String body); String read(String questionId); Map<String, Object> getAssessmentProperties(String questionId, List properties); void update(String questionId, String body); void updateAssessmentProperties(String questionId, Map<String, Object> map); Map<String, Object> getItems(List<String> identifiers, List<String> properties); }
AssessmentStore { public Map<String, Object> getItems(List<String> identifiers, List<String> properties) { TelemetryManager.log("Bulk Get Items for identifiers: " + identifiers + " | Properties: " + properties); Session session = CassandraConnector.getSession(); List<String> propertiesTofetch = new ArrayList<String>(properties); assessmentExternalBlobProperties.stream().forEach(x -> { if(propertiesTofetch.contains(x)) { propertiesTofetch.add("blobAsText(" + x + ") as " + x); propertiesTofetch.remove(x); } }); if(!propertiesTofetch.contains("question_id")) propertiesTofetch.add("question_id"); String query = getSelectStatement(identifiers, propertiesTofetch); try { PreparedStatement ps = session.prepare(query); BoundStatement bound = new BoundStatement(ps); ResultSet rs = session.execute(bound); Map<String, Object> itemsMap = new HashMap<>(); if (null != rs) { while (rs.iterator().hasNext()) { Row row = rs.iterator().next(); Map<String, Object> propertyMap = new HashMap<String, Object>(); properties.forEach(prop -> propertyMap.put((String) prop, row.getString(prop))); itemsMap.put(row.getString("question_id"), propertyMap); } return itemsMap; } } catch (Exception e) { TelemetryManager.error("Error! Executing get items: " + e.getMessage(), e); throw new ServerException(CassandraConnectorStoreParam.ERR_SERVER_ERROR.name(), "Error fetching items from cassandra."); } return null; } AssessmentStore(); void save(String questionId, String body); String read(String questionId); Map<String, Object> getAssessmentProperties(String questionId, List properties); void update(String questionId, String body); void updateAssessmentProperties(String questionId, Map<String, Object> map); Map<String, Object> getItems(List<String> identifiers, List<String> properties);  }