Some clean code refactorings

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-05-19 17:28:45 +02:00
parent 0f75c63878
commit 79d604ca0b
10 changed files with 102 additions and 105 deletions

View File

@@ -114,7 +114,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication manager without principal") @Description("Tests authentication manager without principal")
public void testAuthenticationeBadCredantialsWithoutPricipal() { public void testAuthenticationeBadCredantialsWithoutPricipal() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
try { try {
authenticationManager.doAuthenticate(securityToken); authenticationManager.doAuthenticate(securityToken);
fail("BadCredentialsException was excepeted since principal was missing"); fail("BadCredentialsException was excepeted since principal was missing");
@@ -128,7 +128,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication manager without wrong credential") @Description("Tests authentication manager without wrong credential")
public void testAuthenticationBadCredantialsWithWrongCredential() { public void testAuthenticationBadCredantialsWithWrongCredential() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue( when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
@@ -146,7 +146,7 @@ public class AmqpControllerAuthenticationTest {
@Description("Tests authentication successfull") @Description("Tests authentication successfull")
public void testSuccessfullAuthentication() { public void testSuccessfullAuthentication() {
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue( when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
@@ -161,7 +161,7 @@ public class AmqpControllerAuthenticationTest {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -180,7 +180,7 @@ public class AmqpControllerAuthenticationTest {
public void testAuthenticationMessageBadCredantialsWithWrongCredential() { public void testAuthenticationMessageBadCredantialsWithWrongCredential() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue( when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);
@@ -203,7 +203,7 @@ public class AmqpControllerAuthenticationTest {
public void testSuccessfullMessageAuthentication() { public void testSuccessfullMessageAuthentication() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID, final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, CONTROLLLER_ID,
FileResource.sha1("12345")); FileResource.createFileResourceBySha1("12345"));
when(tenantConfigurationManagement.getConfigurationValue( when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE); .thenReturn(CONFIG_VALUE_TRUE);

View File

@@ -264,7 +264,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which does not exists") @Description("Tests that an download request is denied for an artifact which does not exists")
public void authenticationRequestDeniedForArtifactWhichDoesNotExists() { public void authenticationRequestDeniedForArtifactWhichDoesNotExists() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -283,7 +283,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is denied for an artifact which is not assigned to the requested target") @Description("Tests that an download request is denied for an artifact which is not assigned to the requested target")
public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() { public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);
@@ -307,7 +307,7 @@ public class AmqpMessageHandlerServiceTest {
@Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target") @Description("Tests that an download request is allowed for an artifact which exists and assigned to the requested target")
public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException { public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarget() throws MalformedURLException {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.sha1("12345")); final TenantSecurityToken securityToken = new TenantSecurityToken(TENANT, "123", FileResource.createFileResourceBySha1("12345"));
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties); messageProperties);

View File

@@ -135,7 +135,7 @@ public class TenantSecurityToken {
* the SHA1 key of the file to obtain * the SHA1 key of the file to obtain
* @return the {@link FileResource} with SHA1 key set * @return the {@link FileResource} with SHA1 key set
*/ */
public static FileResource sha1(final String sha1) { public static FileResource createFileResourceBySha1(final String sha1) {
final FileResource resource = new FileResource(); final FileResource resource = new FileResource();
resource.sha1 = sha1; resource.sha1 = sha1;
return resource; return resource;
@@ -148,7 +148,7 @@ public class TenantSecurityToken {
* the filename of the file to obtain * the filename of the file to obtain
* @return the {@link FileResource} with filename set * @return the {@link FileResource} with filename set
*/ */
public static FileResource filename(final String filename) { public static FileResource createFileResourceByFilename(final String filename) {
final FileResource resource = new FileResource(); final FileResource resource = new FileResource();
resource.filename = filename; resource.filename = filename;
return resource; return resource;

View File

@@ -47,7 +47,7 @@ import com.google.common.collect.UnmodifiableIterator;
*/ */
public abstract class AbstractHttpControllerAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter { public abstract class AbstractHttpControllerAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractHttpControllerAuthenticationFilter.class); private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpControllerAuthenticationFilter.class);
private static final String TENANT_PLACE_HOLDER = "tenant"; private static final String TENANT_PLACE_HOLDER = "tenant";
private static final String CONTROLLER_ID_PLACE_HOLDER = "controllerId"; private static final String CONTROLLER_ID_PLACE_HOLDER = "controllerId";
@@ -73,10 +73,12 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
/** /**
* Constructor for sub-classes. * Constructor for sub-classes.
* *
* @param systemManagement * @param tenantConfigurationManagement
* the system management service * the tenant configuration service
* @param tenantAware * @param tenantAware
* the tenant aware service * the tenant aware service
* @param systemSecurityContext
* the system secruity context
*/ */
public AbstractHttpControllerAuthenticationFilter(final TenantConfigurationManagement tenantConfigurationManagement, public AbstractHttpControllerAuthenticationFilter(final TenantConfigurationManagement tenantConfigurationManagement,
final TenantAware tenantAware, final SystemSecurityContext systemSecurityContext) { final TenantAware tenantAware, final SystemSecurityContext systemSecurityContext) {
@@ -136,28 +138,28 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
final String requestURI = request.getRequestURI(); final String requestURI = request.getRequestURI();
if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) { if (pathExtractor.match(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI)) {
LOGGER.debug("retrieving principal from URI request {}", requestURI); LOG.debug("retrieving principal from URI request {}", requestURI);
final Map<String, String> extractUriTemplateVariables = pathExtractor final Map<String, String> extractUriTemplateVariables = pathExtractor
.extractUriTemplateVariables(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI); .extractUriTemplateVariables(request.getContextPath() + CONTROLLER_REQUEST_ANT_PATTERN, requestURI);
final String controllerId = extractUriTemplateVariables.get(CONTROLLER_ID_PLACE_HOLDER); final String controllerId = extractUriTemplateVariables.get(CONTROLLER_ID_PLACE_HOLDER);
final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER); final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER);
if (LOGGER.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOGGER.trace("Parsed tenant {} and controllerId {} from path request {}", tenant, controllerId, LOG.trace("Parsed tenant {} and controllerId {} from path request {}", tenant, controllerId,
requestURI); requestURI);
} }
return createTenantSecruityTokenVariables(request, tenant, controllerId); return createTenantSecruityTokenVariables(request, tenant, controllerId);
} else if (pathExtractor.match(request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI)) { } else if (pathExtractor.match(request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI)) {
LOGGER.debug("retrieving path variables from URI request {}", requestURI); LOG.debug("retrieving path variables from URI request {}", requestURI);
final Map<String, String> extractUriTemplateVariables = pathExtractor.extractUriTemplateVariables( final Map<String, String> extractUriTemplateVariables = pathExtractor.extractUriTemplateVariables(
request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI); request.getContextPath() + CONTROLLER_DL_REQUEST_ANT_PATTERN, requestURI);
final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER); final String tenant = extractUriTemplateVariables.get(TENANT_PLACE_HOLDER);
if (LOGGER.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOGGER.trace("Parsed tenant {} from path request {}", tenant, requestURI); LOG.trace("Parsed tenant {} from path request {}", tenant, requestURI);
} }
return createTenantSecruityTokenVariables(request, tenant, "anonymous"); return createTenantSecruityTokenVariables(request, tenant, "anonymous");
} else { } else {
if (LOGGER.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOGGER.trace("request {} does not match the path pattern {}, request gets ignored", requestURI, LOG.trace("request {} does not match the path pattern {}, request gets ignored", requestURI,
CONTROLLER_REQUEST_ANT_PATTERN); CONTROLLER_REQUEST_ANT_PATTERN);
} }
return null; return null;
@@ -166,7 +168,8 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
private TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request, private TenantSecurityToken createTenantSecruityTokenVariables(final HttpServletRequest request,
final String tenant, final String controllerId) { final String tenant, final String controllerId) {
final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, controllerId, FileResource.sha1("")); final TenantSecurityToken secruityToken = new TenantSecurityToken(tenant, controllerId,
FileResource.createFileResourceBySha1(""));
final UnmodifiableIterator<String> forEnumeration = Iterators.forEnumeration(request.getHeaderNames()); final UnmodifiableIterator<String> forEnumeration = Iterators.forEnumeration(request.getHeaderNames());
forEnumeration.forEachRemaining(header -> secruityToken.getHeaders().put(header, request.getHeader(header))); forEnumeration.forEachRemaining(header -> secruityToken.getHeaders().put(header, request.getHeader(header)));
return secruityToken; return secruityToken;

View File

@@ -23,14 +23,10 @@ import org.springframework.util.AntPathMatcher;
* tenant from a request pattern {@link #TENANT_AWARE_CONTROLLER_PATTERN} and * tenant from a request pattern {@link #TENANT_AWARE_CONTROLLER_PATTERN} and
* stores the retrieved tenant in the {@link TenantAwareAuthenticationDetails}. * stores the retrieved tenant in the {@link TenantAwareAuthenticationDetails}.
* *
*
*/ */
public class ControllerTenantAwareAuthenticationDetailsSource public class ControllerTenantAwareAuthenticationDetailsSource
implements AuthenticationDetailsSource<HttpServletRequest, TenantAwareAuthenticationDetails> { implements AuthenticationDetailsSource<HttpServletRequest, TenantAwareAuthenticationDetails> {
/**
*
*/
private static final String TENANT_AWARE_CONTROLLER_PATTERN = "/{tenant}/controller/**"; private static final String TENANT_AWARE_CONTROLLER_PATTERN = "/{tenant}/controller/**";
private static final Logger LOGGER = LoggerFactory private static final Logger LOGGER = LoggerFactory
.getLogger(ControllerTenantAwareAuthenticationDetailsSource.class); .getLogger(ControllerTenantAwareAuthenticationDetailsSource.class);
@@ -38,19 +34,12 @@ public class ControllerTenantAwareAuthenticationDetailsSource
private final AntPathMatcher pathExtractor; private final AntPathMatcher pathExtractor;
/** /**
* * Constructor.
*/ */
public ControllerTenantAwareAuthenticationDetailsSource() { public ControllerTenantAwareAuthenticationDetailsSource() {
pathExtractor = new AntPathMatcher(); pathExtractor = new AntPathMatcher();
} }
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.authentication.AuthenticationDetailsSource#
* buildDetails(java. lang.Object)
*/
@Override @Override
public TenantAwareAuthenticationDetails buildDetails(final HttpServletRequest request) { public TenantAwareAuthenticationDetails buildDetails(final HttpServletRequest request) {
return new TenantAwareWebAuthenticationDetails(getTenantFromRequestUri(request), request.getRemoteAddr(), true); return new TenantAwareWebAuthenticationDetails(getTenantFromRequestUri(request), request.getRemoteAddr(), true);

View File

@@ -28,7 +28,7 @@ import org.springframework.security.web.authentication.preauth.AbstractPreAuthen
public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter { public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
public static final String REQUEST_ID_REGEX_PATTERN = ".*\\/downloadId\\/.*"; public static final String REQUEST_ID_REGEX_PATTERN = ".*\\/downloadId\\/.*";
private static final Logger LOGGER = LoggerFactory.getLogger(HttpDownloadAuthenticationFilter.class); private static final Logger LOG = LoggerFactory.getLogger(HttpDownloadAuthenticationFilter.class);
private final Pattern pattern; private final Pattern pattern;
private final Cache cache; private final Cache cache;
@@ -50,7 +50,7 @@ public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedPr
if (!matcher.matches()) { if (!matcher.matches()) {
return null; return null;
} }
LOGGER.debug("retrieving id from URI request {}", requestURI); LOG.debug("retrieving id from URI request {}", requestURI);
final String[] groups = requestURI.split("\\/"); final String[] groups = requestURI.split("\\/");
final String id = groups[groups.length - 1]; final String id = groups[groups.length - 1];
if (id == null) { if (id == null) {

View File

@@ -32,9 +32,6 @@ import org.springframework.hateoas.Identifiable;
* by this entity listener cause the cache keys are calculated with the ID of * by this entity listener cause the cache keys are calculated with the ID of
* the entity. * the entity.
* *
*
*
*
*/ */
public class CacheFieldEntityListener { public class CacheFieldEntityListener {
@@ -48,24 +45,21 @@ public class CacheFieldEntityListener {
*/ */
@PostLoad @PostLoad
public void postLoad(final Object target) { public void postLoad(final Object target) {
if (target instanceof Identifiable) { if (!isIdentifiable(target)) {
return;
}
final CacheFieldCallback cacheFieldCallback = (type, field, cacheKey, entityId) -> {
final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager(); final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager();
@SuppressWarnings("rawtypes")
final String id = ((Identifiable) target).getId().toString();
final Class<? extends Object> type = target.getClass();
findCacheFields(type, id, new CacheFieldCallback() {
@Override
public void fromCache(final Field field, final String cacheKey, final Serializable id)
throws IllegalAccessException {
final Cache cache = cacheManager.getCache(type.getName()); final Cache cache = cacheManager.getCache(type.getName());
final ValueWrapper valueWrapper = cache final ValueWrapper valueWrapper = cache
.get(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey)); .get(CacheKeys.entitySpecificCacheKey(entityId.toString(), cacheKey));
if (valueWrapper != null && valueWrapper.get() != null) { if (valueWrapper != null && valueWrapper.get() != null) {
FieldUtils.writeField(field, target, valueWrapper.get(), true); FieldUtils.writeField(field, target, valueWrapper.get(), true);
} }
} };
});
} findCacheFields((Identifiable<?>) target, cacheFieldCallback);
} }
/** /**
@@ -77,30 +71,32 @@ public class CacheFieldEntityListener {
*/ */
@PostRemove @PostRemove
public void postDelete(final Object target) { public void postDelete(final Object target) {
if (target instanceof Identifiable) { if (!isIdentifiable(target)) {
return;
}
final CacheFieldCallback cacheFieldCallback = (type, field, cacheKey, entityId) -> {
final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager(); final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager();
@SuppressWarnings("rawtypes")
final String id = ((Identifiable) target).getId().toString();
final Class<? extends Object> type = target.getClass();
findCacheFields(type, id, new CacheFieldCallback() {
@Override
public void fromCache(final Field field, final String cacheKey, final Serializable id)
throws IllegalAccessException {
final Cache cache = cacheManager.getCache(type.getName()); final Cache cache = cacheManager.getCache(type.getName());
cache.evict(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey)); cache.evict(CacheKeys.entitySpecificCacheKey(entityId.toString(), cacheKey));
} };
});
} findCacheFields((Identifiable<?>) target, cacheFieldCallback);
} }
private void findCacheFields(final Class<? extends Object> type, final Serializable id, private boolean isIdentifiable(final Object target) {
final CacheFieldCallback callback) { return target instanceof Identifiable;
}
private void findCacheFields(final Identifiable<?> target, final CacheFieldCallback callback) {
final String id = target.getId().toString();
final Class<?> type = target.getClass();
final Field[] declaredFields = type.getDeclaredFields(); final Field[] declaredFields = type.getDeclaredFields();
for (final Field field : declaredFields) { for (final Field field : declaredFields) {
if (field.getAnnotation(CacheField.class) != null) { if (field.getAnnotation(CacheField.class) != null) {
try { try {
final CacheField annotation = field.getAnnotation(CacheField.class); final CacheField annotation = field.getAnnotation(CacheField.class);
callback.fromCache(field, annotation.key(), id); callback.fromCache(type, field, annotation.key(), id);
} catch (final IllegalAccessException e) { } catch (final IllegalAccessException e) {
LOGGER.error("cannot access the field {} for the entity {}, ignoring the cacheable field", field, LOGGER.error("cannot access the field {} for the entity {}, ignoring the cacheable field", field,
type, e); type, e);
@@ -109,23 +105,26 @@ public class CacheFieldEntityListener {
} }
} }
@FunctionalInterface
private interface CacheFieldCallback { private interface CacheFieldCallback {
/** /**
* callback methods which is called by the * callback methods which is called when a field is annotated with
* {@link CacheFieldEntityListener#findCacheFields(Class, Serializable, CacheFieldCallback)} * {@link CacheField}.
* in case a field is annotated with {@link CacheField}.
* *
* @param type
* the type of the target.
* @param field * @param field
* the field which is annotaed with {@link CacheField} * the field which is annotaed with {@link CacheField}
* @param cacheKey * @param cacheKey
* the configured cache key in the annotation * the configured cache key in the annotation
* {@link CacheField#key()} * {@link CacheField#key()}
* @param id * @param entityId
* the ID of the entity * the ID of the entity
* @throws IllegalAccessException * @throws IllegalAccessException
* in case the field cannot be accessed * in case the field cannot be accessed
*/ */
void fromCache(final Field field, final String cacheKey, Serializable id) throws IllegalAccessException; void fromCache(Class<?> type, final Field field, final String cacheKey, Serializable entityId)
throws IllegalAccessException;
} }
} }

View File

@@ -50,13 +50,11 @@ import com.vaadin.ui.themes.ValoTheme;
/** /**
* Vaadin management UI. * Vaadin management UI.
* *
*
*
*
*/ */
@SuppressWarnings("serial")
@Title("hawkBit Update Server") @Title("hawkBit Update Server")
public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(HawkbitUI.class); private static final Logger LOG = LoggerFactory.getLogger(HawkbitUI.class);
private static final String EMPTY_VIEW = ""; private static final String EMPTY_VIEW = "";
@@ -139,7 +137,7 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
contentVerticalLayout.addComponent(content); contentVerticalLayout.addComponent(content);
content.setStyleName("view-content"); content.setStyleName("view-content");
content.setSizeFull(); content.setSizeFull();
rootLayout.setExpandRatio(contentVerticalLayout, 1.0f); rootLayout.setExpandRatio(contentVerticalLayout, 1.0F);
contentVerticalLayout.setStyleName("main-content"); contentVerticalLayout.setStyleName("main-content");
contentVerticalLayout.setExpandRatio(content, 1.0F); contentVerticalLayout.setExpandRatio(content, 1.0F);
setContent(rootLayout); setContent(rootLayout);
@@ -154,6 +152,8 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
} }
final Navigator navigator = new Navigator(this, content); final Navigator navigator = new Navigator(this, content);
navigator.addViewChangeListener(new ViewChangeListener() { navigator.addViewChangeListener(new ViewChangeListener() {
private static final long serialVersionUID = 1L;
@Override @Override
public boolean beforeViewChange(final ViewChangeEvent event) { public boolean beforeViewChange(final ViewChangeEvent event) {
return true; return true;
@@ -197,7 +197,7 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
* as set * as set
* @return String as preferred locale * @return String as preferred locale
*/ */
private String getLocaleId(final Set<String> availableLocalesInApp) { private static String getLocaleId(final Set<String> availableLocalesInApp) {
final String[] localeChain = getLocaleChain(); final String[] localeChain = getLocaleChain();
String spLocale = SPUIDefinitions.DEFAULT_LOCALE; String spLocale = SPUIDefinitions.DEFAULT_LOCALE;
if (null != localeChain) { if (null != localeChain) {
@@ -217,23 +217,27 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener {
* *
* @return String as locales * @return String as locales
*/ */
private String[] getLocaleChain() { private static String[] getLocaleChain() {
String[] localeChain = null; String[] localeChain = null;
// Fetch all cookies from the request // Fetch all cookies from the request
final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies(); final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();
if (cookies != null) { if (cookies == null) {
return localeChain;
}
for (final Cookie c : cookies) { for (final Cookie c : cookies) {
if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) { if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) {
localeChain = c.getValue().split("#"); localeChain = c.getValue().split("#");
break; break;
} }
} }
}
return localeChain; return localeChain;
} }
private class ManagementViewProvider implements ViewProvider { private class ManagementViewProvider implements ViewProvider {
private static final long serialVersionUID = 1L;
@Override @Override
public String getViewName(final String viewAndParameters) { public String getViewName(final String viewAndParameters) {
return viewProvider.getViewName(getStartView(viewAndParameters)); return viewProvider.getViewName(getStartView(viewAndParameters));

View File

@@ -158,7 +158,7 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW
detailAndUploadLayout.setComponentAlignment(dadw, Alignment.MIDDLE_CENTER); detailAndUploadLayout.setComponentAlignment(dadw, Alignment.MIDDLE_CENTER);
} }
detailAndUploadLayout.setExpandRatio(artifactDetailsLayout, 1.0f); detailAndUploadLayout.setExpandRatio(artifactDetailsLayout, 1.0F);
detailAndUploadLayout.setSizeFull(); detailAndUploadLayout.setSizeFull();
detailAndUploadLayout.addStyleName("group"); detailAndUploadLayout.addStyleName("group");
detailAndUploadLayout.setSpacing(true); detailAndUploadLayout.setSpacing(true);
@@ -177,9 +177,9 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW
mainLayout.addComponent(detailAndUploadLayout, 2, 0); mainLayout.addComponent(detailAndUploadLayout, 2, 0);
mainLayout.addComponent(deleteActionsLayout, 1, 1); mainLayout.addComponent(deleteActionsLayout, 1, 1);
mainLayout.addComponent(uplaodButtonsLayout, 2, 1); mainLayout.addComponent(uplaodButtonsLayout, 2, 1);
mainLayout.setRowExpandRatio(0, 1.0f); mainLayout.setRowExpandRatio(0, 1.0F);
mainLayout.setColumnExpandRatio(1, 0.5f); mainLayout.setColumnExpandRatio(1, 0.5F);
mainLayout.setColumnExpandRatio(2, 0.5f); mainLayout.setColumnExpandRatio(2, 0.5F);
mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER); mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER);
mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER); mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER);
return mainLayout; return mainLayout;
@@ -201,8 +201,8 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW
private void maximizeSwTable() { private void maximizeSwTable() {
mainLayout.removeComponent(detailAndUploadLayout); mainLayout.removeComponent(detailAndUploadLayout);
removeOtherComponents(); removeOtherComponents();
mainLayout.setColumnExpandRatio(1, 1f); mainLayout.setColumnExpandRatio(1, 1F);
mainLayout.setColumnExpandRatio(2, 0f); mainLayout.setColumnExpandRatio(2, 0F);
} }
private void minimizeArtifactoryDetails() { private void minimizeArtifactoryDetails() {
@@ -219,15 +219,15 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW
mainLayout.removeComponent(smTableLayout); mainLayout.removeComponent(smTableLayout);
detailAndUploadLayout.removeComponent(dadw); detailAndUploadLayout.removeComponent(dadw);
removeOtherComponents(); removeOtherComponents();
mainLayout.setColumnExpandRatio(1, 0f); mainLayout.setColumnExpandRatio(1, 0F);
mainLayout.setColumnExpandRatio(2, 1f); mainLayout.setColumnExpandRatio(2, 1F);
} }
private void addOtherComponents() { private void addOtherComponents() {
mainLayout.addComponent(deleteActionsLayout, 1, 1); mainLayout.addComponent(deleteActionsLayout, 1, 1);
mainLayout.addComponent(uplaodButtonsLayout, 2, 1); mainLayout.addComponent(uplaodButtonsLayout, 2, 1);
mainLayout.setColumnExpandRatio(1, 0.5f); mainLayout.setColumnExpandRatio(1, 0.5F);
mainLayout.setColumnExpandRatio(2, 0.5f); mainLayout.setColumnExpandRatio(2, 0.5F);
mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER); mainLayout.setComponentAlignment(deleteActionsLayout, Alignment.BOTTOM_CENTER);
mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER); mainLayout.setComponentAlignment(uplaodButtonsLayout, Alignment.BOTTOM_CENTER);
} }
@@ -240,6 +240,8 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW
private void hideDropHints() { private void hideDropHints() {
UI.getCurrent().addClickListener(new ClickListener() { UI.getCurrent().addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override @Override
public void click(final com.vaadin.event.MouseEvents.ClickEvent event) { public void click(final com.vaadin.event.MouseEvents.ClickEvent event) {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT); eventBus.publish(this, DragEvent.HIDE_DROP_HINT);

View File

@@ -36,9 +36,9 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> { public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
private static final long serialVersionUID = -333786310371208962L; private static final long serialVersionUID = -333786310371208962L;
private Sort sort = new Sort(Direction.DESC, "filename"); private Sort sort = new Sort(Direction.DESC, "filename");
private transient ArtifactManagement artifactManagement = null; private transient ArtifactManagement artifactManagement;
private transient Page<LocalArtifact> firstPagetArtifacts = null; private transient Page<LocalArtifact> firstPagetArtifacts;
private Long baseSwModuleId = null; private Long baseSwModuleId;
/** /**
* Parametric Constructor. * Parametric Constructor.