Skip to content
Snippets Groups Projects

CD.591: Prepare report for cables with FBS tags no longer available in CHESS

Closed Lars Johansson requested to merge task/CD-591 into master
2 files
+ 91
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -3,6 +3,7 @@ package org.openepics.cable.webservice;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -187,6 +188,8 @@ public class ReportResourceImpl implements ReportResource {
@Override
public Response reportCablesWithEssNamesWithoutFbsTags() {
// Unofficial report with cables for which ESS name but not FBS tag is used
final List<Cable> cablesToExport = cableService.getCablesWithEssNamesWithoutFbsTags();
final CableSaver cableSaver = new CableSaver(cablesToExport);
final InputStream inputStream = cableSaver.save();
@@ -207,4 +210,82 @@ public class ReportResourceImpl implements ReportResource {
}
}
@Override
public Response reportCablesFbsTagNoChessMapping() {
// Unofficial report with cables for which at least one FBS tag is without mapping in CHESS
// find fbs elements and mappings cable name to fbs element
final List<FbsElement> fbsElements = fbsService.getAllFbsElements();
Map<String, FbsElement> mappingsFbsTagToFbsElement = null;
if (!fbsElements.isEmpty()) {
mappingsFbsTagToFbsElement =
FbsUtil.readMappingsTagToFbsElement(fbsElements);
LOGGER.log(Level.INFO, "count mappings fbs tag: "
+ (mappingsFbsTagToFbsElement != null ? mappingsFbsTagToFbsElement.size() : "null"));
}
// check if fbs elements and mappings cable to fbs element available
final List<Cable> cablesToExport = new ArrayList<>();
String fbsTag = null;
String fromFbsTag = null;
String fromEnclosureFbsTag = null;
String toFbsTag = null;
String toEnclosureFbsTag = null;
// loop through cables
for (Cable cable : cableService.getCables()) {
// not consider deleted cables
if (CableStatus.DELETED.equals(cable.getStatus())) {
continue;
}
// cable
// name - fbs tag
// from endpoint
// ess name - fbs tag
// enclosure ess name - enclosure fbs tag
// to endpoint
// ess name - fbs tag
// enclosure ess name - enclosure fbs tag
fbsTag = cable.getFbsTag();
fromFbsTag = cable.getEndpointA().getDeviceFbsTag();
fromEnclosureFbsTag = cable.getEndpointA().getRackFbsTag();
toFbsTag = cable.getEndpointB().getDeviceFbsTag();
toEnclosureFbsTag = cable.getEndpointB().getRackFbsTag();
if (!StringUtils.isEmpty(fbsTag) && mappingsFbsTagToFbsElement.get(fbsTag) == null) {
cablesToExport.add(cable);
} else if (!StringUtils.isEmpty(fromFbsTag) && mappingsFbsTagToFbsElement.get(fromFbsTag) == null) {
cablesToExport.add(cable);
} else if (!StringUtils.isEmpty(fromEnclosureFbsTag) && mappingsFbsTagToFbsElement.get(fromEnclosureFbsTag) == null) {
cablesToExport.add(cable);
} else if (!StringUtils.isEmpty(toFbsTag) && mappingsFbsTagToFbsElement.get(toFbsTag) == null) {
cablesToExport.add(cable);
} else if (!StringUtils.isEmpty(toEnclosureFbsTag) && mappingsFbsTagToFbsElement.get(toEnclosureFbsTag) == null) {
cablesToExport.add(cable);
}
}
final CableSaver cableSaver = new CableSaver(cablesToExport);
final InputStream inputStream = cableSaver.save();
try {
byte[] bytes = IOUtils.toByteArray(inputStream);
return Response.ok()
.entity(bytes)
.header("Content-Disposition", "attachment; filename=\"cdb_cables.xlsx\"")
.type(MediaType.APPLICATION_OCTET_STREAM)
.build();
} catch (Exception e) {
LOGGER.log(Level.INFO,
"Report for cables with FBS tag(s) without mapping in CHESS "
+ "could not be made available, message: " + e.getMessage());
return null;
}
}
}
Loading