use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.
the class HandleAssetUtil method getAssetsFromNlyte.
/**
* @param nlyteAssets
* @return
*/
public List<Asset> getAssetsFromNlyte(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap) {
List<Asset> assetsFromNlyte = new ArrayList<Asset>();
Asset asset;
for (NlyteAsset nlyteAsset : nlyteAssets) {
asset = new Asset();
asset.setAssetNumber(nlyteAsset.getAssetNumber());
asset.setCabinetAssetNumber(String.valueOf(nlyteAsset.getCabinetAssetID()));
asset.setCabinetName(nlyteAsset.getCabinetName());
asset.setTag(nlyteAsset.getTag());
asset.setSerialnumber(nlyteAsset.getSerialNumber());
asset.setAssetName(nlyteAsset.getAssetName());
asset.setRow(nlyteAsset.getGridReferenceRow());
asset.setCol(nlyteAsset.getGridReferenceColumn());
asset = supplementLocation(asset, nlyteAsset.getLocationGroupID(), locationMap);
asset = supplementMaterial(asset, nlyteAsset.getMaterialID(), manufacturerMap, materialMap);
// we need to refactor the code
if (asset.getCategory() == null) {
continue;
}
if (asset.getCategory() == AssetCategory.Server) {
if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
Parent parent = new Parent();
parent.setType(AssetCategory.Chassis.name());
parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
asset.setParent(parent);
}
// set the tenant information.
List<CustomField> fields = nlyteAsset.getCustomFields();
if (fields != null) {
Tenant tenant = new Tenant();
for (CustomField cf : fields) {
if (cf.getDataLabel().equals(CustomField.Owner)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setOwner(dataValue);
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.Tenant_EndUser)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.HaaS_RequestedBy)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.Tenant_Manager)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenantManager(dataValue);
}
}
}
asset.setTenant(tenant);
}
}
if (asset.getCategory().equals(AssetCategory.Cabinet)) {
String contiguousUSpace = nlyteAsset.getContiguousUSpace();
if (contiguousUSpace != null) {
int freeSize = 0;
String[] contiguousUSpaces = contiguousUSpace.split(FlowgateConstant.SPILIT_FLAG);
for (String uSpace : contiguousUSpaces) {
freeSize += Integer.parseInt(uSpace);
}
asset.setFreeCapacity(freeSize);
}
List<CabinetU> cabinetus = nlyteAsset.getCabinetUs();
if (cabinetus != null && !cabinetus.isEmpty()) {
List<com.vmware.flowgate.common.model.CabinetU> flowgateCabinetUs = new ArrayList<com.vmware.flowgate.common.model.CabinetU>();
for (CabinetU cabinetu : cabinetus) {
com.vmware.flowgate.common.model.CabinetU flowgateCabinetU = new com.vmware.flowgate.common.model.CabinetU();
flowgateCabinetU.setAssetsOnUnit(cabinetu.getAssetsOnU());
flowgateCabinetU.setCabinetUNumber(cabinetu.getCabinetUNumber());
if (CabinetU_State_Full.equals(cabinetu.getCabinetUState())) {
flowgateCabinetU.setUsed(true);
} else if (CabinetU_State_Free.equals(cabinetu.getCabinetUState())) {
flowgateCabinetU.setUsed(false);
}
flowgateCabinetUs.add(flowgateCabinetU);
}
try {
String cabinetUsInfo = mapper.writeValueAsString(flowgateCabinetUs);
HashMap<String, String> justficationfields = new HashMap<String, String>();
justficationfields.put(FlowgateConstant.CABINETUNITS, cabinetUsInfo);
asset.setJustificationfields(justficationfields);
} catch (JsonProcessingException e) {
logger.error("Failed to get info of cabinetUs.");
}
}
}
if (asset.getCategory().equals(AssetCategory.Chassis)) {
handleChassisSolts(asset, nlyteAsset);
}
if (asset.getCategory().equals(AssetCategory.Networks)) {
if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
Parent parent = new Parent();
parent.setType(AssetCategory.Chassis.name());
parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
asset.setParent(parent);
}
}
asset.setAssetSource(nlyteSource);
AssetStatus status = new AssetStatus();
status.setNetworkMapping(NetworkMapping.UNMAPPED);
status.setPduMapping(PduMapping.UNMAPPED);
asset.setStatus(status);
UMounting uMounting = nlyteAsset.getuMounting();
if (uMounting != null) {
asset.setCabinetUnitPosition(uMounting.getCabinetUNumber());
switch(MountingSide.valueOf(uMounting.getMountingSide())) {
case Front:
asset.setMountingSide(MountingSide.Front);
break;
case Back:
asset.setMountingSide(MountingSide.Back);
break;
case Unmounted:
asset.setMountingSide(MountingSide.Unmounted);
break;
default:
break;
}
}
asset.setCreated(System.currentTimeMillis());
assetsFromNlyte.add(asset);
}
return assetsFromNlyte;
}
use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets3.
@Test
public void testHandleAssets3() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Server);
Parent parent = new Parent();
parent.setParentId("ouqwenkja72hoas9034a");
parent.setType("Chassis");
asset2.setParent(parent);
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
TestCase.assertEquals("ouqwenkja72hoas9034a", assetTosave.getParent().getParentId());
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets.
/**
* New asset have chassis info but old assets none
*/
@Test
public void testHandleAssets() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
asset.setCapacity(8);
asset.setFreeCapacity(2);
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Chassis);
HashMap<String, String> justficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slots.add(slot1);
Map<String, String> chassisInfoMap = new HashMap<String, String>();
chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
ObjectMapper mapper = new ObjectMapper();
try {
String slotsString = mapper.writeValueAsString(slots);
chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
String chassisInfo = mapper.writeValueAsString(chassisInfoMap);
justficationMap.put(FlowgateConstant.CHASSIS, chassisInfo);
asset2.setJustificationfields(justficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
String chassisInfo = justfications.get(FlowgateConstant.CHASSIS);
try {
Map<String, String> newChassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
TestCase.assertEquals(chassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE));
String chassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> flowgateSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
TestCase.assertEquals(slot1.getMountingSide(), flowgateSlots.get(0).getMountingSide());
TestCase.assertEquals(slot1.getMountedAssetNumber(), flowgateSlots.get(0).getMountedAssetNumber());
TestCase.assertEquals(slot1.getColumnPosition(), flowgateSlots.get(0).getColumnPosition());
TestCase.assertEquals(slot1.getRowPosition(), flowgateSlots.get(0).getRowPosition());
TestCase.assertEquals(slot1.getSlotName(), flowgateSlots.get(0).getSlotName());
} catch (Exception e) {
TestCase.fail(e.getMessage());
}
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset.getCapacity(), assetTosave.getCapacity());
TestCase.assertEquals(asset.getFreeCapacity(), assetTosave.getFreeCapacity());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets2.
@Test
public void testHandleAssets2() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Chassis);
HashMap<String, String> justficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slots.add(slot1);
Map<String, String> chassisInfoMap = new HashMap<String, String>();
chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
ObjectMapper mapper = new ObjectMapper();
try {
String slotsString = mapper.writeValueAsString(slots);
chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
String chassisInfo = mapper.writeValueAsString(chassisInfoMap);
justficationMap.put(FlowgateConstant.CHASSIS, chassisInfo);
asset2.setJustificationfields(justficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
HashMap<String, String> oldjustficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> oldslots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot oldslot1 = createFlowgateChassisSlot();
oldslot1.setMountingSide("Back");
oldslot1.setMountedAssetNumber(5523);
oldslots.add(oldslot1);
Map<String, String> oldChassisInfoMap = new HashMap<String, String>();
oldChassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
try {
String oldSlotsString = mapper.writeValueAsString(oldslots);
oldChassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, oldSlotsString);
String oldChassisInfo = mapper.writeValueAsString(oldChassisInfoMap);
oldjustficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
oldAsset2.setJustificationfields(oldjustficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
String chassisInfo = justfications.get(FlowgateConstant.CHASSIS);
try {
Map<String, String> newChassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
TestCase.assertEquals(chassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE));
String chassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> flowgateSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
TestCase.assertEquals(slot1.getMountingSide(), flowgateSlots.get(0).getMountingSide());
TestCase.assertEquals(slot1.getMountedAssetNumber(), flowgateSlots.get(0).getMountedAssetNumber());
TestCase.assertEquals(slot1.getColumnPosition(), flowgateSlots.get(0).getColumnPosition());
TestCase.assertEquals(slot1.getRowPosition(), flowgateSlots.get(0).getRowPosition());
TestCase.assertEquals(slot1.getSlotName(), flowgateSlots.get(0).getSlotName());
} catch (Exception e) {
TestCase.fail(e.getMessage());
}
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.
the class HandleAssetUtil method handleAssets.
public List<Asset> handleAssets(List<Asset> toUpdateAssets, Map<Long, Asset> exsitingaAssetMap) {
List<Asset> resultAsset = new ArrayList<Asset>();
List<Asset> updateAsset = new ArrayList<Asset>();
Asset exsitingAsset = null;
if (exsitingaAssetMap == null) {
return toUpdateAssets;
}
for (Asset asset : toUpdateAssets) {
boolean isUpdated = false;
if (exsitingaAssetMap.containsKey(asset.getAssetNumber())) {
exsitingAsset = exsitingaAssetMap.get(asset.getAssetNumber());
if (valueIsChanged(exsitingAsset.getCabinetName(), asset.getCabinetName())) {
exsitingAsset.setCabinetName(asset.getCabinetName());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getTag(), asset.getTag())) {
exsitingAsset.setTag(asset.getTag());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getCapacity(), asset.getCapacity())) {
exsitingAsset.setCapacity(asset.getCapacity());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getFreeCapacity(), asset.getFreeCapacity())) {
exsitingAsset.setFreeCapacity(asset.getFreeCapacity());
}
exsitingAsset.setSerialnumber(asset.getSerialnumber());
exsitingAsset.setAssetName(asset.getAssetName());
exsitingAsset.setRegion(asset.getRegion());
exsitingAsset.setCountry(asset.getCountry());
exsitingAsset.setCity(asset.getCity());
exsitingAsset.setBuilding(asset.getBuilding());
exsitingAsset.setFloor(asset.getFloor());
if (valueIsChanged(exsitingAsset.getRoom(), asset.getRoom())) {
exsitingAsset.setRoom(asset.getRoom());
isUpdated = true;
}
exsitingAsset.setModel(asset.getModel());
exsitingAsset.setManufacturer(asset.getManufacturer());
exsitingAsset.setCategory(asset.getCategory());
exsitingAsset.setSubCategory(asset.getSubCategory());
exsitingAsset.setLastupdate(System.currentTimeMillis());
if (valueIsChanged(exsitingAsset.getRow(), asset.getRow())) {
exsitingAsset.setRow(asset.getRow());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getCol(), asset.getCol())) {
exsitingAsset.setCol(asset.getCol());
isUpdated = true;
}
if (exsitingAsset.getMountingSide() != asset.getMountingSide()) {
exsitingAsset.setMountingSide(asset.getMountingSide());
isUpdated = true;
}
String oldOwner = null;
String newOwner = null;
String oldTenantValue = null;
String newTenantValue = null;
String oldTenantManager = null;
String newTenantManager = null;
Tenant oldTenant = exsitingAsset.getTenant();
Tenant newTenant = asset.getTenant();
if (oldTenant != null) {
oldOwner = oldTenant.getOwner();
oldTenantValue = oldTenant.getTenant();
oldTenantManager = oldTenant.getTenantManager();
}
if (newTenant != null) {
newOwner = newTenant.getOwner();
newTenantValue = newTenant.getTenant();
newTenantManager = newTenant.getTenantManager();
}
if (valueIsChanged(oldOwner, newOwner) || valueIsChanged(oldTenantValue, newTenantValue) || valueIsChanged(oldTenantManager, newTenantManager)) {
exsitingAsset.setTenant(asset.getTenant());
isUpdated = true;
}
if (exsitingAsset.getCategory().equals(AssetCategory.Cabinet)) {
if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS) != null) {
exsitingAsset.getJustificationfields().put(FlowgateConstant.CABINETUNITS, asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS));
isUpdated = true;
}
}
if (exsitingAsset.getCategory().equals(AssetCategory.Chassis)) {
if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CHASSIS) != null) {
HashMap<String, String> newJustficationMap = asset.getJustificationfields();
HashMap<String, String> oldJustficationMap = exsitingAsset.getJustificationfields();
String newChassisInfo = newJustficationMap.get(FlowgateConstant.CHASSIS);
String oldChassisInfo = oldJustficationMap.get(FlowgateConstant.CHASSIS);
Map<String, String> newChassisInfoMap = null;
Map<String, String> oldChassisInfoMap = null;
try {
if (newChassisInfo != null) {
newChassisInfoMap = mapper.readValue(newChassisInfo, new TypeReference<Map<String, String>>() {
});
}
if (oldChassisInfo != null) {
oldChassisInfoMap = mapper.readValue(oldChassisInfo, new TypeReference<Map<String, String>>() {
});
}
} catch (Exception e) {
logger.error("Failed to read the data of chassis");
}
if (oldChassisInfoMap == null) {
if (newChassisInfoMap != null) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
} else {
if (newChassisInfoMap != null) {
if (valueIsChanged(oldChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE))) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
} else {
String newChassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
String oldChassisSlots = oldChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> newFlowgateChassisSlots = null;
List<FlowgateChassisSlot> oldFlowgateChassisSlots = null;
if (newChassisSlots != null) {
if (oldChassisSlots != null) {
try {
newFlowgateChassisSlots = mapper.readValue(newChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
oldFlowgateChassisSlots = mapper.readValue(oldChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
} catch (Exception e) {
logger.error("Failed to read the data of chassis");
}
if (chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots)) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
} else {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
}
}
}
}
}
}
if (exsitingAsset.getCategory().equals(AssetCategory.Server) || exsitingAsset.getCategory().equals(AssetCategory.Networks)) {
Parent oldParent = exsitingAsset.getParent();
String oldParentId = null;
String oldParentType = null;
if (oldParent != null) {
oldParentId = oldParent.getParentId();
oldParentType = oldParent.getType();
}
Parent newParent = asset.getParent();
String newParentId = null;
String newParentType = null;
if (newParent != null) {
newParentId = newParent.getParentId();
newParentType = newParent.getType();
}
if (valueIsChanged(oldParentId, newParentId) || valueIsChanged(oldParentType, newParentType)) {
exsitingAsset.setParent(newParent);
isUpdated = true;
}
}
if (isUpdated) {
updateAsset.add(exsitingAsset);
}
} else {
asset.setCreated(System.currentTimeMillis());
resultAsset.add(asset);
}
}
resultAsset.addAll(updateAsset);
return resultAsset;
}
Aggregations