1 package org.argeo.people.core.imports;
2
3 import java.util.Map;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7
8 import org.argeo.connect.util.ConnectJcrUtils;
9 import org.argeo.people.PeopleConstants;
10 import org.argeo.people.PeopleException;
11 import org.argeo.util.CsvParserWithLinesAsMap;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class TemplateCatalogueCsvFileParser extends CsvParserWithLinesAsMap {
27
28 private final Node node;
29 private final static String SINGLE_VALUE_PROP_PREFIX = "single:";
30
31 public TemplateCatalogueCsvFileParser(Node node) {
32 super();
33 this.node = node;
34 }
35
36 @Override
37 protected void processLine(Integer lineNumber, Map<String, String> line) {
38 try {
39 String propName = line
40 .get(PeopleConstants.IMPORT_CATALOGUE_KEY_COL);
41 String valuesStr = line
42 .get(PeopleConstants.IMPORT_CATALOGUE_VALUES_COL);
43
44 if (propName.startsWith(SINGLE_VALUE_PROP_PREFIX)) {
45 node.setProperty(
46 propName.substring(SINGLE_VALUE_PROP_PREFIX.length()),
47 valuesStr);
48 } else {
49 String[] values = ConnectJcrUtils
50 .parseAndClean(
51 valuesStr,
52 PeopleConstants.IMPORT_CATALOGUE_VALUES_SEPARATOR,
53 true);
54 node.setProperty(propName, values);
55 }
56 } catch (RepositoryException e) {
57 throw new PeopleException("Cannot process line " + lineNumber + " "
58 + line, e);
59 }
60 }
61 }