/
DevOpsCommandResponseRegistry.java
executable file
·57 lines (47 loc) · 2.23 KB
/
DevOpsCommandResponseRegistry.java
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
/*
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.signals.commands.devops;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.signals.base.AbstractJsonParsableRegistry;
import org.eclipse.ditto.signals.base.JsonParsable;
import org.eclipse.ditto.signals.base.JsonParsableRegistry;
/**
* A {@link JsonParsableRegistry} aware of all {@link DevOpsCommandResponse}s.
*/
@Immutable
public final class DevOpsCommandResponseRegistry extends AbstractJsonParsableRegistry<DevOpsCommandResponse>
implements JsonParsableRegistry<DevOpsCommandResponse> {
private DevOpsCommandResponseRegistry(final Map<String, JsonParsable<DevOpsCommandResponse>> parseStrategies) {
super(parseStrategies);
}
/**
* Returns a new {@code DevOpsCommandRegistry}.
*
* @return the registry.
*/
public static DevOpsCommandResponseRegistry newInstance() {
final Map<String, JsonParsable<DevOpsCommandResponse>> parseStrategies = new HashMap<>();
parseStrategies.put(ChangeLogLevelResponse.TYPE, ChangeLogLevelResponse::fromJson);
parseStrategies.put(RetrieveLoggerConfigResponse.TYPE, RetrieveLoggerConfigResponse::fromJson);
parseStrategies.put(RetrieveStatisticsResponse.TYPE, RetrieveStatisticsResponse::fromJson);
parseStrategies.put(RetrieveStatisticsDetailsResponse.TYPE, RetrieveStatisticsDetailsResponse::fromJson);
parseStrategies.put(AggregatedDevOpsCommandResponse.TYPE,
(jsonObject, dittoHeaders) -> AggregatedDevOpsCommandResponse.fromJson(jsonObject, dittoHeaders, parseStrategies));
return new DevOpsCommandResponseRegistry(parseStrategies);
}
@Override
protected String resolveType(final JsonObject jsonObject) {
return jsonObject.getValueOrThrow(DevOpsCommandResponse.JsonFields.TYPE);
}
}