Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2bd0b1a
Add asset attribute configuration import and export
Ekhorn Oct 1, 2026
f91f493
Keep access and attribute link meta items with the asset
Ekhorn Nov 10, 2026
70f7125
Add config-template setup
Ekhorn Nov 9, 2026
4f78508
Add side padding to configuration item cards
Ekhorn Nov 11, 2026
f2352b4
Add model and test guidelines to AGENTS.md
Ekhorn Nov 13, 2026
00782b9
Drop redundant @JsonProperty annotations
Ekhorn Nov 13, 2026
5a05f41
Use MetaMap and AttributeMap in configuration templates
Ekhorn Nov 13, 2026
9d3aed1
Explain why exported attributes are sorted
Ekhorn Nov 13, 2026
90d54e1
Start the container once in ConfigurationTemplateTest
Ekhorn Nov 13, 2026
1dbd199
Merge remote-tracking branch 'origin/main' into feature/import-export…
Ekhorn Nov 13, 2026
fba05fd
Report where a configuration template fails to import
Ekhorn Nov 13, 2026
22f3bf9
Validate imported templates as saving the asset does
Ekhorn Nov 13, 2026
ed33802
Fix spotless issue
Ekhorn Nov 13, 2026
f9c2e69
Change AttributeConfiguration classes into records
Ekhorn Nov 16, 2026
0bd0e09
Disable configuration template import on unsaved assets
Ekhorn Nov 16, 2026
390cd4b
Leave custom attributes out of configuration templates
Ekhorn Nov 16, 2026
b8c7acd
Add configuration template UI tests
Ekhorn Nov 16, 2026
0ac0676
Go back to the file selection from a rejected template
Ekhorn Nov 16, 2026
0a1e682
Wait for file step to close dialog in config template tests
Ekhorn Nov 17, 2026
317846d
Rename ConfigurationItem to ConfigurationItemView
Ekhorn Nov 18, 2026
87ee78e
Test export and import by a restricted user
Ekhorn Nov 18, 2026
5c8f81e
Use slotted dialog content and attribute bindings in config templates
Ekhorn Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ ex.response.withCloseable { r ->
}
```

Start the container in `setupSpec`, not in each feature method, and remove any test-specific resources in `cleanup`. The container is reused, but starting it still costs a couple of seconds per method.

### Running tests

When running integration tests, part of the stack (PostgreSQL and Keycloak) must be running. Start it with `docker compose -f profile/dev-testing.yml -p openremote up -d --no-build`.

Spock snapshots are stored under `model/src/test/resources/snapshots`. Rewrite them with `./gradlew :model:test -PupdateSnapshots` and review the resulting diff, since a mismatch is only reported as a test failure otherwise.

## Model and JSON

Don't put `@JsonProperty` on `@JsonCreator` parameters whose name already matches the property; the build compiles with `-parameters` and registers `ParameterNamesModule`. Add it only when the names differ.

Keep Jackson types (`JsonNode`, `ObjectNode`) out of model fields and public signatures; they are an implementation dependency. Use the typed model instead: `AttributeMap`, `MetaMap`, `NamedMap`, or the DTO itself.

Bind a request body to its model class and validate it with JSR-380 (`@NotNull`, `@NotBlank`, `@Min`, ...), so each violation carries its path; see `AssetValidator`. Read a JSON tree only where each kind of defect needs its own error, and keep the tree inside the method that reads it.

`NamedMap`, so `AttributeMap` and `MetaMap`, is unordered. Use `LinkedHashMap` to keep an order that already carries meaning, and `TreeMap` only when a sorted, stable serialization is the goal.

## REST resources

### Endpoint roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetResource;
import org.openremote.model.asset.AssetTree;
import org.openremote.model.asset.ConfigurationTemplate;
import org.openremote.model.asset.ConfigurationTemplateImportFailure;
import org.openremote.model.asset.ConfigurationTemplateImportPreview;
import org.openremote.model.asset.ConfigurationTemplateImportRequest;
import org.openremote.model.asset.UserAssetLink;
import org.openremote.model.attribute.*;
import org.openremote.model.http.RequestParams;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.query.filter.RealmPredicate;
import org.openremote.model.security.ClientRole;
import org.openremote.model.util.ConfigurationTemplateUtil;
import org.openremote.model.util.TextUtil;
import org.openremote.model.util.ValueUtil;

Expand Down Expand Up @@ -466,6 +471,75 @@
}
}

@Override
public ConfigurationTemplate exportConfigurationTemplate(
RequestParams requestParams, String assetId, List<String> attributeNames) {
// Reuses the read access rules of #get, including the protected view for a restricted user
ConfigurationTemplate document =
ConfigurationTemplateUtil.export(get(requestParams, assetId), attributeNames);

if (document.getAttributes() == null || document.getAttributes().isEmpty()) {
throw new WebApplicationException("No configuration items to export", BAD_REQUEST);
}
return document;
}

@Override
public ConfigurationTemplateImportPreview previewConfigurationTemplateImport(
RequestParams requestParams, String assetId, ConfigurationTemplateImportRequest request) {

Asset<?> storageAsset = assetStorageService.find(assetId, true);

if (storageAsset == null) {
LOG.fine("Asset not found: assetID=" + assetId);

Check warning on line 494 in manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the built-in formatting to construct this argument.

See more on https://sonarcloud.io/project/issues?id=openremote_openremote&issues=AaEI2jQ846-QiBaKjzmO&open=AaEI2jQ846-QiBaKjzmO&pullRequest=3380
throw new WebApplicationException(NOT_FOUND);
}

throwIfNotRealmActiveAndAccessible(storageAsset.getRealm());

if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), assetId)) {
LOG.fine(
"Forbidden access for restricted user: username="
+ getUsername()
+ ", assetID="
+ assetId);

Check warning on line 505 in manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the built-in formatting to construct this argument.

See more on https://sonarcloud.io/project/issues?id=openremote_openremote&issues=AaEI2jQ846-QiBaKjzmQ&open=AaEI2jQ846-QiBaKjzmQ&pullRequest=3380
throw new WebApplicationException(FORBIDDEN);
}

if (request == null || request.getDraft() == null) {
throw new WebApplicationException("An asset draft is required", BAD_REQUEST);
}

Asset<?> draft = request.getDraft();

if (!Objects.equals(assetId, draft.getId())
|| !Objects.equals(storageAsset.getRealm(), draft.getRealm())
|| !Objects.equals(storageAsset.getType(), draft.getType())) {
throw importFailure(
ConfigurationTemplateImportPreview.failed(
ConfigurationTemplateImportFailure.DRAFT_MISMATCH));
}

ConfigurationTemplateImportPreview preview =
ConfigurationTemplateUtil.preview(draft, request.getDocument());

if (preview.getFailure() != null) {
throw importFailure(preview);
}

return preview;
}

protected WebApplicationException importFailure(ConfigurationTemplateImportPreview preview) {
Response.Status status =
preview.getFailure() == ConfigurationTemplateImportFailure.DRAFT_MISMATCH
? CONFLICT
: BAD_REQUEST;

return new WebApplicationException(
Response.status(status).entity(preview).type(MediaType.APPLICATION_JSON_TYPE).build());
}

@Override
public AttributeWriteResult writeAttributeValue(
RequestParams requestParams, String assetId, String attributeName, Object value) {
Expand Down
81 changes: 81 additions & 0 deletions model/src/main/java/org/openremote/model/asset/AssetResource.java
Comment thread
richturner marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,87 @@ Asset<?> update(
value = ASSET_UPDATE)))
Asset<?> asset);

/**
* Retrieve a configuration template of the asset: a user editable document holding the type and
* metadata of every attribute that has metadata. Metadata that grants access or links attributes
* stays with the asset. Repeat the attributeName query parameter to export a subset of them.
* Access follows the same rules as {@link #get}. A 400 status is returned if nothing is left to
* export.
*/
@GET
@Path("{assetId}/configurationTemplate")
@Produces(APPLICATION_JSON)
@RolesAllowed({Constants.READ_ASSETS_ROLE})
@Operation(
operationId = "exportConfigurationTemplate",
summary = "Export a configuration template of an asset",
description =
"Returns a versioned document holding the type and metadata of each attribute that has metadata, limited to the requested attribute names when any are given. Metadata that grants access or links attributes stays with the asset, and attributes without other metadata are never included. Exporting nothing is rejected.")
@OpenApiResponses.Ok
@OpenApiResponses.Authenticated
@OpenApiResponses.BadRequest
@OpenApiResponses.NotFound
ConfigurationTemplate exportConfigurationTemplate(
@BeanParam RequestParams requestParams,
@Parameter(description = ASSET_ID, example = EXAMPLE_ASSET_ID) @PathParam("assetId")
String assetId,
@Parameter(
description =
"Attribute names to export. Repeat the query parameter for multiple attributes, omit it to export all attributes that have metadata.",
style = ParameterStyle.FORM,
explode = Explode.TRUE)
@QueryParam("attributeName")
List<String> attributeNames);

/**
* Validate a configuration template against an asset draft and report what importing it would do,
* without storing anything. The returned patched attributes are for the client to apply to the
* draft once the user confirms, so the same access as {@link #update} is required. A 400 status
* is returned if no draft is given or the template cannot be imported, and a 409 status if the
* draft no longer identifies the persisted asset. A rejected template is answered with the
* preview, whose failure names the reason and, where known, the location within the template.
*/
@POST
@Path("{assetId}/configurationTemplate/import")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@RolesAllowed({Constants.WRITE_ASSETS_ROLE})
@Operation(
operationId = "previewConfigurationTemplateImport",
summary = "Preview a configuration template import",
description =
"Validates the document, matches its attributes against the draft by name and type, and returns the compatibility report together with the draft attributes holding the imported metadata. Metadata that grants access or links attributes is ignored, and the draft keeps its own. Nothing is stored; the client applies the patch after the user confirms.")
@OpenApiResponses.Ok
@OpenApiResponses.Authenticated
@ApiResponse(
responseCode = "400",
description =
"The draft is missing, or the document cannot be imported; a rejected document is answered with the preview, whose failure names the reason and failureLocation, where known, the attribute, metadata item and parameter",
content = {
@Content(
mediaType = APPLICATION_JSON,
schema = @Schema(implementation = ConfigurationTemplateImportPreview.class)),
@Content(mediaType = "text/plain", schema = @Schema(implementation = String.class))
})
@OpenApiResponses.NotFound
@ApiResponse(
responseCode = "409",
description =
"The draft no longer identifies the persisted asset; the preview failure is DRAFT_MISMATCH",
content =
@Content(
mediaType = APPLICATION_JSON,
schema = @Schema(implementation = ConfigurationTemplateImportPreview.class)))
ConfigurationTemplateImportPreview previewConfigurationTemplateImport(
@BeanParam RequestParams requestParams,
@Parameter(description = ASSET_ID, example = EXAMPLE_ASSET_ID) @PathParam("assetId")
String assetId,
@RequestBody(
required = true,
description =
"The asset draft being edited and the contents of the selected configuration file.")
@NotNull ConfigurationTemplateImportRequest request);

/**
* Updates an attribute of an asset. Regular users can only update assets in their authenticated
* realm, the superuser can update assets in other (all) realms. A 403 status is returned if a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026, OpenRemote Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.model.asset;

import io.swagger.v3.oas.annotations.media.Schema;
import org.openremote.model.attribute.MetaMap;
import org.openremote.model.value.MetaHolder;

/**
* The configuration of a single {@link org.openremote.model.attribute.Attribute} within an {@link
* ConfigurationTemplate}. The attribute name is the document map key, so it is not repeated here.
*/
@Schema(
description =
"Configuration of a single attribute; the attribute name is the key within the document.")
public record AttributeConfiguration(
@Schema(description = "Value descriptor name of the attribute, e.g. number.") String type,
@Schema(description = "Metadata keyed by meta-item name, exactly as stored on the attribute.")
MetaMap meta)
implements MetaHolder {

@Override
public MetaMap getMeta() {
return meta;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026, OpenRemote Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.model.asset;

import io.swagger.v3.oas.annotations.media.Schema;

/** An attribute of a {@link ConfigurationTemplate} as reported to the user. */
@Schema(description = "Name and type of an attribute within an imported document.")
public record AttributeConfigurationSummary(
@Schema(description = "Attribute name.") String name,
@Schema(description = "Value descriptor name of the attribute, e.g. number.") String type) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026, OpenRemote Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.model.asset;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* An attribute that cannot be imported because the target attribute holds a different value type.
*/
@Schema(description = "Attribute skipped on import because the target type differs.")
public record AttributeConfigurationTypeMismatch(
@Schema(description = "Attribute name.") String name,
@Schema(description = "Value descriptor name within the imported document.")
String importedType,
@Schema(description = "Value descriptor name of the target attribute.") String targetType) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2026, OpenRemote Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.model.asset;

import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;

/**
* A configuration template: a user editable document holding the configuration of the {@link
* org.openremote.model.attribute.Attribute}s of an {@link Asset}. Attributes are keyed by attribute
* name.
*/
@Schema(
description =
"Versioned configuration template holding the attribute configuration of an asset, keyed by attribute name.")
public class ConfigurationTemplate {

/** The only document version this release can read and write. */
public static final int CURRENT_VERSION = 1;

@Schema(description = "Document format version.", example = "1")
protected int version;
Comment thread
richturner marked this conversation as resolved.
Resolved

@Schema(description = "Asset type the template was exported from.")
protected String assetType;

@Schema(description = "Attribute configuration keyed by attribute name.")
protected Map<String, AttributeConfiguration> attributes;

@JsonCreator
public ConfigurationTemplate(
int version, String assetType, Map<String, AttributeConfiguration> attributes) {
this.version = version;
this.assetType = assetType;
this.attributes = attributes;
}

public int getVersion() {
return version;
}

public String getAssetType() {
return assetType;
}

public Map<String, AttributeConfiguration> getAttributes() {
return attributes;
}
}
Loading
Loading