Search code examples
javaremedy

Update "categorization" with Java API BMC Remedy before closing incident


I have an inherited project, a BMC Remedy application and never worked with this Remedy stuff. This project modifies Incidents and Work Orders from remedy through the Remedy API. I have literally no idea on this.

There's a process that closes incidents that are in resolved state and have not been modified in the last 36 hours. Sometimes, those incidents have the 'categorization' field empty, and the client wants to fill this categorization before closing it.

This is part of the code:

Connection to Remedy:

public static void main(String args[]) {

        // Inicializamos el logger
        java.util.logging.LogManager.getLogManager().reset();

        try {

            // Nos conectamos a Remedy y a MySQL
            LOGGER.info("Conectando a bases de datos");
            if (!connect()) {
                throw new Exception("Fallo al conectar a Remedy o a MySQL");
            }

            // Metodo para cerrar incidecias resueltas
            remedy.cerrarIncidencias(sql.queryResueltas36h());
            
            // Desconectamos de Remedy y MySQL
            disconnect();

        } catch (Exception e) {
            LOGGER.error("Error critico: ", e);
            try {
                remedy.desconectar();
            } catch (Exception e1) {
            }
            try {
                sql.desconectar();
            } catch (Exception e1) {
            }
        }
    }

Function to closing incidents:

public void cerrarIncidencias(List<String> incs) throws Exception {
        int contador = 1;
        for (String inc : incs) {
            try {

                // Obtenemos la incidencia
                QualifierInfo qual = server.parseQualification("HPD:Help Desk", "'Incident Number' = \"" + inc + "\"");
                List<Entry> entries = server.getListEntryObjects("HPD:Help Desk", qual, 0, 0, null,
                        Constantes.CAMPOS_HPD_HELP_DESK_CERRAR_INCIDENCIA, false, null);

                // Rellenamos un comentario generico
                Entry comment = new Entry();
                comment.put(Constantes.HPD_WORKLOG_DETAILED_DESCRIPTION, new Value("Cierre automatico tras 36 horas en resuelto."));
                comment.put(Constantes.HPD_WORKLOG_INCIDENT_NUMBER, new Value(inc));
                comment.put(Constantes.HPD_WORKLOG_DESCRIPTION, new Value("----"));
                comment.put(Constantes.HPD_WORKLOG_WORKLOG_TYPE, new Value(8000));

                for (Entry entry : entries) {
                    entry.put(Constantes.HPD_HELP_DESK_STATUS, new Value(5)); // Estado a cerrado
                    if (entry.get(Constantes.HPD_HELP_DESK_ASSIGNEE_LOGIN_ID).getValue() == null) {
                        entry.put(Constantes.HPD_HELP_DESK_ASSIGNEE_LOGIN_ID, new Value("lmoren70"));
                        entry.put(Constantes.HPD_HELP_DESK_ASSIGNEE, new Value("Luis Manuel Moreno Rodriguez")); // Usuario asignado
                    }
                    server.setEntry("HPD:Help Desk", entry.getEntryId(), entry, null, 0);
                    server.createEntry("HPD:WorkLog", comment);
                    LOGGER.info("Incidencia " + inc + " cerrada con exito - " + contador + " de " + incs.size());
                }
            } catch (Exception e) {
                LOGGER.error("Incidencia " + inc + " NO se ha podido cerrar - " + contador + " de " + incs.size() + "\n"
                        + e.getMessage());
            }
            contador++;
        }
    }

Query: I thought to do an update directly to the database BUT this database reads from Remedy, so I have to update Remedy.

public List<String> queryResueltas36h() {
        String query = "SELECT inc FROM vdf_tickets, vdf_groups WHERE status = 'Resuelto' AND LENGTH(inc) > 9 "
                + "AND vdf_groups.group = creator_group AND (vdf_groups.categorization = 'TES' OR vdf_groups.group IN ('TES', 'ARCA', 'NetOps TES Assurance')) "
                + "AND last_resolved_date < DATE_ADD(NOW(), INTERVAL -36 HOUR) ORDER BY inc DESC";
        List<String> incs = new ArrayList<String>();
        try {
            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
                String inc = rs.getString("inc");
                incs.add(inc);
            }
            stmt.close();
        } catch (Exception e) {
            LOGGER.error("Error al obtener lista de incidencias de la base de datos", e);
            try {
                stmt.close();
            } catch (Exception e1) {
            }
        }
        return incs;
    }

What I want is to put the categorization to 'TES', in case there's no categorization.

One option I thought is to do an automation with Selenium and Python and not touching this code, but is far better to have all in the same project.


Solution

  • You need to update your cerrarIncidencias function. But first you need to ask what categorisation you need to update.

    There are three levels of categorisation.

    1. Operational Categorisation
    2. Product Categorisation
    3. Resolution Categorisation

    So decide which one you want to populate and get the field id for that field. For this example, I will say Categorisation Tier 1 which is 1000000063 You'll need to add to CAMPOS_HPD_HELP_DESK_CATEGORISATION_TIER1=1000000063 to your Constantes file.

    Then in your block

    for (Entry entry : entries)
    

    You need something like:

    if (entry.get(Constantes.CAMPOS_HPD_HELP_DESK_CATEGORISATION_TIER1).getValue() == null) {
        entry.put(Constantes.CAMPOS_HPD_HELP_DESK_CATEGORISATION_TIER1, new Value("Your Value for Categorisation Tier 1"));
    }