LiferayWriter implements WriterWithFeedback<Result, IndexedRecord, IndexedRecord> { @Override public void write(Object object) throws IOException { if (!_isIndexedRecord(object)) { return; } IndexedRecord indexedRecord = (IndexedRecord)object; cleanWrites(); Operation operation = _liferayOutputProperties.getOperation(); try { if (Operation.Delete == operation) { doDelete(indexedRecord); } else if (Operation.Insert == operation) { doInsert(indexedRecord); } else if (Operation.Update == operation) { doUpdate(indexedRecord); } else { _indexedRecordJsonObjectConverter.reject( indexedRecord, TalendRuntimeException.createUnexpectedException( "Unsupported write operation " + operation)); } _result.totalCount++; } catch (Exception exception) { _indexedRecordJsonObjectConverter.reject(indexedRecord, exception); } } LiferayWriter(
		LiferayWriteOperation liferayWriteOperation,
		LiferayOutputProperties liferayOutputProperties); @Override void cleanWrites(); @Override Result close(); void doDelete(IndexedRecord indexedRecord); void doInsert(IndexedRecord indexedRecord); void doUpdate(IndexedRecord indexedRecord); @Override Iterable<IndexedRecord> getRejectedWrites(); @Override Iterable<IndexedRecord> getSuccessfulWrites(); @Override WriteOperation<Result> getWriteOperation(); @Override void open(String uId); @Override void write(Object object);  }
@Test public void testWrite() throws Exception { String openApiModule = "/headless-openapi-module/v1.0"; String endpoint = "/catalogs/{siteId}/product"; LiferayRequestContentAggregatorSink liferayRequestContentAggregatorSink = new LiferayRequestContentAggregatorSink(); LiferayOutputProperties testLiferayOutputProperties = _getLiferayOutputProperties( Operation.Insert, openApiModule, _OAS_URL, endpoint, "siteId"); JsonObject oasJsonObject = readObject("openapi.json"); Schema postContentSchema = getSchema( "/v1.0/catalogs/{siteId}/product", "POST", oasJsonObject); testLiferayOutputProperties.resource.inboundSchemaProperties.schema. setValue(postContentSchema); testLiferayOutputProperties.resource.outboundSchemaProperties.schema. setValue(postContentSchema); LiferayWriter liferayWriter = new LiferayWriter( new LiferayWriteOperation( liferayRequestContentAggregatorSink, testLiferayOutputProperties), testLiferayOutputProperties); liferayWriter.open("aaaa-bbbb-cccc-dddd"); liferayWriter.write( _createIndexedRecordFromFile( "product_content.json", postContentSchema)); JsonObject outputJsonObject = liferayRequestContentAggregatorSink.getOutputJsonObject(); Assert.assertTrue( "Output has name", outputJsonObject.containsKey("name")); JsonObject nameJsonObject = outputJsonObject.getJsonObject("name"); Assert.assertNotNull("name is json object", nameJsonObject); Assert.assertTrue( "Name has key hr_HR", nameJsonObject.containsKey("hr_HR")); }
@Test(expected = IOException.class) public void testWriteNullIndexedRecord() throws Exception { String openApiModule = "/headless-openapi-module/v1.0"; String endpoint = "/bigdecimal/{id}"; LiferayOutputProperties testLiferayOutputProperties = _getLiferayOutputProperties( Operation.Update, openApiModule, _OAS_URL, endpoint, "id"); testLiferayOutputProperties.setupProperties(); LiferayWriter liferayWriter = new LiferayWriter( new LiferayWriteOperation( new LiferaySink(), testLiferayOutputProperties), testLiferayOutputProperties); liferayWriter.write(null); }