@Override public void save(StageStatus status) { Preferences node = Preferences.userRoot().node(STAGE_PATH); try { node.put(STAGE_STATUS_KEY, JSON.std.asString(status)); LOG.trace("Stage status saved {}", status); } catch (IOException e) { LOG.error("Unable to increment modules usage statistics", e); } }
@Override public StageStatus getLatestStatus() { Preferences node = Preferences.userRoot().node(STAGE_PATH); try { String statusString = node.get(STAGE_STATUS_KEY, ""); if (isNotBlank(statusString)) { return JSON.std.beanFrom(StageStatus.class, statusString); } } catch (IOException e) { LOG.error("Unable to get latest stage status", e); } return StageStatus.NULL; }
@Override @SuppressWarnings("unchecked") public Map<String, Map<String, String>> loadWorkspace(File workspace) { requireNotNull(workspace, "Workspace file cannot be null"); Map<String, Map<String, String>> data = Collections.emptyMap(); try (FileInputStream stream = new FileInputStream(workspace)) { data = (Map) JSON.std.mapFrom(stream); } catch (Exception e) { // make it unchecked throw new RuntimeException(e); } return data; }
public void incrementUsageFor(String moduleId) { Preferences node = Preferences.userRoot().node(USAGE_PATH).node(moduleId); String json = node.get(MODULE_USAGE_KEY, ""); try { if (isNotBlank(json)) { node.put(MODULE_USAGE_KEY, JSON.std.asString(JSON.std.beanFrom(ModuleUsage.class, json).inc())); } else { node.put(MODULE_USAGE_KEY, JSON.std.asString(ModuleUsage.fistUsage(moduleId))); } LOG.trace("Usage incremented for module {}", moduleId); } catch (IOException e) { LOG.error("Unable to increment modules usage statistics", e); } finally { incrementTotalUsage(); } }
@Override public void saveWorkspace(Map<String, Map<String, String>> data, File destination) { requireNotNull(destination, "Destination file cannot be null"); LOG.debug(DefaultI18nContext.getInstance().i18n("Saving workspace data to {0}", destination.getAbsolutePath())); try { JSON.std.with(JSON.Feature.PRETTY_PRINT_OUTPUT).without(JSON.Feature.WRITE_NULL_PROPERTIES) .write(data, destination); LOG.info(DefaultI18nContext.getInstance().i18n("Workspace saved")); } catch (Exception e) { // make it unchecked throw new RuntimeException(e); } }
@Override public List<PremiumModule> getPremiumModules() { try { return JSON.std.with(Feature.READ_ONLY, true).listOfFrom(PremiumModule.class, new URL(pdfsam.property(ConfigurableProperty.PREMIUM_MODULES_URL))); } catch (IOException e) { LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to retrieve premium features description"), e); } return Collections.emptyList(); }
public DZoneReadPojoJacksonJr() { json = JSON.std /* 01-Jun-2016, tatu: Should NOT use deferred maps as they can * skew results */ .without(JSON.Feature.USE_DEFERRED_MAPS); }
protected Object[] arrayFrom(String serialized) throws JSONObjectException, IOException { return JSON.std.arrayFrom(serialized); }
@Override public String getLatestVersion() { try { return JSON.std.mapFrom(jsonSource).getOrDefault(CURRENT_VERSION_KEY, "").toString(); } catch (IOException e) { LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to find the latest available version."), e); } return EMPTY; }
public List<ModuleUsage> getUsages() { Preferences prefs = Preferences.userRoot().node(USAGE_PATH); List<ModuleUsage> retList = new ArrayList<>(); try { List<String> jsons = Arrays.stream(prefs.childrenNames()).parallel().map(name -> prefs.node(name)) .map(node -> node.get(MODULE_USAGE_KEY, "")).filter(json -> isNotBlank(json)).collect(toList()); for (String json : jsons) { retList.add(JSON.std.beanFrom(ModuleUsage.class, json)); } } catch (BackingStoreException | IOException e) { LOG.error("Unable to get modules usage statistics", e); } return retList; }
@Override public String _writeAsString(MeasurementPOJO items) throws Exception { return json.asString(items); } }
@Override public List<NewsData> getLatestNews() { try { return JSON.std.with(Feature.READ_ONLY, true).listOfFrom(NewsData.class, new URL(pdfsam.property(ConfigurableProperty.NEWS_URL))); } catch (IOException e) { LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to retrieve latest news"), e); } return Collections.emptyList(); }
public DZoneReadMapJacksonJr() { json = JSON.std /* 01-Jun-2016, tatu: Should NOT use deferred maps as they can * skew results */ .without(JSON.Feature.USE_DEFERRED_MAPS); }
@Override public Map<?,?> _readMap(String input) throws Exception { return json.mapFrom(input); } }
@Override public MeasurementPOJO _readItems(String input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); } }
@Override public Map<?,?> _readMap(InputStream input) throws Exception { return json.mapFrom(input); }
@Override public MeasurementPOJO _readItems(byte[] input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); }
@Override public Map<?,?> _readMap(byte[] input) throws Exception { return json.mapFrom(input); }
@Override public MeasurementPOJO _readItems(InputStream input) throws Exception { return json.beanFrom(MeasurementPOJO.class, input); }