/** {@inheritDoc} */ @Override public void importProperties(Collection<Property<?>> properties) { // Do not use target as the delete/create operation will be traced if (properties != null) { for (Property<?> property : properties) { if (existProperty(property.getName())) { deleteProperty(property.getName()); } createProperty(property); } } }
/** {@inheritDoc} */ @Override public boolean isEmpty() { Set < String > pNames = listPropertyNames(); return pNames == null || pNames.isEmpty(); }
/** {@inheritDoc} */ @Override public void updateProperty(String name, String newValue) { // Read from redis, feature not found if no present Property<?> p = readProperty(name); // Update within Object p.setValueFromString(newValue); // Serialization and update key, update TTL updateProperty(p); }
/** {@inheritDoc} */ @Override public <T> void updateProperty(Property<T> prop) { Util.assertNotNull(prop); // Delete deleteProperty(prop.getName()); // Create createProperty(prop); }
/** * Check that current feature does not exist. * * @param uid * current feature identifier.s */ protected void assertPropertyNotExist(String uid) { Util.assertHasLength(uid); if (existProperty(uid)) { throw new PropertyAlreadyExistException(uid); } }
/** {@inheritDoc} */ @Override public Property<?> readProperty(String name, Property < ? > defaultValue) { try { return readProperty(name); } catch(PropertyNotFoundException pnf) { return defaultValue; } }
/** {@inheritDoc} */ public String toJson() { StringBuilder sb = new StringBuilder("{"); sb.append("\"type\":\"" + this.getClass().getName() + "\""); Set<String> myProperties = readAllProperties().keySet(); sb.append(",\"numberOfProperties\":" + myProperties.size()); sb.append(",\"properties\":["); boolean first = true; for (String myProperty : myProperties) { if (!first) { sb.append(","); } first = false; sb.append("\"" + myProperty + "\""); } sb.append("]}"); return sb.toString(); }
/** * Validate property name and existence * * @param uid * target uid */ protected void assertPropertyExist(String name) { Util.assertHasLength(name); if (!existProperty(name)) { throw new PropertyNotFoundException(name); } }
/** * Initialize store from XML Configuration File. * * @param xmlConfFile * xml configuration file */ public Map<String, Property<?>> importPropertiesFromXmlFile(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, Property<?>> properties = conf.getProperties(); // Override existing configuration within database for (Map.Entry<String,Property<?>> featureName : properties.entrySet()) { if (existProperty(featureName.getKey())) { deleteProperty(featureName.getKey()); } createProperty(featureName.getValue()); } return properties; }