target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test void shouldReturnNullWhenToStringAndValueIsNull() { String converted = typeConverter.toString(TestClass.class, null, null); assertThat(converted).isNull(); }
@Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
@Test void shouldThrowExceptionWhenTypeIsNullAndToString() { assertThatThrownBy(() -> typeConverter.toString(null, null, null)) .isExactlyInstanceOf(NullPointerException.class) .hasMessage("type cannot be null"); }
@Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
JsonConverter implements TypeConverter<T> { @Override public String toString(Type type, T value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); if (value == null) { return null; } try { ObjectWriter objectWriter = objectMapper.writer(); return objectWriter.writeValueAsString(value); } catch (JsonProcessingException e) { throw new UncheckedIOException("Unable to process JSON.", e); } } JsonConverter(); JsonConverter(boolean ignoreConverterAttribute); @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
@Test public void shouldCreateEmptyKeySet() { KeyGenerator keyGenerator = emptyKeyGenerator(); List<String> configurationKeys = emptyList(); KeyGenerator fallbackKeyPrefixGenerator = emptyKeyGenerator(); List<String> keys = KeySetUtils.keySet(keyGenerator, configurationKeys, fallbackKeyPrefixGenerator, null); assertThat(keys).isEmpty(); }
public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey); }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey); }
@Test public void shouldGenerateKeySet() { KeyGenerator keyGenerator = keyGenerator("fallback", "fallback.p1", "fallback.p1.p2"); List<String> configurationKeys = asList("key", "alternateKey", "duplicate", "duplicate"); KeyGenerator fallbackKeyPrefixGenerator = keyGenerator("fallbackKeyPrefix"); String fallbackKey = "fallbackKey"; List<String> keys = KeySetUtils.keySet(keyGenerator, configurationKeys, fallbackKeyPrefixGenerator, fallbackKey); assertThat(keys).containsSequence( "fallback.key", "fallback.alternateKey", "fallback.duplicate", "fallback.p1.key", "fallback.p1.alternateKey", "fallback.p1.duplicate", "fallback.p1.p2.key", "fallback.p1.p2.alternateKey", "fallback.p1.p2.duplicate", "fallbackKeyPrefix.key", "fallbackKeyPrefix.alternateKey", "fallbackKeyPrefix.duplicate", "fallbackKey" ); }
public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey); }
KeySetUtils { public static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey) { requireNonNull(keyGenerator, "keyGenerator cannot be null"); requireNonNull(keys, "keys cannot be null"); Set<String> keySet = new LinkedHashSet<>(keyGenerator.computeKeys(keys)); if (fallbackKeyPrefixGenerator != null) { keySet.addAll(fallbackKeyPrefixGenerator.computeKeys(keys)); } if (isNotBlank(fallbackKey)) { keySet.add(fallbackKey); } List<String> result = new ArrayList<>(keySet.size()); keySet.forEach(k -> result.add(k.intern())); return result; } private KeySetUtils(); static List<String> keySet(KeyGenerator keyGenerator, List<String> keys, KeyGenerator fallbackKeyPrefixGenerator, String fallbackKey); }
@Test public void shouldExecuteMainWithoutExceptions() { SpringAnnotationBasedExample.main(new String[0]); }
public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } }
SpringAnnotationBasedExample { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } } }
SpringAnnotationBasedExample { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } } }
SpringAnnotationBasedExample { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } } static void main(String[] args); }
SpringAnnotationBasedExample { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringAnnotationBasedExample.class)) { context.getBean(SpringAnnotationBasedExample.class).run(); } } static void main(String[] args); }
@Test public void shouldProvidePrefixForSubConfiguration() { List<String> prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfiguration")); assertThat(prefixes).containsSequence("subConfiguration"); prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurations")); assertThat(prefixes).containsSequence("subConfigurations"); }
@Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvidePrefixForSubConfigurationWithPrefix() { List<String> prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurationWithPrefix")); assertThat(prefixes).isEmpty(); prefixes = extractor.getPrefixes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurationWithPrefixList")); assertThat(prefixes).isEmpty(); }
@Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<String> getPrefixes(Class<?> configurationType) { Key keyAnnotation = findAnnotation(configurationType, Key.class); String[] prefixes = (keyAnnotation == null) ? null : keyAnnotation.value(); if (prefixes != null && prefixes.length == 0) { prefixes = new String[]{decapitalize(configurationType.getSimpleName())}; } return prefixes == null ? emptyList() : unmodifiableList(asList(prefixes)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideDefaultValuesForSubConfigurationList() { List<Map<String, String>> values = extractor.getSubConfigurationListDefaultValues(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurations")); assertThat(values).hasSize(2); assertThat(values.get(0)).contains( entry("one", "1"), entry("two", "first")); assertThat(values.get(1)).contains( entry("one", "2"), entry("two", "second")); }
@Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDefaultsAnnotations(subConfigurationClazz, method); return getDefaultValues(defaultsAnnotations); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDefaultsAnnotations(subConfigurationClazz, method); return getDefaultValues(defaultsAnnotations); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDefaultsAnnotations(subConfigurationClazz, method); return getDefaultValues(defaultsAnnotations); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDefaultsAnnotations(subConfigurationClazz, method); return getDefaultValues(defaultsAnnotations); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method) { Class<?> subConfigurationClazz = getSubConfigurationListElementType(configurationType, method); Annotation[] defaultsAnnotations = getDefaultsAnnotations(subConfigurationClazz, method); return getDefaultValues(defaultsAnnotations); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideDefaultValuesForSubConfiguration() { Map<String, String> values = extractor.getSubConfigurationDefaultValues(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfiguration")); assertThat(values).hasSize(2); assertThat(values).contains( entry("one", "1"), entry("two", "the one")); }
@Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnotation(method.getReturnType(), DefaultsAnnotation.class).value(); @SuppressWarnings("unchecked") Annotation annotation = findAnnotation(method, (Class<? extends Annotation>) defaultsAnnotation); return getDefaultValues(annotation); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnotation(method.getReturnType(), DefaultsAnnotation.class).value(); @SuppressWarnings("unchecked") Annotation annotation = findAnnotation(method, (Class<? extends Annotation>) defaultsAnnotation); return getDefaultValues(annotation); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnotation(method.getReturnType(), DefaultsAnnotation.class).value(); @SuppressWarnings("unchecked") Annotation annotation = findAnnotation(method, (Class<? extends Annotation>) defaultsAnnotation); return getDefaultValues(annotation); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnotation(method.getReturnType(), DefaultsAnnotation.class).value(); @SuppressWarnings("unchecked") Annotation annotation = findAnnotation(method, (Class<? extends Annotation>) defaultsAnnotation); return getDefaultValues(annotation); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method) { if (!isAnnotationDeclaredLocally(method.getReturnType(), DefaultsAnnotation.class)) { return emptyMap(); } Class<?> defaultsAnnotation = findAnnotation(method.getReturnType(), DefaultsAnnotation.class).value(); @SuppressWarnings("unchecked") Annotation annotation = findAnnotation(method, (Class<? extends Annotation>) defaultsAnnotation); return getDefaultValues(annotation); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideAttributesForValueProperty() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class, getMethod(TestConfiguration.class, "getUrl")); assertThat(attributes).containsExactly( entry("custom", "url")); }
@Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideAttributesForSubConfigurationProperty() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfiguration")); assertThat(attributes).containsExactly( entry("custom", "sub-configuration")); }
@Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideAttributesForSubConfigurationListProperty() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class, getMethod(TestConfiguration.class, "getSubConfigurations")); assertThat(attributes).containsExactly( entry("custom", "sub-configuration-list")); }
@Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideAttributesForType() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class); assertThat(attributes).containsExactly( entry("type1", "value1"), entry("type2", "value2")); }
@Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldProvideAttributesForCustomMetaAnnotations() { Map<String, String> attributes = extractor.attributes(TestConfiguration.class, getMethod(TestConfiguration.class, "getCustomMetaAnnotations")); assertThat(attributes).containsOnly( entry("fixed-one", "one"), entry("fixed-two", "two"), entry("custom", "custom-meta"), entry("attribute", "custom-attribute"), entry("another-attribute", "another-custom-attribute") ); }
@Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
AnnotationMetadataExtractor implements MetadataExtractor { @Override public Map<String, String> attributes(Class<?> configurationType) { return AttributesUtils.attributes(getMetaAttributes(configurationType)); } static MetadataExtractor getInstance(); @Override boolean isConfigurationClass(Class<?> clazz); @Override boolean isAbstractConfiguration(Class<?> clazz); @Override boolean isValueConfigurationMethod(Class<?> configurationType, Method method); @Override boolean isSubConfigurationMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationType(Class<?> configurationType, Method method); @Override boolean isSubConfigurationListMethod(Class<?> configurationType, Method method); @Override Class<?> getSubConfigurationListElementType(Class<?> configurationType, Method method); @Override String getDescription(Class<?> configurationType); @Override String getDescription(Class<?> configurationType, Method method); @Override List<String> getKeys(Class<?> configurationType, Method method); @Override List<String> getPrefixes(Class<?> configurationType); @Override List<String> getPrefixes(Class<?> configurationType, Method method); @Override boolean shouldResetPrefix(Class<?> configurationType, Method method); @Override String getFallbackKey(Class<?> configurationType, Method method); @Override @SuppressWarnings("unchecked") Class<TypeConverter<?>> getTypeConverter(Class<?> configurationType, Method method); @Override String getEncryptionProvider(Class<?> configurationType, Method method); @Override Integer getDefaultSubConfigurationListSize(Class<?> configurationType, Method method); @Override OptionalValue<String> getDefaultValue(Class<?> configurationType, Method method); @Override Map<String, String> getSubConfigurationDefaultValues(Class<?> configurationType, Method method); @Override List<Map<String, String>> getSubConfigurationListDefaultValues(Class<?> configurationType, Method method); @Override Map<String, String> attributes(Class<?> configurationType); @Override Map<String, String> attributes(Class<?> configurationType, Method method); }
@Test public void shouldExtractAttributesFromFixedAnnotation() { Map<String, String> attributes = getMetaAttributes(FixedAttributesUsage.class); assertThat(attributes).containsOnly( entry("one", "value-one"), entry("two", "value-two") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExecuteMainWithoutExceptions() { SpringExample.main(new String[0]); }
public static void main(String[] args) { new SpringExample().run(); }
SpringExample { public static void main(String[] args) { new SpringExample().run(); } }
SpringExample { public static void main(String[] args) { new SpringExample().run(); } }
SpringExample { public static void main(String[] args) { new SpringExample().run(); } static void main(String[] args); }
SpringExample { public static void main(String[] args) { new SpringExample().run(); } static void main(String[] args); }
@Test public void shouldExtractAttributesFromFixedAnnotationForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(FixedAttributesUsage.class, "fixedAnnotationOnly")); assertThat(attributes).containsOnly( entry("one", "value-one"), entry("two", "value-two") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromFixedAnnotationAndMetaForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(FixedAttributesUsage.class, "fixedAnnotationAndMeta")); assertThat(attributes).containsOnly( entry("one", "value-one"), entry("two", "value-two"), entry("another-meta", "anotherValue") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromCustomizableForType() { Map<String, String> attributes = getMetaAttributes(CustomizableValueUsage.class); assertThat(attributes).containsOnly( entry("name", "type-level") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromCustomizableForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(CustomizableValueUsage.class, "customizableOnly")); assertThat(attributes).containsOnly( entry("name", "method-level") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromCustomizableAndMetaForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(CustomizableValueUsage.class, "customizableAndMeta")); assertThat(attributes).containsOnly( entry("name", "method-level-with-additional-meta"), entry("another-meta", "anotherValue") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromMultipleAttributesForType() { Map<String, String> attributes = getMetaAttributes(MultipleAttributesUsage.class); assertThat(attributes).containsOnly( entry("first", "first-attribute-value"), entry("second", "second-attribute-value") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromMultipleAttributesForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(MultipleAttributesUsage.class, "customizableOnly")); assertThat(attributes).containsOnly( entry("first", "first-attribute-value"), entry("second", "second-attribute-value") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromMultipleAttributesAndMetaForMethod() { Map<String, String> attributes = getMetaAttributes(getMethod(MultipleAttributesUsage.class, "customizableAndMeta")); assertThat(attributes).containsOnly( entry("first", "first-attribute-value"), entry("second", "defaultSecondValue"), entry("another-meta", "anotherValue-meta") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExtractAttributesFromManyAnnotationsForMethod() { Map<String, String> attributes = getMetaAttributes(MultipleAnnotationsUsage.class); assertThat(attributes).containsOnly( entry("one", "value-one"), entry("two", "value-two"), entry("name", "custom-value"), entry("first", "first"), entry("second", "second"), entry("meta", "custom-meta") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldFindAllMetaDataInTheHierarchy() { Map<String, String> attributes; attributes = getMetaAttributes(BaseConfiguration.class); assertThat(attributes).containsOnly( entry("name", "type-base"), entry("base", "type-base") ); attributes = getMetaAttributes(ChildConfiguration.class); assertThat(attributes).containsOnly( entry("name", "type-child"), entry("base", "type-base"), entry("child", "type-base") ); attributes = getMetaAttributes(getMethod(BaseConfiguration.class, "getValue")); assertThat(attributes).containsOnly( entry("name", "property-base"), entry("meta", "property-base") ); attributes = getMetaAttributes(getMethod(ChildConfiguration.class, "getAnotherValue")); assertThat(attributes).containsOnly( entry("name", "another-property-child") ); attributes = getMetaAttributes(getMethod(ChildConfiguration.class, "getAnotherValue")); assertThat(attributes).containsOnly( entry("name", "another-property-child") ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldExecuteMainWithoutExceptions() { CoreExample.main(new String[0]); }
public static void main(String[] args) { new CoreExample().run(); }
CoreExample { public static void main(String[] args) { new CoreExample().run(); } }
CoreExample { public static void main(String[] args) { new CoreExample().run(); } }
CoreExample { public static void main(String[] args) { new CoreExample().run(); } static void main(String[] args); }
CoreExample { public static void main(String[] args) { new CoreExample().run(); } static void main(String[] args); }
@Test public void shouldFailIfNotAllAttributesAreAnnotated() { assertThrows(IllegalArgumentException.class, () -> getMetaAttributes(NotAllAttributesAreAnnotatedUsage.class), "All @com.sabre.oss.conf4j.internal.model.provider.annotation.AttributesExtractorTest$NotAllAttributesAreAnnotated(annotated=annotatedValue, notAnnotated=notAnnotatedValue) " + "annotations attributes must be annotated with @com.sabre.oss.conf4j.annotation.Meta." ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldFailIfMoreThanAttributeIsDefined() { assertThrows(IllegalArgumentException.class, () -> getMetaAttributes(TooManyAttributesUsage.class), "@com.sabre.oss.conf4j.internal.model.provider.annotation.AttributesExtractorTest$TooManyAttributes(attribute=attribute, anotherAttribute=anotherAttribute) " + "annotation is meta-annotated with @com.sabre.oss.conf4j.annotation.Meta and define more than one attribute: " + "anotherAttribute, attribute " ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldFailIfInvalidAttributeType() { assertThrows(IllegalArgumentException.class, () -> getMetaAttributes(InvalidAttributeTypeUsage.class), "@com.sabre.oss.conf4j.internal.model.provider.annotation.AttributesExtractorTest$InvalidAttributeType(attribute=[1, 2]) " + "annotation is meta-annotated with @com.sabre.oss.conf4j.annotation.Meta and its attribute 'attribute' " + "type is [Ljava.lang.String;. Only scalar, simple types are supported." ); }
static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
AttributesExtractor { static Map<String, String> getMetaAttributes(Class<?> clazz) { requireNonNull(clazz, "clazz cannot be null"); return attributesByTypeCache.computeIfAbsent(clazz, c -> getMetaAttributes(getAnnotations(c))); } private AttributesExtractor(); }
@Test public void shouldFindPublicAbstractMethodInClass() throws NoSuchMethodException { abstract class TestClass { public abstract int propertyA(); } Collection<Method> methods = methodsProvider.getAllDeclaredMethods(TestClass.class); assertThat(methods).contains(TestClass.class.getMethod("propertyA")); }
public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
@Test public void shouldFindPublicAbstractMethodInheritedFromAbstractMethod() throws NoSuchMethodException { abstract class AbstractClass { public abstract int propertyA(); } abstract class TestClass extends AbstractClass { public abstract int propertyB(); } Collection<Method> methods = methodsProvider.getAllDeclaredMethods(TestClass.class); assertThat(methods).contains(AbstractClass.class.getMethod("propertyA"), TestClass.class.getMethod("propertyB")); }
public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
@Test public void shouldFindMethodInheritedFromInterface() throws NoSuchMethodException { abstract class TestClass implements TestInterface { public abstract int propertyB(); } Collection<Method> methods = methodsProvider.getAllDeclaredMethods(TestClass.class); assertThat(methods).contains(TestInterface.class.getMethod("propertyA"), TestClass.class.getMethod("propertyB")); }
public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
@Test public void shouldHandleMethodFromSubclass() throws NoSuchMethodException { abstract class BaseConf { public abstract Integer propertyA(); } abstract class SpecificConf extends BaseConf { @Override public abstract Integer propertyA(); } abstract class AbstractClass { public abstract BaseConf propertyB(); } abstract class TestClass extends AbstractClass { @Override public abstract SpecificConf propertyB(); } Collection<Method> methods = methodsProvider.getAllDeclaredMethods(TestClass.class); assertThat(methods).contains(TestClass.class.getMethod("propertyB")); }
public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
MethodsProvider { public Collection<Method> getAllDeclaredMethods(Class<?> configurationType) { Class<?> type = configurationType; Set<MethodWrapper> methods = new LinkedHashSet<>(addMethods(type.getMethods())); if (type.getSuperclass() != null) { do { methods.addAll(addMethods(type.getDeclaredMethods())); type = type.getSuperclass(); } while (!Object.class.equals(type)); } return methods.stream() .map(MethodWrapper::getMethod) .collect(toList()); } Collection<Method> getAllDeclaredMethods(Class<?> configurationType); }
@Test public void shouldReturnFromFallbackKey() { when(source.getValue("fallback.p1.p2.key", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldReturnFromFallbackAlternateKey() { when(source.getValue("fallback.p1.p2.alternateKey", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldReturnFromFallbackPrefix() { when(source.getValue("fallback.key", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldResolvePropertyPlaceholdersSetWithCorrectOrder() { assertThat(source.getValue("property.only.in.A", null)).isEqualTo(present("A")); assertThat(source.getValue("property.only.in.B", null)).isEqualTo(present("B")); assertThat(source.getValue("property.in.A.and.B", null)).isEqualTo(present("B")); }
@Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySources) { OptionalValue<String> value = getProperty(propertySource, key); if (value.isPresent()) { return value; } } return absent(); }
PropertySourceConfigurationSource implements ConfigurationSource, BeanFactoryAware, EnvironmentAware, InitializingBean { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySources) { OptionalValue<String> value = getProperty(propertySource, key); if (value.isPresent()) { return value; } } return absent(); } }
PropertySourceConfigurationSource implements ConfigurationSource, BeanFactoryAware, EnvironmentAware, InitializingBean { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySources) { OptionalValue<String> value = getProperty(propertySource, key); if (value.isPresent()) { return value; } } return absent(); } }
PropertySourceConfigurationSource implements ConfigurationSource, BeanFactoryAware, EnvironmentAware, InitializingBean { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySources) { OptionalValue<String> value = getProperty(propertySource, key); if (value.isPresent()) { return value; } } return absent(); } void setPropertySources(PropertySources propertySources); @Override void setBeanFactory(BeanFactory beanFactory); @Override void setEnvironment(Environment environment); void setConversionService(ConversionService conversionService); @Override void afterPropertiesSet(); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
PropertySourceConfigurationSource implements ConfigurationSource, BeanFactoryAware, EnvironmentAware, InitializingBean { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (PropertySource<?> propertySource : flattenedPropertySources) { OptionalValue<String> value = getProperty(propertySource, key); if (value.isPresent()) { return value; } } return absent(); } void setPropertySources(PropertySources propertySources); @Override void setBeanFactory(BeanFactory beanFactory); @Override void setEnvironment(Environment environment); void setConversionService(ConversionService conversionService); @Override void afterPropertiesSet(); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
@Test public void shouldReturnFromFallbackKeyPrefix() { Mockito.lenient().when(source.getValue("fallbackKeyPrefix.key", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldNotReturnFallbackKeyPrefixValueWhenFallbackKeyPrefixIsEmpty() { Mockito.lenient().when(source.getValue(".key", null)).thenReturn(present("value")); fallbackKeyPrefixGenerator = emptyKeyGenerator(); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("methodDefaultValue")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldReturnFallbackKeyValue() { when(source.getValue("fallbackKey", null)).thenReturn(present("value")); OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("value")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldNotReturnFallbackKeyValueWhenFallbackKeyIsEmpty() { Mockito.lenient().when(source.getValue("", null)).thenReturn(present("value")); fallbackKey = null; OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("methodDefaultValue")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldReturnMethodDefaultValue() { OptionalValue<String> result = provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); assertThat(result).isEqualTo(present("methodDefaultValue")); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldCallValueProcessor() { ConfigurationValueProcessor configurationValueProcessor = mock(ConfigurationValueProcessor.class); when(configurationValueProcessor.process(any(ConfigurationValue.class))).thenAnswer(invocation -> invocation.getArguments()[0]); when(source.getValue("fallback.key", null)).thenReturn(present("fallback.key")); provider = new DefaultConfigurationValueProvider(singletonList(configurationValueProcessor)); provider.getConfigurationValue(typeConverter, source, metadata(getKeySet(), defaultValue, notEncrypted)); verify(configurationValueProcessor, times(1)).process(any(ConfigurationValue.class)); }
@Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
DefaultConfigurationValueProvider implements ConfigurationValueProvider { @Override public <T> OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata) { requireNonNull(typeConverter, "typeConverter cannot be null"); requireNonNull(metadata, "metadata cannot be null"); OptionalValue<String> value = absent(); String resolvedKey = null; Map<String, String> attributes = metadata.getAttributes(); if (configurationSource != null) { ConfigurationEntry configurationEntry = configurationSource.findEntry(metadata.getKeySet(), attributes); if (configurationEntry != null) { resolvedKey = configurationEntry.getKey(); value = present(configurationEntry.getValue()); } } boolean fromDefaultValue = value.isAbsent(); if (fromDefaultValue) { value = metadata.getDefaultValue(); } if (value.isAbsent()) { return absent(); } String resolvedValue = value.get(); String val = applyProcessors(new ConfigurationValue(resolvedKey, resolvedValue, fromDefaultValue, metadata.getEncryptionProvider(), attributes)); @SuppressWarnings("unchecked") TypeConverter<T> currentTypeConverter = defaultIfNull((TypeConverter<T>) metadata.getTypeConverter(), typeConverter); return present(currentTypeConverter.fromString(metadata.getType(), val, attributes)); } DefaultConfigurationValueProvider(List<ConfigurationValueProcessor> configurationValueProcessors); @Override OptionalValue<T> getConfigurationValue(TypeConverter<T> typeConverter, ConfigurationSource configurationSource, PropertyMetadata metadata); }
@Test public void shouldReturnNullWhenPropertiesAreNull() { Map<String, String> properties = null; Map<String, String> attributes = attributes(properties); assertThat(attributes).isNull(); }
public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
@Test public void shouldConstructFromMap() { Map<String, String> properties = MapUtils.of("key1", "val1", "key2", "val2"); Map<String, String> attributes = attributes(properties); assertThat(attributes).isNotNull(); assertThat(attributes).contains(entry("key1", "val1"), entry("key2", "val2")); }
public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
@Test public void shouldBeImmutable() { assertThrows(UnsupportedOperationException.class, () -> attributes(MapUtils.of("key", "value")).put("anything", "value") ); }
public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
@Test public void shouldMergeToNullWhenBothAreNull() { Map<String, String> merged = mergeAttributes(null, null); assertThat(merged).isNull(); }
public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size() + child.size()); merged.putAll(parent); merged.putAll(child); return getCached(unmodifiableMap(merged), false); }
AttributesUtils implements Serializable { public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size() + child.size()); merged.putAll(parent); merged.putAll(child); return getCached(unmodifiableMap(merged), false); } }
AttributesUtils implements Serializable { public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size() + child.size()); merged.putAll(parent); merged.putAll(child); return getCached(unmodifiableMap(merged), false); } private AttributesUtils(); }
AttributesUtils implements Serializable { public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size() + child.size()); merged.putAll(parent); merged.putAll(child); return getCached(unmodifiableMap(merged), false); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
AttributesUtils implements Serializable { public static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child) { if (parent == null) { return getCached(child, true); } if (child == null) { return getCached(parent, true); } Map<String, String> merged = new LinkedHashMap<>(parent.size() + child.size()); merged.putAll(parent); merged.putAll(child); return getCached(unmodifiableMap(merged), false); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
@Test public void shouldIntegrateWithSpring() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class)) { TypeConverter<?> typeConverter = context.getBean(TypeConverter.class); assertThat(typeConverter).isInstanceOf(CachingTypeConverter.class); Long val = (Long) typeConverter.fromString(Long.class, "10", null); Long val2 = (Long) typeConverter.fromString(Long.class, "10", null); assertThat(val).isEqualTo(10L); assertThat(val2).isSameAs(val); SampleConfiguration configuration = context.getBean(SampleConfiguration.class); Long valueFromConfiguration = configuration.getValue(); assertThat(valueFromConfiguration).isEqualTo(10L); assertThat(valueFromConfiguration).isSameAs(val); } }
@SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } }
CachingTypeConverter implements TypeConverter<T>, InitializingBean { @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } } }
CachingTypeConverter implements TypeConverter<T>, InitializingBean { @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } } }
CachingTypeConverter implements TypeConverter<T>, InitializingBean { @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } } TypeConverter<?> getTypeConverter(); void setTypeConverter(TypeConverter<T> typeConverter); CacheManager getCacheManager(); void setCacheManager(CacheManager cacheManager); String getCacheName(); void setCacheName(String cacheName); @Override void afterPropertiesSet(); @Override boolean isApplicable(Type type, Map<String, String> attributes); @SuppressWarnings("unchecked") @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
CachingTypeConverter implements TypeConverter<T>, InitializingBean { @SuppressWarnings("unchecked") @Override public T fromString(Type type, String value, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); SimpleKey key = new SimpleKey(type, attributes, value); ValueWrapper valueWrapper = cache.get(key); if (valueWrapper != null) { return (T) valueWrapper.get(); } else { T val = typeConverter.fromString(type, value, attributes); valueWrapper = cache.putIfAbsent(key, val); if (valueWrapper == null) { return val; } else { return (T) valueWrapper.get(); } } } TypeConverter<?> getTypeConverter(); void setTypeConverter(TypeConverter<T> typeConverter); CacheManager getCacheManager(); void setCacheManager(CacheManager cacheManager); String getCacheName(); void setCacheName(String cacheName); @Override void afterPropertiesSet(); @Override boolean isApplicable(Type type, Map<String, String> attributes); @SuppressWarnings("unchecked") @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
@Test public void shouldProvideSameInstanceForSameProperties() { Map<String, String> properties = MapUtils.of("key1", "value1", "key2", "value2"); Map<String, String> sameProperties = new HashMap<>(properties); Map<String, String> attributes = attributes(properties); Map<String, String> attributesForSameProperties = attributes(sameProperties); assertThat(attributesForSameProperties).isSameAs(attributes); }
public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
AttributesUtils implements Serializable { public static Map<String, String> attributes(Map<String, String> attributes) { return getCached(attributes, true); } private AttributesUtils(); static Map<String, String> attributes(Map<String, String> attributes); static Map<String, String> mergeAttributes(Map<String, String> parent, Map<String, String> child); }
@Test public void shouldGetProperties() { Bean bean = new Bean(); assertThat(getProperty(bean, "intValue")).isEqualTo(0); assertThat(getProperty(bean, "stringValue")).isNull(); assertThat(getProperty(bean, "beanValue")).isNull(); bean.setIntValue(1); assertThat(getProperty(bean, "intValue")).isEqualTo(bean.getIntValue()); bean.setStringValue("string"); assertThat(getProperty(bean, "stringValue")).isSameAs(bean.getStringValue()); bean.setBeanValue(new Bean()); assertThat(getProperty(bean, "beanValue")).isSameAs(bean.getBeanValue()); }
public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void shouldSetProperties() { Bean bean = new Bean(); setProperty(bean, "intValue", 1); assertThat(bean.getIntValue()).isEqualTo(1); setProperty(bean, "stringValue", "string"); assertThat(bean.getStringValue()).isEqualTo("string"); Bean beanValue = new Bean(); setProperty(bean, "beanValue", beanValue); assertThat(bean.getBeanValue()).isSameAs(beanValue); setProperty(bean, "stringValue", null); assertThat(bean.getStringValue()).isNull(); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyShouldThrowNoSuchMethodExceptionWhenPropertyNotFound() { assertThrows(IllegalArgumentException.class, () -> getProperty(new Bean(), "unknownProperty")); }
public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyShouldThrowNoSuchMethodExceptionWhenPropertyIsCapitalized() { assertThrows(IllegalArgumentException.class, () -> getProperty(new Bean(), "BeanValue")); }
public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyShouldThrowNullPointerExceptionWhenNullBean() { assertThrows(NullPointerException.class, () -> getProperty(null, "intValue")); }
public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyShouldThrowNullPointerExceptionWhenNullPropertyName() { assertThrows(NullPointerException.class, () -> getProperty(new Bean(), null)); }
public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static Object getProperty(Object bean, String name) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method readMethod = descriptor.getReadMethod(); return readMethod.invoke(bean, EMPTY_OBJECT_ARRAY); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to get property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void setPropertyShouldThrowExceptionWhenPropertyTypeMismatch() { assertThrows(IllegalArgumentException.class, () -> setProperty(new Bean(), "beanValue", "invalid-type")); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void setPropertyShouldThrowNoSuchMethodExceptionWhenPropertyNotFound() { assertThrows(IllegalArgumentException.class, () -> setProperty(new Bean(), "unknownProperty", null)); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void setPropertyShouldThrowNoSuchMethodExceptionWhenPropertyIsCapitalized() { assertThrows(IllegalArgumentException.class, () -> setProperty(new Bean(), "BeanValue", null)); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void shouldBeApplicableForMultipleXmlTypes() { assertThat(jaxbTypeConverter.isApplicable(XmlRootConfiguration01.class, null)).isTrue(); assertThat(jaxbTypeConverter.isApplicable(XmlRootConfiguration02.class, null)).isTrue(); }
@Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
@Test public void setPropertyShouldThrowNullPointerExceptionWhenNullBean() { assertThrows(NullPointerException.class, () -> setProperty(null, "intValue", 1)); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void setPropertyShouldThrowNullPointerExceptionWhenNullPropertyName() { assertThrows(NullPointerException.class, () -> setProperty(new Bean(), null, null)); }
public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static void setProperty(Object bean, String name, Object value) { requireNonNull(bean, "bean cannot be null"); requireNonNull(name, "name cannot be null"); Class<?> beanClass = bean.getClass(); try { PropertyDescriptor descriptor = findPropertyDescriptor(beanClass, name); Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { throw new IllegalArgumentException("Unable to set property '" + name + " on " + bean.getClass() + " because setter of type " + descriptor.getPropertyType() + " is not available"); } writeMethod.invoke(bean, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Unable to set property " + name + " on " + bean.getClass(), e); } } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyNameShouldProvidePropertyNameFromValidAccessor() { assertThat(getPropertyName(getMethod(Bean.class, "getIntValue"))).isEqualTo("intValue"); assertThat(getPropertyName(getMethod(Bean.class, "setIntValue"))).isEqualTo("intValue"); assertThat(getPropertyName(getMethod(Bean.class, "getStringValue"))).isEqualTo("stringValue"); assertThat(getPropertyName(getMethod(Bean.class, "isBooleanValue"))).isEqualTo("booleanValue"); assertThat(getPropertyName(getMethod(Bean.class, "setBooleanValue"))).isEqualTo("booleanValue"); }
public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyNameShouldThrowNPEWhenMethodIsNull() { assertThrows(NullPointerException.class, () -> getPropertyName(null)); }
public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void getPropertyNameShouldThrowIAEWhenMethodIsNotGetterNorSetter() { assertThrows(IllegalArgumentException.class, () -> getPropertyName(getMethod(Bean.class, "equals"))); }
public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
PropertyUtils { public static String getPropertyName(Method method) { requireNonNull(method, "method cannot be null"); String name = method.getName(); if (name.startsWith("set")) { if (method.getParameterCount() != 1) { throw new IllegalArgumentException("Method " + method + " is not a valid setter."); } name = name.substring(3); } else if (name.startsWith("get") || name.startsWith("is")) { if (method.getParameterCount() != 0 || void.class.equals(method.getReturnType())) { throw new IllegalArgumentException("Method " + method + " is not a valid getter."); } name = name.substring(name.startsWith("get") ? 3 : 2); } else { throw new IllegalArgumentException("Method " + name + " is not a valid getter nor setter."); } return decapitalize(name); } private PropertyUtils(); static String getPropertyName(Method method); static Object getProperty(Object bean, String name); static void setProperty(Object bean, String name, Object value); }
@Test public void shouldReturnValuesFromProperSource() { assertThat(source.getValue(A_KEY, null).get()).isEqualTo(A_KEY); assertThat(source.getValue(B_KEY, null).get()).isEqualTo(B_KEY); }
@Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (ConfigurationSource source : sources) { OptionalValue<String> value = source.getValue(key, attributes); if (value.isPresent()) { return value; } } return absent(); }
MultiConfigurationSource implements ConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (ConfigurationSource source : sources) { OptionalValue<String> value = source.getValue(key, attributes); if (value.isPresent()) { return value; } } return absent(); } }
MultiConfigurationSource implements ConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (ConfigurationSource source : sources) { OptionalValue<String> value = source.getValue(key, attributes); if (value.isPresent()) { return value; } } return absent(); } MultiConfigurationSource(List<ConfigurationSource> sources); }
MultiConfigurationSource implements ConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (ConfigurationSource source : sources) { OptionalValue<String> value = source.getValue(key, attributes); if (value.isPresent()) { return value; } } return absent(); } MultiConfigurationSource(List<ConfigurationSource> sources); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
MultiConfigurationSource implements ConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); for (ConfigurationSource source : sources) { OptionalValue<String> value = source.getValue(key, attributes); if (value.isPresent()) { return value; } } return absent(); } MultiConfigurationSource(List<ConfigurationSource> sources); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
@Test public void shouldFindValuesInProperSource() { assertThat(source.findEntry(asList("NotExistingKey", B_KEY), null)).isEqualTo(new ConfigurationEntry(B_KEY, B_KEY)); }
@Override public ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes) { requireNonNull(keys, "keys cannot be null"); for (ConfigurationSource source : sources) { ConfigurationEntry entry = source.findEntry(keys, attributes); if (entry != null) { return entry; } } return null; }
MultiConfigurationSource implements ConfigurationSource { @Override public ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes) { requireNonNull(keys, "keys cannot be null"); for (ConfigurationSource source : sources) { ConfigurationEntry entry = source.findEntry(keys, attributes); if (entry != null) { return entry; } } return null; } }
MultiConfigurationSource implements ConfigurationSource { @Override public ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes) { requireNonNull(keys, "keys cannot be null"); for (ConfigurationSource source : sources) { ConfigurationEntry entry = source.findEntry(keys, attributes); if (entry != null) { return entry; } } return null; } MultiConfigurationSource(List<ConfigurationSource> sources); }
MultiConfigurationSource implements ConfigurationSource { @Override public ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes) { requireNonNull(keys, "keys cannot be null"); for (ConfigurationSource source : sources) { ConfigurationEntry entry = source.findEntry(keys, attributes); if (entry != null) { return entry; } } return null; } MultiConfigurationSource(List<ConfigurationSource> sources); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
MultiConfigurationSource implements ConfigurationSource { @Override public ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes) { requireNonNull(keys, "keys cannot be null"); for (ConfigurationSource source : sources) { ConfigurationEntry entry = source.findEntry(keys, attributes); if (entry != null) { return entry; } } return null; } MultiConfigurationSource(List<ConfigurationSource> sources); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override ConfigurationEntry findEntry(Collection<String> keys, Map<String, String> attributes); }
@Test public void shouldGetSingleValueFromUnderlyingMap() { ConfigurationSource source = new MapConfigurationSource(of("key1", "value1", "key2", "value2")); String value = source.getValue("key2", null).get(); assertThat(value).isEqualTo("value2"); }
@Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); String value = source.get(key); return value != null || source.containsKey(key) ? present(value) : absent(); }
MapConfigurationSource implements IterableConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); String value = source.get(key); return value != null || source.containsKey(key) ? present(value) : absent(); } }
MapConfigurationSource implements IterableConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); String value = source.get(key); return value != null || source.containsKey(key) ? present(value) : absent(); } MapConfigurationSource(Map<String, String> source); }
MapConfigurationSource implements IterableConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); String value = source.get(key); return value != null || source.containsKey(key) ? present(value) : absent(); } MapConfigurationSource(Map<String, String> source); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override Iterable<ConfigurationEntry> getAllConfigurationEntries(); }
MapConfigurationSource implements IterableConfigurationSource { @Override public OptionalValue<String> getValue(String key, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); String value = source.get(key); return value != null || source.containsKey(key) ? present(value) : absent(); } MapConfigurationSource(Map<String, String> source); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override Iterable<ConfigurationEntry> getAllConfigurationEntries(); }
@Test public void shouldIterateOver() { MapConfigurationSource source = new MapConfigurationSource(of("key1", "value1", "key2", "value2")); Iterable<ConfigurationEntry> iterable = source.getAllConfigurationEntries(); assertThat(iterable).containsExactly(new ConfigurationEntry("key1", "value1"), new ConfigurationEntry("key2", "value2")); }
@Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { return new MapConfigurationEntryIterable(source); }
MapConfigurationSource implements IterableConfigurationSource { @Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { return new MapConfigurationEntryIterable(source); } }
MapConfigurationSource implements IterableConfigurationSource { @Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { return new MapConfigurationEntryIterable(source); } MapConfigurationSource(Map<String, String> source); }
MapConfigurationSource implements IterableConfigurationSource { @Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { return new MapConfigurationEntryIterable(source); } MapConfigurationSource(Map<String, String> source); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override Iterable<ConfigurationEntry> getAllConfigurationEntries(); }
MapConfigurationSource implements IterableConfigurationSource { @Override public Iterable<ConfigurationEntry> getAllConfigurationEntries() { return new MapConfigurationEntryIterable(source); } MapConfigurationSource(Map<String, String> source); @Override OptionalValue<String> getValue(String key, Map<String, String> attributes); @Override Iterable<ConfigurationEntry> getAllConfigurationEntries(); }
@Test public void shouldSetAndGetValue() { WritableConfigurationSource mapConfigurationSource = new WritableMapConfigurationSource(new HashMap<>()); mapConfigurationSource.setValue("key", "value", null); OptionalValue<String> value = mapConfigurationSource.getValue("key", null); assertThat(value.isPresent()).isTrue(); assertThat(value.get()).isEqualTo("value"); }
@Override public void setValue(String key, String value, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); source.put(key, value); }
WritableMapConfigurationSource extends MapConfigurationSource implements WritableConfigurationSource { @Override public void setValue(String key, String value, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); source.put(key, value); } }
WritableMapConfigurationSource extends MapConfigurationSource implements WritableConfigurationSource { @Override public void setValue(String key, String value, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); source.put(key, value); } WritableMapConfigurationSource(Map<String, String> source); }
WritableMapConfigurationSource extends MapConfigurationSource implements WritableConfigurationSource { @Override public void setValue(String key, String value, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); source.put(key, value); } WritableMapConfigurationSource(Map<String, String> source); @Override void setValue(String key, String value, Map<String, String> attributes); @Override OptionalValue<String> removeValue(String key, Map<String, String> attributes); }
WritableMapConfigurationSource extends MapConfigurationSource implements WritableConfigurationSource { @Override public void setValue(String key, String value, Map<String, String> attributes) { requireNonNull(key, "key cannot be null"); source.put(key, value); } WritableMapConfigurationSource(Map<String, String> source); @Override void setValue(String key, String value, Map<String, String> attributes); @Override OptionalValue<String> removeValue(String key, Map<String, String> attributes); }
@Test public void shouldNotBeApplicableForNonXmlTypes() { assertThat(jaxbTypeConverter.isApplicable(NonXmlConfiguration.class, null)).isFalse(); }
@Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
JaxbConverter implements TypeConverter<T> { @Override public boolean isApplicable(Type type, Map<String, String> attributes) { requireNonNull(type, "type cannot be null"); return type instanceof Class && ((AnnotatedElement) type).getAnnotation(XmlRootElement.class) != null; } @Override boolean isApplicable(Type type, Map<String, String> attributes); @Override T fromString(Type type, String value, Map<String, String> attributes); @Override String toString(Type type, T value, Map<String, String> attributes); }
@Test public void shouldClearFieldAndDisabledButtonWhenMatchingChangeoverNormWasnotFound() throws Exception { when(changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine)).thenReturn(null); when(view.getComponentByReference(NUMBER)).thenReturn(number); when(view.getComponentByReference(FROM_TECHNOLOGY)).thenReturn(fromTechLookup); when(view.getComponentByReference(TO_TECHNOLOGY)).thenReturn(toTechLookup); when(view.getComponentByReference(FROM_TECHNOLOGY_GROUP)).thenReturn(fromTechGpLookup); when(view.getComponentByReference(TO_TECHNOLOGY_GROUP)).thenReturn(toTechGpLookup); when(view.getComponentByReference(CHANGEOVER_TYPE)).thenReturn(changeoverTypField); when(view.getComponentByReference(DURATION)).thenReturn(durationField); when(view.getComponentByReference(PRODUCTION_LINE)).thenReturn(productionLineLookup); when(view.getComponentByReference("form")).thenReturn(form); when(view.getComponentByReference("window")).thenReturn((ComponentState) window); when(window.getRibbon()).thenReturn(ribbon); when(ribbon.getGroupByName("matching")).thenReturn(matching); when(ribbon.getGroupByName("editing")).thenReturn(matching); when(matching.getItemByName("edit")).thenReturn(edit); listeners.matchingChangeoverNorm(view, state, null); Mockito.verify(fromTechLookup).setFieldValue(null); Mockito.verify(edit).setEnabled(false); }
public void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { Entity fromTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_FROM_TECHNOLOGY)) .getEntity(); Entity toTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_TO_TECHNOLOGY)).getEntity(); Entity productionLine = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_PRODUCTION_LINE)) .getEntity(); FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity changeoverNorm = changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine); if (changeoverNorm == null) { clearField(viewDefinitionState); changeStateEditButton(viewDefinitionState, false); form.setFieldValue(null); } else { form.setFieldValue(changeoverNorm.getId()); fillField(viewDefinitionState, changeoverNorm); changeStateEditButton(viewDefinitionState, true); } }
MatchingChangeoverNormsDetailsListeners { public void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { Entity fromTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_FROM_TECHNOLOGY)) .getEntity(); Entity toTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_TO_TECHNOLOGY)).getEntity(); Entity productionLine = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_PRODUCTION_LINE)) .getEntity(); FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity changeoverNorm = changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine); if (changeoverNorm == null) { clearField(viewDefinitionState); changeStateEditButton(viewDefinitionState, false); form.setFieldValue(null); } else { form.setFieldValue(changeoverNorm.getId()); fillField(viewDefinitionState, changeoverNorm); changeStateEditButton(viewDefinitionState, true); } } }
MatchingChangeoverNormsDetailsListeners { public void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { Entity fromTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_FROM_TECHNOLOGY)) .getEntity(); Entity toTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_TO_TECHNOLOGY)).getEntity(); Entity productionLine = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_PRODUCTION_LINE)) .getEntity(); FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity changeoverNorm = changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine); if (changeoverNorm == null) { clearField(viewDefinitionState); changeStateEditButton(viewDefinitionState, false); form.setFieldValue(null); } else { form.setFieldValue(changeoverNorm.getId()); fillField(viewDefinitionState, changeoverNorm); changeStateEditButton(viewDefinitionState, true); } } }
MatchingChangeoverNormsDetailsListeners { public void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { Entity fromTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_FROM_TECHNOLOGY)) .getEntity(); Entity toTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_TO_TECHNOLOGY)).getEntity(); Entity productionLine = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_PRODUCTION_LINE)) .getEntity(); FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity changeoverNorm = changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine); if (changeoverNorm == null) { clearField(viewDefinitionState); changeStateEditButton(viewDefinitionState, false); form.setFieldValue(null); } else { form.setFieldValue(changeoverNorm.getId()); fillField(viewDefinitionState, changeoverNorm); changeStateEditButton(viewDefinitionState, true); } } void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void redirectToChangedNormsDetails(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void enabledButtonAfterSelectionTechnologies(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void changeStateEditButton(final ViewDefinitionState view, final boolean enabled); void clearField(final ViewDefinitionState view); void fillField(final ViewDefinitionState view, final Entity entity); }
MatchingChangeoverNormsDetailsListeners { public void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { Entity fromTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_FROM_TECHNOLOGY)) .getEntity(); Entity toTechnology = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_TO_TECHNOLOGY)).getEntity(); Entity productionLine = ((LookupComponent) viewDefinitionState.getComponentByReference(MATCHING_PRODUCTION_LINE)) .getEntity(); FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Entity changeoverNorm = changeoverNormsService.getMatchingChangeoverNorms(fromTechnology, toTechnology, productionLine); if (changeoverNorm == null) { clearField(viewDefinitionState); changeStateEditButton(viewDefinitionState, false); form.setFieldValue(null); } else { form.setFieldValue(changeoverNorm.getId()); fillField(viewDefinitionState, changeoverNorm); changeStateEditButton(viewDefinitionState, true); } } void matchingChangeoverNorm(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void redirectToChangedNormsDetails(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void enabledButtonAfterSelectionTechnologies(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void changeStateEditButton(final ViewDefinitionState view, final boolean enabled); void clearField(final ViewDefinitionState view); void fillField(final ViewDefinitionState view, final Entity entity); }
@Test public final void shouldNotPerformEntityStateChangeIfOwnerHasValidationErrors() { AlmostRealStateChangeService stateChangeService = new AlmostRealStateChangeService(); given(stateChangeContext.isOwnerValid()).willReturn(true, false); stateChangeService.changeState(stateChangeContext); verify(stateChangeContext).setStatus(StateChangeStatus.FAILURE); }
@Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
@Test public final void shouldMarkStateChangeAsFailureAndRethrowExceptionWhenStateChangePhaseThrowsException() { ExceptionThrowingStateChangeService stateChangeService = new ExceptionThrowingStateChangeService(); try { stateChangeService.changeState(stateChangeContext); } catch (StateChangeException e) { verify(stateChangeContext).setStatus(StateChangeStatus.FAILURE); verify(stateChangeContext, Mockito.atLeastOnce()).save(); } }
@Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
@Test public final void shouldMarkStateChangeAsFailureAndRethrowExceptionWhenOwnerEntityValidatorThrowException() { AlmostRealStateChangeService stateChangeService = new AlmostRealStateChangeService(); given(ownerDD.callValidators(Mockito.any(Entity.class))).willThrow(new RuntimeException()); try { stateChangeService.changeState(stateChangeContext); } catch (StateChangeException e) { verify(stateChangeContext).setStatus(StateChangeStatus.FAILURE); verify(stateChangeContext, Mockito.atLeastOnce()).save(); } }
@Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
@Test public final void shouldMarkStateChangeAsFailureWhenOwnerIsInvalid() { AlmostRealStateChangeService stateChangeService = new AlmostRealStateChangeService(); given(owner.isValid()).willReturn(false); given(ownerDD.callValidators(owner)).willReturn(false); stateChangeService.changeState(stateChangeContext); verify(stateChangeContext).setStatus(StateChangeStatus.FAILURE); verify(stateChangeContext, Mockito.atLeastOnce()).save(); }
@Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
AbstractStateChangeAspect implements StateChangeService { @Override public void changeState(final StateChangeContext stateChangeContext) { try { performStateChange(stateChangeContext); } catch (Exception exception) { LOGGER.warn("Can't perform state change", exception); stateChangeContext.setStatus(StateChangeStatus.FAILURE); stateChangeContext.addMessage("states.messages.change.failure.internalServerError", StateMessageType.FAILURE); stateChangeContext.save(); throw new StateChangeException(exception); } } @Override void changeState(final StateChangeContext stateChangeContext); }
@Test public void shouldSetStateToDraftWhenInitializeTrackingDetailsViewIfProductionTrackingIsntSaved() { given(productionTrackingForm.getEntityId()).willReturn(null); given(productionTrackingForm.getEntity()).willReturn(productionTracking); given(productionTracking.getField(ProductionTrackingFields.STATE)).willReturn(ProductionTrackingStateStringValues.DRAFT); productionTrackingDetailsHooks.initializeProductionTrackingDetailsView(view); verify(stateField, times(1)).setFieldValue(ProductionTrackingStateStringValues.DRAFT); verify(isDisabledField, times(1)).setFieldValue(false); verify(productionTrackingService, never()).setTimeAndPieceworkComponentsVisible(view, order); }
public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } void onBeforeRender(final ViewDefinitionState view); void setCriteriaModifierParameters(final ViewDefinitionState view); void initializeProductionTrackingDetailsView(final ViewDefinitionState view); void changeFieldComponentsEnabledAndGridsEditable(final ViewDefinitionState view); void updateRibbonState(final ViewDefinitionState view); }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } void onBeforeRender(final ViewDefinitionState view); void setCriteriaModifierParameters(final ViewDefinitionState view); void initializeProductionTrackingDetailsView(final ViewDefinitionState view); void changeFieldComponentsEnabledAndGridsEditable(final ViewDefinitionState view); void updateRibbonState(final ViewDefinitionState view); }
@Test public void shouldSetStateToAcceptedWhenInitializeTrackingDetailsViewIfProductionTrackingIsSaved() { given(productionTrackingForm.getEntityId()).willReturn(1L); given(productionTrackingForm.getEntity()).willReturn(productionTracking); given(productionTracking.getField(ProductionTrackingFields.STATE)).willReturn( ProductionTrackingStateStringValues.ACCEPTED); given(orderLookup.getEntity()).willReturn(order); productionTrackingDetailsHooks.initializeProductionTrackingDetailsView(view); verify(stateField, times(1)).setFieldValue(ProductionTrackingStateStringValues.ACCEPTED); verify(isDisabledField, times(1)).setFieldValue(false); verify(productionTrackingService, times(1)).setTimeAndPieceworkComponentsVisible(view, order); }
public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } void onBeforeRender(final ViewDefinitionState view); void setCriteriaModifierParameters(final ViewDefinitionState view); void initializeProductionTrackingDetailsView(final ViewDefinitionState view); void changeFieldComponentsEnabledAndGridsEditable(final ViewDefinitionState view); void updateRibbonState(final ViewDefinitionState view); }
ProductionTrackingDetailsHooks { public void initializeProductionTrackingDetailsView(final ViewDefinitionState view) { FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(ProductionTrackingFields.STATE); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFields.ORDER); FieldComponent isDisabledField = (FieldComponent) view.getComponentByReference(L_IS_DISABLED); Entity productionTracking = productionTrackingForm.getEntity(); stateField.setFieldValue(productionTracking.getField(ProductionTrackingFields.STATE)); stateField.requestComponentUpdateState(); Entity order = orderLookup.getEntity(); isDisabledField.setFieldValue(false); if (order != null) { productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); } } void onBeforeRender(final ViewDefinitionState view); void setCriteriaModifierParameters(final ViewDefinitionState view); void initializeProductionTrackingDetailsView(final ViewDefinitionState view); void changeFieldComponentsEnabledAndGridsEditable(final ViewDefinitionState view); void updateRibbonState(final ViewDefinitionState view); }
@Test public void shouldNotSetTimeAndPieceworkTabVisibleIfTypeIsBasic() { String typeOfProductionRecording = TypeOfProductionRecording.BASIC.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME)).willReturn(true); given(order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK)).willReturn(true); given(productionCountingService.isTypeOfProductionRecordingBasic(typeOfProductionRecording)).willReturn(true); given(productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)).willReturn(false); productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); verify(technologyOperationComponentLookup).setVisible(false); verify(timeTab).setVisible(false); verify(pieceworkTab).setVisible(false); verify(calcTotalLaborTimeRibbonBtn).setEnabled(false); verify(calcTotalLaborTimeRibbonBtn).requestUpdate(true); }
@Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
@Test public void shoulsSetTimeAndPieceworkTabVisibleIfTypeIsCumulated() { String typeOfProductionRecording = TypeOfProductionRecording.CUMULATED.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME)).willReturn(true); given(order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK)).willReturn(true); given(productionCountingService.isTypeOfProductionRecordingBasic(typeOfProductionRecording)).willReturn(false); given(productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)).willReturn(false); productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); verify(technologyOperationComponentLookup).setVisible(false); verify(timeTab).setVisible(true); verify(pieceworkTab).setVisible(false); verify(calcTotalLaborTimeRibbonBtn).setEnabled(true); verify(calcTotalLaborTimeRibbonBtn).requestUpdate(true); }
@Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
@Test public void shoulsSetTimeAndPieceworkTabVisibleIfTypeIsForEach() { String typeOfProductionRecording = TypeOfProductionRecording.FOR_EACH.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME)).willReturn(true); given(order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK)).willReturn(true); given(productionCountingService.isTypeOfProductionRecordingBasic(typeOfProductionRecording)).willReturn(false); given(productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)).willReturn(true); productionTrackingService.setTimeAndPieceworkComponentsVisible(view, order); verify(technologyOperationComponentLookup).setVisible(true); verify(timeTab).setVisible(true); verify(pieceworkTab).setVisible(true); verify(calcTotalLaborTimeRibbonBtn).setEnabled(true); verify(calcTotalLaborTimeRibbonBtn).requestUpdate(true); }
@Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
ProductionTrackingServiceImpl implements ProductionTrackingService { @Override public void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order) { String recordingType = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingType); boolean recordingTypeEqualsBasic = TypeOfProductionRecording.BASIC.getStringValue().equals(recordingType); LookupComponent tocComponent = (LookupComponent) view .getComponentByReference(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT); tocComponent.setVisible(recordingTypeEqualsForEach); tocComponent.setRequired(recordingTypeEqualsForEach); boolean registerProductionTime = order.getBooleanField(OrderFieldsPC.REGISTER_PRODUCTION_TIME); view.getComponentByReference(L_TIME_TAB).setVisible(registerProductionTime && !recordingTypeEqualsBasic); ProductionTrackingState recordState = getTrackingState(view); final FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); if (form.getEntityId() != null) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonActionItem calcTotalLaborTimeBtn = window.getRibbon().getGroupByName(L_WORK_TIME_RIBBON_GROUP) .getItemByName(L_CALC_LABOR_TOTAL_TIME_RIBBON_BUTTON); calcTotalLaborTimeBtn.setEnabled(registerProductionTime && !recordingTypeEqualsBasic && ProductionTrackingState.DRAFT.equals(recordState)); calcTotalLaborTimeBtn.requestUpdate(true); } boolean registerPiecework = order.getBooleanField(OrderFieldsPC.REGISTER_PIECEWORK); view.getComponentByReference(L_PIECEWORK_TAB).setVisible(registerPiecework && recordingTypeEqualsForEach); } @Override void setTimeAndPieceworkComponentsVisible(final ViewDefinitionState view, final Entity order); @Override ProductionTrackingState getTrackingState(final ViewDefinitionState view); @Override void changeProducedQuantityFieldState(final ViewDefinitionState viewDefinitionState); @Override void fillProductionLineLookup(final ViewDefinitionState view); @Override void changeState(Entity productionTracking, ProductionTrackingState state); @Override Entity correct(Entity productionTracking); @Override void unCorrect(Entity correctingProductionTracking); }
@Test public final void shouldOrderCanBeClosedWhenTypeIsCummulativeAndAcceptingLastRecord() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.CUMULATED); productionTrackingIsLast(); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertTrue(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public void shouldEnabledButtonForCopyNorms() throws Exception { String averageLaborHourlyCostValue = "50"; when(averageLaborHourlyCost.getFieldValue()).thenReturn(averageLaborHourlyCostValue); orderDetailsHooks.enabledButtonForCopyNorms(view); Mockito.verify(copyToOperationsNorms).setEnabled(true); }
public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } void enabledButtonForCopyNorms(final ViewDefinitionState view); }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } void enabledButtonForCopyNorms(final ViewDefinitionState view); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsCummulativeAndAcceptingLastRecordButAutoCloseIsNotEnabled() { stubTypeOfProductionRecording(TypeOfProductionRecording.CUMULATED); productionTrackingIsLast(); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsCummulativeAndAcceptingNotLastRecord() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.CUMULATED); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndAcceptingNotLastRecord() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); stubSearchCriteriaResults(1L, 2L, 3L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndThereIsNotEnoughtLastRecords() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndRecordIsNotLastAndThereIsNotEnoughtLastRecords() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); stubSearchCriteriaResults(1L, 2L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanBeClosedWhenTypeIsForEachOpAndRecordIsLastAndThereIsEnoughtLastRecords() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L, 3L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertTrue(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndRecordIsLastAndThereIsEnoughtLastRecordsButAutoCloseIsNotEnabled() { stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L, 3L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanBeClosedWhenTypeIsForEachOpAndRecordIsLastAndThereIsMoreThanEnoughtLastRecords() { orderHasEnabledAutoClose(); productionTrackingIsLast(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); stubSearchCriteriaResults(1L, 2L, 3L, 4L, 5L, 6L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertTrue(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndRecordIsLastAndThereIsMoreThanEnoughtLastRecordsButAutoCloseIsNotEnabled() { stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L, 3L, 4L, 5L, 6L); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public final void shouldOrderCanBeClosedWhenTypeIsForEachOpAndRecordIsLastAndIsAlreadyAcceptedButThereIsEnoughtRecords() { orderHasEnabledAutoClose(); stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L, 3L, PRODUCTION_RECORD_ID); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertTrue(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public void shouldDisbaleButtonForCopyNorms() throws Exception { String averageLaborHourlyCostValue = ""; when(averageLaborHourlyCost.getFieldValue()).thenReturn(averageLaborHourlyCostValue); orderDetailsHooks.enabledButtonForCopyNorms(view); Mockito.verify(copyToOperationsNorms).setEnabled(false); }
public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } void enabledButtonForCopyNorms(final ViewDefinitionState view); }
AvgLaborCostCalcForOrderDetailsHooks { public void enabledButtonForCopyNorms(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference("window"); RibbonActionItem copyToOperationsNorms = window.getRibbon().getGroupByName("hourlyCostNorms") .getItemByName("copyToOperationsNorms"); FieldComponent averageLaborHourlyCost = (FieldComponent) view.getComponentByReference(AVERAGE_LABOR_HOURLY_COST); if (StringUtils.isEmpty((String) averageLaborHourlyCost.getFieldValue())) { copyToOperationsNorms.setEnabled(false); } else { copyToOperationsNorms.setEnabled(true); } copyToOperationsNorms.requestUpdate(true); } void enabledButtonForCopyNorms(final ViewDefinitionState view); }
@Test public final void shouldOrderCanNotBeClosedWhenTypeIsForEachOpAndRecordIsLastButIsAlreadyAccepted() { stubTypeOfProductionRecording(TypeOfProductionRecording.FOR_EACH); productionTrackingIsLast(); stubSearchCriteriaResults(1L, 2L, PRODUCTION_RECORD_ID); boolean shouldClose = orderClosingHelper.orderShouldBeClosed(productionTracking); assertFalse(shouldClose); }
public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
OrderClosingHelper { public boolean orderShouldBeClosed(final Entity productionTracking) { Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER); if (order == null) { return false; } Boolean autoCloseOrder = order.getBooleanField(OrderFieldsPC.AUTO_CLOSE_ORDER); Boolean isLastRecord = productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING); TypeOfProductionRecording recType = TypeOfProductionRecording.parseString(order .getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)); return isLastRecord && autoCloseOrder && (!(TypeOfProductionRecording.FOR_EACH.equals(recType)) || eachOperationHasLastRecords(order, productionTracking)); } boolean orderShouldBeClosed(final Entity productionTracking); }
@Test public void shouldSetQuantityTechnologyProductionLineAndTechnicalProductionCostPerUnitFieldsAndSaveEntity() { BigDecimal quantity = BigDecimal.TEN; BigDecimal doneQuantity = BigDecimal.TEN; given(productionBalance.getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS)).willReturn( BigDecimal.valueOf(100)); given(order.getDecimalField(OrderFields.PLANNED_QUANTITY)).willReturn(quantity); given(order.getDecimalField(OrderFields.DONE_QUANTITY)).willReturn(doneQuantity); given(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(productionLine); generateProductionBalanceWithCosts.doTheCostsPart(productionBalance); verify(productionBalance).setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); verify(productionBalance).setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); verify(productionBalance).setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); verify(productionBalance).setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, BigDecimal.TEN.setScale(5, RoundingMode.HALF_EVEN)); }
public void doTheCostsPart(final Entity productionBalance) { Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); productionBalance.setField(ProductionBalanceFields.ORDER, order); BigDecimal quantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY); productionBalance.setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); productionBalance.setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); productionBalance.setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); costCalculationService.calculateOperationsAndProductsCosts(productionBalance); final BigDecimal productionCosts = costCalculationService.calculateProductionCost(productionBalance); final BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY); costCalculationService.calculateTotalCosts(productionBalance, productionCosts, doneQuantity); BigDecimal perUnit = BigDecimal.ZERO; if (!BigDecimalUtils.valueEquals(BigDecimal.ZERO, doneQuantity)) { BigDecimal totalTechnicalProductionCosts = productionBalance .getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS); perUnit = totalTechnicalProductionCosts.divide(doneQuantity, numberService.getMathContext()); } productionBalance.setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, numberService.setScale(perUnit)); }
GenerateProductionBalanceWithCosts implements Observer { public void doTheCostsPart(final Entity productionBalance) { Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); productionBalance.setField(ProductionBalanceFields.ORDER, order); BigDecimal quantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY); productionBalance.setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); productionBalance.setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); productionBalance.setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); costCalculationService.calculateOperationsAndProductsCosts(productionBalance); final BigDecimal productionCosts = costCalculationService.calculateProductionCost(productionBalance); final BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY); costCalculationService.calculateTotalCosts(productionBalance, productionCosts, doneQuantity); BigDecimal perUnit = BigDecimal.ZERO; if (!BigDecimalUtils.valueEquals(BigDecimal.ZERO, doneQuantity)) { BigDecimal totalTechnicalProductionCosts = productionBalance .getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS); perUnit = totalTechnicalProductionCosts.divide(doneQuantity, numberService.getMathContext()); } productionBalance.setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, numberService.setScale(perUnit)); } }
GenerateProductionBalanceWithCosts implements Observer { public void doTheCostsPart(final Entity productionBalance) { Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); productionBalance.setField(ProductionBalanceFields.ORDER, order); BigDecimal quantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY); productionBalance.setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); productionBalance.setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); productionBalance.setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); costCalculationService.calculateOperationsAndProductsCosts(productionBalance); final BigDecimal productionCosts = costCalculationService.calculateProductionCost(productionBalance); final BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY); costCalculationService.calculateTotalCosts(productionBalance, productionCosts, doneQuantity); BigDecimal perUnit = BigDecimal.ZERO; if (!BigDecimalUtils.valueEquals(BigDecimal.ZERO, doneQuantity)) { BigDecimal totalTechnicalProductionCosts = productionBalance .getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS); perUnit = totalTechnicalProductionCosts.divide(doneQuantity, numberService.getMathContext()); } productionBalance.setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, numberService.setScale(perUnit)); } }
GenerateProductionBalanceWithCosts implements Observer { public void doTheCostsPart(final Entity productionBalance) { Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); productionBalance.setField(ProductionBalanceFields.ORDER, order); BigDecimal quantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY); productionBalance.setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); productionBalance.setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); productionBalance.setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); costCalculationService.calculateOperationsAndProductsCosts(productionBalance); final BigDecimal productionCosts = costCalculationService.calculateProductionCost(productionBalance); final BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY); costCalculationService.calculateTotalCosts(productionBalance, productionCosts, doneQuantity); BigDecimal perUnit = BigDecimal.ZERO; if (!BigDecimalUtils.valueEquals(BigDecimal.ZERO, doneQuantity)) { BigDecimal totalTechnicalProductionCosts = productionBalance .getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS); perUnit = totalTechnicalProductionCosts.divide(doneQuantity, numberService.getMathContext()); } productionBalance.setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, numberService.setScale(perUnit)); } @Override void update(final Observable observable, final Object object); void doTheCostsPart(final Entity productionBalance); void fillFieldsAndGrids(final Entity productionBalance); }
GenerateProductionBalanceWithCosts implements Observer { public void doTheCostsPart(final Entity productionBalance) { Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); productionBalance.setField(ProductionBalanceFields.ORDER, order); BigDecimal quantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY); productionBalance.setField(ProductionBalanceFieldsPCWC.QUANTITY, quantity); productionBalance.setField(ProductionBalanceFieldsPCWC.TECHNOLOGY, technology); productionBalance.setField(ProductionBalanceFieldsPCWC.PRODUCTION_LINE, productionLine); costCalculationService.calculateOperationsAndProductsCosts(productionBalance); final BigDecimal productionCosts = costCalculationService.calculateProductionCost(productionBalance); final BigDecimal doneQuantity = order.getDecimalField(OrderFields.DONE_QUANTITY); costCalculationService.calculateTotalCosts(productionBalance, productionCosts, doneQuantity); BigDecimal perUnit = BigDecimal.ZERO; if (!BigDecimalUtils.valueEquals(BigDecimal.ZERO, doneQuantity)) { BigDecimal totalTechnicalProductionCosts = productionBalance .getDecimalField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COSTS); perUnit = totalTechnicalProductionCosts.divide(doneQuantity, numberService.getMathContext()); } productionBalance.setField(ProductionBalanceFieldsPCWC.TOTAL_TECHNICAL_PRODUCTION_COST_PER_UNIT, numberService.setScale(perUnit)); } @Override void update(final Observable observable, final Object object); void doTheCostsPart(final Entity productionBalance); void fillFieldsAndGrids(final Entity productionBalance); }
@Test public void shouldGenerateReportCorrectly() throws Exception { Locale locale = Locale.getDefault(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = mock(Entity.class); given(productionBalanceWithFileName.getDataDefinition()).willReturn(productionBalanceDD); given(fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix)).willReturn( productionBalanceWithFileName); generateProductionBalanceWithCosts.generateBalanceWithCostsReport(productionBalance); verify(productionBalanceWithCostsPdfService).generateDocument(productionBalanceWithFileName, locale, localePrefix); verify(productionBalanceWithFileName).setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); verify(productionBalanceDD).save(productionBalanceWithFileName); }
void generateBalanceWithCostsReport(final Entity productionBalance) { Locale locale = LocaleContextHolder.getLocale(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix); String localePrefixToMatch = localePrefix; try { productionBalanceWithCostsPdfService.generateDocument(productionBalanceWithFileName, locale, localePrefixToMatch); productionBalanceWithFileName.setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); productionBalanceWithFileName.getDataDefinition().save(productionBalanceWithFileName); } catch (IOException e) { throw new IllegalStateException("Problem with saving productionBalanceWithCosts report", e); } catch (DocumentException e) { throw new IllegalStateException("Problem with generating productionBalanceWithCosts report", e); } }
GenerateProductionBalanceWithCosts implements Observer { void generateBalanceWithCostsReport(final Entity productionBalance) { Locale locale = LocaleContextHolder.getLocale(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix); String localePrefixToMatch = localePrefix; try { productionBalanceWithCostsPdfService.generateDocument(productionBalanceWithFileName, locale, localePrefixToMatch); productionBalanceWithFileName.setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); productionBalanceWithFileName.getDataDefinition().save(productionBalanceWithFileName); } catch (IOException e) { throw new IllegalStateException("Problem with saving productionBalanceWithCosts report", e); } catch (DocumentException e) { throw new IllegalStateException("Problem with generating productionBalanceWithCosts report", e); } } }
GenerateProductionBalanceWithCosts implements Observer { void generateBalanceWithCostsReport(final Entity productionBalance) { Locale locale = LocaleContextHolder.getLocale(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix); String localePrefixToMatch = localePrefix; try { productionBalanceWithCostsPdfService.generateDocument(productionBalanceWithFileName, locale, localePrefixToMatch); productionBalanceWithFileName.setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); productionBalanceWithFileName.getDataDefinition().save(productionBalanceWithFileName); } catch (IOException e) { throw new IllegalStateException("Problem with saving productionBalanceWithCosts report", e); } catch (DocumentException e) { throw new IllegalStateException("Problem with generating productionBalanceWithCosts report", e); } } }
GenerateProductionBalanceWithCosts implements Observer { void generateBalanceWithCostsReport(final Entity productionBalance) { Locale locale = LocaleContextHolder.getLocale(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix); String localePrefixToMatch = localePrefix; try { productionBalanceWithCostsPdfService.generateDocument(productionBalanceWithFileName, locale, localePrefixToMatch); productionBalanceWithFileName.setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); productionBalanceWithFileName.getDataDefinition().save(productionBalanceWithFileName); } catch (IOException e) { throw new IllegalStateException("Problem with saving productionBalanceWithCosts report", e); } catch (DocumentException e) { throw new IllegalStateException("Problem with generating productionBalanceWithCosts report", e); } } @Override void update(final Observable observable, final Object object); void doTheCostsPart(final Entity productionBalance); void fillFieldsAndGrids(final Entity productionBalance); }
GenerateProductionBalanceWithCosts implements Observer { void generateBalanceWithCostsReport(final Entity productionBalance) { Locale locale = LocaleContextHolder.getLocale(); String localePrefix = "productionCounting.productionBalanceWithCosts.report.fileName"; Entity productionBalanceWithFileName = fileService.updateReportFileName(productionBalance, ProductionBalanceFields.DATE, localePrefix); String localePrefixToMatch = localePrefix; try { productionBalanceWithCostsPdfService.generateDocument(productionBalanceWithFileName, locale, localePrefixToMatch); productionBalanceWithFileName.setField(ProductionBalanceFieldsPCWC.GENERATED_WITH_COSTS, Boolean.TRUE); productionBalanceWithFileName.getDataDefinition().save(productionBalanceWithFileName); } catch (IOException e) { throw new IllegalStateException("Problem with saving productionBalanceWithCosts report", e); } catch (DocumentException e) { throw new IllegalStateException("Problem with generating productionBalanceWithCosts report", e); } } @Override void update(final Observable observable, final Object object); void doTheCostsPart(final Entity productionBalance); void fillFieldsAndGrids(final Entity productionBalance); }
@Test public void shouldAddTimeBalanceAndProductionCostsIfTypeCumulatedAndHourly() throws Exception { String typeOfProductionRecording = TypeOfProductionRecording.CUMULATED.getStringValue(); String calculateOperationCostMode = CalculateOperationCostMode.HOURLY.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(productionBalance.getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE)).willReturn( calculateOperationCostMode); given(productionCountingService.isTypeOfProductionRecordingCumulated(typeOfProductionRecording)).willReturn(true); given(productionCountingService.isCalculateOperationCostModeHourly(calculateOperationCostMode)).willReturn(true); productionBalanceWithCostsPdfService.buildPdfContent(document, productionBalance, locale); verify(productionBalancePdfService).addTimeBalanceAsPanel(document, productionBalance, locale); verify(document).add(threeColumnTable); }
@Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }
@Test public void shouldNotAddTimeBalanceAndProductionCostsIfTypeIsNotHourly() throws Exception { String typeOfProductionRecording = TypeOfProductionRecording.CUMULATED.getStringValue(); String calculateOperationCostMode = CalculateOperationCostMode.PIECEWORK.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(productionBalance.getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE)).willReturn( calculateOperationCostMode); given(productionCountingService.isTypeOfProductionRecordingCumulated(typeOfProductionRecording)).willReturn(true); given(productionCountingService.isCalculateOperationCostModePiecework(calculateOperationCostMode)).willReturn(true); productionBalanceWithCostsPdfService.buildPdfContent(document, productionBalance, locale); verify(productionBalancePdfService, never()).addTimeBalanceAsPanel(document, productionBalance, locale); verify(document, never()).add(threeColumnTable); }
@Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }
@Test public void shouldNotAddTimeBalanceAndProductionCostsIfTypeIsNotCumulated() throws Exception { String typeOfProductionRecording = TypeOfProductionRecording.FOR_EACH.getStringValue(); String calculateOperationCostMode = CalculateOperationCostMode.HOURLY.getStringValue(); given(order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING)).willReturn(typeOfProductionRecording); given(productionBalance.getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE)).willReturn( calculateOperationCostMode); given(productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)).willReturn(true); given(productionCountingService.isCalculateOperationCostModeHourly(calculateOperationCostMode)).willReturn(true); productionBalanceWithCostsPdfService.buildPdfContent(document, productionBalance, locale); verify(productionBalancePdfService, never()).addTimeBalanceAsPanel(document, productionBalance, locale); verify(document, never()).add(threeColumnTable); }
@Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }
ProductionBalanceWithCostsPdfService extends PdfDocumentService { @Override protected void buildPdfContent(final Document document, final Entity productionBalance, final Locale locale) throws DocumentException { String documentTitle = translationService.translate("productionCounting.productionBalance.report.title", locale); String documentAuthor = translationService.translate("smartReport.commons.generatedBy.label", locale); pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, productionBalance.getDateField(ProductionBalanceFields.DATE)); PdfPTable topTable = pdfHelper.createPanelTable(2); topTable.addCell(productionBalancePdfService.createLeftPanel(productionBalance, locale)); topTable.addCell(productionBalancePdfService.createRightPanel(productionBalance, locale)); topTable.setSpacingBefore(20); document.add(topTable); PdfPTable parametersForCostsPanel = createParametersForCostsPanel(productionBalance, locale); parametersForCostsPanel.setSpacingBefore(20); document.add(parametersForCostsPanel); Entity order = productionBalance.getBelongsToField(ProductionBalanceFields.ORDER); String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING); String calculateOperationCostMode = productionBalance .getStringField(ProductionBalanceFields.CALCULATE_OPERATION_COST_MODE); final boolean isTypeOfProductionRecordingCumulated = productionCountingService .isTypeOfProductionRecordingCumulated(typeOfProductionRecording); final boolean isTypeOfProductionRecordingForEach = productionCountingService .isTypeOfProductionRecordingForEach(typeOfProductionRecording); final boolean isCalculateOperationCostModeHourly = productionCountingService .isCalculateOperationCostModeHourly(calculateOperationCostMode); final boolean isCalculateOperationCostModePiecework = productionCountingService .isCalculateOperationCostModePiecework(calculateOperationCostMode); if (isCalculateOperationCostModeHourly && isTypeOfProductionRecordingCumulated) { PdfPTable assumptionForCumulatedRecordsPanel = createAssumptionsForCumulatedRecordsPanel(productionBalance, locale); assumptionForCumulatedRecordsPanel.setSpacingBefore(20); document.add(assumptionForCumulatedRecordsPanel); } PdfPTable bottomTable = pdfHelper.createPanelTable(2); bottomTable.addCell(createCostsPanel(productionBalance, locale)); bottomTable.addCell(createOverheadsAndSummaryPanel(productionBalance, locale)); bottomTable.setSpacingBefore(20); bottomTable.setSpacingAfter(20); document.add(bottomTable); productionBalancePdfService.addInputProductsBalance(document, productionBalance, locale); addMaterialCost(document, productionBalance, locale); productionBalancePdfService.addOutputProductsBalance(document, productionBalance, locale); if (isCalculateOperationCostModeHourly) { if (isTypeOfProductionRecordingCumulated) { productionBalancePdfService.addTimeBalanceAsPanel(document, productionBalance, locale); addProductionCosts(document, productionBalance, locale); } else if (isTypeOfProductionRecordingForEach) { productionBalancePdfService.addMachineTimeBalance(document, productionBalance, locale); addCostsBalance("machine", document, productionBalance, locale); productionBalancePdfService.addLaborTimeBalance(document, productionBalance, locale); addCostsBalance("labor", document, productionBalance, locale); } } else if (isCalculateOperationCostModePiecework) { productionBalancePdfService.addPieceworkBalance(document, productionBalance, locale); addCostsBalance("cycles", document, productionBalance, locale); } costCalculationPdfService.printMaterialAndOperationNorms(document, productionBalance, locale); } PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale); @Override String getReportTitle(final Locale locale); }