Permalink
Browse files

Fixes #59, public assets and improved restricted access, new AssetMod…

…elProvider SPI
  • Loading branch information...
christianbauer committed Dec 3, 2017
1 parent e72b0e8 commit fe0119e6e708048ae7d75f811addbe4bde06f5c1
Showing with 1,278 additions and 560 deletions.
  1. +9 −5 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AbstractAssetActivity.java
  2. +2 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetBaseView.java
  3. +2 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEdit.java
  4. +6 −1 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditActivity.java
  5. +19 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java
  6. +17 −5 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml
  7. +2 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
  8. +11 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java
  9. +22 −8 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
  10. +16 −0 manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
  11. +10 −8 manager/client/src/main/java/org/openremote/manager/client/assets/attributes/MetaEditor.java
  12. +4 −0 manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java
  13. +28 −0 manager/client/src/main/java/org/openremote/manager/client/widget/FormAnchor.java
  14. +5 −1 manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties
  15. +16 −4 manager/client/src/main/webapp/css/style.html
  16. +5 −0 manager/client/src/main/webapp/css/theme.html
  17. +3 −3 manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
  18. +1 −1 manager/server/src/main/java/org/openremote/manager/server/asset/AssetAttributeLinkingService.java
  19. +89 −0 manager/server/src/main/java/org/openremote/manager/server/asset/AssetModel.java
  20. +129 −128 manager/server/src/main/java/org/openremote/manager/server/asset/AssetResourceImpl.java
  21. +2 −2 manager/server/src/main/java/org/openremote/manager/server/asset/AssetRoute.java
  22. +63 −57 manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
  23. +18 −12 manager/server/src/main/java/org/openremote/manager/server/asset/ServerAsset.java
  24. +2 −0 manager/server/src/main/java/org/openremote/manager/server/rules/RulesEngine.java
  25. +27 −27 manager/server/src/main/java/org/openremote/manager/server/setup/AbstractManagerSetup.java
  26. +1 −1 manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java
  27. +10 −9 ...rg/openremote/manager/server/setup/database/{V20171031_01__Schema.sql → V20171203_01__Schema.sql}
  28. +24 −9 manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetResource.java
  29. +166 −35 model/src/main/java/org/openremote/model/asset/AbstractAssetQuery.java
  30. +28 −17 model/src/main/java/org/openremote/model/asset/Asset.java
  31. +16 −8 model/src/main/java/org/openremote/model/asset/AssetAttribute.java
  32. +47 −113 model/src/main/java/org/openremote/model/asset/AssetMeta.java
  33. +31 −0 model/src/main/java/org/openremote/model/asset/AssetModelProvider.java
  34. +38 −0 model/src/main/java/org/openremote/model/asset/DefaultAssetModelProvider.java
  35. +18 −8 model/src/main/java/org/openremote/model/asset/UserAsset.java
  36. +6 −0 model/src/main/java/org/openremote/model/attribute/Attribute.java
  37. +3 −24 model/src/main/java/org/openremote/model/attribute/MetaItem.java
  38. +70 −7 model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
  39. +36 −0 model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
  40. +3 −0 model/src/main/java/org/openremote/model/value/ObjectValue.java
  41. +1 −0 model/src/main/resources/META-INF/services/org.openremote.model.asset.AssetModelProvider
  42. +11 −0 profile/dev-testing.yml
  43. +2 −2 test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
  44. +149 −56 test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
  45. +99 −0 test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
  46. +11 −9 test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -211,6 +211,7 @@ public void writeAssetToView() {
view.setLocation(asset.getCoordinates());
view.showDroppedPin(asset.getGeoFeature(20));
view.flyTo(asset.getCoordinates());
view.setAccessPublicRead(asset.isAccessPublicRead());
}
@Override
@@ -360,8 +361,10 @@ protected void validateAttribute(boolean clientSideOny, AssetAttribute attribute
}
protected Optional<MetaItemDescriptor> getMetaItemDescriptor(MetaItem item) {
return AssetMeta
.getAssetMeta(item.getName().orElse(""))
// TODO Should use meta item descriptors from server
return Arrays.stream(AssetMeta.values())
.filter(assetMeta -> assetMeta.getUrn().equals(item.getName().orElse("")))
.findFirst()
.map(assetMeta -> (MetaItemDescriptor)assetMeta);
}
@@ -398,10 +401,11 @@ protected boolean isValueReadOnly(ValueHolder valueHolder) {
// Meta item value is read only if value is fixed
if (valueHolder instanceof MetaItem) {
return ((MetaItem) valueHolder).getName()
.flatMap(AssetMeta::getAssetMeta)
// TODO Should use meta item descriptors from server
return Arrays.stream(AssetMeta.values())
.filter(assetMeta -> assetMeta.getUrn().equals(((MetaItem) valueHolder).getName()))
.map(AssetMeta::isValueFixed)
.orElse(false);
.findFirst().orElse(false);
}
if (valueHolder instanceof AssetAttribute) {
@@ -75,6 +75,8 @@
void flyTo(double[] coordinates);
void setAccessPublicRead(boolean enabled);
void setAttributeViews(List<AttributeView> attributeViews);
void addAttributeViews(List<AttributeView> attributeViews);
@@ -39,6 +39,8 @@
void onMapClicked(double lng, double lat);
void onAccessPublicRead(boolean enabled);
void onAssetTypeSelected(AssetType value);
boolean addAttribute(String name, String type);
@@ -86,7 +86,7 @@
protected final AssetAttributeMapper assetAttributeMapper;
protected final Consumer<ConstraintViolation[]> validationErrorHandler;
protected List<ProtocolDescriptor> protocolDescriptors = new ArrayList<>();
protected List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>(Arrays.asList(AssetMeta.values()));
protected List<MetaItemDescriptor> metaItemDescriptors = new ArrayList<>(Arrays.asList(AssetMeta.values())); // TODO Get meta item descriptors from server
double[] selectedCoordinates;
protected List<AssetAttribute> initialAssetAttributes;
@@ -196,6 +196,11 @@ public void onMapClicked(double lng, double lat) {
view.setLocation(selectedCoordinates);
}
@Override
public void onAccessPublicRead(boolean enabled) {
asset.setAccessPublicRead(enabled);
}
@Override
public void onAssetTypeSelected(AssetType type) {
asset.setType(type);
@@ -116,6 +116,11 @@
@UiField
MapWidget mapWidget;
@UiField
FormGroup accessPublicReadGroup;
@UiField
FormCheckBox accessPublicReadCheckBox;
/* ############################################################################ */
@UiField
@@ -216,6 +221,12 @@ public String render(AssetType assetType) {
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
accessPublicReadCheckBox.addValueChangeHandler(event -> {
if (presenter != null) {
presenter.onAccessPublicRead(event.getValue());
}
});
splitPanel.setOnResize(() -> mapWidget.resize());
}
@@ -234,6 +245,8 @@ public void setPresenter(Presenter presenter) {
parentAssetSelector.init();
locationOutput.setCoordinates(null, null);
centerMapButton.setEnabled(false);
accessPublicReadCheckBox.setValue(false);
typeGroup.setVisible(false);
typeGroup.setError(false);
typeListBox.setValue(null);
typeListBox.setAcceptableValues(new ArrayList<>());
@@ -416,6 +429,11 @@ void centerMapClicked(ClickEvent e) {
presenter.centerMap();
}
@Override
public void setAccessPublicRead(boolean enabled) {
accessPublicReadCheckBox.setValue(enabled);
}
/* ############################################################################ */
@Override
@@ -442,6 +460,7 @@ public void setType(String type) {
@Override
public void setTypeEditable(boolean editable) {
typeGroup.setVisible(editable);
typeListBox.setEnabled(editable);
typeInput.setReadOnly(!editable);
customTypeInfoLabel.setVisible(editable && typeListBox.getValue() == AssetType.CUSTOM);
@@ -13,13 +13,13 @@
.mapWidget {
margin: 0 0 1em 1em;
height: 17em;
height: 19em;
}
.stringEditor {
min-width: 5em;
width: 100%;
}
min-width: 5em;
width: 100%;
}
.numberEditor {
min-width: 5em;
@@ -125,14 +125,26 @@
</w:FormGroupActions>
</w:actions>
</w:FormGroup>
<w:FormGroup ui:field="accessPublicReadGroup">
<w:label>
<w:FormLabel text="{managerMessages.publicAccess}"/>
</w:label>
<w:field>
<w:FormField addStyleNames="larger">
<w:FormCheckBox ui:field="accessPublicReadCheckBox"/>
</w:FormField>
</w:field>
</w:FormGroup>
</div>
<w:MapWidget ui:field="mapWidget"
addStyleNames="flex self-end {style.mapWidget} {widgetStyle.ItemWithBorder}"/>
</div>
<div class="layout horizontal center wrap">
<w:FormGroup ui:field="typeGroup" addStyleNames="flex">
<w:FormGroup ui:field="typeGroup" addStyleNames="flex" visible="false">
<w:label>
<w:FormLabel text="{managerMessages.assetType}"/>
</w:label>
@@ -33,4 +33,6 @@
void setFormBusy(boolean busy);
void setIconAndType(String icon, String type);
void setAccessPublicReadAnchor(String path);
}
@@ -19,6 +19,7 @@
*/
package org.openremote.manager.client.assets.asset;
import com.google.gwt.http.client.URL;
import com.google.inject.Provider;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.app.dialog.JsonEditor;
@@ -53,6 +54,7 @@
import org.openremote.model.datapoint.NumberDatapoint;
import org.openremote.model.event.shared.TenantFilter;
import org.openremote.model.simulator.SimulatorState;
import org.openremote.model.value.Values;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -275,6 +277,15 @@ protected void fetchAgentStatus(String agentId) {
public void writeAssetToView() {
super.writeAssetToView();
view.setIconAndType(asset.getWellKnownType().getIcon(), asset.getType());
// Build the link manually, shorter result than AssetQueryMapper, and we must hardcode the path anyway
String query = Values.createObject()
.put("select", Values.createObject().put("include", Values.create("ALL")))
.put("id", Values.create(asset.getId()))
.toJson();
view.setAccessPublicReadAnchor(
"/" + asset.getTenantRealm() + "/asset/public/query?q=" + URL.encodeQueryString(query)
);
}
protected List<FormButton> createAttributeActions(AssetAttribute attribute, AttributeViewImpl view) {
@@ -26,6 +26,7 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import com.google.inject.Provider;
import org.openremote.manager.client.Environment;
@@ -42,8 +43,6 @@
import org.openremote.model.Constants;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetType;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.geo.GeoJSON;
import org.openremote.model.value.ObjectValue;
@@ -128,6 +127,13 @@
@UiField
MapWidget mapWidget;
@UiField
FormGroup accessPublicReadGroup;
@UiField
FormCheckBox accessPublicReadCheckBox;
@UiField
FormAnchor accessPublicReadAnchor;
/* ############################################################################ */
FlowPanel liveUpdatesNavItem = new FlowPanel();
@@ -149,7 +155,6 @@
final List<AttributeView> attributeViews = new ArrayList<>();
protected Presenter presenter;
protected Asset asset;
protected EventRegistration<AttributeEvent> eventRegistration;
@Inject
public AssetViewImpl(AssetBrowser assetBrowser,
@@ -223,10 +228,9 @@ public void setPresenter(Presenter presenter) {
mapWidget.setVisible(false);
showDroppedPin(GeoJSON.EMPTY_FEATURE_COLLECTION);
if (eventRegistration != null) {
environment.getEventBus().remove(eventRegistration);
eventRegistration = null;
}
accessPublicReadGroup.setVisible(false);
accessPublicReadCheckBox.setValue(false);
accessPublicReadAnchor.setHref("");
attributeViews.clear();
attributeViewContainer.clear();
@@ -329,6 +333,17 @@ public void flyTo(double[] coordinates) {
}
}
@Override
public void setAccessPublicRead(boolean enabled) {
accessPublicReadGroup.setVisible(enabled);
accessPublicReadCheckBox.setValue(enabled);
}
@Override
public void setAccessPublicReadAnchor(String path) {
accessPublicReadAnchor.setHref(Window.Location.getProtocol() + "//" + Window.Location.getHost() + path);
}
@Override
public void setAttributeViews(List<AttributeView> attributeViews) {
this.attributeViews.clear();
@@ -356,7 +371,6 @@ public void removeAttributeViews(List<AttributeView> attributeViews) {
@Override
public void setIconAndType(String icon, String type) {
headline.setIcon(icon);
// TODO: Should unknown/undefined asset type default to custom
AssetType assetType = AssetType.getByValue(type).orElse(AssetType.CUSTOM);
if (assetType == AssetType.CUSTOM) {
headline.setSub(type);
@@ -122,6 +122,22 @@
</w:actions>
</w:FormGroup>
<w:FormGroup ui:field="accessPublicReadGroup">
<w:label>
<w:FormLabel text="{managerMessages.publicAccess}"/>
</w:label>
<w:field>
<w:FormField addStyleNames="larger">
<g:HTMLPanel styleName="layout horizontal center">
<w:FormCheckBox ui:field="accessPublicReadCheckBox" enabled="false"/>
<w:FormAnchor ui:field="accessPublicReadAnchor"
target="_blank"
text="{managerMessages.shareLink}"/>
</g:HTMLPanel>
</w:FormField>
</w:field>
</w:FormGroup>
</div>
<w:MapWidget ui:field="mapWidget"
@@ -299,9 +299,7 @@ public MetaEditor(Environment environment, AttributeView.Style style, String exi
}
}
metaItemDescriptors.addAll(
Arrays.asList(environment.getSecurityService().isSuperUser() ? AssetMeta.values() : AssetMeta.unRestricted())
);
metaItemDescriptors.addAll(Arrays.asList(AssetMeta.values())); // TODO Get meta item descriptors from server
this.metaItemDescriptors = metaItemDescriptors.stream()
.filter(metaItemDescriptor -> {
@@ -349,7 +347,7 @@ protected String getAddButtonLabel() {
protected List<MetaItemEditor> getExistingItemEditors() {
return IntStream.range(0, itemListPanel.getWidgetCount())
.mapToObj(i -> (MetaItemEditor)itemListPanel.getWidget(i))
.mapToObj(i -> (MetaItemEditor) itemListPanel.getWidget(i))
.collect(Collectors.toList());
}
@@ -376,11 +374,15 @@ protected IsWidget createItemValueEditor(MetaItemEditor itemEditor) {
}
protected void onMetaItemTypeChanged(MetaItemEditor itemEditor, boolean updateItem) {
Optional<AssetMeta> assetMeta = AssetMeta.getAssetMeta(itemEditor.nameList.getSelectedValue());
if (updateItem) {
itemEditor.item.clearValue();
Value initialValue = assetMeta.map(AssetMeta::getInitialValue).orElse(null);
// TODO Should use meta item descriptors from server
Value initialValue = Arrays.stream(AssetMeta.values())
.filter(assetMeta -> assetMeta.getUrn().equals(itemEditor.nameList.getSelectedValue()))
.map(MetaItemDescriptor::getInitialValue)
.findFirst().orElse(null);
ValueType valueType = EnumUtil.enumFromString(ValueType.class, itemEditor.typeList.getSelectedValue()).orElse(null);
if (valueType == ValueType.BOOLEAN && initialValue == null) {
initialValue = Values.create(false);
@@ -484,7 +486,7 @@ public void onValidationStateChange(AttributeValidationResult validationResult)
List<MetaItemEditor> editors = getExistingItemEditors();
IntStream.range(0, editors.size())
.forEach(i -> {
MetaItemEditor editor = editors.get(i);
MetaItemEditor editor = editors.get(i);
List<ValidationFailure> failures = !hasMetaFailures ? null : validationResult.getMetaFailures().get(i);
updateEditorFailures(editor, failures);
}
@@ -522,4 +522,8 @@
String refreshDeviceRegistrations();
String tenant();
String publicAccess();
String shareLink();
}
Oops, something went wrong.

0 comments on commit fe0119e

Please sign in to comment.