/
RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.java
83 lines (72 loc) · 3.39 KB
/
RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.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
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
/*
* Copyright (c) 2017 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
*
* Contributors:
* Bosch Software Innovations GmbH - initial contribution
*/
package org.eclipse.ditto.signals.commands.live.query;
import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.eclipse.ditto.model.things.FeatureDefinition;
import org.eclipse.ditto.signals.commands.base.CommandResponse;
import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswer;
import org.eclipse.ditto.signals.commands.live.query.RetrieveFeatureDefinitionLiveCommandAnswerBuilder.ResponseFactory;
import org.eclipse.ditto.signals.commands.things.ThingErrorResponse;
import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException;
import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinitionResponse;
/**
* A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link
* RetrieveFeatureDefinitionLiveCommand}.
*/
@ParametersAreNonnullByDefault
@NotThreadSafe
final class RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl
extends AbstractLiveCommandAnswerBuilder<RetrieveFeatureDefinitionLiveCommand, ResponseFactory>
implements RetrieveFeatureDefinitionLiveCommandAnswerBuilder {
private RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl(final RetrieveFeatureDefinitionLiveCommand command) {
super(command);
}
/**
* Returns a new instance of {@code RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl}.
*
* @param command the command to build an answer for.
* @return the instance.
* @throws NullPointerException if {@code command} is {@code null}.
*/
public static RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl newInstance(
final RetrieveFeatureDefinitionLiveCommand command) {
return new RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl(command);
}
@Override
protected CommandResponse doCreateResponse(
final Function<ResponseFactory, CommandResponse<?>> createResponseFunction) {
return createResponseFunction.apply(new ResponseFactoryImpl());
}
@ParametersAreNonnullByDefault
@Immutable
private final class ResponseFactoryImpl implements ResponseFactory {
@Nonnull
@Override
public RetrieveFeatureDefinitionResponse retrieved(final FeatureDefinition featureProperties) {
return RetrieveFeatureDefinitionResponse.of(command.getThingId(), command.getFeatureId(), featureProperties,
command.getDittoHeaders());
}
@Nonnull
@Override
public ThingErrorResponse featureDefinitionNotAccessibleError() {
return errorResponse(command.getThingId(),
FeatureDefinitionNotAccessibleException.newBuilder(command.getThingId(),
command.getFeatureId())
.dittoHeaders(command.getDittoHeaders())
.build());
}
}
}