summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/openecomp/vid/services/AaiServiceImpl.java
blob: 38b670fe522dbae966d38dc0bd43c8b35bc5df97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.openecomp.vid.services;

import org.ecomp.aai.model.AaiAICZones.AicZones;
import org.openecomp.vid.aai.*;
import org.openecomp.vid.aai.model.AaiGetServicesRequestModel.*;
import org.openecomp.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.openecomp.vid.model.*;
import org.openecomp.vid.roles.RoleValidator;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Oren on 7/4/17.
 */
public class AaiServiceImpl implements AaiService {


    @Autowired
    private AaiClientInterface aaiClient;


    @Override
    public SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator) {
        AaiResponse<SubscriberList> subscriberResponse = aaiClient.getAllSubscribers();
        SubscriberFilteredResults subscriberFilteredResults =
                new SubscriberFilteredResults(roleValidator,subscriberResponse.getT(),
                        subscriberResponse.getErrorMessage(),
                        subscriberResponse.getHttpCode());

        return subscriberFilteredResults;
    }

    @Override
    public AaiResponse getSubscriberData(String subscriberId, RoleValidator roleProvider) {
        AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId);
        String subscriberGlobalId = subscriberResponse.getT().globalCustomerId;
        for (ServiceSubscription serviceSubscription : subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
            String serviceType = serviceSubscription.serviceType;
            serviceSubscription.isPermitted = roleProvider.isServicePermitted(subscriberGlobalId,serviceType);;
        }
        return subscriberResponse;

    }

    @Override
    public AaiResponse getServices(RoleValidator roleValidator) {
        AaiResponse<GetServicesAAIRespone> subscriberResponse = aaiClient.getServices();
        for (org.openecomp.vid.aai.model.AaiGetServicesRequestModel.Service service :subscriberResponse.getT().service){
            service.isPermitted = true;
        }
        return subscriberResponse;
    }

    @Override
    public AaiResponse<GetTenantsResponse[]> getTenants(String globalCustomerId, String serviceType, RoleValidator roleValidator) {
        AaiResponse<GetTenantsResponse[]> aaiGetTenantsResponse = aaiClient.getTenants(globalCustomerId,serviceType);
        GetTenantsResponse[] tenants = aaiGetTenantsResponse.getT();
        for (int i=0;i<tenants.length;i++){
            tenants[i].isPermitted = roleValidator.isTenantPermitted(globalCustomerId,serviceType, tenants[i].tenantID);
        }
        return aaiGetTenantsResponse;
    }

	@Override
	public AaiResponse getAaiZones() {
		AaiResponse<AicZones> response = aaiClient.getAllAicZones();
		return response;
	}
}