@* * Copyright (c) 2024 SEP AG * All Rights Reserved. * * The source and all intellectual and technical concepts contained * herein is and remains the property of SEP AG and may be covered * by U.S., German and Foreign Patents. Any distribution, use and * modification is strictly forbidden unless prior written permission * is obtained from SEP AG. *@ @args() { List location_ids List client_ids Map> clients List> items List> tcitems Map info Locale locale Boolean csv String sep String date_column String fromDate String toDate String defaultDataSize de.sep.sesam.util.RendererUtils rendererUtils } @*Queries: * [ * { * "paramName" : "location_ids", * "condition" : [ * "@// @(exist:location_ids,list)", * "@// @(exist:client_ids,list)", * "@returnIf((location_ids != null && !location_ids.isEmpty()) || (client_ids != null && !client_ids.isEmpty()))" * ], * "query" : [ * "SELECT", * "id", * "FROM", * "locations" * ], * "converter" : [ * "toList(id)" * ] * }, * { * "paramName" : "client_ids", * "condition" : [ * "@returnIf(location_ids == null || location_ids.isEmpty())" * ], * "query" : [ * "SELECT", * "client_id", * "FROM", * "clients", * "WHERE", * "location in (WITH RECURSIVE children(id) AS (SELECT l.id FROM locations l WHERE l.id in @(sqlList:@(location_ids))", * "UNION ALL SELECT l.id from children c,locations l where l.parent=c.id) SELECT * FROM children)" * ], * "converter" : [ * "toList(client_id)" * ] * }, * { * "paramName" : "clients", * "condition" : [ * "@returnIf(client_ids == null || client_ids.isEmpty())" * ], * "query" : [ * "SELECT", * "clients.client_id,", * "clients.name as name,", * "locations.name as location,", * "clients.os as os,", * "clients.sesam_version as version", * "FROM", * "clients, locations", * "WHERE", * "clients.client_id in @(sqlList:@(client_ids))", * "AND", * "locations.id = clients.location", * "ORDER BY", * "locations.name, clients.client_id" * ], * "converter" : [ * "toMap(client_id)" * ] * }, * { * "paramName" : "tcitems", * "dateRangeSourceTable" : "tc", * "query" : [ * "SELECT", * "tc.tasks_client_id,", * "tc.client_id,", * "tc.name,", * "tc.task,", * "tc.source as task_source,", * "tc.accessmode,", * "tc.location", * "FROM", * "tasks_clients tc", * "WHERE", * "(tc.tasks_client_id <> tc.client_id)" * ] * }, * { * "paramName" : "items", * "dateRangeSourceTable" : "r", * "condition" : [ * "@returnIf(client_ids == null || client_ids.isEmpty())" * ], * "query" : [ * "SELECT", * "r.client_id,", * "r.task,", * "r.backup_type,", * "t.source as task_source,", * "rl.saveset as saveset_id,", * "rl.pool as media_pool,", * "r.data_size", * "FROM", * "results r", * "LEFT OUTER JOIN (", * "SELECT saveset,backup_id,label,pool FROM result_lbls", * ") AS rl ON r.saveset = rl.backup_id", * "LEFT OUTER JOIN (", * "SELECT task,source FROM tasks", * ") AS t ON r.task = t.task", * "WHERE", * "@(dateRange:@(date_column))", * "AND", * "r.data_size is not null", * "ORDER BY", * "r.client_id, r.task, r.media_pool" * ] * } * ] *@ @include("../commons/tags.html") @include("../commons/functions.html") @{ if (sep.equals("")) { // Default separator is TAB sep = "\t"; } } @if(!csv) { @i18n("Document.Title") @include("../commons/styles.html") @include("../commons/images.html") @sepReportHeader("SEP Report")

@sepTitleBox("Title", sepFnGetToday(locale), "") @if (date_column == "sesam_date") { @sepDateRangeLabel(sepFnGetDate(sepFnStringToDate(fromDate), locale), sepFnGetDate(sepFnStringToDate(toDate), locale), date_column) } else { @sepDateRangeLabel(sepFnGetDateLong(sepFnStringToDate(fromDate), locale), sepFnGetDateLong(sepFnStringToDate(toDate), locale), date_column) } @returnIf(clients == null || clients.isEmpty()) @returnIf(items == null || items.isEmpty()) @// ====== BEGIN OF CODE ADDED BY KRI } @{ // create list of clients with virtual clients List virtuals = new ArrayList<>(); // List of clients with virtual clients List virtuals1 = new ArrayList<>(); // List of virtuals clients for (Map tcitem : tcitems) { Long cl_id; String accessmode; cl_id = (Long) tcitem.get("tasks_client_id"); if ( !virtuals.contains(cl_id) ) { virtuals.add(cl_id); } cl_id = (Long) tcitem.get("client_id"); accessmode = String.valueOf(tcitem.get("accessmode")); // it is a virtual client if 'tasks_client_id' is different to 'client_id' if ( !virtuals1.contains(cl_id) && accessmode.equals("VIRTUAL") ) { virtuals1.add(cl_id); } } // search for clients with virtual clients in the backup tasks String xx = "
======================================="; Map>> ListOfLists = new HashMap<>(); Map idxlist = new HashMap<>(); Long idx = 0L; for (Map item : items) { Long cl_id, vcl_id; String cl_id_s; cl_id = (Long) item.get("client_id"); if (virtuals.contains(cl_id)) { // if it is a client with virtual clients check if there are associated tasks for (Map tcitem : tcitems) { if ( String.valueOf(item.get("task")).equals(String.valueOf(tcitem.get("task"))) ) { // task found in 'tasks_clients' if ( cl_id == (Long) tcitem.get("tasks_client_id")) { vcl_id = (Long)tcitem.get("client_id"); // xx = xx + "
Virtual id=" + vcl_id + ": " + cl_id + " -- " + item.get("task"); // Client of this job is a virtual client because there is a different 'tasks_client_id' in 'tasks_clients' // Now copy most of the task dataset and adapt 'client_id', 'location' and 'client' fields to the virtual client // At the end append this new dataset to a templist which will be nserted or appended to the job list 'items' List> templist = new ArrayList<>(); Map tempelement = new HashMap<>(); tempelement.put("client_id", tcitem.get("client_id")); tempelement.put("task", item.get("task")); tempelement.put("task_source", item.get("task_source")); tempelement.put("saveset", item.get("saveset")); tempelement.put("data_size", item.get("data_size")); tempelement.put("media_pool", item.get("media_pool")); tempelement.put("backup_type", item.get("backup_type")); if ( ListOfLists.get( vcl_id ) == null ) { templist.add(tempelement); ListOfLists.put(vcl_id, templist); } else { ListOfLists.get(vcl_id).add(tempelement); } // xx = xx + "
=== templist: " + templist.size(); // xx = xx + "
=== ListOfLists: " + vcl_id + ": " + ListOfLists.get(vcl_id).size(); // xx = xx + "
=== ListOfLists: " + ListOfLists.size(); } } } } // save index where tasks for all client_ids statrts for later insert of virtual tasks if (client_ids.contains(cl_id)) { idxlist.put(cl_id, idx); } idx = idx + 1L; } xx = xx + "

====================================="; for (Long key : ListOfLists.keySet() ) { // key is the virtual client id idx = idxlist.get(key); if (idx==null) { // xx = xx + "
addAll key: " + key + " -- " + idx + " -- " + ListOfLists.get(key).size(); items.addAll(ListOfLists.get(key)); } else { // xx = xx + "
addObj key: " + key + " -- " + idx + " -- " + ListOfLists.get(key).size(); for (Map obj : ListOfLists.get(key) ) { items.add(Long.valueOf(idx).intValue(), obj); } } } } @if(!csv) { } @// ========= END OF CODE ADDED BY KRI ========== @{ Object client_id = null; String client_name = null; String client_location = null; long total = 0; long all_total = 0; String task = null; String pool = null; boolean hasOpenTable = false; boolean printLocationInfo = false; String csvout = ""; String cl_name = ""; String cl_location = ""; String backup_type = ""; String taskSource = ""; } @for (Map item : items) { @{ Object key = item.get("client_id"); boolean newClient = false; if (!client_ids.contains(key)) { continue; } if (client_id == null || !client_id.equals(key)) { newClient = true; client_id = key; } String previousClientLocation = client_location; Map client = clients.get(key); client_name = client != null ? String.valueOf(client.get("name")) : "-"; client_location = client != null ? String.valueOf(client.get("location")) : "-"; String client_os = client != null ? String.valueOf(client.get("os")) : "-"; String client_version = client != null ? String.valueOf(client.get("version")) : "-"; if ("null".equalsIgnoreCase(client_name)) { client_name = "-"; } if ("null".equalsIgnoreCase(client_location)) { client_location = "-"; } if ("null".equalsIgnoreCase(client_os)) { client_os = "-"; } if ("null".equalsIgnoreCase(client_version)) { client_version = "-"; } if (location_ids != null && !location_ids.isEmpty()) { if (previousClientLocation == null || !previousClientLocation.equals(client_location)) { printLocationInfo = true; } } } @if(newClient) { @if(hasOpenTable) { @if(task) { @{ all_total += total; } @// ====== output ===== @if(!csv) { @(task) @(taskSource) @(pool) @sepFnFormatBytes(rendererUtils, total, defaultDataSize) } else { @{ csvout = csvout + cl_name + sep + cl_location + sep + task + sep + taskSource + sep + pool + sep + backup_type + sep + total + sep + sepFnFormatBytes(rendererUtils, total, defaultDataSize).trim() + sep + sep + "\n"; } } } @// ====== output ===== @if(!csv) { @i18n("Summary.Total"): @sepFnFormatBytes(rendererUtils, all_total, defaultDataSize) } else { @{ csvout = csvout + cl_name + sep + cl_location + sep + sep + sep + sep + sep + sep + sep + all_total + sep + sepFnFormatBytes(rendererUtils, all_total, defaultDataSize).trim() + "\n"; } } @{ hasOpenTable = false; } } @{ total = 0; all_total = 0; task = null; pool = null; } @if(printLocationInfo) { @// ====== output ===== @if(!csv) { @sepTitleLabel("Client.Info.Location", " " + client_location) } @{ printLocationInfo = false; } } @{ cl_name = client_name; cl_location = client_location; if (virtuals1.contains(key)) { client_name = client_name + " (VIRTUAL)"; } } @// ====== output ===== @if(!csv) { @sepTitleLabel("Client.Info.Name", " " + client_name) @sepInfoLabel("Client.Info.Location", client_location) @sepInfoLabel("Client.Info.OS", client_os) @sepInfoLabel("Client.Info.Version", client_version)

} @{ hasOpenTable = true; } } @{ boolean doRenderRow = false; String currentTask = String.valueOf(item.get("task")); String currentPool = String.valueOf(item.get("media_pool")); Object currentDataSize = item.get("data_size"); String currentTaskSource = String.valueOf(item.get("task_source")); backup_type = String.valueOf(item.get("backup_type")); if (task == null || (currentTask != null && currentTask.equals(task) && currentPool != null && currentPool.equals(pool))) { task = currentTask; if (currentDataSize != null) { total += Long.valueOf(String.valueOf(currentDataSize)); } pool = currentPool; taskSource = currentTaskSource; } else{ doRenderRow = true; } } @if(doRenderRow) { @{ all_total += total; } @// ====== output ===== @if(!csv) { } else { @{ csvout = csvout + cl_name + sep + cl_location + sep + task + sep + taskSource + sep + pool + sep + backup_type + sep + total + sep + sepFnFormatBytes(rendererUtils, total, defaultDataSize).trim() + sep + sep + "\n"; } } @{ total = 0; task = currentTask; if (currentDataSize != null) { total += Long.valueOf(String.valueOf(currentDataSize)); } pool = currentPool; taskSource = currentTaskSource; } } } @if(hasOpenTable) { @if(task) { @{ all_total += total; } @// ====== output ===== @if(!csv) { } else { @{ csvout = csvout + cl_name + sep + cl_location + sep + task + sep + taskSource + sep + pool + sep + backup_type + sep + total + sep + sepFnFormatBytes(rendererUtils, total, defaultDataSize).trim() + sep + sep + "\n"; } } } @// ====== output ===== @if(!csv) {
@i18n("Column.Task") @i18n("Column.Source") @i18n("Column.Pool") @i18n("Column.Size")
@(task) @(taskSource) @(pool) @sepFnFormatBytes(rendererUtils, total, defaultDataSize)
@(task) @(taskSource) @(pool) @sepFnFormatBytes(rendererUtils, total, defaultDataSize)
@i18n("Summary.Total"): @sepFnFormatBytes(rendererUtils, all_total, defaultDataSize)
} else { @{ csvout = csvout + cl_name + sep + cl_location + sep + sep + sep + sep + sep + sep + sep + all_total + sep + sepFnFormatBytes(rendererUtils, all_total, defaultDataSize).trim() + "\n"; } } @{ hasOpenTable = false; } } @// ====== output ===== @if(!csv) { } else { @(csvout) }