@Test public void doAction() throws PersistenceException { RemoveMultiValues action = new RemoveMultiValues(ATTR, new String[] {VAL1, VAL2}); action.doAction(resource); verify(valueMap, times(1)).put(ATTR, new String[] {}); }
@Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } valuesList.removeAll(Arrays.asList(values)); properties.put(name, valuesList.toArray(new String[] {})); return "Removing values " + Arrays.toString(values) + " from multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); }
RemoveMultiValues implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } valuesList.removeAll(Arrays.asList(values)); properties.put(name, valuesList.toArray(new String[] {})); return "Removing values " + Arrays.toString(values) + " from multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } }
RemoveMultiValues implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } valuesList.removeAll(Arrays.asList(values)); properties.put(name, valuesList.toArray(new String[] {})); return "Removing values " + Arrays.toString(values) + " from multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } RemoveMultiValues(@Nonnull String name, @Nonnull String[] values); }
RemoveMultiValues implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } valuesList.removeAll(Arrays.asList(values)); properties.put(name, valuesList.toArray(new String[] {})); return "Removing values " + Arrays.toString(values) + " from multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } RemoveMultiValues(@Nonnull String name, @Nonnull String[] values); @Override String doAction(@Nonnull Resource resource); }
RemoveMultiValues implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { String[] currentValues = properties.get(name, String[].class); List<String> valuesList = new ArrayList<>(); if (currentValues != null && currentValues.length > 0) { Collections.addAll(valuesList, currentValues); } valuesList.removeAll(Arrays.asList(values)); properties.put(name, valuesList.toArray(new String[] {})); return "Removing values " + Arrays.toString(values) + " from multi-value property " + name + ": " + Arrays.toString(currentValues) + " results in " + valuesList + " for resource " + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } RemoveMultiValues(@Nonnull String name, @Nonnull String[] values); @Override String doAction(@Nonnull Resource resource);  }