aboutsummaryrefslogtreecommitdiffstats
path: root/ccsdk-app-common/src/main/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientMockImpl.java
blob: 75d373afc2fdf0ceb76d7e29d75683e218ebc387 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package org.onap.ccsdk.dashboard.rest;

import java.io.InputStream;
import java.util.Collection;
import java.util.Optional;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Stream;

import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException;
import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException;
import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException;
import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException;
import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException;
import org.onap.ccsdk.dashboard.model.ECTransportModel;
import org.onap.ccsdk.dashboard.model.inventory.InventoryProperty;
import org.onap.ccsdk.dashboard.model.inventory.Service;
import org.onap.ccsdk.dashboard.model.inventory.ServiceList;
import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams;
import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList;
import org.onap.ccsdk.dashboard.model.inventory.ServiceType;
import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList;
import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams;
import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;

public class RestInventoryClientMockImpl implements InventoryClient {

	private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestInventoryClientMockImpl.class);
	/**
	 * For mock outputs
	 */
	private final ObjectMapper objectMapper = new ObjectMapper();

	public RestInventoryClientMockImpl() {
	// Do not serialize null values
	objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
	// Register Jdk8Module() for Stream and Optional types
	objectMapper.registerModule(new Jdk8Module());
	}
	
	private String getMockDataContent(final String path) {
		String result = null;
		try {
			InputStream is = getClass().getResourceAsStream(path);
			if (is == null)
				throw new Exception("Failed to find resource at path " + path);
			Scanner scanner = new Scanner(is, "UTF-8");
			result = scanner.useDelimiter("\\A").next();
			scanner.close();
			is.close();
		} catch (Exception ex) {
			logger.error("getMockDataContent failed", ex);
			throw new RuntimeException(ex);
		}
		return result;
	}

	/**
	 * Creates an input stream using the specified path and requests the mapper
	 * create an object of the specified type.
	 * 
	 * @param modelClass
	 *            Model class
	 * @param path
	 *            Path to classpath resource
	 * @return Instance of modelClass
	 */
	private ECTransportModel getMockData(final Class<? extends ECTransportModel> modelClass, final String path) {
		ECTransportModel result = null;
		String json = getMockDataContent(path);
		try {
			result = (ECTransportModel) objectMapper.readValue(json, modelClass);
		} catch (Exception ex) {
			logger.error("getMockData failed", ex);
			throw new RuntimeException(ex);
		}
		return result;
	}

	@Override
	public Stream<ServiceType> getServiceTypes() {
		ServiceTypeList mockData = (ServiceTypeList)getMockData(ServiceTypeList.class, "/serviceTypesList.json");
		Collection<ServiceType> collection = mockData.items;
		
		return collection.stream();
	}

	@Override
	public Stream<ServiceType> getServiceTypes(ServiceTypeQueryParams serviceTypeQueryParams) {
		ServiceTypeList mockData = (ServiceTypeList)getMockData(ServiceTypeList.class, "/serviceTypesList.json");
		Collection<ServiceType> collection = mockData.items;
		
		return collection.stream();
	}

	@Override
	public ServiceRefList getServicesForType(ServiceQueryParams serviceQueryParams) {
		return null;
	}
	@Override
	public ServiceType addServiceType(ServiceType serviceType) throws ServiceTypeActiveException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ServiceType addServiceType(ServiceTypeRequest serviceTypeRequest) throws ServiceTypeActiveException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Optional<ServiceType> getServiceType(String typeId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void deleteServiceType(String typeId)
			throws ServiceTypeNotFoundException, ServiceTypeAlreadyDeactivatedException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Stream<Service> getServices() {
		ServiceList mockData = (ServiceList)getMockData(ServiceList.class, "/serviceList.json");
		Collection<Service> collection = mockData.items;
		
		return collection.stream();
	}

	@Override
	public Stream<Service> getServices(ServiceQueryParams serviceQueryParams) {
		ServiceList mockData = (ServiceList)getMockData(ServiceList.class, "/serviceList.json");
		Collection<Service> collection = mockData.items;
		
		return collection.stream();
	}

	@Override
	public Set<InventoryProperty> getPropertiesOfServices(String propertyName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Optional<Service> getService(String serviceId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void putService(String typeId, Service service) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteService(String serviceId) throws ServiceNotFoundException, ServiceAlreadyDeactivatedException {
		// TODO Auto-generated method stub
		
	}
}