/** {@inheritDoc} */ @Override public void removeFromGroup(String featureId, String groupName) { Util.assertParamHasLength(groupName, "groupName (#2)"); if (!existGroup(groupName)) { throw new GroupNotFoundException(groupName); } // retrieve Feature f = read(featureId); f.setGroup(null); // persist modification update(f); }
sb.append("\"type\":\"" + this.getClass().getName() + "\""); sb.append(JsonUtils.cacheJson(this)); Set<String> myFeatures = readAll().keySet(); sb.append(",\"numberOfFeatures\":" + myFeatures.size()); sb.append(",\"features\":["); sb.append("\"" + myFeature + "\""); Set<String> myGroups = readAllGroups(); sb.append("],\"numberOfGroups\":" + myGroups.size()); sb.append(",\"groups\":[");
/** {@inheritDoc} */ @Override public Set<String> readAllGroups() { Map < String, Feature > features = readAll(); Set < String > groups = new HashSet<String>(); for (Map.Entry<String,Feature> uid : features.entrySet()) { groups.add(uid.getValue().getGroup()); } groups.remove(null); groups.remove(""); return groups; }
/** * Check that current feature does not exist. * * @param uid * current feature identifier.s */ protected void assertFeatureNotExist(String uid) { Util.assertHasLength(uid); if (exist(uid)) { throw new FeatureAlreadyExistException(uid); } }
/** {@inheritDoc} */ @Override public String toString() { return toJson(); }
/** * Validate feature uid. * * @param uid * target uid */ protected void assertGroupExist(String groupName) { Util.assertHasLength(groupName); if (!existGroup(groupName)) { throw new GroupNotFoundException(groupName); } }
/** * Initialize store from XML Configuration File. * * @param xmlConfFile * xml configuration file */ public Map < String, Feature > importFeaturesFromXmlFile(String xmlConfFile) { // Argument validation if (xmlConfFile == null || xmlConfFile.isEmpty()) { throw new IllegalArgumentException("Configuration filename cannot be null nor empty"); } // Load as Inputstream InputStream xmlIS = getClass().getClassLoader().getResourceAsStream(xmlConfFile); if (xmlIS == null) { throw new IllegalArgumentException("File " + xmlConfFile + " could not be read, please check path and rights"); } // Use the Feature Parser XmlConfig conf = new XmlParser().parseConfigurationFile(xmlIS); Map < String, Feature > features = conf.getFeatures(); importFeatures(features.values()); return features; }
/** {@inheritDoc} */ @Override public boolean existGroup(String groupName) { Util.assertParamHasLength(groupName, "groupName"); Map < String, Feature > features = readAll(); Map < String, Feature > group = new HashMap< String, Feature >(); for (Map.Entry<String,Feature> uid : features.entrySet()) { if (groupName.equals(uid.getValue().getGroup())) { group.put(uid.getKey(), uid.getValue()); } } return !group.isEmpty(); }
/** * Validate feature uid. * * @param uid * target uid */ protected void assertFeatureExist(String uid) { Util.assertHasLength(uid); if (!exist(uid)) { throw new FeatureNotFoundException(uid); } }
/** {@inheritDoc} */ @Override public String toJson() { String json = super.toJson(); // Remove last } to enrich the json document json = json.substring(0, json.length() - 1) + ",\"xmlInputFile\":"; // No filename inputstream, set to true) if (null == fileName) { json += "null"; } else { json += "\"" + this.fileName + "\""; } json += "}"; return json; }
/** {@inheritDoc} */ @Override public Map<String, Feature> readGroup(String groupName) { Util.assertParamHasLength(groupName, "groupName"); Map < String, Feature > features = readAll(); Map < String, Feature > group = new HashMap< String, Feature >(); for (Map.Entry<String,Feature> uid : features.entrySet()) { if (groupName.equals(uid.getValue().getGroup())) { group.put(uid.getKey(), uid.getValue()); } } if (group.isEmpty()) { throw new GroupNotFoundException(groupName); } return group; }