Skip to content

Commit a8a8f46

Browse files
committed
Merge remote-tracking branch 'upstream/main' into celsius
2 parents 100e138 + c6be254 commit a8a8f46

59 files changed

Lines changed: 4103 additions & 172 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public Response get(@Context SecurityContext securityContext, @Context Request r
213213
.map(rule -> EnrichedRuleDTOMapper.map(rule, ruleManager, managedRuleProvider)); // map matching rules
214214
if (summary != null && summary) {
215215
rules = dtoMapper.limitToFields(rules,
216-
"uid,templateUID,templateState,name,visibility,description,status,tags,editable");
216+
"uid,templateUID,templateState,name,visibility,description,status,tags,configuration,editable");
217217
}
218218

219219
return Response.ok(new Stream2JSONInputStream(rules)).build();

bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/TemplateResource.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import javax.ws.rs.core.Response;
2525
import javax.ws.rs.core.Response.Status;
2626

27-
import org.eclipse.jdt.annotation.NonNull;
2827
import org.eclipse.jdt.annotation.NonNullByDefault;
2928
import org.eclipse.jdt.annotation.Nullable;
3029
import org.openhab.core.automation.dto.RuleTemplateDTO;
3130
import org.openhab.core.automation.dto.RuleTemplateDTOMapper;
3231
import org.openhab.core.automation.template.RuleTemplate;
33-
import org.openhab.core.automation.template.Template;
3432
import org.openhab.core.automation.template.TemplateRegistry;
3533
import org.openhab.core.io.rest.LocaleService;
3634
import org.openhab.core.io.rest.RESTConstants;
@@ -73,20 +71,20 @@ public class TemplateResource implements RESTResource {
7371
public static final String PATH_TEMPLATES = "templates";
7472

7573
private final LocaleService localeService;
76-
private final TemplateRegistry<@NonNull RuleTemplate> templateRegistry;
74+
private final TemplateRegistry<RuleTemplate> templateRegistry;
7775

7876
@Activate
7977
public TemplateResource( //
8078
final @Reference LocaleService localeService,
81-
final @Reference TemplateRegistry<@NonNull RuleTemplate> templateRegistry) {
79+
final @Reference TemplateRegistry<RuleTemplate> templateRegistry) {
8280
this.localeService = localeService;
8381
this.templateRegistry = templateRegistry;
8482
}
8583

8684
@GET
8785
@Produces(MediaType.APPLICATION_JSON)
8886
@Operation(operationId = "getTemplates", summary = "Get all available templates.", responses = {
89-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Template.class)))) })
87+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = RuleTemplateDTO.class)))) })
9088
public Response getAll(
9189
@HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language) {
9290
Locale locale = localeService.getLocale(language);
@@ -99,7 +97,7 @@ public Response getAll(
9997
@Path("/{templateUID}")
10098
@Produces(MediaType.APPLICATION_JSON)
10199
@Operation(operationId = "getTemplateById", summary = "Gets a template corresponding to the given UID.", responses = {
102-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Template.class))),
100+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = RuleTemplateDTO.class))),
103101
@ApiResponse(responseCode = "404", description = "Template corresponding to the given UID does not found.") })
104102
public Response getByUID(
105103
@HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language,

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Module.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ public interface Module {
7777
* @return the current configuration values of the {@link Module}.
7878
*/
7979
Configuration getConfiguration();
80+
81+
/**
82+
* The "magic key" used for {@link Module}s that depend on shared context that isn't part of the {@link Module}
83+
* object itself, for example the {@link Action}s of DSL rules with definitions outside the {@code rule} section.
84+
* The information is stored in the {@link Module}'s {@link Configuration}. The payload is a {@link Boolean}.
85+
*/
86+
static String SHARED_CONTEXT = "sharedContext";
8087
}

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/Rule.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ default TemplateState getTemplateState() {
167167
return null;
168168
}
169169

170+
/**
171+
* The "magic key" used for the source code string itself when storing {@link Rule}'s source code in its
172+
* {@link Configuration}. A {@link Rule} can only have a source code if it is created by a script. The payload
173+
* is a string containing the whole source code.
174+
*/
175+
static String SOURCE = "source";
176+
177+
/**
178+
* The "magic key" used for the source code type when storing {@link Rule}'s source code in its
179+
* {@link Configuration}. A {@link Rule} can only have a source code if it is created by a script. The payload
180+
* is a string containing OH's "quasi MIME-type" for the scripting language of the source code.
181+
*/
182+
static String SOURCE_TYPE = "sourceType";
183+
170184
/**
171185
* This enum represent the different states a rule can have in respect to rule templates.
172186
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.core.automation.converter;
14+
15+
import java.util.Collection;
16+
import java.util.List;
17+
18+
import org.eclipse.jdt.annotation.NonNullByDefault;
19+
import org.eclipse.jdt.annotation.Nullable;
20+
import org.openhab.core.automation.Rule;
21+
import org.openhab.core.converter.ObjectParser;
22+
23+
/**
24+
* {@link RuleParser} is the interface to implement by any file parser for {@link Rule} object.
25+
*
26+
* @author Ravi Nadahar - Initial contribution
27+
*/
28+
@NonNullByDefault
29+
public interface RuleParser extends ObjectParser<Rule> {
30+
31+
/**
32+
* Parse the provided {@code syntax} string without impacting the rule registry.
33+
*
34+
* @param syntax the syntax in format.
35+
* @param errors the {@link List} to use to report errors.
36+
* @param warnings the {@link List} to be used to report warnings.
37+
* @return The model name used for parsing if the parsing succeeded without errors; {@code null} otherwise.
38+
*/
39+
@Override
40+
@Nullable
41+
String startParsingFormat(String syntax, List<String> errors, List<String> warnings);
42+
43+
/**
44+
* Get the {@link Rule} objects found when parsing the format.
45+
*
46+
* @param modelName the model name used when parsing.
47+
* @return The {@link Collection} of {@link Rule}s.
48+
*/
49+
@Override
50+
Collection<Rule> getParsedObjects(String modelName);
51+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.core.automation.converter;
14+
15+
import java.util.Collection;
16+
import java.util.List;
17+
import java.util.Locale;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.eclipse.jdt.annotation.Nullable;
21+
import org.openhab.core.automation.Rule;
22+
import org.openhab.core.converter.ObjectSerializer;
23+
import org.openhab.core.converter.SerializabilityResult;
24+
import org.openhab.core.io.dto.SerializationException;
25+
26+
/**
27+
* {@link RuleSerializer} is the interface to implement by any file generator for {@link Rule} object.
28+
*
29+
* @author Ravi Nadahar - Initial contribution
30+
*/
31+
@NonNullByDefault
32+
public interface RuleSerializer extends ObjectSerializer<Rule> {
33+
34+
/**
35+
* Checks if the specified rules are serializable with this {@link RuleSerializer}. Returned results are in the same
36+
* order as the specified rules.
37+
*
38+
* @param rules the {@link List} of {@link Rule}s to check.
39+
* @return The resulting {@link List} of {@link SerializabilityResult}s.
40+
*/
41+
List<SerializabilityResult<String>> checkSerializability(Collection<Rule> rules);
42+
43+
/**
44+
* Specify the {@link List} of {@link Rule}s to be serialized and associate them with an identifier.
45+
*
46+
* @param id the identifier of the {@link Rule} format generation.
47+
* @param rules the {@link List} of {@link Rule}s to serialize.
48+
* @param option the option that determines how to serialize the {@link Rule}s.
49+
* @throws SerializationException If one or more of the rules can't be serialized.
50+
*/
51+
void setRulesToBeSerialized(String id, List<Rule> rules, RuleSerializationOption option)
52+
throws SerializationException;
53+
54+
/**
55+
* An enum representing the different rule serialization options.
56+
*/
57+
public enum RuleSerializationOption {
58+
59+
/** Empty collections and normally irrelevant fields are hidden */
60+
NORMAL("Normal"),
61+
62+
/** Everything is serialized, including empty collections */
63+
INCLUDE_ALL("Include all"),
64+
65+
/** Only the fields required in a rule stub to be used with a template is serialized */
66+
STUB_ONLY("Stub only"),
67+
68+
/** Template information is stripped, otherwise like {@link #NORMAL} */
69+
STRIP_TEMPLATE("Strip template");
70+
71+
private final String friendlyName;
72+
73+
private RuleSerializationOption(String friendlyName) {
74+
this.friendlyName = friendlyName;
75+
}
76+
77+
@Override
78+
public String toString() {
79+
return friendlyName;
80+
}
81+
82+
public static @Nullable RuleSerializationOption fromString(@Nullable String id) {
83+
if (id == null || id.isBlank()) {
84+
return null;
85+
}
86+
String upId = id.toUpperCase(Locale.ROOT).trim();
87+
for (RuleSerializationOption option : values()) {
88+
if (upId.equals(option.name()) || upId.equalsIgnoreCase(option.friendlyName)
89+
|| upId.equalsIgnoreCase(option.friendlyName.replace(" ", ""))
90+
|| upId.equalsIgnoreCase(option.friendlyName.replace(" ", "-"))) {
91+
return option;
92+
}
93+
}
94+
return null;
95+
}
96+
}
97+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2010-2026 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.core.automation.converter;
14+
15+
import java.util.Collection;
16+
import java.util.List;
17+
18+
import org.eclipse.jdt.annotation.NonNullByDefault;
19+
import org.eclipse.jdt.annotation.Nullable;
20+
import org.openhab.core.automation.template.RuleTemplate;
21+
import org.openhab.core.converter.ObjectParser;
22+
23+
/**
24+
* {@link RuleTemplateParser} is the interface to implement by any file parser for {@link RuleTemplate} object.
25+
*
26+
* @author Ravi Nadahar - Initial contribution
27+
*/
28+
@NonNullByDefault
29+
public interface RuleTemplateParser extends ObjectParser<RuleTemplate> {
30+
31+
/**
32+
* Parse the provided {@code syntax} string without impacting the rule template registry.
33+
*
34+
* @param syntax the syntax in format.
35+
* @param errors the {@link List} to use to report errors.
36+
* @param warnings the {@link List} to be used to report warnings.
37+
* @return The model name used for parsing if the parsing succeeded without errors; {@code null} otherwise.
38+
*/
39+
@Override
40+
@Nullable
41+
String startParsingFormat(String syntax, List<String> errors, List<String> warnings);
42+
43+
/**
44+
* Get the {@link RuleTemplate} objects found when parsing the format.
45+
*
46+
* @param modelName the model name used when parsing.
47+
* @return The {@link Collection} of {@link RuleTemplate}s.
48+
*/
49+
@Override
50+
Collection<RuleTemplate> getParsedObjects(String modelName);
51+
}

0 commit comments

Comments
 (0)