NIFI-2540: Exclude from templates the parts of property descriptors that are not necessary. Also ensure that Property Descriptors are not completely removed from Controller Services.

This closes #828
This commit is contained in:
Mark Payne 2016-08-10 11:36:21 -04:00 committed by Oleg Zhurakousky
parent d9720239f5
commit 85877a73dc
2 changed files with 38 additions and 15 deletions

View File

@ -31,10 +31,10 @@ public class PropertyDescriptorDTO {
private String description;
private String defaultValue;
private List<AllowableValueDTO> allowableValues;
private boolean required;
private boolean sensitive;
private boolean dynamic;
private boolean supportsEl;
private Boolean required;
private Boolean sensitive;
private Boolean dynamic;
private Boolean supportsEl;
private String identifiesControllerService;
/**
@ -113,11 +113,11 @@ public class PropertyDescriptorDTO {
@ApiModelProperty(
value = "Whether the property is required."
)
public boolean isRequired() {
public Boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
public void setRequired(Boolean required) {
this.required = required;
}
@ -127,11 +127,11 @@ public class PropertyDescriptorDTO {
@ApiModelProperty(
value = "Whether the property is sensitive and protected whenever stored or represented."
)
public boolean isSensitive() {
public Boolean isSensitive() {
return sensitive;
}
public void setSensitive(boolean sensitive) {
public void setSensitive(Boolean sensitive) {
this.sensitive = sensitive;
}
@ -141,11 +141,11 @@ public class PropertyDescriptorDTO {
@ApiModelProperty(
value = "Whether the property is dynamic (user-defined)."
)
public boolean isDynamic() {
public Boolean isDynamic() {
return dynamic;
}
public void setDynamic(boolean dynamic) {
public void setDynamic(Boolean dynamic) {
this.dynamic = dynamic;
}
@ -155,11 +155,11 @@ public class PropertyDescriptorDTO {
@ApiModelProperty(
value = "Whether the property supports expression language."
)
public boolean getSupportsEl() {
public Boolean getSupportsEl() {
return supportsEl;
}
public void setSupportsEl(boolean supportsEl) {
public void setSupportsEl(Boolean supportsEl) {
this.supportsEl = supportsEl;
}

View File

@ -178,9 +178,11 @@ public class TemplateUtils {
if (processorConfig.getDescriptors() != null) {
final Collection<PropertyDescriptorDTO> descriptors = processorConfig.getDescriptors().values();
for (PropertyDescriptorDTO descriptor : descriptors) {
if (descriptor.isSensitive()) {
if (Boolean.TRUE.equals(descriptor.isSensitive())) {
processorProperties.put(descriptor.getName(), null);
}
scrubPropertyDescriptor(descriptor);
}
}
}
@ -207,6 +209,26 @@ public class TemplateUtils {
}
}
/**
* The only thing that we really need from the Property Descriptors in the templates is the
* flag that indicates whether or not the property identifies a controller service.
* Everything else is unneeded and makes templates very verbose and more importantly makes it
* so that if one of these things changes, the template itself changes, which makes it hard to
* use a CM tool for versioning. So we remove all that we don't need.
*
* @param descriptor the ProeprtyDescriptor to scrub
*/
private static void scrubPropertyDescriptor(final PropertyDescriptorDTO descriptor) {
descriptor.setAllowableValues(null);
descriptor.setDefaultValue(null);
descriptor.setDescription(null);
descriptor.setDisplayName(null);
descriptor.setDynamic(null);
descriptor.setRequired(null);
descriptor.setSensitive(null);
descriptor.setSupportsEl(null);
}
private static void scrubControllerServices(final Set<ControllerServiceDTO> controllerServices) {
for (final ControllerServiceDTO serviceDTO : controllerServices) {
final Map<String, String> properties = serviceDTO.getProperties();
@ -214,13 +236,14 @@ public class TemplateUtils {
if (properties != null && descriptors != null) {
for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
if (descriptor.isSensitive()) {
if (Boolean.TRUE.equals(descriptor.isSensitive())) {
properties.put(descriptor.getName(), null);
}
scrubPropertyDescriptor(descriptor);
}
}
serviceDTO.setDescriptors(null);
serviceDTO.setCustomUiUrl(null);
serviceDTO.setValidationErrors(null);
}