First implemtation of REST-API
Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
committed by
Nonnenmacher Fabian
parent
088df73ea9
commit
f3fa085c62
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -20,10 +21,15 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.report.model.SystemUsageReport;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetTypeException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidPollingTimeException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
|
||||
import org.eclipse.hawkbit.repository.model.TenantMetaData;
|
||||
import org.eclipse.hawkbit.repository.model.helper.DurationHelper;
|
||||
import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
||||
@@ -461,4 +467,29 @@ public class SystemManagement implements EnvironmentAware {
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
public void updateTenantConfiguration(SystemConfigurationRequestBodyPut systemConReq) {
|
||||
|
||||
DurationHelper dh = new DurationHelper();
|
||||
|
||||
TenantMetaData tenantMetaData = getTenantMetadata();
|
||||
|
||||
String ddstypeKey = systemConReq.getDefaultDistributionSetType();
|
||||
|
||||
if (distributionSetTypeRepository.findAll(DistributionSetTypeSpecification.byKey(ddstypeKey)).isEmpty()) {
|
||||
throw new InvalidDistributionSetTypeException(
|
||||
String.format("The specified default distribution set type %s doe not exist.", ddstypeKey));
|
||||
}
|
||||
|
||||
try {
|
||||
tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime()));
|
||||
tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime()));
|
||||
} catch (DateTimeParseException ex) {
|
||||
throw new InvalidPollingTimeException(ex);
|
||||
}
|
||||
|
||||
updateTenantMetadata(tenantMetaData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.exception.SpServerRtException;
|
||||
|
||||
/**
|
||||
* This Exception is thrown, when the user wants to set a distribution set which
|
||||
* does not exist,
|
||||
*
|
||||
*/
|
||||
public class InvalidDistributionSetTypeException extends SpServerRtException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new CancelActionNotAllowed with
|
||||
* {@link SpServerError#SP_ACTION_NOT_CANCELABLE} error.
|
||||
*/
|
||||
public InvalidDistributionSetTypeException() {
|
||||
super(SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* for the exception
|
||||
*/
|
||||
public InvalidDistributionSetTypeException(final Throwable cause) {
|
||||
super(SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* of the error
|
||||
*/
|
||||
public InvalidDistributionSetTypeException(final String message) {
|
||||
super(message, SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.exception.SpServerRtException;
|
||||
|
||||
public class InvalidPollingTimeException extends SpServerRtException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new CancelActionNotAllowed with
|
||||
* {@link SpServerError#SP_ACTION_NOT_CANCELABLE} error.
|
||||
*/
|
||||
public InvalidPollingTimeException() {
|
||||
super(SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* for the exception
|
||||
*/
|
||||
public InvalidPollingTimeException(final Throwable cause) {
|
||||
super(SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* of the error
|
||||
*/
|
||||
public InvalidPollingTimeException(final String message) {
|
||||
super(message, SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user