- Fix Sonar issues in the classes : UpdatePropertyToolInternal, MigratePserverAndPnfEquipType,
UniquePropertyCheck, AuditOXM, PrintVertexDetails, DataGroomingTasks,
DeletePInterface, MigrateDataFromASDCToConfiguration, MigrateSAREvcInventory,
MigrateModelVer, PserverDedupWithDifferentSourcesOfTruth, GenericQueryProcessor,
DataExportTasks
Issue-ID: AAI-2963
Signed-off-by: Rodrigo Lima <rodrigo.lima@yoppworks.com>
Change-Id: I76ff744153805a009d8378b9839f83456d9ebe5c
public class DataExportTasks {
private static final Logger LOGGER;
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+
+ private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
static {
System.setProperty("aai.service.name", DataExportTasks.class.getSimpleName());
if ( "false".equalsIgnoreCase(enableMultipleSnapshots)){
// find the second to latest data snapshot
snapshot = findSnapshot();
- snapshotFilePath = snapshot.getAbsolutePath();
+ snapshotFilePath = snapshot != null ?snapshot.getAbsolutePath() : null;
if ( "true".equalsIgnoreCase (enablePartialGraph) ) {
String[] command = new String[2];
command[0] = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "bin" + AAIConstants.AAI_FILESEP + "dynamicPayloadPartial.sh";
private AaiScheduledTaskAuditLog auditLog;
private static final Logger LOGGER = LoggerFactory.getLogger(DataGroomingTasks.class);
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+ private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Autowired
private LoaderFactory loaderFactory;
if (debugOn) {
// This is much slower, but sometimes we need to find out which single line is
// causing a failure
- try {
+ try(FileOutputStream subFileStr = new FileOutputStream(fname)) {
int okCount = 0;
int failCount = 0;
Long debugDelayMsL = new Long(debugDelayMs);
- FileOutputStream subFileStr = new FileOutputStream(fname);
GraphWriter graphWriter = null;
if ("gryo".equalsIgnoreCase(snapshotType)) {
+ "], aai-uri = [" + aaiUri + "]. ";
System.out.println(fmsg);
LOGGER.debug(" PrintVertexDetails " + fmsg);
- // e.printStackTrace();
}
}
System.out.println(" -- Printed " + okCount + " vertexes out to " + fname + ", with " + failCount
+ " failed.");
- subFileStr.close();
} catch (Exception e) {
AAIException ae = new AAIException("AAI_6128", e , "Error running PrintVertexDetails in debugon");
ErrorLogHelper.logException(ae);
vtxList.add(gt.next());
}
- try {
+ try(FileOutputStream subFileStr = new FileOutputStream(fname)) {
int count = vtxList.size();
Iterator<Vertex> vSubItr = vtxList.iterator();
- FileOutputStream subFileStr = new FileOutputStream(fname);
if ("gryo".equalsIgnoreCase(snapshotType)) {
jg.io(IoCore.gryo()).writer().create().writeVertices(subFileStr, vSubItr, Direction.BOTH);
} else {
jg.io(IoCore.graphson()).writer().create().writeVertices(subFileStr, vSubItr, Direction.BOTH);
}
- subFileStr.close();
String pmsg = " -- Printed " + count + " vertexes out to " + fname;
System.out.println(pmsg);
LOGGER.debug(" PrintVertexDetails " + pmsg);
if (namespace == null) {
namespace = "";
}
- boolean isTopLevel = namespace != "";
+ boolean isTopLevel = !namespace.isEmpty();
List<String> unique = Arrays.asList(uniqueProps.split(","));
Set<String> indexed = temp.getIndexedProperties();
Set<String> keys = temp.getKeys();
if (filePath != null && !filePath.isEmpty()) {
// Add vertex Ids listed from the given file name
- try {
+ try(BufferedReader br = new BufferedReader(new FileReader(filePath))) {
logAndPrint("Loading file at: " + filePath);
- BufferedReader br = new BufferedReader(new FileReader(filePath));
+
StringBuilder sb = new StringBuilder();
String nextLine = br.readLine();
}
String allVertexIdsString = sb.toString();
logAndPrint("All vertex IDs from file " + filePath + ":\n" + allVertexIdsString);
- br.close();
} catch (IOException ioe) {
logErrorAndPrint("ERROR reading in text file failed.", ioe);
}
if (cousins == null || cousins.isEmpty()) {
if (children == null || children.isEmpty()) {
logger.info("Delete p-interface: " + getVertexURI(pInterfV));
- pInterfV.remove();
+ if(pInterfV != null) pInterfV.remove();
count++;
} else {
skipCount++;
logger.error("Found Exception" , a);
} finally {
try {
- br.close();
+ if(br !=null) br.close();
} catch (IOException e) {
success = false;
logger.error("Found Exception" , e);
private Vertex createNewConfigurationFromSARData(Map<String, String> sarColValues, Vertex forwardingPathVtx, int lineNumber) {
Vertex configurationVtx = null;
- String forwardingPathId = forwardingPathVtx.value(this.FOWARDING_PATH_ID);
+ String forwardingPathId = forwardingPathVtx !=null ? forwardingPathVtx.value(this.FOWARDING_PATH_ID) : "";
try {
List<Vertex> configList = g.V(forwardingPathVtx).out("org.onap.relationships.inventory.Uses").has("aai-node-type","configuration")
try {
Introspector evc = loader.introspectorFromName(EVC_NODE_TYPE);
evcVtx = serializer.createNewVertex(evc);
- evcId = configurationVtx.value(this.PROPERTY_CONFIGURATION_ID);
+ evcId = configurationVtx != null ? configurationVtx.value(this.PROPERTY_CONFIGURATION_ID) : "";
String cir = sarColValues.get("evcAccessCIR");
int length = cir.length();
String uri = String.format("/service-design-and-creation/models/model/%s/model-vers/model-ver/%s", currrentValueModelInvariantID, currentValueModelVersionID);
String propertyKey = NODETYPEKEYMAP.get(nodeTypeString);
- String propertyValue = vertex.value(propertyKey).toString();
- logger.info("Processing "+nodeTypeString+ " vertex with key "+vertex.value(propertyKey).toString());
+ String propertyValue = vertex != null ? vertex.value(propertyKey).toString() : "";
+ logger.info("Processing "+nodeTypeString+ " vertex with key "+ propertyValue);
Vertex modelVerVertex = null;
if (modelVerUriVtxIdMap.containsKey(uri)){
currentValueOfEquipType = getEquipTypeNodeValue(vertex);
hostName = getHostNameNodeValue(vertex);
if("Server".equals(currentValueOfEquipType) ||"server".equals(currentValueOfEquipType) ){
- vertex.property(EQUIP_TYPE_PROPERTY, "SERVER");
+ if(vertex != null) vertex.property(EQUIP_TYPE_PROPERTY, "SERVER");
this.touchVertexProperties(vertex, false);
logger.info("changed Pserver equip-type from " + currentValueOfEquipType + " to SERVER having hostname : " + hostName);
pserverCount++;
currentValueOfEquipType = getEquipTypeNodeValue(vertex);
pnfName = getPnfNameNodeValue(vertex);
if("Switch".equals(currentValueOfEquipType)||"switch".equals(currentValueOfEquipType)){
- vertex.property(EQUIP_TYPE_PROPERTY, "SWITCH");
+ if(vertex != null) vertex.property(EQUIP_TYPE_PROPERTY, "SWITCH");
this.touchVertexProperties(vertex, false);
logger.info("changed Pnf equip-type from "+ currentValueOfEquipType +" to SWITCH having pnf-name :" + pnfName);
pnfCount++;
@Override
public Optional<String[]> getAffectedNodeTypes() {
- return null;
+ return Optional.empty();
}
@Override
Map<String, Object> params = new HashMap<>();
String query = "";
if (this.isGremlin) {
- query = gremlin.get();
+ query = gremlin.isPresent() ? gremlin.get() : "";
}else if (this.isDsl) {
- String dslUserQuery = dsl.get();
+ String dslUserQuery = dsl.isPresent() ? dsl.get() : "";
if(dslQueryProcessorOptional.isPresent()){
String dslQuery = dslQueryProcessorOptional.get().parseAaiQuery(dslUserQuery);
query = groovyQueryBuilder.executeTraversal(dbEngine, dslQuery, params);
String propertyName = args[0];
Graph graph = null;
- try {
+ try(JanusGraph tGraph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(UniquePropertyCheck.class.getSimpleName()).withGraphType("realtime").buildConfiguration())) {
AAIConfig.init();
System.out.println(" ---- NOTE --- about to open graph (takes a little while)--------\n");
- JanusGraph tGraph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(UniquePropertyCheck.class.getSimpleName()).withGraphType("realtime").buildConfiguration());
-
+
if( tGraph == null ) {
logAndPrint(logger, " Error: Could not get JanusGraph ");
System.exit(1);