Search in sources :

Example 1 with JsonResultForMaterial

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;
}
Also used : JsonResultForMaterial(com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial) JsonResultForMaterial(com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial) Material(com.vmware.flowgate.nlyteworker.model.Material) URLDecoder(java.net.URLDecoder) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) LinkedList(java.util.LinkedList)

Aggregations

NlyteWorkerException (com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)1 JsonResultForMaterial (com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial)1 Material (com.vmware.flowgate.nlyteworker.model.Material)1 URLDecoder (java.net.URLDecoder)1 LinkedList (java.util.LinkedList)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1