Fixed review findings

This commit is contained in:
Nonnenmacher Fabian (INST-ICM/BSV-AS)
2016-03-04 12:02:59 +01:00
parent 0e9991b0a4
commit 9646e1eabc
17 changed files with 152 additions and 197 deletions

View File

@@ -84,7 +84,7 @@ public class TenantConfigurationManagement implements EnvironmentAware {
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
final Class<T> propertyType) throws TenantConfigurationValidatorException {
final Class<T> propertyType) {
if (!configurationKey.getDataType().isAssignableFrom(propertyType)) {
throw new TenantConfigurationValidatorException(
@@ -130,8 +130,7 @@ public class TenantConfigurationManagement implements EnvironmentAware {
* {@code propertyType}
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
public TenantConfigurationValue<?> getConfigurationValue(final TenantConfigurationKey configurationKey)
throws TenantConfigurationValidatorException {
public TenantConfigurationValue<?> getConfigurationValue(final TenantConfigurationKey configurationKey) {
return getConfigurationValue(configurationKey, configurationKey.getDataType());
}
@@ -156,8 +155,8 @@ public class TenantConfigurationManagement implements EnvironmentAware {
* {@code propertyType}
*/
@PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION)
public <T> T getGlobalConfigurationValue(final TenantConfigurationKey configurationKey, final Class<T> propertyType)
throws TenantConfigurationValidatorException {
public <T> T getGlobalConfigurationValue(final TenantConfigurationKey configurationKey,
final Class<T> propertyType) {
if (!configurationKey.getDataType().isAssignableFrom(propertyType)) {
throw new TenantConfigurationValidatorException(
@@ -167,10 +166,11 @@ public class TenantConfigurationManagement implements EnvironmentAware {
final T valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType);
if (valueInProperties != null) {
return valueInProperties;
if (valueInProperties == null) {
return conversionService.convert(configurationKey.getDefaultValue(), propertyType);
}
return conversionService.convert(configurationKey.getDefaultValue(), propertyType);
return valueInProperties;
}
/**
@@ -206,14 +206,11 @@ public class TenantConfigurationManagement implements EnvironmentAware {
TenantConfiguration tenantConfiguration = tenantConfigurationRepository
.findByKey(configurationKey.getKeyName());
if (tenantConfiguration != null)
{
tenantConfiguration.setValue(value.toString());
} else
{
if (tenantConfiguration == null) {
tenantConfiguration = new TenantConfiguration(configurationKey.getKeyName(), value.toString());
} else {
tenantConfiguration.setValue(value.toString());
}
final TenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository.save(tenantConfiguration);

View File

@@ -320,22 +320,21 @@ public class TargetInfo implements Persistable<Long>, Serializable {
* before this method returns {@code null}
*/
public PollStatus getPollStatus() {
if (lastTargetQuery != null) {
final Duration pollTime = durationHelper.formattedStringToDuration(TenantConfigurationManagement
.getInstance().getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class)
.getValue());
final Duration overdueTime = durationHelper
.formattedStringToDuration(TenantConfigurationManagement.getInstance()
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
.getValue());
final LocalDateTime currentDate = LocalDateTime.now();
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
ZoneId.systemDefault());
final LocalDateTime nextPollDate = lastPollDate.plus(pollTime);
final LocalDateTime overdueDate = nextPollDate.plus(overdueTime);
return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate);
if (lastTargetQuery == null) {
return null;
}
return null;
final Duration pollTime = durationHelper.formattedStringToDuration(TenantConfigurationManagement.getInstance()
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue());
final Duration overdueTime = durationHelper.formattedStringToDuration(TenantConfigurationManagement
.getInstance().getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
.getValue());
final LocalDateTime currentDate = LocalDateTime.now();
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
ZoneId.systemDefault());
final LocalDateTime nextPollDate = lastPollDate.plus(pollTime);
final LocalDateTime overdueDate = nextPollDate.plus(overdueTime);
return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate);
}
/**
@@ -378,23 +377,14 @@ public class TargetInfo implements Persistable<Long>, Serializable {
return lastPollDate;
}
/**
* @return the nextPollDate
*/
public LocalDateTime getNextPollDate() {
return nextPollDate;
}
/**
* @return the overdueDate
*/
public LocalDateTime getOverdueDate() {
return overdueDate;
}
/**
* @return the current date
*/
public LocalDateTime getCurrentDate() {
return currentDate;
}

View File

@@ -16,16 +16,16 @@ package org.eclipse.hawkbit.repository.model;
*/
public class TenantConfigurationValue<T> {
private T value;
private Long lastModifiedAt;
private String lastModifiedBy;
private Long createdAt;
private String createdBy;
private boolean isGlobal = true;
private TenantConfigurationValue() {
}
private T value = null;
private boolean isGlobal = true;
private Long lastModifiedAt = null;
private String lastModifiedBy = null;
private Long createdAt = null;
private String createdBy = null;
/**
* Gets the value.
*