@Test public void shouldRemoveDifferentEntryIntoList() throws Exception { operation.xpath = "lists:double"; operation.value = 2.0; operation.run(doc); Double[] doubleValues = (Double[]) doc.getPropertyValue("lists:double"); assertEquals(1, doubleValues.length); operation.xpath = "lists:boolean"; operation.value = false; operation.run(doc); Boolean[] booleanValues = (Boolean[]) doc.getPropertyValue("lists:boolean"); assertEquals(1, booleanValues.length); operation.xpath = "lists:integer"; operation.value = 1L; operation.run(doc); Long[] longValues = (Long[]) doc.getPropertyValue("lists:integer"); assertEquals(1, longValues.length); operation.xpath = "lists:date"; operation.value = now; operation.run(doc); Calendar[] dateValues = (Calendar[]) doc.getPropertyValue("lists:date"); assertEquals(0, dateValues.length); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getType(); checkFieldType(type, value); List<Serializable> array = Arrays.asList((Serializable[]) p.getValue()); if (array == null) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } List<Serializable> list = new ArrayList<>(array); if (!list.contains(value)) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } do { list.remove(value); p.setValue(list); } while (list.contains(value) && isRemoveAll); if (save) { doc = session.saveDocument(doc); session.save(); } return doc; }
RemoveEntryOfMultiValuedProperty extends AbstractOperationMultiValuedProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getType(); checkFieldType(type, value); List<Serializable> array = Arrays.asList((Serializable[]) p.getValue()); if (array == null) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } List<Serializable> list = new ArrayList<>(array); if (!list.contains(value)) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } do { list.remove(value); p.setValue(list); } while (list.contains(value) && isRemoveAll); if (save) { doc = session.saveDocument(doc); session.save(); } return doc; } }
RemoveEntryOfMultiValuedProperty extends AbstractOperationMultiValuedProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getType(); checkFieldType(type, value); List<Serializable> array = Arrays.asList((Serializable[]) p.getValue()); if (array == null) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } List<Serializable> list = new ArrayList<>(array); if (!list.contains(value)) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } do { list.remove(value); p.setValue(list); } while (list.contains(value) && isRemoveAll); if (save) { doc = session.saveDocument(doc); session.save(); } return doc; }  }
RemoveEntryOfMultiValuedProperty extends AbstractOperationMultiValuedProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getType(); checkFieldType(type, value); List<Serializable> array = Arrays.asList((Serializable[]) p.getValue()); if (array == null) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } List<Serializable> list = new ArrayList<>(array); if (!list.contains(value)) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } do { list.remove(value); p.setValue(list); } while (list.contains(value) && isRemoveAll); if (save) { doc = session.saveDocument(doc); session.save(); } return doc; }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); }
RemoveEntryOfMultiValuedProperty extends AbstractOperationMultiValuedProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getType(); checkFieldType(type, value); List<Serializable> array = Arrays.asList((Serializable[]) p.getValue()); if (array == null) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } List<Serializable> list = new ArrayList<>(array); if (!list.contains(value)) { log.info(String.format("Value \"%s\" not found in %s, can't remove it", value, doc.getPathAsString())); return doc; } do { list.remove(value); p.setValue(list); } while (list.contains(value) && isRemoveAll); if (save) { doc = session.saveDocument(doc); session.save(); } return doc; }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); static final String ID; static final Log log; }