diff --git a/src/main/java/com/evolveum/polygon/connector/csv/CsvConfiguration.java b/src/main/java/com/evolveum/polygon/connector/csv/CsvConfiguration.java index aff9366..c2d3925 100644 --- a/src/main/java/com/evolveum/polygon/connector/csv/CsvConfiguration.java +++ b/src/main/java/com/evolveum/polygon/connector/csv/CsvConfiguration.java @@ -155,6 +155,13 @@ public boolean isHeaderExists() { return config.isHeaderExists(); } + @ConfigurationProperty( + displayMessageKey = "UI_CSV_HEADER_ROW", + helpMessageKey = "UI_CSV_HEADER_ROW_HELP") + public int getHeaderRow() { + return config.getHeaderRow(); + } + @ConfigurationProperty( displayMessageKey = "UI_CSV_READ_ONLY", helpMessageKey = "UI_CSV_READ_ONLY_HELP") @@ -188,6 +195,10 @@ public void setHeaderExists(boolean headerExists) { config.setHeaderExists(headerExists); } + public void setHeaderRow(int headerRow) { + config.setHeaderRow(headerRow); + } + public void setObjectClassDefinition(File objectClassDefinition) { this.objectClassDefinition = objectClassDefinition; } diff --git a/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandler.java b/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandler.java index 23d5c14..5c14821 100644 --- a/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandler.java +++ b/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandler.java @@ -58,9 +58,9 @@ private Map initHeader(File csvFile) { Iterator iterator = parser.iterator(); CSVRecord record = null; - while (iterator.hasNext()) { + for (int i = 1; i <= configuration.getHeaderRow() && iterator.hasNext(); i++) { record = iterator.next(); - if (!isRecordEmpty(record)) { + if (i == configuration.getHeaderRow() && !isRecordEmpty(record)) { break; } } @@ -270,7 +270,7 @@ public Uid create(ObjectClass oc, Set set, OperationOptions oo) { // we don't want to skip header in any case, but if it's there just // write it to tmp file as "standard" record. We can't handle first row // as header in case there are more columns with the same name. - if (configuration.isHeaderExists() && iterator.hasNext()) { + for (int i = 1; i <= configuration.getHeaderRow() && iterator.hasNext(); i++) { CSVRecord record = iterator.next(); printer.printRecord(record); } @@ -389,7 +389,7 @@ public FilterTranslator createFilterTranslator(ObjectClass oc, Operation } private boolean skipRecord(CSVRecord record) { - if (configuration.isHeaderExists() && record.getRecordNumber() == 1) { + if (configuration.isHeaderExists() && record.getRecordNumber() <= configuration.getHeaderRow()) { return true; } diff --git a/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandlerConfiguration.java b/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandlerConfiguration.java index 16506d2..31cfe63 100644 --- a/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandlerConfiguration.java +++ b/src/main/java/com/evolveum/polygon/connector/csv/ObjectClassHandlerConfiguration.java @@ -35,6 +35,7 @@ public class ObjectClassHandlerConfiguration { private boolean trailingDelimiter = false; private boolean trim = false; private boolean headerExists = true; + private int headerRow = 1; private String uniqueAttribute; private String nameAttribute; @@ -71,6 +72,7 @@ public ObjectClassHandlerConfiguration(ObjectClass oc, Map value setTrailingDelimiter(Util.getSafeValue(values, "trailingDelimiter", false, Boolean.class)); setTrim(Util.getSafeValue(values, "trim", false, Boolean.class)); setHeaderExists(Util.getSafeValue(values, "headerExists", true, Boolean.class)); + setHeaderRow(Util.getSafeValue(values, "headerRow", 1, Integer.class)); setUniqueAttribute(Util.getSafeValue(values, "uniqueAttribute", null, String.class)); setNameAttribute(Util.getSafeValue(values, "nameAttribute", null, String.class)); @@ -119,6 +121,14 @@ public void setHeaderExists(boolean headerExists) { this.headerExists = headerExists; } + public int getHeaderRow() { + return headerRow; + } + + public void setHeaderRow(int headerRow) { + this.headerRow = headerRow; + } + public ObjectClass getObjectClass() { return objectClass; } diff --git a/src/main/resources/com/evolveum/polygon/connector/csv/Messages.properties b/src/main/resources/com/evolveum/polygon/connector/csv/Messages.properties index 3648eb8..86f99a1 100644 --- a/src/main/resources/com/evolveum/polygon/connector/csv/Messages.properties +++ b/src/main/resources/com/evolveum/polygon/connector/csv/Messages.properties @@ -37,6 +37,8 @@ UI_CSV_OBJECT_CLASS_DEFINITION=Object class definition UI_CSV_OBJECT_CLASS_DEFINITION_HELP=File which contains definitions for other object classes. UI_CSV_HEADER_EXISTS=Header exists UI_CSV_HEADER_EXISTS_HELP=Whether header exists in csv file. +UI_CSV_HEADER_ROW=Header row +UI_CSV_HEADER_ROW_HELP=Which row the header is on in the csv. Default value is 1. UI_CSV_TMP_FOLDER=Tmp folder UI_CSV_TMP_FOLDER_HELP=Folder where csv connector can write temporary files. By default the same folder as where csv file resides. UI_CSV_READ_ONLY=Read only