/** * Returns property value as human-readable string . * * @return Returns property value as human-readable string . */ public String getFormattedValue() { return getValue().toString(); }
/** * Returns true if the name of the property field is bounded to is matching the logical name * of the update property. * * @param updatedProperty * {@link SingleProperty}. * @return Returns true if the name of the property field is bounded to is matching the * logical name of the update property. */ public boolean isPropertyMatching(SingleProperty<?> updatedProperty) { return property.equals(updatedProperty.getLogicalName()); } }
/** * {@inheritDoc} */ @Override protected String getErrorMessage(SingleProperty<? extends T> property) { return "Value of property '" + property.getName() + "' must not be empty String/Collection/Map"; } }
/** * Default constructor. * * @param property * {@link SingleProperty} to create update for. */ public RestoreDefaultPropertyUpdate(SingleProperty<V> property) { if (null == property) { throw new IllegalArgumentException("Property can not be null."); } this.propertyLogicalName = property.getLogicalName(); this.defaultValue = property.getDefaultValue(); }
/** * Retrieves against value from {@link #than} for given property. If parsing fails the * {@link PropertyValidation} will be filled with error and <code>null</code> will be returned * as value. * * @param property * Property to get against value for. * @param propertyValidation * Validation to report errors. * @return Value or <code>null</code> if parsing fails. */ private T getAgainstValue(SingleProperty<? extends T> property, PropertyValidation propertyValidation) { T against = property.parseLiteral(than); if (null == against) { ValidationError validationError = new ValidationError(Collections.<SingleProperty<?>> singletonList(property), "Validation of property " + property.getName() + " failed because literal (" + than + ") to compare against can not be parsed."); propertyValidation.addValidationError(validationError); } return against; }
/** * Validates the update value against the property and if validation passes returns the * {@link AbstractPropertyUpdate} object. * * @param updateValue * Update value * @return {@link AbstractPropertyUpdate} * @throws PropertyValidationException * If validation fails. */ public AbstractPropertyUpdate<T> createAndValidatePropertyUpdate(T updateValue) throws PropertyValidationException { if (getValue().equals(updateValue)) { throw new PropertyValidationException("Update value for creating property update can not be same as current property value."); } PropertyValidation propertyValidation = this.validateForValue(updateValue); // if has errors raise exception, otherwise create property update if (propertyValidation.hasErrors()) { throw new PropertyValidationException(propertyValidation); } else { return this.createPropertyUpdate(updateValue); } }
T value = (T) compareProperty.getValue(); T against = (T) againstProperty.getValue(); if (Objects.equals(compareProperty.getLogicalName(), propertyUpdate.getPropertyLogicalName())) { value = (T) propertyUpdate.getUpdateValue(); if (Objects.equals(againstProperty.getLogicalName(), propertyUpdate.getPropertyLogicalName())) { against = (T) propertyUpdate.getUpdateValue(); if (Objects.equals(value, compareProperty.getValue()) && Objects.equals(against, againstProperty.getValue())) { return;
@Test public void validatorIsGreaterThanOrEqual() { when(singleProperty.getValue()).thenReturn(Integer.valueOf(10)); when(singleProperty.getLogicalName()).thenReturn("my.property"); GreaterOrEqualValidator<Number> validator = new GreaterOrEqualValidator<>(); when(singleProperty.parseLiteral(null)).thenReturn(9, 10, 11); validator.validate(singleProperty, propertyValidation); verifyZeroInteractions(propertyValidation); validator.validate(singleProperty, propertyValidation); validator.validate(singleProperty, propertyValidation); verify(propertyValidation, times(1)).addValidationError(Matchers.<ValidationError> anyObject()); }
/** * Sends property update event. * * @param newValue * New value. */ protected void sendPropertyUpdateEvent(V newValue) { if (!property.getValue().equals(newValue)) { try { propertyUpdate = property.createAndValidatePropertyUpdate(newValue); propertyUpdateListener.propertyUpdated(property, propertyUpdate); } catch (PropertyValidationException e) { PropertyValidation propertyValidation = e.getPropertyValidation(); propertyUpdateListener.propertyValidationFailed(property, propertyValidation); } } else { propertyUpdateListener.propertyUpdateCanceled(property); propertyUpdate = null; // NOPMD } }
if (null == property) { throw new Exception("Property " + propertyUpdate.getPropertyLogicalName() + " can not be updated because the property does not exist in the current configuration."); } else if (!property.canUpdate(propertyUpdate)) { throw new Exception("Property " + propertyUpdate.getPropertyLogicalName() + " can not be updated because the property update value is not valid."); SingleProperty<Object> property = configuration.forLogicalName(propertyUpdate.getPropertyLogicalName()); if (propertyUpdate.isRestoreDefault()) { property.setToDefaultValue(); } else { property.setValue(propertyUpdate.getUpdateValue()); String value = property.isPassword() ? property.getFormattedValue().replaceAll(".", "*") : property.getFormattedValue(); LOG.info("Property '" + property.getName() + "' successfully updated, new value is " + value);
name.setText(property.getName() + ":"); name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); info.setToolTipText(property.getDescription()); info.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); if (property.isServerRestartRequired()) { serverRestart.setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_WARNING)); serverRestart.setToolTipText("Changing this property requires restart of the CMR");
PropertySection section = new PropertySection(); SingleProperty<Long> property = new LongProperty("", "", "property1", defaultValue, false, false); property.setValue(45523L); section.addProperty(property); configuration.addSection(section); propertyManager.updateConfiguration(configurationUpdate, false); assertThat(property.getValue(), is(defaultValue)); ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(propertyUpdateExecutor, times(1)).executePropertyUpdates(captor.capture());
if (!getValue().getClass().equals(updateValue.getClass())) { return false; if (getValue().equals(updateValue)) { return false; PropertyValidation propertyValidation = this.validateForValue((T) updateValue); return !propertyValidation.hasErrors();
/** * {@inheritDoc} */ @Override public void register(Properties properties) { if (CollectionUtils.isNotEmpty(singleProperties)) { for (SingleProperty<?> property : singleProperties) { property.register(properties); } } }
/** * {@inheritDoc} */ @Override public boolean isAdvanced() { if (CollectionUtils.isNotEmpty(singleProperties)) { for (SingleProperty<?> singleProperty : singleProperties) { if (singleProperty.isAdvanced()) { return true; } } } return false; }
if ((null == property) || !property.canUpdate(propertyUpdate)) { notValidList.add(propertyUpdate); continue; property.setToDefaultValue(); } else { property.setValue(propertyUpdate.getUpdateValue());
/** * {@inheritDoc} */ @Override public boolean isServerRestartRequired() { if (CollectionUtils.isNotEmpty(singleProperties)) { for (SingleProperty<?> singleProperty : singleProperties) { if (singleProperty.isServerRestartRequired()) { return true; } } } return false; }
assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); assertThat(singleProperty.canUpdate(propertyUpdate), is(false)); assertThat(singleProperty.canUpdate(propertyUpdate), is(true));
@Test public void marshalConfigurationUpdate() throws JAXBException, PropertyValidationException { ConfigurationUpdate configurationUpdate = new ConfigurationUpdate(); SingleProperty<String> property1 = new StringProperty("title", "Define title", "properties.title", "Lorem ipsum", true, false); configurationUpdate.addPropertyUpdate(property1.createAndValidatePropertyUpdate("New value")); SingleProperty<Long> property2 = new LongProperty("speed", "Define speed", "properties.speed", 10L, true, true); configurationUpdate.addPropertyUpdate(property2.createAndValidatePropertyUpdate(1000L)); SingleProperty<Boolean> property3 = new BooleanProperty("boolean", "Define boolean", "properties.boolean", true, true, true); configurationUpdate.addPropertyUpdate(property3.createAndValidatePropertyUpdate(false)); JAXBContext context = JAXBContext.newInstance(ConfigurationUpdate.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(configurationUpdate, System.out); marshaller.marshal(configurationUpdate, f); Unmarshaller unmarshaller = context.createUnmarshaller(); Object object = unmarshaller.unmarshal(f); assertThat(object, is(instanceOf(ConfigurationUpdate.class))); assertThat((ConfigurationUpdate) object, is(equalTo(configurationUpdate))); }
/** * Test that {@link Properties} will reseted to default if it's included in the * {@link ConfigurationUpdate}. */ @Test @SuppressWarnings("unchecked") public void savedPropertyRestoreToDefaultUpdate() throws JAXBException, IOException, SAXException { String defaultValue = "value1"; Configuration configuration = new Configuration(); PropertySection section = new PropertySection(); SingleProperty<String> property = new StringProperty("", "", "property1", defaultValue, false, false); property.setValue("someotherthandefault"); section.addProperty(property); configuration.addSection(section); doReturn(configuration).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(Configuration.class)); doReturn(configurationUpdate).when(transformator).unmarshall(Matchers.<Path> anyObject(), Matchers.<Path> anyObject(), eq(ConfigurationUpdate.class)); AbstractPropertyUpdate<String> propertyUpdate = mock(AbstractPropertyUpdate.class); when(propertyUpdate.getPropertyLogicalName()).thenReturn("property1"); when(propertyUpdate.isRestoreDefault()).thenReturn(true); when(configurationUpdate.getPropertyUpdates()).thenReturn(Collections.<IPropertyUpdate<?>> singleton(propertyUpdate)); Properties properties = propertyManager.getProperties(); assertThat(properties.getProperty("property1"), is(equalTo(defaultValue))); assertThat(properties.size(), is(1)); }