@Test public void testGetValue() { final CsvValueAdapter adapter = (rawValue, requiredType, impExColumn, tuple) -> rawValue; String reExpKey = "((\\D?\\S{4,}){1,}).*-?.*"; String reExpValue = ".*-.*\\s{1,}((\\D?\\S{4,}){1,})\\s{0,}.*"; CsvExportColumnImpl column = new CsvExportColumnImpl(); CsvExportTupleImpl tuple = new CsvExportTupleImpl(new Object()); assertNull(column.getValue(null, adapter, tuple)); String rawValue = "rawValue"; assertEquals(rawValue, column.getValue(rawValue, adapter, tuple)); column.setValueRegEx("(.*)"); assertEquals(rawValue, column.getValue(rawValue, adapter, tuple)); column.setValueRegEx("(raw)"); assertEquals("raw", column.getValue(rawValue, adapter, tuple)); column.setValueRegEx("(Value)"); assertEquals("Value", column.getValue(rawValue, adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("SomeKey", column.getValue("SomeKey - Value", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Ключик", column.getValue("Ключик - Значение", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Ключик", column.getValue(" Ключик - Значение", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals(getprops(), "result", column.getValue("as фыф result - шум 34 123.56 значение sd ыв #", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("результат", column.getValue("as фыф результат - шум 34 123.56 значение sd ыв #", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Діамант жовтий", column.getValue("фыв 3 фвк Діамант жовтий 3/ 6 - 0,10 Ct", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Кубічний цирконій", column.getValue("2 Кубічний цирконій - 66 шт", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Онікс,перли,кварц димчастий", column.getValue("0 Онікс,перли,кварц димчастий - гр", adapter, tuple)); column.setValueRegEx(reExpKey); assertEquals("Онікс", column.getValue("Онікс -", adapter, tuple)); column.setValueRegEx(".*\\s{0,}\\-\\s{0,}(Value)"); assertEquals("Value", column.getValue("SomeKey - ValueZZZ", adapter, tuple)); column.setValueRegEx(reExpValue); assertEquals("Value", column.getValue("SomeKey - Value", adapter, tuple)); column.setValueRegEx(reExpValue); assertEquals("Значение", column.getValue(" Ключ - Значение", adapter, tuple)); column.setValueRegEx(reExpValue); assertEquals("значение", column.getValue("as фыф результат-шум 34 123.56 значение sd ыв #", adapter, tuple)); column.setValueRegEx(".*\\b([a-z]{3,})\\b.*"); assertEquals("word", column.getValue("1234sdcvdfv hfkdf34 word 2134", adapter, tuple)); column.setValueRegExTemplate("My '$1'"); assertEquals("My 'word'", column.getValue("1234sdcvdfv hfkdf34 word 2134", adapter, tuple)); column.setValueRegExTemplate(""); column.setValueRegEx("\\b(\\S\\D{3,})\\b"); assertEquals("word", column.getValue("1234sdcvdfv hfkdf34 word 2134", adapter, tuple)); column.setValueRegEx("\\b(\\S\\D{3,})\\b"); assertEquals("слово", column.getValue("1234sdcvdfv hfkdf34 слово 2134", adapter, tuple)); }
@Override public String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple) { if (getValueConstant() != null) { return getValueConstant(); } else if (rawValue != null) { final String strValue = (String) adapter.fromRaw(rawValue, ImpExValues.STRING, this, tuple); if (strValue != null) { if (getPattern() != null) { Matcher matcher = getPattern().matcher(strValue); if (StringUtils.isBlank(getValueRegExTemplate())) { if (matcher.find()) { return matcher.group(getValueRegExGroup()).trim(); } else { return null; } } else { if (matcher.matches()) { return matcher.replaceFirst(getValueRegExTemplate()).trim(); } else { return null; } } } return strValue; } } return null; }
CsvExportColumnImpl implements CsvExportColumn, Serializable { @Override public String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple) { if (getValueConstant() != null) { return getValueConstant(); } else if (rawValue != null) { final String strValue = (String) adapter.fromRaw(rawValue, ImpExValues.STRING, this, tuple); if (strValue != null) { if (getPattern() != null) { Matcher matcher = getPattern().matcher(strValue); if (StringUtils.isBlank(getValueRegExTemplate())) { if (matcher.find()) { return matcher.group(getValueRegExGroup()).trim(); } else { return null; } } else { if (matcher.matches()) { return matcher.replaceFirst(getValueRegExTemplate()).trim(); } else { return null; } } } return strValue; } } return null; } }
CsvExportColumnImpl implements CsvExportColumn, Serializable { @Override public String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple) { if (getValueConstant() != null) { return getValueConstant(); } else if (rawValue != null) { final String strValue = (String) adapter.fromRaw(rawValue, ImpExValues.STRING, this, tuple); if (strValue != null) { if (getPattern() != null) { Matcher matcher = getPattern().matcher(strValue); if (StringUtils.isBlank(getValueRegExTemplate())) { if (matcher.find()) { return matcher.group(getValueRegExGroup()).trim(); } else { return null; } } else { if (matcher.matches()) { return matcher.replaceFirst(getValueRegExTemplate()).trim(); } else { return null; } } } return strValue; } } return null; } CsvExportColumnImpl();  CsvExportColumnImpl(final String columnHeader, final String fieldType,
                               final String name, final String valueRegEx, final String lookupQuery); }
CsvExportColumnImpl implements CsvExportColumn, Serializable { @Override public String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple) { if (getValueConstant() != null) { return getValueConstant(); } else if (rawValue != null) { final String strValue = (String) adapter.fromRaw(rawValue, ImpExValues.STRING, this, tuple); if (strValue != null) { if (getPattern() != null) { Matcher matcher = getPattern().matcher(strValue); if (StringUtils.isBlank(getValueRegExTemplate())) { if (matcher.find()) { return matcher.group(getValueRegExGroup()).trim(); } else { return null; } } else { if (matcher.matches()) { return matcher.replaceFirst(getValueRegExTemplate()).trim(); } else { return null; } } } return strValue; } } return null; } CsvExportColumnImpl();  CsvExportColumnImpl(final String columnHeader, final String fieldType,
                               final String name, final String valueRegEx, final String lookupQuery); @Override int getGroupCount(final String rawValue); @Override String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple); @Override Object getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvImpExTuple tuple); @Override String getColumnHeader(); void setColumnHeader(final String columnHeader); @Override String getFieldType(); void setFieldType(final String fieldType); @Override String getDataType(); void setDataType(final String dataType); @Override String getName(); void setName(final String name); @Override String getValueRegEx(); void setValueRegEx(final String valueRegEx); @Override Integer getValueRegExGroup(); void setValueRegExGroup(final Integer valueRegExGroup); @Override String getValueRegExTemplate(); void setValueRegExTemplate(final String valueRegExTemplate); @Override String getLookupQuery(); void setLookupQuery(final String lookupQuery); @Override CsvExportDescriptor getDescriptor(); void setDescriptor(CsvExportDescriptor descriptor); @Override CsvExportDescriptor getParentDescriptor(); @Override void setParentDescriptor(final CsvExportDescriptor parentDescriptor); @Override boolean isUseMasterObject(); @Override void setUseMasterObject(final boolean useMasterObject); @Override String getValueConstant(); void setValueConstant(final String valueConstant); @Override String getEntityType(); void setEntityType(final String entityType); @Override String getLanguage(); void setLanguage(final String language); @Override String getContext(); void setContext(final String context); @Override String toString(); }
CsvExportColumnImpl implements CsvExportColumn, Serializable { @Override public String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple) { if (getValueConstant() != null) { return getValueConstant(); } else if (rawValue != null) { final String strValue = (String) adapter.fromRaw(rawValue, ImpExValues.STRING, this, tuple); if (strValue != null) { if (getPattern() != null) { Matcher matcher = getPattern().matcher(strValue); if (StringUtils.isBlank(getValueRegExTemplate())) { if (matcher.find()) { return matcher.group(getValueRegExGroup()).trim(); } else { return null; } } else { if (matcher.matches()) { return matcher.replaceFirst(getValueRegExTemplate()).trim(); } else { return null; } } } return strValue; } } return null; } CsvExportColumnImpl();  CsvExportColumnImpl(final String columnHeader, final String fieldType,
                               final String name, final String valueRegEx, final String lookupQuery); @Override int getGroupCount(final String rawValue); @Override String getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvExportTuple tuple); @Override Object getValue(final Object rawValue, final CsvValueAdapter adapter, final CsvImpExTuple tuple); @Override String getColumnHeader(); void setColumnHeader(final String columnHeader); @Override String getFieldType(); void setFieldType(final String fieldType); @Override String getDataType(); void setDataType(final String dataType); @Override String getName(); void setName(final String name); @Override String getValueRegEx(); void setValueRegEx(final String valueRegEx); @Override Integer getValueRegExGroup(); void setValueRegExGroup(final Integer valueRegExGroup); @Override String getValueRegExTemplate(); void setValueRegExTemplate(final String valueRegExTemplate); @Override String getLookupQuery(); void setLookupQuery(final String lookupQuery); @Override CsvExportDescriptor getDescriptor(); void setDescriptor(CsvExportDescriptor descriptor); @Override CsvExportDescriptor getParentDescriptor(); @Override void setParentDescriptor(final CsvExportDescriptor parentDescriptor); @Override boolean isUseMasterObject(); @Override void setUseMasterObject(final boolean useMasterObject); @Override String getValueConstant(); void setValueConstant(final String valueConstant); @Override String getEntityType(); void setEntityType(final String entityType); @Override String getLanguage(); void setLanguage(final String language); @Override String getContext(); void setContext(final String context); @Override String toString();  }