Skip to content

Commit

Permalink
MGR-89 Support type-safe properties (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Jan 14, 2020
1 parent 64ae7ba commit 08ffd8a
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 194 deletions.
16 changes: 4 additions & 12 deletions application-home/conf/datasources/ds-properties.xml
Expand Up @@ -267,21 +267,13 @@
<param name="id" />
</params>
<meta-data binding="property" bindClass="org.appng.application.manager.form.PropertyForm">
<field name="shortName" type="text" readonly="true">
<label>name</label>
</field>
<field name="string" type="text" readonly="true">
<label>activeValue</label>
<field name="type" type="text" hidden="true" />
<field name="value" type="text">
<label>value</label>
</field>
<field name="defaultString" type="text" readonly="true">
<label>defaultvalue</label>
</field>
<field name="actualString" type="text">
<label>value</label>
</field>
<field name="clob" type="longtext" format="auto">
<label>clobvalue</label>
</field>
<field name="description" type="longtext" readonly="true">
<label>description</label>
</field>
Expand Down Expand Up @@ -315,4 +307,4 @@
</bean>
</datasource>

</datasources>
</datasources>
78 changes: 44 additions & 34 deletions application-home/conf/pages/pg-sites.xml
Expand Up @@ -88,7 +88,8 @@
<section>
<!-- create -->
<element passive="true">
<action id="create-site-property" onSuccess="/sites/update/${siteid}#tab_site-properties" eventId="propertyEvent">
<action id="create-site-property" onSuccess="/sites/update/${siteid}#tab_site-properties"
eventId="propertyEvent">
<params>
<param name="siteid">${siteid}</param>
<param name="form_action">${form_action}</param>
Expand All @@ -99,7 +100,8 @@
</element>
<!-- update -->
<element passive="true">
<action id="update-site-property" onSuccess="/sites/update/${siteid}#tab_site-properties" eventId="propertyEvent">
<action id="update-site-property" onSuccess="/sites/update/${siteid}#tab_site-properties"
eventId="propertyEvent">
<params>
<param name="siteid">${siteid}</param>
<param name="propertyid">${subentityid1}</param>
Expand All @@ -122,33 +124,11 @@
</section>

<!-- site application properites -->
<!-- overview -->
<section>
<element>
<datasource id="select-site-application">
<params>
<param name="appid">${selectedappid}</param>
<param name="siteid">${siteid}</param>
<param name="mode">select</param>
<param name="defaultlink">/sites/update/${siteid}</param>
<param name="defaultlinkanchor">#tab_select-site-application</param>
</params>
<condition expression="${action eq 'update'}" />
</datasource>
</element>
<element>
<datasource id="site-application-properties">
<params>
<param name="appid">${selectedappid}</param>
<param name="siteid">${siteid}</param>
<param name="propId">${subentityid2}</param>
</params>
<condition expression="${action eq 'update' and not empty selectedappid}" />
</datasource>
</element>
<!-- create -->
<element passive="true">
<action id="create-site-application-property" onSuccess="/sites/update/${siteid}?selectedappid=${subentityid1}#tab_select-site-application"
<action id="create-site-application-property"
onSuccess="/sites/update/${siteid}?selectedappid=${subentityid1}#tab_select-site-application"
eventId="propertyEvent">
<params>
<param name="siteid">${siteid}</param>
Expand All @@ -161,7 +141,8 @@
</element>
<!-- update -->
<element passive="true">
<action id="update-site-application-property" onSuccess="/sites/update/${siteid}?selectedappid=${subentityid1}#tab_select-site-application"
<action id="update-site-application-property"
onSuccess="/sites/update/${siteid}?selectedappid=${subentityid1}#tab_select-site-application"
eventId="propertyEvent">
<params>
<param name="appid">${subentityid1}</param>
Expand All @@ -172,6 +153,30 @@
expression="${action eq 'update' and not empty siteid and subentity1 eq 'app-property' and subaction1 eq 'update' and not empty subentityid1 and not empty subentityid2}" />
</action>
</element>
<!-- select application -->
<element folded="${not empty subentityid1}">
<datasource id="select-site-application">
<params>
<param name="appid">${selectedappid}</param>
<param name="siteid">${siteid}</param>
<param name="mode">select</param>
<param name="defaultlink">/sites/update/${siteid}</param>
<param name="defaultlinkanchor">#tab_select-site-application</param>
</params>
<condition expression="${action eq 'update'}" />
</datasource>
</element>
<!-- overview -->
<element>
<datasource id="site-application-properties">
<params>
<param name="appid">${selectedappid}</param>
<param name="siteid">${siteid}</param>
<param name="propId">${subentityid2}</param>
</params>
<condition expression="${action eq 'update' and not empty selectedappid}" />
</datasource>
</element>
</section>

<!-- site applications -->
Expand Down Expand Up @@ -211,7 +216,8 @@
<!-- Database Connections -->
<section>
<element passive="true">
<action eventId="databaseConnectionEvent" id="updateConnection" onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="updateConnection"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<params>
<param name="id">${subentityid1}</param>
<param name="form_action">${form_action}</param>
Expand Down Expand Up @@ -299,7 +305,8 @@
<!-- hidden inline actions -->
<section hidden="true">
<element>
<action eventId="databaseConnectionEvent" id="delete" onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="delete"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<params>
<param name="form_action">${form_action}</param>
<param name="id">${conId}</param>
Expand All @@ -310,7 +317,8 @@
</action>
</element>
<element>
<action eventId="databaseConnectionEvent" id="testConnection" onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="testConnection"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<params>
<param name="form_action">${form_action}</param>
<param name="id">${conId}</param>
Expand All @@ -321,7 +329,8 @@
</action>
</element>
<element>
<action eventId="databaseConnectionEvent" id="resetConnection" onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="resetConnection"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<params>
<param name="form_action">${form_action}</param>
<param name="id">${conId}</param>
Expand All @@ -348,7 +357,8 @@
</action>
</element>
<element>
<action id="toggle-applicationstate" onSuccess="/sites/update/${siteid}#tab_site-applications" eventId="applicationEvent" forceForward="false">
<action id="toggle-applicationstate" onSuccess="/sites/update/${siteid}#tab_site-applications"
eventId="applicationEvent" forceForward="false">
<params>
<param name="siteid">${siteid}</param>
<param name="appid">${appid}</param>
Expand All @@ -357,7 +367,8 @@
</action>
</element>
<element>
<action eventId="propertyEvent" id="delete-site-property" onSuccess="/sites/update/${siteid}#tab_site-properties">
<action eventId="propertyEvent" id="delete-site-property"
onSuccess="/sites/update/${siteid}#tab_site-properties">
<params>
<param name="form_action">${form_action}</param>
<param name="propertyid">${propertyid}</param>
Expand Down Expand Up @@ -405,7 +416,6 @@
<param name="siteid">${siteid}</param>
</params>
</action>
</element>
</section>
</structure>
</page>
Expand Down
4 changes: 2 additions & 2 deletions application-home/dictionary/manager-messages.properties
Expand Up @@ -43,7 +43,7 @@ cache.statistics.avgPutTime=Average put time (ms)
cache.statistics.avgGetTime=Average get time (ms)
cache.statistics.avgRemovalTime=Average removal time (ms)
changedOn=Changed on
clobvalue=Multilined value
clobvalue=Multiline value
clusterState=Cluster Status
cluster.notAvailable=No cluster information available, please check your configuration!
cluster.disabled=Clustering is disabled.
Expand Down Expand Up @@ -214,7 +214,7 @@ property.deleted=Property has been deleted.
property.edit=Edit property
property.exists=Another property with this name already exists.
property.not.exists=Property does not exist.
property.stringOrClob=Please set the value or the multilined value.
property.stringOrClob=Please set the value or the multiline value.
property.update.error=Failed to update the property.
property.updated=Property has been updated.
published=Published
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.appng.application.manager.business;

import org.apache.commons.lang3.StringUtils;
import org.appng.api.ActionProvider;
import org.appng.api.BusinessException;
import org.appng.api.DataContainer;
Expand All @@ -24,13 +25,17 @@
import org.appng.api.Options;
import org.appng.api.Request;
import org.appng.api.model.Application;
import org.appng.api.model.Property;
import org.appng.api.model.Property.Type;
import org.appng.api.model.SimpleProperty;
import org.appng.api.model.Site;
import org.appng.application.manager.MessageConstants;
import org.appng.application.manager.form.PropertyForm;
import org.appng.application.manager.service.Service;
import org.appng.application.manager.service.ServiceAware;
import org.appng.core.domain.PropertyImpl;
import org.appng.xml.platform.FieldDef;
import org.appng.xml.platform.FieldType;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -63,11 +68,23 @@ public DataContainer getData(Site site, Application application, Environment env
data = service.searchProperties(fp, siteId, applicationId, propertyName);
if (null != data.getItem()) {
PropertyForm propertyForm = (PropertyForm) data.getItem();
propertyForm.setProperty(new PropertyWrapper(propertyForm.getProperty()));
PropertyWrapper propertyWrapper = new PropertyWrapper(propertyForm.getProperty());
Type type = propertyWrapper.getType();
FieldType expectedType = getFieldTypeForPropertyType(type);
FieldDef field = fp.getField("property.value");
field.setType(expectedType);
if (FieldType.DECIMAL.equals(expectedType)) {
String value = propertyWrapper.getActualString();
int dotIdx = value.indexOf('.');
int fraction = dotIdx > 0 ? value.substring(dotIdx + 1).length() : 3;
field.setFormat("#." + StringUtils.repeat('#', fraction));
}
field.getLabel().setValue(propertyWrapper.getShortName());
propertyForm.setProperty(propertyWrapper);
} else {
@SuppressWarnings("unchecked")
Page<PropertyImpl> page = (Page<PropertyImpl>) data.getPage();
data.setPage(page.map(p -> new PropertyWrapper(p)));
data.setPage(page.map(p -> new PropertyWrapper(p, true)));
}
} catch (BusinessException ex) {
String message = request.getMessage(ex.getMessageKey(), ex.getMessageArgs());
Expand All @@ -78,13 +95,31 @@ public DataContainer getData(Site site, Application application, Environment env
return data;
}

private FieldType getFieldTypeForPropertyType(Type type) {
switch (type) {
case INT:
return FieldType.INT;
case DECIMAL:
return FieldType.DECIMAL;
case BOOLEAN:
return FieldType.CHECKBOX;
case PASSWORD:
return FieldType.PASSWORD;
case MULTILINE:
return FieldType.LONGTEXT;
default:
return FieldType.TEXT;
}
}

public void perform(Site site, Application application, Environment environment, Options options, Request request,
PropertyForm propertyForm, FieldProcessor fp) {
String action = getAction(options);
String errorMessage = null;
String okMessage = null;
Service service = getService();
String propertyName = options.getOptionValue(PROPERTY, ID);
String propertyName = options.getString(PROPERTY, ID);

try {
if (ACTION_CREATE.equals(action)) {
errorMessage = MessageConstants.PROPERTY_CREATE_ERROR;
Expand Down Expand Up @@ -113,12 +148,21 @@ public void perform(Site site, Application application, Environment environment,

public class PropertyWrapper extends PropertyImpl {
private SimpleProperty property;
private boolean hidePassword;

PropertyWrapper(SimpleProperty property) {
this(property, true);
}

PropertyWrapper(SimpleProperty property, boolean hidePassword) {
this.property = property;
this.hidePassword = hidePassword;
}

public String getActualString() {
if (hidePassword && Property.Type.PASSWORD.equals(getType())) {
return property.getActualString().replaceAll("\\.", "*");
}
return property.getActualString();
}

Expand All @@ -138,10 +182,18 @@ public Boolean getBoolean() {
return property.getBoolean();
}

public void setBoolean(Boolean value) {
property.setActualString(value.toString());
}

public Integer getInteger() {
return property.getInteger();
}

public void setInteger(Integer value) {
property.setActualString(value.toString());
}

public Float getFloat() {
return property.getFloat();
}
Expand Down Expand Up @@ -170,6 +222,18 @@ public String getDefaultString() {
return property.getDefaultString();
}

public Type getType() {
return property.getType();
}

public Object getValue() {
return property.getValue();
}

public void setValue(Object value) {
property.setValue(value);
}

public String getDescription() {
return property.getDescription();
}
Expand Down
Expand Up @@ -24,14 +24,14 @@
import org.appng.api.Options;
import org.appng.api.Request;
import org.appng.api.model.Application;
import org.appng.api.model.Property;
import org.appng.api.model.Site;
import org.appng.core.domain.PropertyImpl;

/**
* Bindclass used for creating/updating a {@link PropertyImpl}.
*
* @author Matthias Müller
*
*/
public class PropertyForm implements FormValidator {
private PropertyImpl property;
Expand Down Expand Up @@ -61,6 +61,7 @@ public void validate(Site site, Application application, Environment environment
if (isCreate) {
fieldValue = getProperty().getDefaultString();
fieldName = "property.defaultString";
property.determineType();
} else {
fieldValue = getProperty().getActualString();
fieldName = "property.actualString";
Expand All @@ -72,6 +73,11 @@ public void validate(Site site, Application application, Environment environment
fp.addErrorMessage(fp.getField("property.clob"), message);
fp.addErrorMessage(fp.getField(fieldName), message);
}
if (Property.Type.BOOLEAN.equals(getProperty().getType())) {
String stringValue = getProperty().getString();
boolean value = stringValue.equalsIgnoreCase("on") || stringValue.equalsIgnoreCase("true");
getProperty().setValue(value);
}
}

}

0 comments on commit 08ffd8a

Please sign in to comment.