@Test public void doActionReplaceEmptyArray() throws PersistenceException { when(valueMap.containsKey(ATTR)).thenReturn(true); when(valueMap.get(ATTR)).thenReturn(new Boolean[] {}); JoinProperty action = new JoinProperty(ATTR, EMPTY_VALUE); action.doAction(resource); verify(valueMap, times(1)).remove(ATTR); verify(valueMap, times(1)).put(ATTR, EMPTY_VALUE); }
@Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties == null) { return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } if (!properties.containsKey(name)) { return StringUtils.EMPTY; } Object value = properties.get(name); if (!value.getClass().isArray()) { return StringUtils.EMPTY; } Object[] values = (Object[]) value; if (values.length > 0) { Node node = resource.adaptTo(Node.class); try { node.getProperty(name).remove(); node.setProperty(name, StringUtils.join(values, separator)); } catch (RepositoryException e) { throw new PersistenceException(e.getMessage(), e); } return "Joined " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } if (this.emptyValue == null) { properties.remove(name); return "Removed empty " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } properties.remove(name); properties.put(name, this.emptyValue); return "Replaced empty " + value.getClass().getSimpleName() + " property " + name + " with " + this.emptyValue + " for resource " + resource.getPath(); }
JoinProperty implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties == null) { return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } if (!properties.containsKey(name)) { return StringUtils.EMPTY; } Object value = properties.get(name); if (!value.getClass().isArray()) { return StringUtils.EMPTY; } Object[] values = (Object[]) value; if (values.length > 0) { Node node = resource.adaptTo(Node.class); try { node.getProperty(name).remove(); node.setProperty(name, StringUtils.join(values, separator)); } catch (RepositoryException e) { throw new PersistenceException(e.getMessage(), e); } return "Joined " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } if (this.emptyValue == null) { properties.remove(name); return "Removed empty " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } properties.remove(name); properties.put(name, this.emptyValue); return "Replaced empty " + value.getClass().getSimpleName() + " property " + name + " with " + this.emptyValue + " for resource " + resource.getPath(); } }
JoinProperty implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties == null) { return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } if (!properties.containsKey(name)) { return StringUtils.EMPTY; } Object value = properties.get(name); if (!value.getClass().isArray()) { return StringUtils.EMPTY; } Object[] values = (Object[]) value; if (values.length > 0) { Node node = resource.adaptTo(Node.class); try { node.getProperty(name).remove(); node.setProperty(name, StringUtils.join(values, separator)); } catch (RepositoryException e) { throw new PersistenceException(e.getMessage(), e); } return "Joined " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } if (this.emptyValue == null) { properties.remove(name); return "Removed empty " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } properties.remove(name); properties.put(name, this.emptyValue); return "Replaced empty " + value.getClass().getSimpleName() + " property " + name + " with " + this.emptyValue + " for resource " + resource.getPath(); } JoinProperty(@Nonnull String name);  JoinProperty(@Nonnull String name, Object emptyValue);  JoinProperty(@Nonnull String name, Object emptyValue, @Nonnull String separator); }
JoinProperty implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties == null) { return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } if (!properties.containsKey(name)) { return StringUtils.EMPTY; } Object value = properties.get(name); if (!value.getClass().isArray()) { return StringUtils.EMPTY; } Object[] values = (Object[]) value; if (values.length > 0) { Node node = resource.adaptTo(Node.class); try { node.getProperty(name).remove(); node.setProperty(name, StringUtils.join(values, separator)); } catch (RepositoryException e) { throw new PersistenceException(e.getMessage(), e); } return "Joined " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } if (this.emptyValue == null) { properties.remove(name); return "Removed empty " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } properties.remove(name); properties.put(name, this.emptyValue); return "Replaced empty " + value.getClass().getSimpleName() + " property " + name + " with " + this.emptyValue + " for resource " + resource.getPath(); } JoinProperty(@Nonnull String name);  JoinProperty(@Nonnull String name, Object emptyValue);  JoinProperty(@Nonnull String name, Object emptyValue, @Nonnull String separator); @Override String doAction(@Nonnull Resource resource); }
JoinProperty implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties == null) { return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } if (!properties.containsKey(name)) { return StringUtils.EMPTY; } Object value = properties.get(name); if (!value.getClass().isArray()) { return StringUtils.EMPTY; } Object[] values = (Object[]) value; if (values.length > 0) { Node node = resource.adaptTo(Node.class); try { node.getProperty(name).remove(); node.setProperty(name, StringUtils.join(values, separator)); } catch (RepositoryException e) { throw new PersistenceException(e.getMessage(), e); } return "Joined " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } if (this.emptyValue == null) { properties.remove(name); return "Removed empty " + value.getClass().getSimpleName() + " property " + name + " for resource " + resource.getPath(); } properties.remove(name); properties.put(name, this.emptyValue); return "Replaced empty " + value.getClass().getSimpleName() + " property " + name + " with " + this.emptyValue + " for resource " + resource.getPath(); } JoinProperty(@Nonnull String name);  JoinProperty(@Nonnull String name, Object emptyValue);  JoinProperty(@Nonnull String name, Object emptyValue, @Nonnull String separator); @Override String doAction(@Nonnull Resource resource);  }