Search in sources :

Example 1 with JsonResultForAsset

use of com.vmware.flowgate.nlyteworker.model.JsonResultForAsset in project flowgate by vmware.

the class NlyteAPIClient method getAssets.

public List<NlyteAsset> getAssets(boolean isAllData, AssetCategory category) {
    initAuthenticationWebToken();
    String getAssetsUrl = null;
    switch(category) {
        case Server:
            getAssetsUrl = getNlyteServiceEndpoint() + GetServerAssetsURL;
            break;
        case PDU:
            getAssetsUrl = getNlyteServiceEndpoint() + GetPowerStripAssetsURL;
            break;
        case Cabinet:
            getAssetsUrl = getNlyteServiceEndpoint() + GetCabinetsURL;
            break;
        case Networks:
            getAssetsUrl = getNlyteServiceEndpoint() + GetNetworksURL;
            break;
        case Chassis:
            getAssetsUrl = getNlyteServiceEndpoint() + GetChassisURL;
            break;
        default:
            throw new NlyteWorkerException("no such assets of the category ");
    }
    JsonResultForAsset nlyteAssetResult = this.restTemplate.exchange(getAssetsUrl, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
    List<NlyteAsset> nlyteAssets = new LinkedList<NlyteAsset>();
    nlyteAssets = nlyteAssetResult.getValue();
    if (!isAllData) {
        return nlyteAssets;
    }
    URLDecoder decoder = new URLDecoder();
    List<NlyteAsset> nextPageNlyteAssets = null;
    String nextLink = nlyteAssetResult.getOdatanextLink();
    while (nextLink != null && !nextLink.equals("")) {
        nextLink = decoder.decode(nextLink);
        nextPageNlyteAssets = new ArrayList<NlyteAsset>();
        nlyteAssetResult = this.restTemplate.exchange(nextLink, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
        nextPageNlyteAssets = nlyteAssetResult.getValue();
        nlyteAssets.addAll(nextPageNlyteAssets);
        nextLink = nlyteAssetResult.getOdatanextLink();
    }
    HandleAssetUtil util = new HandleAssetUtil();
    nlyteAssets = util.filterUnActivedAsset(nlyteAssets, category);
    return nlyteAssets;
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) JsonResultForAsset(com.vmware.flowgate.nlyteworker.model.JsonResultForAsset) URLDecoder(java.net.URLDecoder) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) LinkedList(java.util.LinkedList)

Aggregations

NlyteWorkerException (com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)1 JsonResultForAsset (com.vmware.flowgate.nlyteworker.model.JsonResultForAsset)1 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)1 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)1 URLDecoder (java.net.URLDecoder)1 LinkedList (java.util.LinkedList)1