/** Searches for objects to return based on the filter provided with offset and limit features. */ public void executeQuery( ObjectClass oclass, String query, ResultsHandler handler, OperationOptions options) { /** Track the number of lines processed. */ long lines = 0; /** Text qualifier character. */ final char textQualifier = cfg.getTextQualifier(); /** Field delimiter. */ final char fieldSeparator = cfg.getFieldDelimiter(); /** Unique identifier field. */ final String uniqueIdField = cfg.getUniqueAttributeName(); /** Internal reader initialized in the constructor. */ BufferedReader rdr = null; try { rdr = cfg.newFileReader(); /** Fields names read from the header. */ List<String> fieldNames = FlatFileConnector.readHeader(rdr, fieldSeparator, textQualifier, uniqueIdField); String line; while ((line = rdr.readLine()) != null) { ++lines; if (line.trim().length() == 0) { LOG.info(MSG_SKIPPING); continue; } LOG.ok("Processing Data Line: {0}", line); List<String> fieldValues = StringUtil.parseLine(line, fieldSeparator, textQualifier); if (fieldValues == null) { LOG.error("Error: {0}", line); break; } else { ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); for (int i = 0; i < fieldValues.size(); ++i) { String name = fieldNames.get(i); String value = fieldValues.get(i); if (name.equals(uniqueIdField)) { bld.setUid(value); bld.setName(value); } else { bld.addAttribute(name, value); } } // create the connector object.. ConnectorObject ret = bld.build(); if (!handler.handle(ret)) { break; } } } } catch (IOException e) { throw new ConnectorIOException(e); } finally { IOUtil.quietClose(rdr); } }
static { ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); for (int i = 0; i < 100; i++) { bld.setUid(Integer.toString(i)); bld.setName(Integer.toString(i)); objects.add(bld.build()); } };
static { boolean enabled = true; for (int i = 0; i < 100; i++) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setUid(String.valueOf(i)); builder.setName(String.format("user%03d", i)); builder.addAttribute(AttributeBuilder.buildEnabled(enabled)); Map<String, Object> mapAttribute = new HashMap<String, Object>(); mapAttribute.put("email", "*****@*****.**"); mapAttribute.put("primary", true); mapAttribute.put("usage", Arrays.asList("home", "work")); builder.addAttribute(AttributeBuilder.build("emails", mapAttribute)); ConnectorObject co = builder.build(); collection.put(co.getName().getNameValue(), co); enabled = !enabled; } }