@Test public void addMoreItemToListPropertyTest() throws IOException, OperationException { String fieldsDataAsJson = readPropertiesFromFile("newFields.json"); try (OperationContext ctx = new OperationContext(coreSession)) { ctx.setInput(doc); OperationChain chain = new OperationChain("testChain"); chain.add(AddItemToListProperty.ID).set("xpath", "ds:fields").set("complexJsonProperties", fieldsDataAsJson); DocumentModel resultDoc = (DocumentModel) service.run(ctx, chain); List<?> dbFields = (List<?>) resultDoc.getPropertyValue("ds:fields"); assertEquals(2, dbFields.size()); } }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } if (save) { doc = session.saveDocument(doc); } return doc; }
AddItemToListProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } if (save) { doc = session.saveDocument(doc); } return doc; } }
AddItemToListProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } if (save) { doc = session.saveDocument(doc); } return doc; }  }
AddItemToListProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } if (save) { doc = session.saveDocument(doc); } return doc; }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); }
AddItemToListProperty { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } if (save) { doc = session.saveDocument(doc); } return doc; }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); static final String ID; }