Skip to content

Commit

Permalink
SHIBUI-2268
Browse files Browse the repository at this point in the history
Adjusted code for better output to the UI of the properties list
  • Loading branch information
chasegawa committed Aug 17, 2022
1 parent a57f9b6 commit 4ac5009
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.internet2.tier.shibboleth.admin.util.EmptyStringToNullConverter;
import lombok.Data;
import org.hibernate.envers.Audited;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.UUID;
Expand All @@ -23,35 +26,52 @@ public class ShibConfigurationProperty {
String configFile;

@Column(name = "default_value")
@Convert(converter = EmptyStringToNullConverter.class)
String defaultValue;

@Column(name = "description")
@Convert(converter = EmptyStringToNullConverter.class)
String description;

@Column(name = "idp_version", nullable = false)
String idpVersion;

@Column(name = "module")
@Convert(converter = EmptyStringToNullConverter.class)
String module;

@Column(name = "module_version")
@Convert(converter = EmptyStringToNullConverter.class)
String moduleVersion;

@Column(name = "note")
@Convert(converter = EmptyStringToNullConverter.class)
String note;

@Column(name = "property_name", nullable = false)
String propertyName;

@Column(name = "property_type", nullable = false)
@JsonIgnore // display type is sent to the ui instead
PropertyType propertyType;

@Column(name = "property_value")
String propertyValue;

@Column(name = "selection_items")
@Convert(converter = EmptyStringToNullConverter.class)
String selectionItems;

public String getDisplayType() {
switch (propertyType) {
case BOOLEAN:
return propertyType.name().toLowerCase();
case INTEGER:
return "number";
case SELECTION_LIST:
return "list";
default: // DURATION, SPRING_BEAN_ID, STRING
return "string";
}
}

public void setPropertyType(String val) {
this.propertyType = PropertyType.valueOf(val);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.internet2.tier.shibboleth.admin.util;

import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class EmptyStringToNullConverter implements AttributeConverter<String, String> {
@Override
public String convertToDatabaseColumn(String string) {
// if whitespace is set on a value, send null to the db
return StringUtils.defaultIfBlank(string, null);
}

@Override
public String convertToEntityAttribute(String dbData) {
// keep nulls from the db as nulls
return dbData;
}
}

0 comments on commit 4ac5009

Please sign in to comment.