use of com.vmware.flowgate.nlyteworker.model.CustomField 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;
}
Aggregations