use of com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial in project flowgate by vmware.
the class NlyteAPIClient method getMaterials.
public List<Material> getMaterials(boolean isAllData, int materialType) {
initAuthenticationWebToken();
String getMaterialsURL = null;
switch(materialType) {
case HandleAssetUtil.bladeServerMaterial:
getMaterialsURL = getNlyteServiceEndpoint() + GetBladeServerMaterialsURL;
break;
case HandleAssetUtil.standardServerMaterial:
getMaterialsURL = getNlyteServiceEndpoint() + GetStandardServerMaterialsURL;
break;
case HandleAssetUtil.powerStripMaterial:
getMaterialsURL = getNlyteServiceEndpoint() + GetPowerStripMaterialsURL;
break;
case HandleAssetUtil.cabinetMaterials:
getMaterialsURL = getNlyteServiceEndpoint() + GetCabinetMaterialsURL;
break;
case HandleAssetUtil.networkMaterials:
getMaterialsURL = getNlyteServiceEndpoint() + GetNetworkMaterialsURL;
break;
case HandleAssetUtil.chassisMaterials:
getMaterialsURL = getNlyteServiceEndpoint() + GetChassisMaterialsURL;
break;
default:
throw new NlyteWorkerException("category should be 'Blade' or 'Standard' for server matreial");
}
List<Material> materials = new LinkedList<Material>();
JsonResultForMaterial materialResult = this.restTemplate.exchange(getMaterialsURL, HttpMethod.GET, getDefaultEntity(), JsonResultForMaterial.class).getBody();
materials.addAll(materialResult.getValue());
if (!isAllData) {
return materials;
}
List<Material> nextPageMaterials = null;
URLDecoder decoder = new URLDecoder();
String nextLink = materialResult.getOdatanextLink();
while (nextLink != null && !nextLink.equals("")) {
nextLink = decoder.decode(nextLink);
nextPageMaterials = new LinkedList<Material>();
try {
materialResult = this.restTemplate.exchange(nextLink, HttpMethod.GET, getDefaultEntity(), JsonResultForMaterial.class).getBody();
} catch (HttpServerErrorException e) {
logger.error("Internal Server Error.The url is " + nextLink);
break;
}
nextPageMaterials = materialResult.getValue();
materials.addAll(nextPageMaterials);
nextLink = materialResult.getOdatanextLink();
}
return materials;
}
Aggregations