Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/efrain-svg/Potes_Freddy_ProgInterfacesG_U3/llms.txt

Use this file to discover all available pages before exploring further.

personaDAO handles all file I/O for the Contact Management App. It reads and writes contacts as semicolon-delimited CSV records, manages the storage directory automatically, and supports both the current six-column format and a legacy five-column format left over from earlier versions of the application. It also provides two overloaded exportarCsv methods used by the controller when the user requests a one-off export to a chosen destination.

Storage location

The data file is always created at a fixed path:
c:/gestionContactos/datosContactos.csv
This path is hardcoded in the constructor and works on Windows. On Linux or macOS the drive letter prefix c:/ is not valid. See the manual build guide for details on this limitation.
The constructor creates both the directory and the file if either is absent, and writes the header row on first creation.

CSV format

NOMBRE;TELEFONO;EMAIL;CATEGORIA;FAVORITO;FECHA_REGISTRO
Ana Torres;555-0101;[email protected];FAMILY;true;2024-03-15
ColumnIndexTypeNotes
NOMBRE0StringContact’s full name
TELEFONO1StringPhone number, stored as-is
EMAIL2StringEmail address
CATEGORIA3StringStored as canonical code: FAMILY, FRIENDS, or WORK
FAVORITO4Boolean string"true" or "false"
FECHA_REGISTRO5ISO-8601 dateyyyy-MM-dd — absent in legacy files
The separator for the internal data file is ;. Exported files also use ; as the separator.

Constructor

src/modelo/personaDAO.java
public personaDAO(persona persona) {
    this.persona = persona;
    File base = new File("c:/gestionContactos");
    if (!base.exists()) {
        base.mkdirs();
    }
    archivo = new File(base.getAbsolutePath(), "datosContactos.csv");
    prepararArchivo();
}
prepararArchivo() checks whether the file exists. If not, it calls archivo.createNewFile() and immediately appends the current header row (NOMBRE;TELEFONO;EMAIL;CATEGORIA;FAVORITO;FECHA_REGISTRO).

Public methods

escribirArchivo()

public boolean escribirArchivo()
Appends the current persona instance’s datosContacto() line to the file. Returns false if the internal persona reference is null. This method is used for single-record appends; bulk saves use actualizarContactos().
Parameter
Returnstrue on success, false if persona is null

leerArchivo()

public List<persona> leerArchivo() throws IOException
Reads the entire file into a StringBuilder, splits on line endings (\r?\n), and parses each non-empty, non-header line into a persona object. Lines with fewer than 5 columns are silently skipped.
src/modelo/personaDAO.java
String[] columnas = registro.split(";");
if (columnas.length < 5) {
    continue;
}

persona p = new persona();
p.setNombre(columnas[0]);
p.setTelefono(columnas[1]);
p.setEmail(columnas[2]);
p.setCategoria(normalizarCategoria(columnas[3]));
p.setFavorito(Boolean.parseBoolean(columnas[4]));

if (columnas.length >= 6) {
    try {
        p.setFechaRegistro(LocalDate.parse(columnas[5]));
    } catch (DateTimeParseException ex) {
        p.setFechaRegistro(LocalDate.now());
    }
} else {
    // Legacy 5-column file: default registration date to today
    p.setFechaRegistro(LocalDate.now());
}
Backward compatibility: files with only five columns (no FECHA_REGISTRO) are handled by the else branch — the registration date defaults to today. Unparseable date strings also fall back to today via DateTimeParseException catch.
Parameter
ReturnsList<persona> — all valid contacts in file order
ThrowsIOException — if the file cannot be read

actualizarContactos(List<persona> personas)

public void actualizarContactos(List<persona> personas) throws IOException
Rewrites the entire data file. Opens a PrintWriter (which truncates the file), writes the current header, then writes one line per persona using p.datosContacto().
ParameterTypeDescription
personasList<persona>Complete contact list to persist
ThrowsIOExceptionIf the file cannot be written
This method performs a full rewrite on every save. For the expected contact list sizes of a desktop address book this is appropriate; there is no partial-update or append strategy for edits and deletes.

exportarCsv(File destino, List<persona> personas)

public void exportarCsv(File destino, List<persona> personas) throws IOException
Convenience overload that builds default English lowercase headers (nombre, telefono, email, categoria, favorito, fecha_registro) and raw field values, then delegates to the two-argument overload below.
ParameterTypeDescription
destinoFileTarget file path chosen by the user
personasList<persona>Contacts to export
ThrowsIOExceptionIf the file cannot be written

exportarCsv(File destino, String[] cabeceras, List<String[]> filas)

public void exportarCsv(File destino, String[] cabeceras, List<String[]> filas) throws IOException
The primary export method. Throws FileNotFoundException if destino is null. Writes cabeceras as the first row, then each String[] in filas as a subsequent row, with CSV escaping applied to every field.
ParameterTypeDescription
destinoFileTarget file path
cabecerasString[]Column header row
filasList<String[]>Data rows, one array per contact
ThrowsFileNotFoundExceptionIf destino is null
ThrowsIOExceptionIf the file cannot be written
The controller builds the cabeceras and filas arguments using the current i18n labels, so exported files are localised to the active language at time of export.

Category normalisation

normalizarCategoria(String valor) is called on every value read from column 3 to canonicalise multilingual or mixed-case category strings:
Input strings (case-insensitive)Canonical code
FAMILY, Familia, FamilyFAMILY
FRIENDS, Amigos, FriendsFRIENDS
WORK, Trabajo, TrabalhoWORK
Anything elseReturned as-is (trimmed)
This allows CSV files edited manually or imported from earlier versions with Spanish category names to be read correctly.

CSV escaping

escaparCsv(String valor) wraps a field in double-quotes and doubles any internal double-quotes when the value contains a semicolon, a double-quote, or a newline character:
src/modelo/personaDAO.java
private String escaparCsv(String valor) {
    String limpio = valor == null ? "" : valor;
    if (limpio.indexOf(SEPARADOR_EXPORTACION) >= 0
            || limpio.contains("\"")
            || limpio.contains("\n")) {
        limpio = limpio.replace("\"", "\"\"");
        return "\"" + limpio + "\"";
    }
    return limpio;
}
null values are treated as empty strings before escaping.

Build docs developers (and LLMs) love