@Override public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings map = getUserDomainMappings(source); if (map.size() > 1) { Mappings updatedMappings = map.remove(mapping); doUpdateMapping(source, updatedMappings.serialize()); } else { doRemoveMapping(source, mapping.asString()); } }
private void removeMappingsFromConfig(MappingSource source, Mappings mappings) { List<String> stored = new ArrayList<>(); for (String c : defaultConfiguration.getStringArray("mapping")) { String mapping = source.getFixedUser() + "@" + source.getFixedDomain() + "=" + mappings.serialize(); if (!c.equalsIgnoreCase(mapping)) { stored.add(c); } } // clear old values defaultConfiguration.clear(); // add stored mappings for (String aStored : stored) { defaultConfiguration.addProperty("mapping", aStored); } } }
@Override public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings map = getUserDomainMappings(source); if (!map.isEmpty()) { Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build(); doUpdateMapping(source, updatedMappings.serialize()); } else { doAddMapping(source, mapping.asString()); } }
private void updateConfiguration(MappingSource source, Mappings oldMappings, Mappings updatedMappings) throws RecipientRewriteTableException { if (oldMappings != null) { removeMappingsFromConfig(source, oldMappings); } if (!updatedMappings.isEmpty()) { defaultConfiguration.addProperty("mapping", source.getFixedUser() + "@" + source.getFixedDomain() + "=" + updatedMappings.serialize()); } try { virtualUserTable.configure(defaultConfiguration); } catch (Exception e) { if (updatedMappings.size() > 0) { throw new RecipientRewriteTableException("Error update mapping", e); } } }